/* Portfolio of real projects: the showcase and lab list on /portfolio and the case pages
   (/portfolio/<slug>). Uses the tokens from styles.css; pages are written by scripts/build-work.mjs. */

/* ---------- Portfolio: showcase of six cases ---------- */
.featured-showcase.work-showcase.is-sticky .featured-stage {
  height: calc(var(--featured-count, 6) * var(--featured-step, 78svh) + 22svh);
}
.work-showcase .featured-scene__media { color: inherit; }
.work-showcase .featured-scene__media img { border-radius: 6px; }
.work-showcase .featured-scene { cursor: pointer; }

/* ---------- Portfolio: lab list ---------- */
/* ---------- Portfolio index: every work in one ruled list ---------- */
.work-index { padding: var(--section-space) 0; scroll-margin-top: var(--header-height); }
.work-index__head {
  margin-bottom: clamp(32px, 4vw, 56px);
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: clamp(24px, 4vw, 64px);
  align-items: end;
}
.work-index__head h2 { font-size: clamp(40px, 4.4vw, 66px); line-height: 1.02; letter-spacing: -0.015em; }
.work-index__head p { max-width: 620px; font-size: clamp(17px, 1.3vw, 19px); line-height: 1.6; }

/* Tabs: words on a rule, the active one underlined. */
.work-tabs {
  margin-bottom: clamp(8px, 1.2vw, 16px);
  display: flex;
  gap: clamp(18px, 2.6vw, 40px);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.work-tabs::-webkit-scrollbar { display: none; }
.work-tabs[hidden] { display: none; }
.work-tabs button {
  flex: none;
  min-height: 48px;
  margin-bottom: -1px;
  padding: 0;
  border: 0;
  border-bottom: 1.5px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: clamp(15px, 1.1vw, 17px);
  white-space: nowrap;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease;
}
.work-tabs button sup { margin-left: 0.35em; color: var(--subtle); font-size: 0.72em; font-variant-numeric: tabular-nums; }
.work-tabs button:hover { color: var(--ink); }
.work-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.work-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.work-index__list { margin: 0; padding: 0; list-style: none; }
.work-index__list > li { border-bottom: 1px solid var(--line); }
.work-index__list > li[hidden] { display: none; }
.work-row {
  padding: clamp(18px, 2vw, 26px) 0;
  display: grid;
  grid-template-columns: clamp(150px, 15vw, 232px) minmax(0, 3fr) minmax(0, 5fr) minmax(120px, 2fr) 24px;
  gap: clamp(16px, 2.6vw, 40px);
  align-items: center;
  color: var(--ink);
}
.work-row__thumb {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface, #110f15);
  box-shadow: 0 0 0 1px var(--line);
}
.work-row__thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: 0.86;
  transition: opacity 320ms ease, transform 700ms var(--ease-out);
}
.work-row__head { display: grid; gap: 6px; }
.work-row__name {
  font-size: clamp(22px, 2vw, 30px);
  font-weight: var(--weight-display);
  font-stretch: var(--stretch-heading);
  line-height: 1.08;
}
.work-row__kind { color: var(--subtle); font-size: 14px; line-height: 1.4; }
.work-row__text { color: var(--muted); font-size: 16px; line-height: 1.6; }
.work-row__stack { color: var(--subtle); font-size: 14px; line-height: 1.5; }
.work-row__go { color: var(--subtle); font-size: 20px; text-align: right; transition: color 180ms ease, transform 420ms var(--ease-out); }
a.work-row:hover .work-row__thumb img,
a.work-row:focus-visible .work-row__thumb img { opacity: 1; transform: scale(1.03); }
a.work-row:hover .work-row__go,
a.work-row:focus-visible .work-row__go { color: var(--ink); transform: translateX(4px); }

