/* Page-specific layer for Change Only X. House style lives in house-style.css. */

/* Controls scrolled into view (Tab, find, anchors) stop below the fixed top bar at every size */
html { scroll-padding-top: calc(var(--bar-h) + 16px); }

/* IBM Plex Mono for the top bar and labels, self-hosted (OFL notice in fonts/) */
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/IBMPlexMono-normal-400.woff2) format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/IBMPlexMono-normal-500.woff2) format('woff2'); }

.stage { background: #000; }
.stage video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block; background: #000;
}
.stage .layer-b { clip-path: inset(0 0 0 0); }
.stage[data-mode='wipe'] .layer-b { clip-path: inset(0 0 0 var(--wipe, 50%)); }
.stage[data-mode='single'] .layer-a { visibility: hidden; }
.stage[data-mode='single'].peek .layer-a { visibility: visible; z-index: 2; }

/* Wipe handle */
.wipe-handle {
  position: absolute; top: 0; bottom: 0; left: var(--wipe, 50%); z-index: 3;
  width: 44px; margin-left: -22px; display: none;
  cursor: ew-resize; touch-action: none;
}
.wipe-handle::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px;
  background: var(--ink); box-shadow: 0 0 0 1px #0005;
}
.wipe-handle span {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--glass-line); border-radius: 50%;
  background: var(--glass); color: var(--accent); backdrop-filter: blur(10px);
}
.wipe-handle:focus-visible { outline: none; }
.wipe-handle:focus-visible span { outline: 2px solid var(--accent); outline-offset: 5px; }
.stage[data-mode='wipe'] .wipe-handle { display: block; }

/* Side by side: two 16:9 frames next to each other */
.stage[data-mode='sbs'] { aspect-ratio: 32 / 9; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--rule); }
.stage[data-mode='sbs'] video { position: relative; inset: auto; height: 100%; }
.stage[data-mode='sbs'] .layer-a { order: 0; }
.stage[data-mode='sbs'] .layer-b { order: 1; clip-path: none; }

/* A / B badges on the media */
.ab-badge {
  position: absolute; bottom: 14px; z-index: 4; display: none;
  padding: 6px 9px; border: 1px solid var(--glass-line); border-radius: 4px;
  background: var(--glass); backdrop-filter: blur(10px); font-size: 10px; color: var(--ink);
}
.ab-badge b { color: var(--accent); font-weight: 600; margin-right: 6px; }
.ab-badge.a { left: 14px; }
.ab-badge.b { right: 14px; }
.stage:not([data-mode='single']) .ab-badge { display: block; }
.stage[data-mode='sbs'] .ab-badge.a { left: 14px; }
.stage.peek .ab-badge.a { display: block; }

.stage-top { z-index: 5; }
.stage-play { z-index: 6; }
.stage.playing .stage-play { display: none; }

