/* ALTER stage: the synced player, the compare wipe, the version rail and the panel.
   Every version is a <video> stacked in one 16:9 box; only the active one is visible. */

:root { --btn-w: 6rem; --controls-h: 3rem; }

.theatre { padding-top: 0.25rem; }
.theatre-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }

/* ---------- Player ---------- */
.player {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  width: 100%; max-width: calc((100vh - var(--bar-h) - var(--controls-h) - 2rem) * 16 / 9);
  margin-inline: auto; background: #000;
  scroll-margin-top: calc(var(--bar-h) + 1rem);
}
@supports (height: 100dvh) {
  .player { max-width: calc((100dvh - var(--bar-h) - var(--controls-h) - 2rem) * 16 / 9); }
}
.player:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.screens { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #000; touch-action: pan-y; }
.screens-fallback, .screen {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover;
}
.screen { z-index: 1; opacity: 0; pointer-events: none; background: transparent; }
.screen.is-under { z-index: 2; opacity: 1; }
.screen.is-leaving { z-index: 3; opacity: 1; }
.screen.is-active { z-index: 4; opacity: 1; }
/* The version is clipped to the right of the divider; the original is never clipped. */
.player.is-compare .screen.is-active:not([data-version='original']),
.player.is-compare .screen.is-leaving:not([data-version='original']) { clip-path: inset(0 0 0 var(--wipe)); }

/* A slow switch: a thin line at the top while the next version loads its frame */
.player.is-waiting .screens::after {
  content: ''; position: absolute; inset: 0 0 auto; z-index: 7; height: 2px;
  background: var(--accent); transform-origin: left; animation: alter-wait 0.9s ease-in-out infinite alternate;
}
@keyframes alter-wait { from { transform: scaleX(0.15); } to { transform: scaleX(1); } }

/* ---------- Compare wipe ---------- */
.wipe { position: absolute; inset: 0; z-index: 5; display: none; pointer-events: none; }
.player.is-compare .wipe { display: block; }
.player.is-compare .screens { cursor: ew-resize; }
.wipe-label {
  position: absolute; top: 0.875rem; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 500 0.75rem / 1.2 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink);
  text-shadow: 0 1px 2px #000c, 0 0 1rem #0008;
}
.wipe-left { left: 1rem; }
.wipe-right { right: 1rem; text-align: right; }
.wipe-handle {
  position: absolute; top: 0; bottom: 0; left: var(--wipe); width: 2.75rem; margin-left: -1.375rem;
  display: grid; place-items: center; pointer-events: auto; cursor: ew-resize; touch-action: none; outline: none;
}
.wipe-handle::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px;
  background: var(--ink); box-shadow: 0 0 0 1px #0003;
}
.wipe-grip {
  position: relative; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%;
  background: var(--ink); color: var(--bg); box-shadow: 0 0.125rem 0.75rem #0007;
}
.wipe-grip svg { width: 1.25rem; height: 1.25rem; }
.wipe-handle:focus-visible .wipe-grip { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Centre Play (house .stage-play), shown while paused outside compare */
.player .stage-play { z-index: 6; gap: 0.75rem; font-size: 0.8125rem; }
.player .stage-play svg { width: 4.25rem; height: 4.25rem; padding: 1.3rem; }

/* ---------- Control strip ---------- */
.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.125rem; min-height: var(--controls-h); padding: 0 0.25rem;
  background: var(--panel); border-top: 1px solid var(--rule);
  container: controls / inline-size;
}
.ctl-text { display: none; }
.ctl {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; flex: none;
  min-width: 2.75rem; min-height: 2.75rem; padding: 0 0.625rem;
  font: 500 0.75rem / 1 var(--mono); letter-spacing: 0.06em; color: var(--ink);
}
.ctl .icon { width: 1.25rem; height: 1.25rem; flex: 0 0 1.25rem; }
.ctl[aria-pressed='true'] { color: var(--accent); }
.player.is-playing .i-play, .player:not(.is-playing) .i-pause { display: none; }
[data-sound][aria-pressed='true'] .cross, [data-sound]:not([aria-pressed='true']) .wave { display: none; }
.time {
  flex: none; padding: 0 0.25rem;
  font: 500 0.75rem / 1 var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap;
}
.scrub {
  --p: 0; position: relative; flex: 1 1 auto; min-width: 3rem; height: 2.75rem; margin: 0 0.625rem;
  display: flex; align-items: center; cursor: pointer; touch-action: none; outline: none;
}
.scrub-track { position: relative; display: block; width: 100%; height: 2px; background: var(--line-2); }
.scrub-fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--p) * 100%); background: var(--ink); }
.scrub-fill::after {
  content: ''; position: absolute; top: 50%; right: -0.375rem; width: 0.75rem; height: 0.75rem; margin-top: -0.375rem;
  border-radius: 50%; background: var(--ink);
}
.scrub:hover .scrub-track { height: 3px; }
.scrub:focus-visible .scrub-track { outline: 2px solid var(--accent); outline-offset: 0.5rem; }
/* The strip answers to its own width, so a larger default font never pushes buttons off screen */
@container controls (min-width: 40rem) { .ctl-text { display: inline; } }
@container controls (max-width: 22rem) {
  /* Tight strip: the scrub gets its own full-width row above the buttons */
  .scrub { order: -1; flex: 1 0 100%; margin: 0; padding: 0 0.75rem; }
  .time { margin-right: auto; }
}
@container controls (max-width: 16.5rem) { .time { display: none; } }