/* In progress: what happens now and what comes next instead of a summary. */
.work-progress { margin-top: clamp(56px, 7vw, 104px); }
.work-progress__title { font-size: clamp(30px, 3vw, 44px); line-height: 1.05; letter-spacing: -0.01em; }
.work-progress__text { margin: 12px 0 clamp(16px, 2vw, 28px); max-width: 560px; }
.work-progress .work-index__list { border-top: 1px solid var(--line); }
.work-row--progress { grid-template-columns: clamp(150px, 15vw, 232px) minmax(0, 3fr) minmax(0, 4fr) minmax(0, 4fr) 24px; }
.work-step { display: grid; gap: 6px; color: var(--muted); font-size: 16px; line-height: 1.55; }
.work-step__label { color: var(--accent); font-size: 13px; letter-spacing: 0.02em; }

/* With tabs, the in-progress list is one of the panels. */
.work-index.has-tabs .work-progress { margin-top: 0; }
.work-index.has-tabs .work-progress__title { display: none; }
.work-index.has-tabs .work-progress .work-index__list { border-top: 0; }
.work-index [role="tabpanel"][hidden] { display: none; }

@media (max-width: 1023px) {
  .work-index__head { grid-template-columns: 1fr; }
  .work-row,
  .work-row--progress {
    grid-template-columns: clamp(112px, 30vw, 200px) minmax(0, 1fr);
    grid-template-areas: "thumb head" "thumb text";
    row-gap: 8px;
    align-items: start;
  }
  .work-row__thumb { grid-area: thumb; }
  .work-row__head { grid-area: head; }
  .work-row__text { grid-area: text; font-size: 15px; }
  .work-row__stack, .work-row__go { display: none; }
  .work-row--progress { grid-template-areas: "thumb head" "thumb now" "thumb next"; }
  .work-row--progress .work-step:nth-of-type(1) { grid-area: now; }
  .work-row--progress .work-step:nth-of-type(2) { grid-area: next; }
  .work-step { font-size: 15px; }
}
@media (max-width: 559px) {
  .work-row,
  .work-row--progress { grid-template-columns: 1fr; grid-template-areas: "thumb" "head" "text"; }
  .work-row--progress { grid-template-areas: "thumb" "head" "now" "next"; }
  .work-row__thumb { max-width: none; }
  .work-row__text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
}

/* ---------- Case page ---------- */
.case-page { padding-top: var(--header-height); }
.case-hero { padding: clamp(48px, 7vw, 112px) 0 clamp(40px, 5vw, 64px); }
.case-back {
  width: fit-content;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 7px;
  transition: color 180ms ease, text-decoration-color 180ms ease;
}
.case-back:hover { color: var(--ink); text-decoration-color: currentColor; }
.case-hero h1 {
  margin-top: clamp(24px, 4vw, 52px);
  font-size: clamp(60px, 9vw, 148px);
  line-height: 0.94;
  letter-spacing: -0.022em;
}
.case-lead {
  max-width: 860px;
  margin-top: clamp(22px, 2.4vw, 32px);
  font-size: clamp(19px, 1.7vw, 25px);
  line-height: 1.5;
}
.case-meta {
  margin: clamp(40px, 5vw, 64px) 0 0;
  padding-top: 20px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  border-top: 1px solid var(--line);
}
.case-meta dt { color: var(--subtle); font-size: 14px; line-height: 1.4; }
.case-meta dd { margin: 6px 0 0; color: var(--ink); font-size: 16px; line-height: 1.45; }

.case-cover { margin-block: 0 var(--section-space); }
.case-cover img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-media);
  background: var(--surface-raised);
}

.case-story { padding-bottom: var(--section-space); display: grid; gap: clamp(48px, 6vw, 88px); }
.case-story__block,
.case-anatomy__head,
.case-details {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: clamp(20px, 4vw, 64px);
}
.case-story__block { padding-top: 28px; border-top: 1px solid var(--line); }
.case-story__block h2 { font-size: clamp(28px, 2.6vw, 40px); line-height: 1.1; letter-spacing: -0.01em; }
.case-story__block p { max-width: 720px; font-size: clamp(17px, 1.3vw, 20px); line-height: 1.66; }
.case-story__block p + p { margin-top: 18px; }