/* Control bar under the stage */
.controls {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 10px 0 12px; border-bottom: 1px solid var(--rule);
}
.controls .tool { width: 36px; height: 36px; padding: 8px; background: var(--panel); border-color: var(--rule); }
.controls .time { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
input[type='range'].scrub { width: 100%; accent-color: var(--accent); height: 20px; background: transparent; }


/* Step detail under the stage */
.step-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 28px; padding: 22px 0 8px; }
.step-detail .kicker { margin: 0 0 8px; font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--accent); }
.step-detail h2 { margin: 0 0 10px; font: 400 clamp(30px, 3vw, 44px) / 1 'Instrument Serif', serif; letter-spacing: -0.02em; }
.step-detail p { margin: 0; font-size: 12px; line-height: 1.65; color: var(--muted); max-width: 68ch; }
.step-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; font-size: 11px; align-content: start; }
.step-detail dt { color: var(--muted); }
.step-detail dd { margin: 0; }
.note {
  margin-top: 12px !important; padding: 10px 12px; border-left: 2px solid var(--accent);
  background: var(--panel); color: var(--ink) !important; font-size: 11px !important;
}
.refs { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.refs figure { margin: 0; width: 132px; }
.refs img { width: 100%; aspect-ratio: 16/10; object-fit: cover; border: 1px solid var(--rule); display: block; }
.refs figcaption { margin-top: 5px; font-size: 10px; color: var(--muted); }

/* Rail thumbnails instead of colour swatches */
.rail-item .thumb { margin-left: auto; width: 46px; height: 26px; flex: 0 0 46px; border: 1px solid #fff2; background: center / cover no-repeat; }
.rail-item.selected .thumb { border-color: var(--accent); }
.rail-item .tag { display: inline-block; margin-left: 6px; font-size: 9px; color: var(--accent); letter-spacing: 0.05em; text-transform: uppercase; }
.rail-item .warn { color: var(--accent); }
.card .count { display: block; margin-bottom: 8px; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: 11px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* Drawer extras */
.table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 10px 0 4px; }
.table th, .table td { text-align: left; padding: 9px 10px 9px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th { font-size: 10px; font-weight: 400; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }
.table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.drawer-body figure { margin: 14px 0; }
.drawer-body figure img { width: 100%; border: 1px solid var(--rule); display: block; }
.drawer-body figcaption { margin-top: 6px; font-size: 11px; color: var(--muted); }
.prompt-block { margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--rule); }
.prompt-block header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.prompt-block h4 { margin: 0; font-size: 14px; font-weight: 600; }
.prompt-block small { display: block; margin-top: 4px; font-size: 10px; color: var(--muted); }
.copy { height: 32px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 4px; font-size: 11px; white-space: nowrap; }
.copy:hover { border-color: var(--accent); }
.gap-list { font-size: 12px; color: var(--muted); line-height: 1.7; padding-left: 18px; }

@media (max-width: 1100px) {
  .step-detail { grid-template-columns: 1fr; gap: 16px; }
}
@media (max-width: 800px) {
  .stage[data-mode='sbs'] { aspect-ratio: 16 / 18; grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .stage[data-mode='sbs'] .ab-badge.a { top: calc(50% - 40px); bottom: auto; }
  .ab-badge { bottom: 10px; }
  .controls .time { min-width: 60px; }
}

/* ---------- The chain: rail connectors + carries ---------- */
.chain-note { margin: 0 0 14px; font-size: 11px; line-height: 1.55; color: var(--muted); }
.chain-note b { color: var(--ink); font-weight: 600; }
#rail { position: relative; }
#rail .rail-item { position: relative; border-top: 0; padding: 12px 0; }
#rail .rail-item:last-of-type { border-bottom: 0; }
#rail .rail-item .num {
  display: grid; place-items: center; flex: 0 0 26px; width: 26px; height: 26px;
  border: 1px solid var(--rule); border-radius: 50%; background: var(--bg); position: relative; z-index: 1;
}
#rail .rail-item.selected .num { border-color: var(--accent); }
#rail .rail-item.done .num { border-color: color-mix(in srgb, var(--accent) 45%, var(--rule)); }
.chain-link {
  position: relative; display: flex; align-items: center; height: 38px; margin-left: 12px; padding-left: 22px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 45%, var(--rule));
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink);
}
.chain-link.lit { border-left-color: var(--accent); }
.chain-link svg {
  position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; padding: 3px; border-radius: 50%;
  background: var(--accent); color: var(--bg); stroke-width: 2.4;
}

.carries { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.carries span {
  padding: 4px 8px; border: 1px solid var(--rule); border-radius: 3px; font-size: 10px; color: var(--muted);
}
.carries span.new { border-color: var(--accent); color: var(--accent); }
.carries .lbl { border: 0; padding: 4px 0; color: var(--muted); }

/* Stage badge swaps with the step */
.stage-badge { z-index: 4; }
/* Over the media on desktop. .stage-wrap also holds the controls and the step detail, so `bottom`
   alone dropped the badge below the detail; anchor it to the 16:9 stage's bottom edge instead. */
@media (min-width: 821px) {
  .stage-wrap { container-type: inline-size; }
  .stage-badge { bottom: auto; top: calc(100cqw * 9 / 16 - 16px); transform: translateY(-100%); }
}
.stage:not([data-mode='single']) ~ .stage-badge { display: none; }

/* ---------- Prompts drawer: prompt + its image inputs ---------- */
.prompt-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 16px; margin-top: 10px; }
.prompt-row .prompt-excerpt { margin: 0; }
.inputs { display: flex; flex-direction: column; gap: 8px; }
.inputs figure { margin: 0; }
.inputs img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border: 1px solid var(--rule); display: block; }
.inputs figcaption { margin-top: 4px; font-size: 10px; line-height: 1.4; color: var(--muted); }
.inputs figcaption b { color: var(--accent); font-weight: 600; margin-right: 4px; }
.inputs .video-in { padding: 10px; border: 1px dashed var(--rule); font-size: 10px; color: var(--muted); }
.inputs .video-in b { color: var(--accent); font-weight: 600; margin-right: 4px; }
.inputs .none { font-size: 10px; color: var(--muted); }

/* How dialog: step media + checks */
.how-steps .step-media { margin-top: 12px; }
.how-steps .step-media img { width: 100%; border: 1px solid var(--line-2); border-radius: 6px; display: block; }
.how-steps .prompt-excerpt { font-size: 11.5px; }
.how-steps .check { font-size: 12px; }
.how-mistakes { margin-top: 28px; }
.how-mistakes > .kicker { margin-bottom: 12px; }
.how-gaps { margin-top: 18px; font-size: 13px; color: var(--muted); }

