/* ============================================================
   Home page — the stage (live 3D, one project at a time on its own
   colored backdrop) and the "More work" tile grid.
   Loaded after style.css on index.html only.
   Phone-first: base rules are for ~360–430px, wider layouts are added
   with min-width queries. Each project supplies its own --tint; the
   stage sets --ink (text color) to match.
   ============================================================ */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:root { --home-ease: cubic-bezier(0.22, 0.61, 0.36, 1); }

/* ------------------------------------------------------------
   Stage
   ------------------------------------------------------------ */

.hero-stage {
  --tint: #e9e9ec;
  --ink: #15151b;
  margin: 10px;
  border-radius: 24px;
  background: var(--tint);
  color: var(--ink);
  text-align: left;
  overflow: hidden;
  transition: background-color 0.8s var(--home-ease), color 0.8s var(--home-ease);
}

/* The footer is laid out before home-carousel.js builds the stage and would
   then visibly jump down (a layout shift); it stays invisible until the
   stage is there. */
main:has(> .hero-stage[hidden]) + .footer { visibility: hidden; }

.stage-inner {
  display: grid;
  gap: 16px;
  padding: 24px 20px 20px;
}

/* The page's heading for screen readers and search engines; the visible
   headline of the stage is the project's own name. */
.stage-intro {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The model area: the still image holds the spot until the live model has
   loaded, then fades out as the model fades in. */
.stage-view {
  position: relative;
  container-type: size;
  height: min(78vw, 52svh);
  min-height: 240px;
}

/* The still and the live model share one 4:3 frame, centred in the view:
   the stills are rendered with the live model's exact camera in a 4:3 box
   (tools/_thumbgen.html), so the swap to live doesn't shift or resize the
   model. --frame-scale enlarges both together. */
.stage-still,
.stage-live {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(min(100cqw, 133.333cqh) * var(--frame-scale, 1.45));
  max-width: none;
  height: auto;
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
}

.stage-still {
  opacity: 0;
  /* Hiding waits for the live model's fade-in, so the two never both dim. */
  transition: opacity 0.2s ease 0.5s;
}

.hero-stage.show-still .stage-still.is-active { opacity: 1; transition-delay: 0s; }

/* The still stays perfectly still. While the model loads, a small blue
   spinner sits in the middle and a thin bar fills along the bottom. */
.stage-loader {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  opacity: 0; transition: opacity 0.25s ease;
}
.hero-stage.is-loading .stage-loader { opacity: 1; transition-delay: 0.15s; }
.stage-spinner {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.55); border-top-color: #2f6df6;
  box-shadow: 0 0 0 1px rgba(47, 109, 246, 0.25);
  animation: stage-spin 0.8s linear infinite;
}
.stage-loadbar {
  position: absolute; left: 14%; right: 14%; bottom: 7%; height: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.5); overflow: hidden;
}
.stage-loadbar i {
  display: block; width: 100%; height: 100%; background: #2f6df6; border-radius: 2px;
  transform: scaleX(0); transform-origin: left center; transition: transform 0.25s ease-out;
}
/* "Couldn't load the 3D model" note (home-carousel.js shows it over the still). */
.stage-note {
  position: absolute; left: 50%; bottom: 5%; z-index: 2; transform: translateX(-50%);
  margin: 0; padding: 8px 14px; width: max-content; max-width: calc(100% - 32px);
  border-radius: 999px; background: rgba(255, 255, 255, 0.92); color: #1d1d1f;
  font-size: 13px; line-height: 1.35; text-align: center;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.12);
}
.stage-note[hidden] { display: none; }
/* Touch screens (home-carousel.js adds .touch-gate): the model ignores
   fingers, so the page scrolls, until it is tapped (.touch-on). */
.hero-stage.touch-gate .live-model.is-active { pointer-events: none; }
.hero-stage.touch-gate.touch-on .live-model.is-active { pointer-events: auto; }
.stage-touch-hint {
  position: absolute; left: 50%; bottom: 9%; z-index: 2; transform: translateX(-50%);
  margin: 0; padding: 7px 13px; width: max-content; max-width: calc(100% - 32px);
  border-radius: 999px; background: rgba(29, 29, 31, 0.72); color: #fff;
  font-size: 12.5px; font-weight: 500; line-height: 1.3; text-align: center;
  pointer-events: none;
}
.hero-stage.touch-on .stage-touch-hint { background: rgba(0, 113, 227, 0.92); }
/* Not while the model is still loading. */
.hero-stage.touch-gate:not(.touch-ready) .stage-touch-hint { display: none; }
/* A blue border around the model's area while it is taking touches. */
.hero-stage.touch-on .stage-view { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 18px; }
.stage-note:not([hidden]) ~ .stage-touch-hint { display: none; }
@keyframes stage-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .stage-spinner { animation-duration: 2.4s; } }