/* The figure: the anatomy kit's dark tones, tinted to the site's violet greys. */
.case-anatomy {
  padding: var(--section-space) 0;
  border-block: 1px solid var(--line);
  background: var(--surface);
}
.case-anatomy__head { margin-bottom: clamp(36px, 4vw, 56px); align-items: end; }
.case-anatomy__head h2,
.case-gallery h2,
.case-variants h2,
.case-details h2 { font-size: clamp(36px, 4vw, 60px); line-height: 1.04; letter-spacing: -0.015em; }
.case-anatomy__head p { max-width: 660px; font-size: clamp(17px, 1.3vw, 19px); line-height: 1.62; }
/* The figure's palette comes from the theme (themes.css builds --anatomy-* from its tokens). */
/* Capped so the whole card, readout included, fits a laptop screen. */
.case-iso { max-width: min(1180px, calc((100svh - var(--header-height) - 120px) * 1.45)); min-width: min(100%, 560px); margin-inline: auto; }
.case-iso .iso-figure { margin: 0; }
.case-iso .iso-plate { border-radius: var(--radius-media); box-shadow: 0 0 0 1px var(--line-strong); }
.case-iso .iso-stage { outline: none; }
.case-iso .iso-stage:focus-visible { outline: 2px solid var(--focus); outline-offset: 6px; border-radius: 4px; }
.case-iso .iso-legend { margin-top: 18px; color: var(--subtle); font-size: 14px; line-height: 1.6; }
.case-iso .iso-caption { max-width: 860px; }

/* Screens in device frames. Every frame is a button that opens the full image. */
.case-gallery { padding-top: var(--section-space); }
.case-gallery h2 { margin-bottom: clamp(32px, 4vw, 56px); }
.case-gallery__wide { display: grid; gap: clamp(48px, 6vw, 88px); }
.case-shot,
.case-variant { margin: 0; min-width: 0; }
.case-shot figcaption,
.case-variant figcaption { margin-top: 14px; color: var(--muted); font-size: 15px; line-height: 1.45; }
.case-frame {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: zoom-in;
}
.case-frame img { width: 100%; height: auto; display: block; }
.case-frame:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.case-frame--browser {
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-strong);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.case-frame__bar {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--line);
  color: var(--subtle);
  font: 500 12px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.02em;
}
.case-frame--landscape,
.case-frame--phone { background: #040306; box-shadow: 0 0 0 1.5px #2e2a35; }
.case-frame--landscape { padding: clamp(6px, 0.8vw, 12px); border-radius: clamp(26px, 4vw, 58px); }
.case-frame--landscape img { border-radius: clamp(20px, 3.2vw, 46px); }
.case-frame--phone { padding: clamp(6px, 0.7vw, 10px); border-radius: clamp(30px, 3.4vw, 50px); }
.case-frame--phone img { border-radius: clamp(24px, 2.8vw, 41px); }
.case-frame--photo,
.case-frame--plain { overflow: hidden; border-radius: var(--radius-media); box-shadow: 0 0 0 1px var(--line-strong); }
.case-gallery__tall {
  margin-top: clamp(64px, 8vw, 120px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 290px));
  justify-content: center;
  gap: clamp(28px, 3vw, 44px) clamp(20px, 2.4vw, 36px);
  align-items: start;
}
.case-gallery__wide:empty,
.case-gallery__tall:empty { display: none; }
.case-gallery__wide + .case-gallery__tall { margin-top: clamp(64px, 8vw, 120px); }
.case-gallery__tall:first-child { margin-top: 0; }

.case-variants { padding-top: var(--section-space); }
.case-variants h2 { margin-bottom: clamp(32px, 4vw, 56px); }
.case-variants__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(28px, 3vw, 44px) clamp(16px, 2vw, 28px); }

