:root {
  --night: #111827;
  --cream: #faf8f5;
  --ivory: #f5f2ed;
  --paper: #edeae4;
  --ink: #1a1a1a;
  --rule: #d4d0c8;
  --navy: #2c4566;
  --navy-deep: #1e3450;
  --riq: #5b6eae;
  --ciq: #c4576a;
  --liq: #4a9080;
  --cyan: #00d0ff;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}
/* the film is its own dark theatre in either colour scheme; these keep the tokens explicit */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --night: #111827; } }
:root[data-theme="dark"] { --night: #111827; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); overflow: hidden; }
body { font-family: var(--sans); color: var(--cream); -webkit-font-smoothing: antialiased; }
button { font: inherit; }

.theatre { position: fixed; inset: 0; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.theatre.idle { cursor: none; }

/* scene frame line: a navy paper tab, top left, fixed position and fixed in/out */
.brow {
  position: absolute; top: clamp(14px, 3vh, 30px); left: clamp(16px, 3vw, 40px);
  display: flex; align-items: baseline; gap: 12px;
  padding: 9px 16px 10px 14px; background: var(--navy-deep); color: var(--cream);
  border-radius: 3px; box-shadow: 3px 3px 0 rgba(0,0,0,.28);
  opacity: 0; translate: -12px 0; pointer-events: none; max-width: calc(100vw - 32px);
}
.brow-n { font: italic 500 clamp(18px, 2.1vw, 26px)/1 var(--serif); color: #8fe8ff; }
.brow-t { font: 600 clamp(11px, 1.05vw, 14px)/1.2 var(--sans); letter-spacing: .08em; text-transform: uppercase; }

.tally {
  position: absolute; top: clamp(14px, 3vh, 30px); right: clamp(16px, 3vw, 40px);
  font: 500 clamp(10px, .95vw, 13px)/1 var(--mono); color: var(--cream);
  background: rgba(17, 24, 39, .82); border: 1px solid rgba(250, 248, 245, .14);
  padding: 9px 12px; border-radius: 3px; opacity: 0; pointer-events: none; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tally b { color: #8fe8ff; font-weight: 500; }

/* captions are cut paper strips */
.caption {
  position: absolute; left: 50%; bottom: clamp(74px, 12vh, 120px); margin: 0;
  translate: -50% 0; max-width: min(88vw, 900px); width: max-content;
  padding: .42em .9em .5em; background: var(--cream); color: var(--ink);
  font: italic 400 clamp(17px, 2.25vw, 32px)/1.25 var(--serif); text-align: center;
  box-shadow: 4px 4px 0 rgba(0,0,0,.22); border-radius: 2px; rotate: -.4deg;
  opacity: 0; pointer-events: none; text-wrap: balance;
}

/* poster */
.poster {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 60%, rgba(30,52,80,.55), rgba(11,17,32,.94) 70%);
  transition: opacity .6s ease, visibility .6s;
}
.poster.gone { opacity: 0; visibility: hidden; }
.poster-inner { text-align: center; max-width: 640px; }
.poster-kicker { font: 600 13px/1 var(--sans); letter-spacing: .18em; text-transform: uppercase; color: #8fe8ff; margin: 0 0 18px; }
.poster-title { font: 400 clamp(52px, 9vw, 112px)/.95 var(--serif); margin: 0 0 18px; letter-spacing: -.02em; }
.poster-title em { font-style: italic; background: linear-gradient(90deg, #8696c8, #e8909d 55%, #7fb5a3); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: .06em; }
.poster-dek { font: 400 clamp(16px, 1.6vw, 20px)/1.5 var(--sans); color: rgba(250,248,245,.78); margin: 0 auto 32px; max-width: 30em; }
.play-big {
  display: inline-flex; align-items: center; gap: 10px; border: 0; cursor: pointer;
  background: var(--cream); color: var(--ink); padding: 14px 28px 14px 22px; border-radius: 999px;
  font: 600 18px/1 var(--sans); box-shadow: 0 0 0 0 rgba(0,208,255,.5); animation: breathe 2.6s ease-in-out infinite;
}
.play-big svg { width: 22px; height: 22px; }
.play-big:hover { background: #fff; }
.play-big:focus-visible, .ctl:focus-visible, .btn:focus-visible, .scrub:focus-visible, .linkish:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
@keyframes breathe { 50% { box-shadow: 0 0 0 12px rgba(0,208,255,0); } 0%, 100% { box-shadow: 0 0 0 0 rgba(0,208,255,.35); } }
.linkish { display: block; margin: 18px auto 0; background: none; border: 0; color: rgba(250,248,245,.7); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; font-size: 15px; }
.linkish:hover { color: var(--cream); }
.poster-turn { display: none; margin: 22px 0 0; font: italic 400 15px/1.4 var(--serif); color: rgba(250,248,245,.6); }
@media (orientation: portrait) and (max-width: 700px) { .poster-turn { display: block; } }

/* end card */
.endcard {
  position: absolute; inset: 0; display: grid; place-items: center end; padding: 16px 4vw 16px 16px;
  opacity: 0; visibility: hidden; pointer-events: none;
}
@media (max-width: 900px), (max-aspect-ratio: 3/2) { .endcard { place-items: center; padding: 16px; } }
.endcard.on { visibility: visible; pointer-events: auto; }
.endcard-inner {
  background: var(--cream); color: var(--ink); text-align: center;
  padding: clamp(24px, 4vw, 44px) clamp(22px, 5vw, 64px) clamp(26px, 4vw, 40px);
  border-radius: 4px; box-shadow: 8px 8px 0 rgba(17,24,39,.35); max-width: 420px; width: 100%;
}
.end-mark { width: min(340px, 70vw); height: auto; display: block; margin: 0 auto -6px; }
.em-iq { font-family: var(--serif); font-weight: 500; fill: var(--ink); letter-spacing: -2px; }
.em-books { font-family: var(--serif); font-weight: 400; font-style: italic; fill: url(#endBooks); }
.end-with { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 14px; font: italic 400 20px/1 var(--serif); color: var(--riq); }
.end-line { margin: 0 0 24px; font: 400 16px/1.5 var(--sans); color: #4a463f; }
.end-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 22px; border-radius: 999px; font: 600 16px/1 var(--sans); text-decoration: none; cursor: pointer; }
.btn-primary { background: var(--navy); color: #fff; border: 0; }
.btn-primary:hover { background: var(--navy-deep); }
.btn-ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--rule); }
.btn-ghost:hover { border-color: var(--navy); }

/* controls */
.controls {
  position: absolute; left: 50%; bottom: clamp(12px, 2.4vh, 24px); translate: -50% 0;
  width: min(940px, calc(100vw - 32px)); display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: rgba(11,17,32,.78); border: 1px solid rgba(250,248,245,.12);
  border-radius: 999px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: opacity .4s ease, translate .4s ease;
}
.theatre.idle .controls { opacity: 0; translate: -50% 10px; }
.theatre.pre .controls { opacity: 0; pointer-events: none; }
.ctl { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; color: var(--cream); cursor: pointer; }
.ctl:hover { background: rgba(250,248,245,.1); }
.ctl svg { width: 20px; height: 20px; }
.ctl-text { width: auto; padding: 0 12px; border-radius: 999px; font: 600 13px/1 var(--sans); letter-spacing: .04em; }
.ctl .i-pause { display: none; }
.ctl .i-mute { display: none; }
.theatre.muted .ctl .i-sound { display: none; }
.theatre.muted .ctl .i-mute { display: block; }
.poster-sound { margin: 14px 0 0; font: 500 13px/1 var(--sans); letter-spacing: .08em; color: rgba(250,248,245,.6); }
.theatre.playing .ctl .i-play { display: none; }
.theatre.playing .ctl .i-pause { display: block; }
.time { flex: none; font: 500 12px/1 var(--mono); color: rgba(250,248,245,.75); font-variant-numeric: tabular-nums; }

.scrub { position: relative; flex: 1; height: 28px; cursor: pointer; touch-action: none; }
.chapters { position: absolute; left: 0; right: 0; top: 11px; height: 6px; display: flex; gap: 3px; }
.chapters span { height: 100%; background: rgba(250,248,245,.22); border-radius: 3px; }
.scrub-fill { position: absolute; left: 0; top: 11px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #8696c8, #e8909d 55%, #7fb5a3); width: 0; pointer-events: none; mix-blend-mode: normal; }
.scrub-head { position: absolute; top: 7px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--cream); box-shadow: 0 0 0 4px rgba(0,208,255,.25); pointer-events: none; }
.scrub-tip {
  position: absolute; bottom: 30px; translate: -50% 0; white-space: nowrap; pointer-events: none;
  background: var(--cream); color: var(--ink); font: 500 12px/1 var(--sans); padding: 7px 9px; border-radius: 3px; opacity: 0; transition: opacity .15s;
}
.scrub:hover .scrub-tip { opacity: 1; }

/* storyboard panel */
.board {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); overflow-y: auto;
  background: var(--cream); color: var(--ink); padding: 26px 24px 40px; box-shadow: -10px 0 0 rgba(0,0,0,.18);
  overscroll-behavior: contain;
}
.board[hidden] { display: none; }
.board-head { position: relative; padding-right: 36px; }
.board-kicker { margin: 0 0 6px; font: 600 12px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--ciq); }
.board-title { margin: 0 0 8px; font: 400 32px/1.05 var(--serif); }
.board-log { margin: 0 0 16px; font: 400 15px/1.5 var(--sans); color: #4a463f; }
.board-close { position: absolute; top: -6px; right: -6px; width: 40px; height: 40px; border: 0; background: none; font-size: 28px; line-height: 1; cursor: pointer; color: var(--ink); }
.board-art { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 12px 0; margin-bottom: 8px; }
.board-art summary { cursor: pointer; font: 600 14px/1 var(--sans); }
.board-art ul { margin: 12px 0 0; padding-left: 18px; font: 400 14px/1.5 var(--sans); color: #3b3832; }
.board-art li + li { margin-top: 6px; }
.board-list { list-style: none; margin: 0; padding: 0; }
.board-list li { border-bottom: 1px solid var(--rule); }
.board-list button {
  display: grid; grid-template-columns: 44px 1fr; gap: 2px 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 14px 6px; cursor: pointer; color: inherit; border-radius: 3px;
}
.board-list button:hover { background: var(--ivory); }
.board-list li.now button { background: #eef0f8; }
.bl-n { grid-row: span 3; font: italic 500 26px/1 var(--serif); color: var(--riq); }
.bl-t { font: 600 15px/1.3 var(--sans); }
.bl-time { font: 500 12px/1.3 var(--mono); color: #8a8578; }
.bl-beat { font: 400 14px/1.5 var(--sans); color: #3b3832; margin-top: 4px; }

@media (max-width: 640px) {
  .time { display: none; }
  .controls { gap: 6px; padding: 6px 8px; }
  .ctl-text { padding: 0 8px; font-size: 12px; }
  .tally { top: auto; bottom: calc(clamp(74px, 12vh, 120px) + 64px); right: 50%; translate: 50% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .play-big { animation: none; }
}

/* short frames: an embed on a landing page, or a phone on its side */
@media (max-height: 480px) {
  .poster-kicker, .poster-dek, .linkish, .poster-turn, .poster-sound { display: none; }
  .poster-title { font-size: clamp(34px, 13vh, 64px); margin-bottom: 14px; }
  .play-big { padding: 10px 22px 10px 16px; font-size: 16px; }
  .caption { font-size: clamp(13px, 4.2vh, 20px); bottom: 56px; }
  .brow { padding: 6px 10px 7px; }
  .brow-n { font-size: 16px; }
  .brow-t { font-size: 10px; }
  .tally { display: none; }
  .controls { bottom: 8px; padding: 4px 8px; }
  .ctl { width: 30px; height: 30px; }
  .endcard-inner { padding: 16px 20px; }
  .end-mark { width: min(220px, 50vw); }
  .end-line { font-size: 13px; margin-bottom: 12px; }
  .end-with { margin-bottom: 8px; font-size: 16px; }
  .btn { min-height: 38px; font-size: 14px; padding: 0 16px; }
}

/* MP4 export: nothing but the film */
.theatre.render .controls, .theatre.render .poster { display: none !important; }
.theatre.render { cursor: none; }
.end-url { display: none; margin: 0; font: 600 20px/1 var(--mono); letter-spacing: .02em; color: var(--ink); }
.theatre.render .end-url { display: block; }
.theatre.render .end-actions { display: none; }
