/* It's Badtime app: library, new story, player. lab/play.html's quiet typographic language: Cormorant Garamond for
   everything the story says, JetBrains Mono for everything the machine says; a night palette and a paper palette.
   The app themes itself from scene.visual.mode (data-mode on <html>); looks never touch it. */
:root {
  --bg: #050505; --ink: rgba(240,236,228,0.95); --mute: rgba(240,236,228,0.46); --line: rgba(240,236,228,0.16);
  --hover: rgba(240,236,228,0.08); --veil: rgba(5,5,5,0.62); --faint: rgba(240,236,228,0.05); --warn: #d9a089;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-mode="paper"] {
  --bg: #efebe3; --ink: rgba(34,30,26,0.93); --mute: rgba(34,30,26,0.55); --line: rgba(34,30,26,0.2);
  --hover: rgba(34,30,26,0.06); --veil: rgba(239,235,227,0.66); --faint: rgba(34,30,26,0.04); --warn: #8a3b22;
  color-scheme: light;
}
/* The night/paper flip fades over the scene's own transition (player.js sets --mode-fade from show()'s transition, 0 on
   a cut). The palette variables themselves are animated, so the page, the HUD, the choices and the caption all move
   together. The background and lines ease across; the ink holds and then swaps at the midpoint, when the background is
   halfway, so text is always the higher-contrast of the two inks and never a mid-grey on a mid-grey. Browsers without
   @property flip instantly, as before. */
@property --bg { syntax: '<color>'; inherits: true; initial-value: #050505; }
@property --ink { syntax: '<color>'; inherits: true; initial-value: rgba(240,236,228,0.95); }
@property --mute { syntax: '<color>'; inherits: true; initial-value: rgba(240,236,228,0.46); }
@property --line { syntax: '<color>'; inherits: true; initial-value: rgba(240,236,228,0.16); }
@property --hover { syntax: '<color>'; inherits: true; initial-value: rgba(240,236,228,0.08); }
@property --veil { syntax: '<color>'; inherits: true; initial-value: rgba(5,5,5,0.62); }
@property --faint { syntax: '<color>'; inherits: true; initial-value: rgba(240,236,228,0.05); }
:root { --mode-fade: 0s;
  transition: --bg var(--mode-fade) ease-in-out, --line var(--mode-fade) ease-in-out, --hover var(--mode-fade) ease-in-out,
    --veil var(--mode-fade) ease-in-out, --faint var(--mode-fade) ease-in-out,
    --ink 0s linear calc(var(--mode-fade) * 0.5), --mute 0s linear calc(var(--mode-fade) * 0.5); }
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { font: 400 17px/1.5 var(--serif); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 1px solid var(--mute); outline-offset: 3px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* ---------- shared pieces */
.mono, .label, .kicker, .meta { font-family: var(--mono); font-weight: 400; letter-spacing: .12em; text-transform: uppercase; }
.label { font-size: 10.5px; line-height: 1.6; color: var(--mute); margin: 0 0 14px; }
.kicker { font-size: 10.5px; color: var(--mute); margin: 0 0 18px; }
.pill { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 10px; padding: 12px 24px; border-radius: 999px;
  border: 1px solid var(--line); font: 400 11px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--ink); background: transparent; transition: background .2s, border-color .2s; }
.pill:hover, .pill:focus-visible { background: var(--hover); border-color: var(--mute); }
.pill[disabled], .pill[aria-disabled="true"] { opacity: .35; cursor: default; pointer-events: none; }
.text-btn { all: unset; cursor: pointer; font: 400 10.5px/1.6 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); padding: 6px 0; }
.text-btn:hover, .text-btn:focus-visible { color: var(--ink); }
.text-btn.danger:hover, .text-btn.danger:focus-visible { color: var(--warn); }

