:root { color-scheme: dark; }
body { margin: 0; background: var(--night); }
a { color: inherit; text-decoration: none; }
button, input, a { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button, input { font: inherit; }
:focus-visible { outline: 2px solid var(--paper); outline-offset: 3px; }
.reader-app { height: 100svh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
.topbar { display: flex; align-items: center; gap: 20px; width: min(1280px, 100%); margin: 0 auto; min-height: 60px; border-bottom: 1px solid var(--line); }
.back-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px; font-size: 14px; color: var(--muted); }
.series { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.series span { color: var(--muted); font: 11px ui-monospace, monospace; white-space: nowrap; }
.series h1 { margin: 0; font: 400 17px/1.5 var(--font-story); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar { margin-left: auto; }
.quiet-button, .nav-button { min-width: 44px; min-height: 44px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--paper); font: 14px/1.5 var(--font-ui); }
.quiet-button:hover:not(:disabled), .nav-button:hover:not(:disabled) { background: #ffffff0e; border-color: #ffffff70; }
.stage-wrap { min-width: 0; min-height: 0; display: flex; overflow: auto; overscroll-behavior: contain; padding: 16px 0; }
/* Hide the browser's text caret when caret browsing is enabled. */
.reader-stage { position: relative; flex-shrink: 0; margin: auto; width: min(100%, max(520px, calc((100dvh - 328px) * 16 / 9))); max-width: 1280px; background: #111; overflow: hidden; isolation: isolate; container-type: inline-size; cursor: pointer; caret-color: transparent; border: 1px solid #ffffff16; }
.art-frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #090909; }
.art { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 420ms ease, transform 1600ms ease; transform: scale(var(--zoom, 1)); transform-origin: var(--focus-x, 50%) var(--focus-y, 50%); }
.art.is-active { opacity: 1; }
/* Captions flow outside the artwork and grow with text or browser zoom. */
.caption { position: relative; min-height: 160px; padding: 24px clamp(20px, 4cqw, 48px); pointer-events: none; border-top: 1px solid #ffffff0c; }
.speaker { margin: 0 0 10px; color: #cbc8c1; font: 13px/1.5 var(--font-ui); }
.speaker:not(:empty)::before { content: ""; display: inline-block; width: 16px; height: 2px; margin-right: 10px; vertical-align: middle; background: #bcb8b0; transform: rotate(-7deg); }
.dialogue-text { margin: 0; min-height: 1.8em; font: 400 clamp(18px, 1.8cqw, 23px)/1.8 var(--font-story); word-break: keep-all; overflow-wrap: anywhere; }
.caption[data-voice="narration"] .dialogue-text { color: #d0cdc7; }
.reader-stage[data-kind="silent"]::before, .reader-stage[data-kind="blackout"]::before { content: ""; display: block; height: 160px; order: 2; }
.reader-stage[data-kind="silent"], .reader-stage[data-kind="blackout"] { display: flex; flex-direction: column; }
.reader-stage[data-kind="silent"] .art-frame, .reader-stage[data-kind="blackout"] .art-frame { flex-shrink: 0; }
.title-card { position: relative; z-index: 4; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: clamp(24px, 4cqw, 48px); background: #111; }
.title-card h2 { margin: 14px 0; font: 400 clamp(48px, 7cqw, 92px)/1.05 var(--font-brush); }
.title-card .eyebrow { margin: 0; }
.title-description { order: 3; max-width: 30em; margin: 20px 0 0; font: 15px/1.8 var(--font-story); color: #c4c1bb; word-break: keep-all; overflow-wrap: anywhere; }
.primary-button { position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center; gap: 24px; min-height: 48px; padding: 12px 24px; border: 0; background: transparent; color: #171717; font: 15px/1.5 var(--font-ui); }
.primary-button::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--paper); clip-path: polygon(2% 7%, 19% 3%, 43% 6%, 68% 0, 99% 5%, 97% 34%, 100% 66%, 98% 93%, 74% 96%, 48% 92%, 18% 100%, 0 95%, 2% 64%, 0 31%); }
.primary-button:hover::before { background: #fff; }
.resume-button { min-height: 44px; margin-top: 4px; padding: 10px 4px; border: 0; background: transparent; color: #c4c1bb; font-size: 14px; text-decoration: underline; text-underline-offset: 5px; }
.title-card #resume { order: 1; } .title-card #start { order: 2; } .title-card .read-hint { order: 4; }
.read-hint { margin: 16px 0 0; color: var(--muted); font: 12px/1.7 var(--font-ui); word-break: keep-all; }
.reader-footer { width: min(1280px, 100%); margin: 0 auto; padding: 10px 0 max(10px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--night); }
.navigation { display: grid; grid-template-columns: minmax(80px, 1fr) auto minmax(80px, 1fr); align-items: center; gap: 16px; max-width: 680px; margin: 0 auto; }
.nav-button { min-height: 48px; } #previous { justify-self: start; }
#next { justify-self: end; width: min(100%, 180px); border-color: var(--paper); background: var(--paper); color: #111; }
#next:hover:not(:disabled) { background: #fff; }
.counter { color: var(--muted); font: 12px ui-monospace, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reader-app[data-view="cover"], .reader-app[data-view="ended"] { grid-template-rows: auto minmax(0, 1fr); }
.reader-app[data-view="cover"] .reader-footer, .reader-app[data-view="ended"] .reader-footer { display: none; }
.settings-dialog { width: min(420px, calc(100% - 32px)); max-height: calc(100svh - 32px); max-height: calc(100dvh - 32px); margin: auto; padding: 24px; overflow: auto; border: 1px solid #ffffff40; border-radius: 4px; background: #161616; color: var(--paper); box-shadow: 0 24px 100px #000b; }
.settings-dialog::backdrop { background: #000b; }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.settings-heading h2 { margin: 0; font: 400 20px var(--font-story); }
.settings-options { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-options .quiet-button { flex: 1; white-space: nowrap; }
.settings-options [aria-pressed="true"] { border-color: var(--paper); }
.progress-area { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.progress-label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 14px; }
.scene-label { color: var(--muted); }
.progress { display: block; width: 100%; min-height: 44px; margin: 8px 0 0; accent-color: var(--paper); cursor: pointer; }
.settings-dialog .read-hint { margin-top: 20px; }
.end-card, .error-state { position: relative; z-index: 9; display: flex; align-items: center; justify-content: center; flex-direction: column; min-height: min(480px, 60svh); padding: 24px; background: #090909; text-align: center; }
.end-card h2 { margin: 20px 0 28px; font: 400 clamp(48px, 7cqw, 92px)/1.1 var(--font-brush); }
.end-actions { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.end-card .back-link { margin-top: 20px; }
.error-state p { color: var(--muted); font-size: 15px; line-height: 1.8; }
.is-ended .art-frame, .reader-stage[data-phase="error"] .art-frame { display: none; }
.reader-stage::after { content: ""; position: absolute; inset: 0; z-index: 8; background: #000; opacity: 0; pointer-events: none; transition: opacity 500ms ease; }
/* Keep the artwork overlay mounted so both sides of a blackout fade smoothly. */
.art-frame::after { content: ""; position: absolute; inset: 0; z-index: 8; background: #000; opacity: 0; pointer-events: none; transition: opacity 1200ms ease-in-out; }
.is-blackout .art-frame::after { opacity: 1; }
.is-ending .reader-stage::after { opacity: 1; }
.is-ending { background: #000; }
.is-ending::before { display: none; }
.is-ending .reader-stage { border-color: transparent; }
.is-ending .topbar, .is-ending .reader-footer { visibility: hidden; }
.is-ended .topbar { visibility: visible; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (max-width: 680px) {
  .reader-app { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
  .topbar { gap: 14px; } .series { gap: 6px; } .series h1 { font-size: 15px; } .series span { font-size: 10px; }
  .toolbar .quiet-button { padding-inline: 12px; } .caption { padding: 22px 20px; }
  .title-card { position: relative; padding: 24px; background: #111; }
  .title-description { font-size: 14px; } .navigation { gap: 12px; }
}
@media (max-width: 680px) and (orientation: portrait) { .reader-stage { margin-block: 0 auto; } }
@media (min-width: 900px) {
  .reader-app[data-view="cover"] .reader-stage { width: 100%; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: center; }
  .reader-app[data-view="cover"] .art-frame { grid-column: 1; grid-row: 1; }
  .reader-app[data-view="cover"] .title-card { grid-column: 2; grid-row: 1; }
  .reader-app[data-view="cover"] .error-state { grid-column: 1 / -1; }
  .title-card h2 { font-size: clamp(48px, 5cqw, 72px); }
}
/* Short, wide screens use separate columns. Content can scroll while navigation
   stays reachable, including when the browser is zoomed in. */
@media (min-width: 560px) and (max-height: 600px) and (min-aspect-ratio: 6/5) {
  .topbar { min-height: 52px; } .stage-wrap { padding-block: 8px; }
  .reader-stage, .reader-stage[data-kind="silent"], .reader-stage[data-kind="blackout"] { width: 100%; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: center; }
  .art-frame { grid-column: 1; grid-row: 1; }
  .caption, .title-card { position: relative; grid-column: 2; grid-row: 1; min-height: 0; padding: 16px 20px; border: 0; background: #111; }
  .dialogue-text { font-size: 18px; line-height: 1.75; } .speaker { margin-bottom: 8px; }
  .title-card h2 { font-size: 48px; margin: 8px 0 12px; }
  .title-description, .title-card .read-hint, .reader-stage[data-kind="silent"]::before, .reader-stage[data-kind="blackout"]::before { display: none; }
  .title-card .eyebrow { font-size: 10px; letter-spacing: .1em; }
  .end-card, .error-state { grid-column: 1 / -1; min-height: 0; }
  .end-card h2 { margin: 12px 0 16px; font-size: 48px; } .end-card .back-link { margin-top: 8px; }
  .reader-footer { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom, 0px)); } .nav-button { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; } .art { transform: none; } }