@media (max-width: 800px) {
  .prompt-row { grid-template-columns: 1fr; }
  .inputs { flex-direction: row; flex-wrap: wrap; }
  .inputs figure, .inputs .video-in { width: calc(50% - 4px); }
}

.action-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 800px) {
  .action-row.three { grid-template-columns: 1fr 1fr; }
  .action-row.three > :last-child { grid-column: 1 / -1; }
}

.chain-link.branch { border-left-style: dashed; color: var(--accent); }

/* Glossary tips: out of the layout while hidden (no sideways scroll on phones), kept inside the edge when shown (app.js) */
.term-tip { display: none; max-width: min(260px, calc(100vw - 48px)); }
.term:hover .term-tip, .term:focus-visible .term-tip, .term[aria-expanded='true'] .term-tip { display: block; }

/* Shared site footer: the runtime mounts its links in [data-exploration-controls] */
.site-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px;
  padding: 22px clamp(16px, 4vw, 56px); border-top: 1px solid var(--line);
  background: var(--exploration-footer-bg); font: 400 12px/1.4 var(--mono); color: var(--muted);
}
.site-foot .foot-id { letter-spacing: 0.1em; text-transform: uppercase; }
.site-foot .foot-pdf { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-decoration: none; }
.site-foot .foot-pdf:hover { color: var(--accent); }
.site-foot .foot-pdf:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.site-foot [data-exploration-controls] { margin-left: auto; border-top: 0; } /* the footer already draws the rule */
@media (max-width: 820px) { .site-foot [data-exploration-controls] { margin-left: 0; width: 100%; } }

/* Keep the title from leaving "X." alone on its own line */
.opening h1 { text-wrap: balance; }

/* ---------- Layout areas: the step detail is a sibling of the stage, placed by the grid ---------- */
.stage-layout { grid-template-rows: auto 1fr; grid-template-areas: 'stage rail' 'detail rail'; row-gap: 0; }
.stage-layout > .stage-wrap { grid-area: stage; }
.stage-layout > .step-detail { grid-area: detail; align-self: start; }
.stage-layout > aside { grid-area: rail; }
.rail-meta { display: none; }
@media (max-width: 1100px) {
  .stage-layout { grid-template-rows: none; grid-template-areas: 'stage' 'detail' 'rail'; }
  .stage-layout > aside { margin-top: 28px; }
}

/* ---------- One screen on desktop ----------
   Wide and tall enough: no page scroll. The opening is one row (statement and intro on one line
   each), the actions and the step detail sit beside the stage, and the chain is a strip of 16:9
   thumbnails under it. The strip's height depends on the stage width (six thumbnails share it),
   so the stage width W solves  W * 9/16 + (W - links) * 3/32 = 100dvh - chrome,  i.e.
   W = (100dvh - chrome + links * 3/32) * 32/21. Keep --fit-chrome in sync with the fixed heights
   below (e2e/change-only-x.spec.ts asserts no scroll and one-line opening text). */