/* Still -> live swap (home-carousel.js adds .swap-now for a moment): no cross-fade. */
.hero-stage.swap-now .live-model,
.hero-stage.swap-now .stage-still { transition: none !important; }

.stage-live { pointer-events: none; }

.live-model {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  --poster-color: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  outline: none;
}

/* All six stage models sit stacked; only the active one shows. */
.live-model.is-active { opacity: 1; }
.hero-stage .live-model.is-active { pointer-events: auto; }

/* The waiting (next) stage model is moved out of the clipped stage once it
   has faded out, so model-viewer counts it as off screen. While two models
   count as on screen, model-viewer draws every frame of the rotating one
   off screen and then copies the whole canvas over (its "multiple scenes"
   path), which was most of the home page's main-thread time. The model still
   loads and gets its first, hidden draw there, so switching stays instant. */
.hero-stage .live-model {
  transform: translateX(-300%);
  transition: opacity 0.5s ease, transform 0s linear 0.5s;
}
.hero-stage .live-model.is-active {
  transform: none;
  transition: opacity 0.5s ease;
}

/* Text */
.stage-text { max-width: 560px; position: relative; z-index: 2; }

.stage-cat {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0.75;
}

.stage-title {
  margin: 0 0 14px;
  font-size: clamp(38px, 10.5vw, 84px);
  line-height: 0.98;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: inherit;
  text-wrap: balance;
  overflow-wrap: normal;
}

.stage-blurb {
  margin: 0 0 22px;
  max-width: 44ch;
  font-size: 17px;
  line-height: 1.45;
  opacity: 0.85;
}

/* The pill button flips colors with the backdrop. */
.stage-cta {
  background: var(--ink);
  color: var(--tint);
  transition: background-color 0.8s var(--home-ease), color 0.8s var(--home-ease), transform 0.2s ease;
}
.stage-cta:hover { background: var(--ink); transform: translateY(-1px); }
.stage-cta svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.stage-text.is-swapping .stage-cat,
.stage-text.is-swapping .stage-title,
.stage-text.is-swapping .stage-blurb,
.stage-text.is-swapping .stage-cta {
  animation: stage-rise 0.7s var(--home-ease) both;
}
.stage-text.is-swapping .stage-title { animation-delay: 0.05s; }
.stage-text.is-swapping .stage-blurb { animation-delay: 0.1s; }
.stage-text.is-swapping .stage-cta { animation-delay: 0.15s; }

@keyframes stage-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

/* Project list + controls */
.stage-all {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: auto;
  font-size: 15px;
  font-weight: 600;
  align-self: center;
}
.stage-all svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.stage-all:hover { text-decoration: underline; text-underline-offset: 4px; }

.stage-side { display: grid; gap: 14px; position: relative; z-index: 2; }

.stage-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -20px;
  padding: 2px 20px;
}
.stage-list::-webkit-scrollbar { display: none; }

.stage-pick {
  position: relative;
  flex: none;
  display: grid;
  grid-template-columns: 56px;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
/* Projects that aren't showing are dimmed. Only the thumbnail and bar fade
   far; the name stays at 85% so it keeps 4.5:1 contrast on every tint. */
.pick-thumb, .pick-bar, .pick-name { transition: opacity 0.25s ease; }
.stage-pick .pick-thumb,
.stage-pick .pick-bar { opacity: 0.6; }
.stage-pick .pick-name { opacity: 0.85; }
.stage-pick:hover > *,
.stage-pick[aria-current] > * { opacity: 1; }

.pick-thumb {
  display: block;
  border-radius: 12px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.25s ease;
}
.stage-pick[aria-current] .pick-thumb { outline-color: var(--ink); }
.pick-thumb img { width: 100%; height: 100%; object-fit: contain; }

/* Phones show thumbnails only; the name stays available to screen readers
   (it is the button's accessible name). */
.pick-name {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.pick-bar {
  display: block;
  height: 2px;
  background: color-mix(in srgb, var(--ink) 22%, transparent);
  border-radius: 2px;
  overflow: hidden;
}
.pick-bar i {
  display: block;
  height: 100%;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
}

.stage-tools { display: flex; gap: 8px; }

.stage-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--ink) 35%, transparent);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.stage-btn:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); border-color: var(--ink); }
.stage-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage-btn svg.icon-fill { fill: currentColor; stroke: none; }

