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

.theme-forest {
  --bg: #f1eadb;
  --ink: #25392d;
  --muted: #58685d;
  --accent: #b75a30;
  --button: #28624e;
  --button-ink: #fff8e8;
  --line: rgba(37, 57, 45, .18);
  --choice-bg: #e8dfcd;
  --focus: #b75a30;
  color-scheme: light;
  background: radial-gradient(95% 85% at 15% 0, #f8f1e4, var(--bg));
}

.theme-sea {
  --bg: #092b39;
  --ink: #f4f0e6;
  --muted: #bfd1d1;
  --accent: #ffbb8c;
  --button: #f4d5a6;
  --button-ink: #103544;
  --line: rgba(244, 240, 230, .2);
  --choice-bg: #174554;
  --focus: #ffbb8c;
  color-scheme: dark;
  background: radial-gradient(95% 85% at 15% 0, #155264, var(--bg));
}

.theme-garden {
  --bg: #f4ecdc;
  --ink: #2c3326;
  --muted: #5f6a58;
  --accent: #c2362f;
  --button: #2f6b45;
  --button-ink: #fff8e8;
  --line: rgba(44, 51, 38, .18);
  --choice-bg: #eae0cb;
  --focus: #c2362f;
  color-scheme: light;
  background: radial-gradient(95% 85% at 15% 0, #faf4e8, var(--bg));
}

.theme-storm {
  --bg: #1c2633;
  --ink: #eef1f4;
  --muted: #aebccb;
  --accent: #f3c55a;
  --button: #f3c55a;
  --button-ink: #1c2633;
  --line: rgba(238, 241, 244, .18);
  --choice-bg: #2a3747;
  --focus: #f3c55a;
  color-scheme: dark;
  background: radial-gradient(95% 85% at 15% 0, #334559, 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; }

.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); }
.progress { display: flex; gap: 6px; margin-left: auto; }
.progress i { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--line); }
.progress i.done { background: var(--accent); }

.stage { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; 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, .55); }
.visual img { display: block; width: 100%; height: 100%; object-fit: cover; }
.copy { max-width: 40em; }
.copy h1 { margin: 0 0 .7em; color: var(--accent); font-size: clamp(1.65rem, 2.4vw, 2.45rem); font-weight: 700; line-height: 1.16; text-wrap: balance; }
.copy p { margin: 0 0 .85em; font-size: clamp(1.09rem, .94rem + .48vw, 1.29rem); line-height: 1.65; text-wrap: pretty; }
.copy .cue { margin-top: 1.2em; color: var(--muted); font-style: italic; }
.copy .question { margin-top: 1.2em; color: var(--accent); font-weight: 700; }

.action { min-height: 54px; margin: 4px 0 20px; padding: 14px 22px; border: 0; border-radius: 999px; background: var(--button); color: var(--button-ink); cursor: pointer; font: 700 1rem/1.2 system-ui, -apple-system, sans-serif; box-shadow: 0 6px 0 rgba(0, 0, 0, .17); transition: transform .17s ease, box-shadow .17s ease; }
.action:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(0, 0, 0, .17); }
.action:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0, 0, 0, .17); }

.choice-heading { margin: 1.4em 0 12px; color: var(--accent); font: 700 .8rem/1.3 system-ui, -apple-system, sans-serif; letter-spacing: .08em; }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.choice { min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--choice-bg); color: var(--ink); text-align: left; cursor: pointer; font: 700 .96rem/1.35 system-ui, -apple-system, sans-serif; transition: transform .18s ease, border-color .18s ease; }
.choice:hover { transform: translateY(-3px); border-color: var(--accent); }
.choice img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 9px; margin-bottom: 9px; }
.choice span { display: block; padding: 2px 3px 4px; }

.end { margin-block: 18px 24px; padding-top: 18px; border-top: 1px solid var(--line); font: 600 1rem/1.5 system-ui, -apple-system, sans-serif; }
.end p { font: inherit; color: var(--muted); }
.again { min-height: 48px; padding: 10px 18px; border: 1px solid var(--accent); border-radius: 999px; background: transparent; color: var(--accent); cursor: pointer; font: 700 .95rem/1.2 system-ui, -apple-system, sans-serif; }
.again:hover { background: var(--choice-bg); }

