/* ============================================================================
   Scene: products, "the product theatre"
   Owned by js/scenes/products.js. Markup: <section class="theatre" id="work">.

   Three layouts from one piece of markup:
   1. Base (no JS, ?noanim, reduced motion, phones): a designed vertical list.
      Frame first, then the copy. Complete and final on its own.
   2. >= 900px, still no theatre: the same list as editorial rows, copy left,
      framed screenshot right, flat.
   3. .is-theatre (added by JS only on desktop, fine pointer, >= 640px tall):
      the stage pins at 100svh and the six acts stack on top of each other;
      the script plays them one beat at a time in 3D.

   Rules this file keeps (README "Traps"):
   - No overflow hidden/clip on the section, the stage or any ancestor of the
     pin. The tints are radial gradients drawn inside their own box, so they
     need no clipping at all.
   - Theatre sizing comes from the viewport (svh + flex), never fixed heights.
   - Brand colours arrive as --brand on each act and are only ever mixed down
     into low-alpha glows; text and lines use tokens.
   ========================================================================== */

.theatre {
  position: relative;
  padding-top: var(--sec-pad);
  /* The site container's content edge, as a padding: the same left edge as
     every other section (176px at 1440), mirrored on the right. */
  --edge: max(var(--gutter), calc((100vw - var(--container)) / 2 + var(--gutter)));
}

/* ------------------------------------------------------------------ intro */
.theatre-intro {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 22px;
  margin-bottom: clamp(48px, 7vw, 96px);
}
.theatre-title { max-width: 15ch; }
.theatre-lede { max-width: 50ch; }

/* ---------------------------------------------------------------- the list */
.theatre-stage { position: relative; }

.theatre-acts {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
  z-index: 1;
}

.act {
  --brand: var(--accent);
  position: relative;
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-bottom: clamp(72px, 14vw, 112px);
  display: grid;
  gap: 30px;
}
.act-visual { order: -1; position: relative; }

/* The soft brand glow behind each frame in the list layouts. In the theatre
   one shared, crossfading tint layer replaces it (see .theatre-tint). */
.act-visual::before {
  content: "";
  position: absolute;
  inset: -18% -12% -22%;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(50% 50% at 50% 55%,
    color-mix(in srgb, var(--brand) 26%, transparent), transparent 72%);
}

/* ------------------------------------------------------------------ frame */
.act-rig { position: relative; z-index: 1; }

.frame {
  position: relative;
  margin: 0;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: var(--hl), var(--shadow-lift);
  overflow: hidden; /* rounds the screenshot; nothing sticky lives inside */
  backface-visibility: hidden;
}

.frame-bar {
  position: relative;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding-inline: 14px;
  background: var(--raised);
  border-bottom: 1px solid var(--line);
}
.frame-bar i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-2);
  box-shadow: inset 0 0 0 1px var(--line-2);
}
.frame-bar span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 120px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--sunken);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1240 / 698;
  object-fit: cover; /* same ratio as the file, so nothing is cropped */
  background: var(--sunken);
}

/* A specular glint that crosses the glass once as a frame settles. It rests
   off-frame, so the static page never shows it. Pure transform. */
.frame-sheen {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(105deg,
    transparent 38%, rgba(255, 255, 255, 0.10) 48%,
    rgba(255, 255, 255, 0.03) 54%, transparent 62%);
  transform: translateX(-110%);
}

/* ------------------------------------------------------------------- copy */
.act-copy { position: relative; z-index: 2; display: grid; justify-items: start; }

.act-index {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 18px;
}
.act-index b { font-weight: 500; color: var(--ink); }
/* In the list layouts a hairline runs from the index, a quiet chapter rule. */
.act-index::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.act-name {
  /* Never larger than the section heading (display-2): heading > name. */
  font-size: clamp(2rem, 8vw, 3.25rem);
  font-weight: 510;
  line-height: 1.0;
  letter-spacing: -0.032em;
  text-wrap: balance;
}

.act-tag {
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.act-desc {
  margin-top: 20px;
  max-width: 46ch;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--ink-2);
  text-wrap: pretty;
}

.act-meta {
  margin-top: 26px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
}

.act-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px 6px 11px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  box-shadow: var(--hl);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
.act-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  border: 1px solid var(--muted);
}
/* In pilot: half lit. Internal build: an empty ring. */
.act-status.is-pilot .dot { background: linear-gradient(90deg, var(--muted) 50%, transparent 50%); }

.act-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-block: 6px;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  /* a hairline underline that warms to the accent on hover */
  background: linear-gradient(var(--line-3), var(--line-3)) 0 100% / 100% 1px no-repeat;
  transition: color var(--t-fast) var(--ease);
}
.act-link svg {
  width: 15px;
  height: 15px;
  flex: none;
  transition: transform 0.36s var(--ease);
}
.act-link:hover { color: var(--accent); background-image: linear-gradient(var(--accent-line), var(--accent-line)); }
.act-link:hover svg { transform: translate(2px, -2px); }
.act-link[href^="#"]:hover svg { transform: translateX(4px); }
.act-link:focus-visible { outline-offset: 5px; }

/* ---------------------------------------------------- editorial rows >= 900 */
@media (min-width: 900px) {
  .act {
    grid-template-columns: minmax(0, 38fr) minmax(0, 62fr);
    align-items: center;
    gap: clamp(48px, 5.6vw, 96px);
    padding-bottom: clamp(96px, 12vw, 160px);
  }
  .act-visual { order: 0; }
  .act-name { font-size: clamp(2.25rem, 3.6vw, 3.25rem); } /* tops out at 52px */
  .act-desc { font-size: clamp(1rem, 1.12vw, 1.125rem); max-width: 42ch; }
}