/* Phones and tablets (the stacked layout): a small Prev / Next row at the
   top of the stage. It replaces the round prev/next buttons at the bottom
   there; desktop keeps only those. */
.stage-topnav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: -8px -8px -4px;
  position: relative;
  z-index: 2;
}
.stage-topbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px 0 10px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 35%, transparent);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.stage-topbtn.stage-next { padding: 0 10px 0 14px; }
.stage-topbtn:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); border-color: var(--ink); }
.stage-topbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 959.98px) {
  .stage-btn.stage-prev,
  .stage-btn.stage-next { display: none; }
}

.hero-stage a:focus-visible,
.hero-stage button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (min-width: 960px) {
  .stage-topnav { display: none; }

  .hero-stage {
    margin: 12px;
    border-radius: 32px;
    height: clamp(600px, calc(100svh - var(--nav-height) - 24px), 960px);
  }

  .stage-inner {
    height: 100%;
    grid-template-columns: minmax(300px, 4.3fr) minmax(0, 6.7fr) 220px;
    grid-template-rows: auto 1fr;
    gap: 0 clamp(16px, 2vw, 32px);
    padding: clamp(28px, 3.4vw, 52px);
  }

  .stage-title { font-size: clamp(44px, 4.5vw, 76px); }

  .stage-view {
    grid-column: 2;
    grid-row: 1 / 3;
    height: auto;
    min-height: 0;
  }

  .stage-text {
    grid-column: 1;
    grid-row: 1 / 3;
    align-self: start;
    position: relative;
    z-index: 1;
  }

  .stage-side {
    grid-column: 3;
    grid-row: 1 / 3;
    grid-template-rows: 1fr auto;
    align-content: stretch;
    gap: 20px;
  }

  .stage-list {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  .stage-pick {
    grid-template-columns: 56px 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 14px;
    row-gap: 4px;
    padding: 6px;
    border-radius: 16px;
  }
  .stage-pick:hover { background: color-mix(in srgb, var(--ink) 9%, transparent); }
  .pick-thumb { grid-row: 1 / 3; }
  .pick-name {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    display: block;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    align-self: end;
  }
  .pick-bar { align-self: start; }


}

/* ------------------------------------------------------------
   Projects page: tile grid
   ------------------------------------------------------------ */

.projects-page { padding: 40px 0 88px; }

.projects-head {
  display: grid;
  gap: 20px;
  margin-bottom: 32px;
}

.projects-head h1 {
  margin: 0;
  font-size: clamp(44px, 7vw, 88px);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.filter-chip {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 980px;
  border: 1.5px solid var(--divider);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filter-chip:hover { border-color: var(--text); }
.filter-chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.filter-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.more-wrap {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

.tile-grid {
  --tile-h: min(76vw, 420px);
  display: grid;
  gap: 40px 20px;
  grid-template-columns: 1fr;
}

/* Until projects-grid.js fills it, hold a screen's height so the footer
   starts below the fold instead of jumping down once the tiles arrive (the
   filled grid is always taller than this). */
.tile-grid:empty { min-height: 100vh; }

.tile { display: block; color: inherit; }
.tile[hidden] { display: none; }

.tile-panel {
  position: relative;
  height: var(--tile-h);
  border-radius: 24px;
  background: var(--tint);
  overflow: hidden;
  container-type: size;
  isolation: isolate;
}

.tile-still,
.tile-live {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100cqw, 133.333cqh);
  max-width: none;
  height: auto;
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
}
/* thumbZoom (projects-data.js): zoom a still whose model sits small in its frame. */
.tile-still { transform: translate(-50%, -50%) scale(var(--zoom, 1)); }

.tile-live { pointer-events: none; }
/* Phones: the next tile's model is built out of sight and kept off-screen (clipped
   by the tile) until it becomes the live one, so it appears instantly. */
.tile-live .live-model:not(.is-active) { transform: translateX(-300%); }
/* The live model starts exactly on the still, so the swap is instant. */
.tile-live .live-model { transition: none; }
.tile.is-live .tile-still { opacity: 0; }
/* Hover (mouse): the live model is built in place but see-through until its first frame
   is drawn, then it and the removal of the still happen in the same frame. Before, it
   showed on top of the still for a couple of frames, a visible double image or flash. */
.tile.is-priming:not(.is-live) .tile-live .live-model { transform: none; opacity: 0; }

/* project.status (projects-data.js), e.g. "In Progress": a badge over the tile's picture. */
.tile-status {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(29, 29, 31, 0.82);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  pointer-events: none;
}

.tile-body { padding: 16px 4px 0; }

.tile-body h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.02em;
  transition: color 0.2s ease;
}
.tile:hover .tile-body h2 { color: var(--accent); }

.tile-cat {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.tile-desc {
  margin: 0;
  max-width: 52ch;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.tile:focus-visible { outline: none; }
.tile:focus-visible .tile-panel { outline: 3px solid var(--accent); outline-offset: 3px; }

@media (min-width: 640px) {
  .tile-grid { grid-template-columns: repeat(2, 1fr); --tile-h: 340px; }
}

@media (min-width: 960px) {
  .more-wrap { padding: 0 32px; }
  .projects-page { padding: 64px 0 120px; }
  .projects-head { grid-template-columns: auto 1fr; align-items: end; gap: 40px; }
  .filter-chips { justify-content: flex-end; }
  /* Repeating asymmetric rhythm: wide + narrow, narrow + wide, half + half. */
  .tile-grid { grid-template-columns: repeat(6, 1fr); --tile-h: clamp(300px, 30vw, 440px); }
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 1) { grid-column: span 4; }
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 2) { grid-column: span 2; }
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 3) { grid-column: span 2; }
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 4) { grid-column: span 4; }
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 5),
  .tile-grid:not(.is-filtered) .tile:nth-child(6n + 6) { grid-column: span 3; }
  .tile-grid.is-filtered { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .hero-stage, .stage-cta, .tile-still { transition: none; }
}