/* Full screen: keep the 16:9 box exact so the wipe maps 1:1 onto the picture */
.player:fullscreen { width: 100%; max-width: none; height: 100%; justify-content: center; }
.player:fullscreen .screens { width: min(100vw, (100vh - var(--controls-h)) * 16 / 9); margin: auto; }
.player:-webkit-full-screen { width: 100%; max-width: none; height: 100%; justify-content: center; }
.player:-webkit-full-screen .screens { width: min(100vw, (100vh - var(--controls-h)) * 16 / 9); margin: auto; }

/* ---------- Version rail ---------- */
.rail-wrap { min-width: 0; }
.rail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.625rem; }
.rail-title { margin: 0; font: 500 0.75rem / 1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.rail-keys { margin: 0; font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.rail-keys kbd { min-width: 1.25rem; height: 1.25rem; margin: 0 0.25rem 0 0.75rem; font-size: 0.6875rem; }
.rail-keys kbd + kbd { margin-left: 0; }

.rail {
  display: flex; gap: 1.25rem; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x proximity; padding: 0.25rem 0.1875rem 0.875rem;
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.rail-group { flex: var(--n) 0 calc(var(--n) * var(--btn-w) + (var(--n) - 1) * 0.5rem); min-width: 0; }
.rail-group-label {
  margin: 0 0 0.625rem; padding-top: 0.625rem; border-top: 1px solid var(--line-2);
  font: 500 0.6875rem / 1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
.rail-row { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 0.5rem; }
.version {
  display: flex; flex-direction: column; gap: 0.5rem; width: 100%; padding: 0; text-align: left;
  color: var(--muted); scroll-snap-align: start; outline-offset: 2px;
}
.version img {
  display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: #000;
  border: 1px solid var(--rule); opacity: 0.72; transition: opacity 0.2s, border-color 0.2s;
}
.version span { font-size: 0.8125rem; line-height: 1.25; }
.version:hover:not(:disabled) { color: var(--ink); }
.version:hover img { opacity: 1; }
.version[aria-pressed='true'] { color: var(--ink); }
.version[aria-pressed='true'] img { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---------- Panel ---------- */
.panel { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.panel-head { display: grid; gap: 0.375rem; }
.panel-mode { margin: 0; font: 500 0.75rem / 1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.panel-title { margin: 0; font: 400 2rem / 1 'Instrument Serif', serif; }
.panel-rule { margin: 0.25rem 0 0; font-size: 1.0625rem; line-height: 1.35; color: var(--ink); }
.panel-block { display: grid; gap: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--rule); }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 2.5rem; }
.panel-label { margin: 0; font: 500 0.6875rem / 1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.prompt {
  margin: 0; padding: 0.75rem 0.875rem; overflow: auto;
  border: 1px solid var(--rule); background: var(--panel);
  font: 400 0.8125rem / 1.55 var(--mono); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere;
}
.prompt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.copy-btn {
  flex: none; min-width: 4.5rem; min-height: 2.5rem; padding: 0 0.875rem; border: 1px solid var(--line-2);
  font: 500 0.75rem / 1 var(--mono); letter-spacing: 0.06em; color: var(--ink);
}
.copy-btn:hover:not(:disabled) { border-color: var(--accent); }
.refs { display: flex; flex-wrap: wrap; gap: 0.625rem; margin: 0; padding: 0; list-style: none; }
.refs a { display: grid; gap: 0.375rem; width: 5.5rem; font-size: 0.75rem; line-height: 1.3; color: var(--muted); text-decoration: none; }
.refs img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: #000; border: 1px solid var(--rule); }
.refs a:hover { color: var(--ink); }
.refs a:hover img { border-color: var(--line-2); }
.panel-note, .qa-note, .panel-hint { margin: 0; font-size: 0.875rem; line-height: 1.5; color: var(--muted); }
.verdict { margin: 0; font: 500 0.75rem / 1 var(--mono); letter-spacing: 0.14em; color: var(--ink); }
.qa-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin: 0; }
.qa-stat { display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 0.375rem; }
.pb-qa .panel-row { min-height: 0; }
.qa-stat dd { margin: 0; font: 400 1.875rem / 1 'Instrument Serif', serif; font-variant-numeric: tabular-nums; color: var(--ink); }
.qa-stat dt { font-size: 0.75rem; line-height: 1.35; color: var(--muted); }
.panel-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.5rem 1.25rem; margin: 0; font-size: 0.9375rem; }
.panel-facts dt { color: var(--muted); }
.panel-facts dd { margin: 0; color: var(--ink); }

/* ---------- Wide: panel to the right of the player, rail under both ---------- */
@media (min-width: 81rem) {
  .theatre-grid {
    grid-template-columns: minmax(0, 1fr) clamp(20rem, 24vw, 26rem);
    grid-template-areas: 'player panel' 'rail rail';
    column-gap: 1.75rem; row-gap: 1.5rem;
  }
  .player { grid-area: player; }
  .rail-wrap { grid-area: rail; }
  /* contain: size keeps the panel from growing the row: it matches the player and scrolls if longer */
  .panel { grid-area: panel; contain: size; overflow-y: auto; padding-right: 0.25rem; scrollbar-width: thin; }
  .prompt { max-height: 6.75rem; }
}

/* ---------- Tablet: panel under the rail in two columns ---------- */
@media (min-width: 40rem) and (max-width: 80.99rem) {
  .panel { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.125rem 2rem; align-items: start; }
  .panel-head { grid-column: 1 / -1; }
  .pb-prompt { grid-column: 1; grid-row: 2 / span 2; }
  .pb-refs, .pb-qa { grid-column: 2; }
  .pb-facts { grid-column: 1; }
  .panel-hint { grid-column: 2; padding-top: 1rem; border-top: 1px solid var(--rule); }
}

/* ---------- Phones ---------- */
@media (max-width: 47.99rem) {
  :root { --btn-w: 7rem; }
  .rail { margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter); scroll-padding-inline: var(--gutter); }
  .rail-group { flex-grow: 0; }
  .wipe-label { top: 0.625rem; font-size: 0.6875rem; letter-spacing: 0.12em; }
  .wipe-left { left: 0.75rem; }
  .wipe-right { right: 0.75rem; }
}
@media (max-width: 47.99rem) and (orientation: portrait) {
  .player { width: auto; max-width: none; margin-inline: calc(-1 * var(--gutter)); }
}

/* Keyboard hints mean nothing on a phone, and at 20rem they push the page sideways. */
@media (max-width: 40rem), (hover: none) {
  .rail-keys { display: none; }
}