@media (min-width: 1101px) and (min-height: 760px) {
  :root {
    --fit-gutter: clamp(24px, 3vw, 56px);
    --fit-side: 380px;
    --fit-gap: 28px;
    --fit-open: 96px;
    --fit-actions: 56px;
    --fit-controls: 58px;
    --fit-strip: 74px; /* the strip without its thumbnails: label row, gaps, two-line titles */
    --fit-links: 130px; /* five 26px arrows between the six thumbnails */
    --fit-foot: 57px;
    --fit-chrome: calc(var(--bar-h) + var(--fit-open) + var(--fit-controls) + var(--fit-strip) + var(--fit-foot) + 16px);
    --stage-w: min(
      calc(100vw - 2 * var(--fit-gutter) - var(--fit-side) - var(--fit-gap)),
      calc((100dvh - var(--fit-chrome) + var(--fit-links) * 3 / 32) * 32 / 21)
    );
    --fit-thumb-h: calc((var(--stage-w) - var(--fit-links)) * 3 / 32);
  }
  body { display: flex; flex-direction: column; min-height: 100dvh; }
  /* One grid for the page: the opening on top, the stage and its chain strip on the left, the
     actions and the step detail on the right (.stage-layout and its children join this grid).
     The minimum width keeps the one-line opening inside the page; any extra goes to the detail. */
  main {
    flex: 1 0 auto; box-sizing: content-box; max-width: none; margin: 0 auto; padding: 0 0 16px;
    width: calc(var(--stage-w) + var(--fit-side) + var(--fit-gap));
    min-width: min(calc(100vw - 2 * var(--fit-gutter)), 1240px);
    display: grid; grid-template-columns: var(--stage-w) minmax(var(--fit-side), 1fr); column-gap: var(--fit-gap);
    grid-template-rows: var(--fit-open) var(--fit-actions) 1fr auto; align-content: start;
    grid-template-areas: 'open open' 'stage actions' 'stage detail' 'rail detail';
  }
  .stage-layout { display: contents; }

  /* Opening: the title, then the statement and the intro on one line each */
  .opening { grid-area: open; height: var(--fit-open); padding: 0 0 16px; align-items: end; justify-content: flex-start; gap: 32px; }
  .opening h1 { font-size: clamp(46px, 3.2vw, 64px); white-space: nowrap; }
  .intro { min-width: 0; }
  .intro .statement { margin-bottom: 6px; font-size: clamp(20px, 1.45vw, 28px); white-space: nowrap; }
  .intro .statement br { display: none; }
  .intro .statement em { margin-left: 0.25em; }
  .intro > p:last-child { max-width: none; white-space: nowrap; }

  .action-row.three { grid-area: actions; display: flex; align-self: start; gap: 6px; margin: 0; }
  .action-row.three .action { flex: 1 1 auto; min-height: 40px; padding: 0 12px; border-radius: 4px; white-space: nowrap; }
  .action-more { display: none; }
  .action-row.three .action small { display: none; }
  .action-row.three .action strong { font-size: 12px; font-weight: 500; }
  .action-row.three .action .icon { display: block; width: 18px; height: 18px; flex-basis: 18px; }

  .controls { height: var(--fit-controls); padding: 0; }
  /* Side by side keeps the 16:9 box (each half shows the same centred crop), so the layout does not jump */
  .stage[data-mode='sbs'] { aspect-ratio: 16 / 9; }

  /* Step detail beside the stage; scrolls inside its column if a step ever outgrows it */
  .stage-layout > .step-detail {
    display: block; padding: 0 4px 0 0; overflow-y: auto; scrollbar-width: thin;
    max-height: calc(var(--stage-w) * 9 / 16 + var(--fit-controls) + var(--fit-strip) + var(--fit-thumb-h) - var(--fit-actions));
  }
  .step-detail h2 { font-size: clamp(30px, 2.2vw, 40px); }
  /* The column has room on large screens: let its text grow a little */
  .step-detail p { font-size: clamp(12px, 0.62vw, 15px); }
  .step-detail .note { font-size: clamp(11px, 0.55vw, 14px) !important; }
  .step-detail dl { font-size: clamp(11px, 0.52vw, 13px); }
  .step-detail .refs { margin-top: 12px; }
  .step-detail .refs figure { width: calc(50% - 4px); max-width: 128px; }
  .step-detail .carries { margin-top: 12px; }
  .step-detail dl { gap: 4px 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }

  /* The chain as a strip: label row, then six 16:9 thumbnails joined by arrows */
  .stage-layout > aside {
    padding-top: 12px;
    display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 16px;
  }
  .rail-label { margin: 0; white-space: nowrap; }
  .rail-meta { display: inline; }
  .chain-note { margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 10px; line-height: 1.5; }
  .chain-note b { font-weight: 500; }
  #rail { grid-column: 1 / -1; display: flex; align-items: start; margin-top: 8px; }
  #rail .rail-item {
    flex: 1 1 0; min-width: 0; padding: 0;
    position: relative; display: grid; grid-template-rows: var(--fit-thumb-h) 30px; align-items: start; gap: 6px;
  }
  #rail .rail-item .thumb { grid-row: 1; width: 100%; height: 100%; margin: 0; border-radius: 3px; }
  #rail .rail-item:hover .thumb { border-color: var(--line-2); }
  #rail .rail-item.selected .thumb { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
  /* The step number sits on the thumbnail's corner so the title gets the full width */
  #rail .rail-item .num { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; font-size: 9px; }
  #rail .rail-item > span:nth-child(2) { grid-row: 2; min-width: 0; }
  #rail .rail-item strong {
    display: -webkit-box; margin: 0; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    font-size: 12px; line-height: 1.25;
  }
  #rail .rail-item small { display: none; }
  .chain-link { flex: 0 0 26px; height: var(--fit-thumb-h); margin: 0; padding: 0; border: 0; justify-content: center; }
  .chain-link span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .chain-link svg { position: static; transform: rotate(-90deg); width: 18px; height: 18px; }
  .chain-link:not(.lit) svg { background: color-mix(in srgb, var(--accent) 35%, var(--rule)); }
  aside .card { display: none; }

  .site-foot { height: var(--fit-foot); flex-wrap: nowrap; padding-top: 0; padding-bottom: 0; }
}
/* Too narrow for the one-line intro: let it wrap rather than leave the page */
@media (min-width: 1101px) and (max-width: 1299px) and (min-height: 760px) {
  :root { --fit-open: 112px; }
  .intro > p:last-child { white-space: normal; }
}