/* ------------------------------------------------------------
   Any window size: the model and the project's name always show.
   Smaller windows drop the extras in this order: description,
   thumbnail names, button. Nothing is cropped.
   ------------------------------------------------------------ */

/* Narrow windows laid out as one column, but short: name first, then the
   model, so both are on screen without scrolling (also phones on their side). */
@media (max-width: 959.98px) and (max-height: 760px) {
  .stage-inner { gap: 6px; padding-top: 16px; }
  .stage-text { display: contents; }
  .stage-cat { order: 1; margin: 6px 0 0; }
  .stage-title { order: 2; margin: 0; font-size: clamp(30px, 8vw, 52px); }
  .stage-view { order: 3; height: max(170px, calc(100svh - var(--nav-height, 64px) - 210px)); min-height: 0; }
  .stage-blurb { order: 4; margin: 8px 0 12px; }
  .stage-actions { order: 5; }
  .stage-side { order: 6; }
  .stage-topnav { order: 0; }
}

@media (min-width: 960px) {
  .hero-stage { height: clamp(420px, calc(100svh - var(--nav-height) - 24px), 960px); }
}

/* Short desktop windows. */
@media (min-width: 960px) and (max-height: 760px) {
  .stage-inner { padding: clamp(20px, 3vw, 36px); }
  .stage-blurb { margin-bottom: 16px; font-size: 16px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
  .stage-actions { margin-top: 0; }
  .stage-title { font-size: clamp(36px, 4.2vw, 64px); }
  .stage-list { gap: 2px; }
  .stage-pick { padding: 4px; grid-template-columns: 44px 1fr; }
  .stage-side { gap: 10px; }
}
@media (min-width: 960px) and (max-height: 560px) {
  .stage-cat { display: none; }
  .stage-blurb { -webkit-line-clamp: 2; font-size: 15px; margin-bottom: 12px; }
  .stage-pick { grid-template-columns: 34px 1fr; padding: 3px; }
  .pick-name { font-size: 12px; }
  .pick-bar { display: none; }
}

@media (min-width: 960px) and (max-height: 470px) { .stage-blurb { display: none; } }

/* Narrow desktop windows: slimmer side column so the model keeps its room. */
@media (min-width: 960px) and (max-width: 1179.98px) {
  .stage-inner { grid-template-columns: minmax(240px, 4fr) minmax(0, 7fr) 168px; }
  .stage-all { font-size: 13px; }
  .stage-tools { gap: 6px; flex-wrap: wrap; }
  .stage-btn { width: 34px; height: 34px; }
}

/* "View project" and "Demo tour" side by side. */
.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stage-tour {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px;
  font: inherit; font-size: 15px; font-weight: 500; color: inherit;
  background: transparent; border: 1.5px solid color-mix(in srgb, var(--ink) 45%, transparent);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.8s var(--home-ease);
}
.stage-tour:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); border-color: var(--ink); }
.stage-tour-icon { font-size: 11px; line-height: 1; }
