:root { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }

.theme-night {
  --bg: #0e1630;
  --ink: #f4eedf;
  --muted: #b9c1d8;
  --accent: #f5c873;
  --button: #f5c873;
  --button-ink: #1b1a2e;
  --line: rgba(244, 238, 223, .18);
  --choice-bg: #1b2549;
  --focus: #f5c873;
  --glow: rgba(245, 200, 115, .22);
  color-scheme: dark;
  background: radial-gradient(95% 85% at 15% 0, #243468, var(--bg));
}

body { color: var(--ink); font-family: Georgia, "Times New Roman", serif; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
h1:focus { outline: none; }

.reader { display: flex; flex-direction: column; width: min(100%, 1380px); height: 100vh; height: 100svh; margin-inline: auto; padding-inline: clamp(16px, 3vw, 38px); }

.topbar { display: flex; align-items: center; gap: 20px; min-height: 64px; border-bottom: 1px solid var(--line); font: 600 .93rem/1.3 system-ui, -apple-system, sans-serif; }
.home { flex: none; color: var(--accent); text-decoration: none; }
.home:hover { text-decoration: underline; text-underline-offset: 4px; }
.book-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.page-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.stage { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-block: 24px 32px; }
.page { display: grid; gap: clamp(26px, 3vw, 44px); animation: appear .45s ease both; }
.visual { position: relative; align-self: start; margin: 0; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 18px; background: var(--choice-bg); box-shadow: 0 22px 50px -32px rgba(0, 0, 0, .8); }
.visual img { display: block; width: 100%; height: 100%; object-fit: cover; }
.copy { max-width: 40em; }
.copy h1 { margin: 0 0 .6em; color: var(--accent); font-size: clamp(1.75rem, 2.6vw, 2.6rem); font-weight: 700; line-height: 1.14; text-wrap: balance; }
.copy p { margin: 0 0 .8em; padding: 2px 6px; margin-inline: -6px; border-radius: 8px; font-size: clamp(1.18rem, 1rem + .6vw, 1.45rem); line-height: 1.65; text-wrap: pretty; transition: background .25s ease, box-shadow .25s ease; }
.copy p.reading, .copy h1.reading { background: var(--glow); box-shadow: 0 0 0 4px var(--glow); }

.items { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; padding: 0; list-style: none; font: 600 .86rem/1.3 system-ui, -apple-system, sans-serif; }
.items li { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.items .icon { font-size: 1.1rem; line-height: 1; }

.choice-heading { margin-top: 1.1em; color: var(--accent); font: 700 1.05rem/1.3 system-ui, -apple-system, sans-serif; }
.choices { display: grid; gap: 12px; margin: 10px 0 20px; }
.choice { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 72px; padding: 9px 18px 9px 9px; border: 2px solid var(--line); border-radius: 20px; background: var(--choice-bg); color: var(--ink); text-align: left; cursor: pointer; font: 700 1.12rem/1.3 system-ui, -apple-system, sans-serif; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.choice .icon { flex: none; display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; background: var(--bg); font-size: 1.85rem; line-height: 1; }
.choice .label { padding-block: 2px; }
.choice:hover { transform: translateY(-2px); border-color: var(--accent); }
.choice:active { transform: scale(.985); }
.choice.reading { border-color: var(--accent); box-shadow: 0 0 0 4px var(--glow); }

.next { display: inline-flex; align-items: center; gap: 14px; min-height: 64px; margin-top: .8em; padding: 12px 22px 12px 26px; border: 0; border-radius: 999px; background: var(--button); color: var(--button-ink); cursor: pointer; font: 700 1.12rem/1.2 system-ui, -apple-system, sans-serif; box-shadow: 0 6px 0 rgba(0, 0, 0, .25); transition: transform .17s ease, box-shadow .17s ease; }
.next .icon { font-size: 1.4rem; line-height: 1; }
.next:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(0, 0, 0, .25); }
.next:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0, 0, 0, .25); }

.end { margin-block: 18px 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.end-title { color: var(--accent); font-size: clamp(1.6rem, 2.4vw, 2.2rem) !important; font-weight: 700; }
.end-note { color: var(--muted); font: 600 .95rem/1.5 system-ui, -apple-system, sans-serif; }
.again { display: inline-flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 22px 10px 14px; border: 2px solid var(--accent); border-radius: 999px; background: transparent; color: var(--accent); cursor: pointer; font: 700 1.05rem/1.2 system-ui, -apple-system, sans-serif; }
.again .icon { font-size: 1.5rem; line-height: 1; }
.again:hover { background: var(--choice-bg); }

.navigation { display: flex; align-items: center; gap: 14px; min-height: 86px; padding-block: 13px calc(13px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); font: 600 .95rem/1.3 system-ui, -apple-system, sans-serif; }
.back { min-height: 54px; padding: 12px 18px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer; font: 700 1rem/1.2 system-ui, -apple-system, sans-serif; }
.back:disabled { opacity: .35; cursor: default; }
.voice { display: inline-flex; align-items: center; gap: 10px; min-height: 54px; margin-left: auto; padding: 12px 22px; border: 2px solid var(--accent); border-radius: 999px; background: transparent; color: var(--accent); cursor: pointer; font: 700 1.05rem/1.2 system-ui, -apple-system, sans-serif; transition: background .18s ease, color .18s ease; }
.voice[aria-pressed="true"] { background: var(--accent); color: var(--button-ink); }
.voice.speaking { animation: pulse 1.6s ease-in-out infinite; }
.voice[hidden] { display: none; }

@keyframes appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--glow); } 50% { box-shadow: 0 0 0 8px transparent; } }

@media (min-width: 880px) and (orientation: landscape) {
  .page { min-height: 100%; grid-template-columns: minmax(0, 1.28fr) minmax(0, 1fr); align-items: start; }
  .visual { position: sticky; top: 24px; width: 100%; max-height: calc(100svh - 194px); }
  .copy { padding: 8px 12px 24px 0; }
}

@media (max-width: 640px) {
  .topbar { min-height: 54px; }
  .book-title { display: none; }
  .stage { padding-top: 16px; }
  .page { gap: 20px; }
  .copy h1 { font-size: 1.7rem; }
  .choice { font-size: 1.02rem; min-height: 66px; }
  .choice .icon { width: 48px; height: 48px; font-size: 1.6rem; }
  .navigation { min-height: 78px; gap: 10px; }
  .back { padding-inline: 14px; }
  .voice { padding-inline: 16px; font-size: .98rem; }
}

@media (prefers-reduced-motion: reduce) {
  .page { animation: none; }
  .voice.speaking { animation: none; }
  .choice, .next, .copy p { transition: none; }
}