/* ---------- library + new story: one quiet column */
.shell { width: min(760px, 100%); margin: 0 auto; padding: max(40px, env(safe-area-inset-top)) 16px 64px; }
.masthead { padding: 6vh 0 44px; border-bottom: 1px solid var(--line); margin-bottom: 36px; }
.masthead h1 { font: 500 clamp(48px, 9vw, 92px)/0.95 var(--serif); letter-spacing: .005em; margin: 0 0 18px; }
.lede { font: italic 400 clamp(19px, 2.3vw, 23px)/1.45 var(--serif); margin: 0 0 30px; max-width: 34em; color: var(--ink); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 26px; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 8px 24px; align-items: start; padding: 20px 0 18px; border-bottom: 1px solid var(--line); }
.row:first-child { border-top: 1px solid var(--line); }
.row-title { font: 500 25px/1.15 var(--serif); margin: 0; }
.row-title em { font-weight: 400; color: var(--mute); }
.row-meta { font: 400 10.5px/1.8 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--mute); margin: 6px 0 0; }
.row-meta .sep { padding: 0 .5em; opacity: .6; }
.progress { height: 1px; background: var(--line); margin-top: 12px; max-width: 320px; }
.progress i { display: block; height: 1px; background: var(--ink); opacity: .7; }
.row-acts { display: flex; gap: 4px 18px; flex-wrap: wrap; justify-content: flex-end; padding-top: 4px; }
.empty { font: italic 400 21px/1.45 var(--serif); color: var(--mute); margin: 8px 0 0; }
.foot { margin-top: 40px; font: 400 10px/1.7 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--mute); }
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  .row-acts { justify-content: flex-start; }
  .masthead { padding-top: 3vh; }
}

.crumbs { margin-bottom: 30px; }
.h1 { font: 500 clamp(40px, 7vw, 64px)/1 var(--serif); margin: 0 0 40px; }
.step { margin-bottom: 40px; }
.options { display: grid; gap: 10px; }
.opt { all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: 1fr; gap: 4px; padding: 18px 20px 18px 46px; position: relative;
  border: 1px solid var(--line); border-radius: 12px; transition: background .2s, border-color .2s; }
.opt::before { content: ''; position: absolute; left: 18px; top: 25px; width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--mute); }
.opt[aria-checked="true"] { border-color: var(--mute); background: var(--faint); }
.opt[aria-checked="true"]::before { background: var(--ink); border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--bg); }
.opt:hover, .opt:focus-visible { background: var(--hover); }
.opt.has-poster { grid-template-columns: 1fr 168px; column-gap: 20px; }
.opt-title { font: 500 24px/1.15 var(--serif); }
.opt-title em { font-weight: 400; font-style: italic; color: var(--mute); font-size: .8em; margin-left: .35em; }
.opt-body { font: 400 17px/1.45 var(--serif); color: var(--ink); opacity: .86; }
.opt-meta { font: 400 10px/1.7 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); margin-top: 6px; }
.opt-meta .tag { border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.opt-poster { grid-column: 2; grid-row: 1 / span 3; width: 168px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #000; align-self: center; }
@media (max-width: 640px) { .opt.has-poster { grid-template-columns: 1fr; } .opt-poster { grid-column: 1; grid-row: auto; width: 100%; margin-top: 10px; } }
.begin-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; padding-top: 6px; }
.note { font: italic 400 17px/1.4 var(--serif); color: var(--mute); }

/* ---------- player: desktop = frame full-bleed with the text overlaying its bottom */
.player { position: fixed; inset: 0; overflow: hidden; background: var(--bg); cursor: default; }
/* the film frame stays within the contract's 4:3 .. 21:9 (docs/look-contract.md §6): letterboxed and centred when the
   window is taller than 4:3 (a portrait tablet) or wider than 21:9. At 16:10 and 16:9 it is the full window, as before */
.player .frame { position: absolute; inset: 0; margin: auto; overflow: hidden;
  width: min(100%, calc(100vh * 21 / 9)); height: min(100%, calc(100vw * 3 / 4)); }
@supports (height: 100dvh) { .player .frame { width: min(100%, calc(100dvh * 21 / 9)); } }
.player .stage { position: absolute; inset: 0; }
.hud { position: absolute; left: 16px; right: 16px; top: max(14px, env(safe-area-inset-top)); display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  font: 400 10.5px/1.6 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); z-index: 4; }
.hud .text-btn { padding: 0; }
.hud .where { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text { position: absolute; left: 50%; transform: translateX(-50%); bottom: max(26px, env(safe-area-inset-bottom)); width: min(720px, calc(100% - 32px)); text-align: center; z-index: 3; }
.text .caption { min-height: 2.9em; }
.hint { margin-top: 10px; font: 400 10px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute); opacity: 0; transition: opacity .6s; }
.hint.on { opacity: 1; }
.choices { list-style: none; margin: 16px auto 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-width: 560px; }
.choices button { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; display: block; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  font: italic 400 clamp(17px, 1.9vw, 21px)/1.35 var(--serif); color: var(--ink); background: var(--veil); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  text-align: left; transition: background .2s, border-color .2s; }
.choices button:hover, .choices button:focus-visible { background: var(--hover); border-color: var(--mute); }
.choices button .k { font: normal 400 10px var(--mono); color: var(--mute); margin-right: 10px; }
.choices button.saved { border-color: var(--ink); background: var(--hover); }
.choices button.saved::after { content: 'your line'; float: right; font: normal 400 9.5px/2.2 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute); margin-left: 10px; }
.choices.picker { max-width: 460px; }
form.free { margin: 14px auto 0; max-width: 560px; display: flex; gap: 8px; }
form.free input { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--veil); color: var(--ink); outline: none;
  font: italic 400 clamp(17px, 1.9vw, 20px)/1.3 var(--serif); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