.case-details { padding: var(--section-space) 0; }
.case-details ul { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.case-details li { padding: 18px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: clamp(16px, 1.2vw, 18px); line-height: 1.6; }
.case-code { margin-top: 32px; }
.case-page--lab .case-anatomy { margin-bottom: var(--section-space); }
.case-next__link--text { grid-template-columns: minmax(0, 1fr); }
.case-stack { margin-top: 24px; color: var(--subtle); font-size: 15px; line-height: 1.6; }

.case-next { padding-bottom: var(--section-space); }
.case-next__link {
  padding-top: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr);
  gap: clamp(24px, 4vw, 64px);
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--ink);
}
.case-next__copy small { display: block; color: var(--subtle); font-size: 15px; }
.case-next__copy strong {
  margin-top: 14px;
  display: block;
  font-size: clamp(48px, 6vw, 96px);
  font-weight: var(--weight-display);
  font-stretch: var(--stretch-display);
  line-height: 0.98;
  letter-spacing: -0.02em;
}
.case-next__copy span { margin-top: 14px; display: block; color: var(--muted); font-size: 16px; }
.case-next__media { overflow: hidden; border-radius: var(--radius-media); background: var(--surface-raised); }
.case-next__media img { width: 100%; height: auto; display: block; transition: transform 700ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .case-next__link:hover .case-next__media img { transform: scale(1.03); }
}

/* Full-size image viewer */
.case-zoom {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(12px, 3vw, 44px);
  border: 0;
  /* The viewer for full-size screenshots stays dark in every theme, like the device frames. */
  background: rgba(5, 4, 7, 0.95);
  color: #eeeaf1;
  place-items: center;
  overscroll-behavior: contain;
}
.case-zoom[open] { display: grid; }
.case-zoom::backdrop { background: transparent; }
.case-zoom img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 88px);
  border-radius: 8px;
  cursor: zoom-out;
}
.case-zoom__close {
  width: 44px;
  height: 44px;
  position: fixed;
  z-index: 2;
  top: clamp(12px, 3vw, 44px);
  right: clamp(12px, 3vw, 44px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

/* Entrance: work.js adds html.work-motion before observing, so nothing stays hidden without it. */
@media (prefers-reduced-motion: no-preference) {
  .work-motion .case-reveal {
    opacity: 0;
    transform: translate3d(0, 32px, 0);
    transition: opacity 700ms ease var(--d, 0ms), transform 1000ms var(--ease-out) var(--d, 0ms);
  }
  .work-motion .case-reveal.is-in { opacity: 1; transform: none; }
  .case-cover img { animation: case-cover-in 1100ms var(--ease-out) 160ms both; }
  @keyframes case-cover-in {
    from { opacity: 0; transform: translate3d(0, 40px, 0) scale(0.985); }
    to { opacity: 1; transform: none; }
  }
}

@media (max-width: 1023px) {
  .featured-showcase.work-showcase.is-sticky .featured-stage {
    height: calc(var(--featured-count, 6) * var(--featured-step, 70svh) + 20svh);
  }
  .case-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 20px; }
}

@media (max-width: 900px) {
  .work-lab__head,
  .case-story__block,
  .case-anatomy__head,
  .case-details,
  .case-next__link { grid-template-columns: minmax(0, 1fr); }
  .work-lab__row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 10px; }
  .work-lab__text { grid-column: 1 / -1; grid-row: 2; }
  .work-lab__stack { grid-column: 1; grid-row: 3; }
  .work-lab__go { grid-column: 2; grid-row: 1; }
  .case-variants__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-next__media { order: -1; }
}

/* Phones: tall screens become a swipeable strip. */
@media (max-width: 767px) {
  .case-gallery__tall {
    margin-inline: calc(var(--gutter) * -1);
    padding: 0 var(--gutter) 8px;
    display: flex;
    gap: 16px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--gutter);
    scrollbar-width: none;
  }
  .case-gallery__tall::-webkit-scrollbar { display: none; }
  .case-gallery__tall > .case-shot { flex: 0 0 min(68vw, 290px); scroll-snap-align: start; }
  .case-gallery__tall[data-count="1"] { justify-content: center; }
  .case-frame__bar { height: 26px; font-size: 10px; }
  .case-hero h1 { font-size: clamp(48px, 14vw, 72px); }
}