.navigation { display: flex; align-items: center; gap: 14px; min-height: 82px; padding-block: 13px calc(13px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); font: 600 .92rem/1.3 system-ui, -apple-system, sans-serif; }
.back { width: 52px; height: 52px; flex: none; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; font-size: 1.5rem; }
.back:disabled { opacity: .35; cursor: default; }
.page-count { margin-right: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.next { display: inline-flex; align-items: center; gap: 12px; min-height: 52px; padding: 12px 20px; border: 0; border-radius: 999px; background: var(--button); color: var(--button-ink); cursor: pointer; font: 700 1rem/1.2 system-ui, -apple-system, sans-serif; }
.next:hover { filter: brightness(1.08); }
.next[hidden] { display: none; }

.bubble { position: absolute; bottom: 4%; z-index: 2; width: 11%; aspect-ratio: 1; border: 2px solid rgba(255, 255, 255, .8); border-radius: 50%; background: radial-gradient(circle at 28% 25%, rgba(255,255,255,.65), transparent 30%), radial-gradient(circle at 80% 75%, rgba(250,174,180,.6), transparent 40%), rgba(188,233,230,.2); box-shadow: inset -4px -6px 14px rgba(80,155,180,.3), 0 0 18px rgba(255,255,255,.35); pointer-events: none; animation: float-up 2.2s ease-out both; }
.page.still { animation: none; }
.visual img.fresh { animation: reveal .7s ease both; }
.visual.follows { touch-action: none; cursor: crosshair; }
.visual img { transition: filter 1.4s ease; }
.visual.is-dark img { filter: brightness(.16) saturate(.5); }

.lens { position: absolute; top: 0; left: 0; z-index: 2; width: 38%; aspect-ratio: 1; border: 7px solid #3d2a1c; border-radius: 50%; background-repeat: no-repeat; box-shadow: 0 0 0 3px rgba(255, 255, 255, .55), 0 14px 30px rgba(0, 0, 0, .45); pointer-events: none; }
.torch { position: absolute; inset: 0; z-index: 2; background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255, 230, 160, .08) 0, rgba(255, 230, 160, .04) 11%, rgba(4, 8, 20, .93) 19%, rgba(3, 6, 16, .97) 100%); pointer-events: none; animation: reveal .5s ease both; }
.stamp { position: absolute; right: 5%; bottom: 8%; z-index: 2; padding: .18em .5em; border: .12em solid #c2362f; border-radius: .18em; color: #c2362f; background: rgba(255, 248, 232, .55); font: 800 clamp(1.8rem, 6vw, 4.2rem)/1 system-ui, -apple-system, sans-serif; letter-spacing: .08em; transform: rotate(-12deg); mix-blend-mode: multiply; pointer-events: none; animation: slam .45s cubic-bezier(.2, 1.6, .4, 1) both; }
.pop { position: absolute; top: 38%; left: 50%; z-index: 3; color: #fff8e8; font: 800 clamp(2rem, 7vw, 4.6rem)/1 system-ui, -apple-system, sans-serif; letter-spacing: .02em; text-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 0 22px rgba(0, 0, 0, .5); white-space: nowrap; pointer-events: none; animation: pop-up 1.5s ease-out both; }

.flash { position: absolute; inset: 0; z-index: 3; background: #fff; pointer-events: none; animation: flash .7s ease-out both; }
.counter { position: absolute; top: 5%; right: 4%; z-index: 3; display: grid; place-items: center; width: clamp(72px, 19%, 150px); aspect-ratio: 1; border-radius: 50%; background: rgba(20, 28, 40, .74); color: #fff8e8; font: 800 clamp(2.3rem, 8vw, 4.8rem)/1 system-ui, -apple-system, sans-serif; font-variant-numeric: tabular-nums; pointer-events: none; }
.counter.tick { animation: tick .35s ease-out; }
.visual.shake { animation: shake .5s ease-in-out; }
.action:disabled { opacity: .55; cursor: default; transform: none; }

@keyframes flash { 0% { opacity: 0; } 8% { opacity: .95; } 18% { opacity: .15; } 26% { opacity: .8; } 100% { opacity: 0; } }
@keyframes tick { from { transform: scale(1.35); } to { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translate(-6px, 3px); } 40% { transform: translate(5px, -4px); } 60% { transform: translate(-4px, 2px); } 80% { transform: translate(3px, -1px); } }
@keyframes reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes slam { from { opacity: 0; transform: rotate(-12deg) scale(2.4); } to { opacity: 1; transform: rotate(-12deg) scale(1); } }
@keyframes pop-up { from { opacity: 0; transform: translate(-50%, 20px) scale(.6); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); } 70% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -40px) scale(1); } }
@keyframes float-up { from { opacity: 0; transform: translateY(35px) scale(.6); } 18% { opacity: 1; } to { opacity: 0; transform: translateY(-260px) translateX(18px) scale(1.3); } }
@keyframes appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@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; }
  .progress { gap: 5px; }
  .progress i { width: 6px; height: 6px; }
  .stage { padding-top: 16px; }
  .page { gap: 20px; }
  .copy h1 { font-size: 1.6rem; }
  .choice { font-size: .86rem; }
  .navigation { min-height: 74px; }
  .page-count { font-size: .8rem; }
  .next { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage { scroll-behavior: auto; }
  .page, .bubble, .visual img.fresh, .torch, .stamp, .flash, .counter.tick { animation: none; }
  .pop { animation: none; transform: translateX(-50%); }
  .visual img { transition: none; }
  .action, .choice { transition: none; }
}