form.free input:focus { border-color: var(--mute); }
form.free input::placeholder { color: var(--mute); }
form.free button { all: unset; cursor: pointer; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); font: 400 10.5px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink); background: var(--veil); }
form.free button:hover { background: var(--hover); }
.skip { all: unset; cursor: pointer; margin-top: 10px; display: inline-block; font: 400 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.skip:hover { color: var(--ink); }

.card { position: absolute; inset: 0; display: grid; place-items: center; z-index: 6; background: var(--veil); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 24px 16px; overflow-y: auto; }
.card .in { width: min(560px, 100%); text-align: center; color: var(--ink); }
.card h1 { font: 500 clamp(34px, 6vw, 64px)/1.02 var(--serif); margin: 0 0 14px; text-wrap: balance; }
.card p { font: italic 400 clamp(18px, 2vw, 22px)/1.45 var(--serif); margin: 0 0 22px; text-wrap: pretty; }
.card .small { font: 400 10.5px/1.7 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--mute); }
.card .support { font: normal 400 15.5px/1.55 var(--serif); border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }
.card .btns { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.card.is-support p { font-style: normal; font-size: clamp(19px, 2.1vw, 22px); }
.player .err { color: var(--warn); }

/* phone portrait: a 4:3 frame at full width, caption and controls below it */
@media (orientation: portrait) and (max-width: 820px) {
  .player { overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
  .hud { position: relative; left: auto; right: auto; top: auto; flex: none; padding: max(12px, env(safe-area-inset-top)) 16px 10px; }
  .player .frame { position: relative; inset: auto; margin: 0; flex: none; width: 100%; height: auto; aspect-ratio: 4 / 3; }
  .text { position: relative; left: auto; transform: none; bottom: auto; width: auto; flex: 1 0 auto; margin: 0; padding: 22px 16px max(28px, env(safe-area-inset-bottom)); text-align: left; }
  .text .caption { min-height: 4.4em; }
  .text .bt-cap-line { text-shadow: none; font-size: 21px; }
  .choices, form.free { margin-left: 0; margin-right: 0; max-width: none; }
  .choices button { backdrop-filter: none; -webkit-backdrop-filter: none; background: transparent; }
  .card { position: fixed; }
}

/* dialogs + toast (library) */
.dialog { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--veil); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); padding: 16px; }
.dialog .in { width: min(440px, 100%); border: 1px solid var(--line); border-radius: 14px; background: var(--bg); padding: 26px 24px 20px; }
.dialog h2 { font: 500 28px/1.1 var(--serif); margin: 0 0 10px; }
.dialog p { font: 400 17px/1.45 var(--serif); margin: 0 0 22px; color: var(--ink); opacity: .86; }
.dialog .btns { display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
.dialog .pill.danger:hover { border-color: var(--warn); color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); padding: 9px 16px; font: 400 10.5px/1.5 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink); }
.toast.is-error { color: var(--warn); }
.boot { position: fixed; inset: 0; display: grid; place-items: center; font: 400 10.5px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute); }
@media (prefers-reduced-motion: reduce) { :root, body, .player, .hint { transition: none; } }