/* ============================================================== THEATRE == */
/* Everything below only applies once the script has decided this screen gets
   the pinned theatre. Without .is-theatre none of it exists. */

/* The intro becomes the opening beat: the script moves it inside the stage,
   where it sits over the copy column until it lifts away. */
.theatre.is-theatre .theatre-intro {
  position: absolute;
  inset: 0;
  z-index: 3;
  max-width: none;
  margin: 0;
  padding-inline: var(--edge);
  padding-top: calc(68px + 3svh);
  padding-bottom: calc(64px + 5svh);
  align-content: center;
  pointer-events: none;
}
/* Tops out at 64px: above the 52px product names, and clear of the frame. */
.is-theatre .theatre-title { font-size: clamp(2.6rem, min(4.3vw, 8svh), 4rem); max-width: 13ch; }
/* The heading glides in on a parallax, so the usual section top padding
   would only add an empty band between the story and the stage. */
.theatre.is-theatre { padding-top: clamp(24px, 4svh, 48px); }
.is-theatre .theatre-lede { max-width: 40ch; }

.theatre.is-theatre .theatre-stage {
  height: 100vh;
  height: 100svh;
}

.is-theatre .theatre-acts { position: absolute; inset: 0; }

.is-theatre .act {
  position: absolute;
  inset: 0;
  max-width: none;
  margin: 0;
  padding-inline: var(--edge);
  /* top clears the fixed nav, bottom clears the progress rail */
  padding-top: calc(68px + 3svh);
  padding-bottom: calc(64px + 5svh);
  grid-template-columns: minmax(0, 34fr) minmax(0, 66fr);
  /* The row is centred, but copy and frame both start at its top, so every
     product's name sits in the same slot and the names roll through it. */
  align-content: center;
  align-items: start;
  gap: clamp(36px, 3.6vw, 64px);
  pointer-events: none;
}
.is-theatre .act.is-active { pointer-events: auto; }
/* Under the active act, so a fading-out act never paints over the next one's
   link while both are partly visible. */
.is-theatre .act.is-active { z-index: 2; }

.is-theatre .act-visual {
  perspective: 1600px;
  perspective-origin: 30% 50%;
  display: flex;
  justify-content: flex-end;
}
.is-theatre .act-visual::before { display: none; }

.is-theatre .act-rig {
  width: 100%;
  /* Height-limit the frame so 16:9 plus its title bar always fits between the
     nav and the progress rail, whatever the aspect of the viewport. */
  max-width: calc((100svh - 68px - 3svh - 64px - 5svh - 34px - 24px) * 1.7765);
  transform-style: preserve-3d;
}
.is-theatre .frame {
  transform: rotateY(-13deg) rotateX(4deg);
  /* Pivot on the right edge: it stays at depth 0, so perspective never pushes
     it past the container's right edge. */
  transform-origin: 100% 50%;
  will-change: transform, opacity;
}

.is-theatre .act-index::after { display: none; }
.is-theatre .act-index { margin-bottom: clamp(16px, 2.6svh, 28px); width: auto; }
.is-theatre .act-name {
  font-size: clamp(2.25rem, min(3.6vw, 6.4svh), 3.25rem); /* tops out at 52px */
}
.is-theatre .act-tag { margin-top: clamp(12px, 2svh, 20px); }
.is-theatre .act-desc {
  margin-top: clamp(16px, 2.6svh, 26px);
  font-size: clamp(1rem, min(1.1vw, 2svh), 1.1rem);
  max-width: 40ch;
}
.is-theatre .act-meta { margin-top: clamp(20px, 3.2svh, 32px); }

/* ------------------------------------------------- brand tint (theatre) */
.theatre-tints {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.theatre-tint {
  position: absolute;
  inset: 0;
  opacity: 0;
  will-change: opacity;
  /* Large enough to bloom well past the frame's edges; the frame hides the
     centre, so the colour that reads is the halo around it. */
  background:
    radial-gradient(46% 62% at 64% 52%,
      color-mix(in srgb, var(--brand) 34%, transparent),
      color-mix(in srgb, var(--brand) 10%, transparent) 46%, transparent 74%),
    radial-gradient(30% 42% at 14% 30%,
      color-mix(in srgb, var(--brand) 11%, transparent), transparent 72%);
}

/* ------------------------------------------------------ progress (theatre) */
.theatre-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(18px, 3.6svh, 40px);
  z-index: 3;
  width: 100%;
  padding-inline: var(--edge);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}
.theatre-progress button {
  display: grid;
  gap: 11px;
  padding: 10px 0 0;
  text-align: start;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--t) var(--ease);
}
.theatre-progress button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theatre-progress button span b { font-weight: 500; color: inherit; margin-inline-end: 8px; }
.theatre-progress button:hover,
.theatre-progress button.is-current { color: var(--ink); }
.theatre-progress .track {
  position: relative;
  height: 2px;
  border-radius: 2px;
  background: var(--line-2);
  /* no overflow clip: inside the pin it registers as layout shift (trap 5) */
}
.theatre-progress .fill {
  position: absolute;
  inset: 0;
  background: var(--ink-2);
  transform-origin: 0 50%;
  transform: scaleX(0);
}
.theatre-progress .is-current .fill { background: var(--accent); }
