@font-face { font-family: 'Baloo 2'; src: url(fonts/baloo2.woff2) format('woff2'); font-weight: 400 800; font-display: swap; }
@font-face { font-family: 'Andika'; src: url(fonts/andika-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Andika'; src: url(fonts/andika-700.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --night: #1b1f52;
  --night-2: #2c2f7a;
  --paper: #fffaf0;
  --ink: #232a66;
  --sun: #ffd24d;
  --coral: #ff7a59;
  --display: 'Baloo 2', 'Trebuchet MS', 'Segoe UI', sans-serif;
  --body: 'Andika', 'Segoe UI', Verdana, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  font-family: var(--body); color: #fff;
  background: var(--bg, var(--night));
  transition: background-color .6s;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 64px; }
.bar-title { flex: 1; margin: 0; font: 800 1.25rem/1.1 var(--display); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; gap: 8px; margin-left: auto; }
.pill, .tog {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 2px solid rgba(255, 255, 255, .35); border-radius: 22px; background: rgba(255, 255, 255, .08);
  font-weight: 700; font-size: .95rem;
}
.pill svg, .tog svg, .round svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tog[aria-pressed="true"] { background: var(--sun); border-color: var(--sun); color: #2a2350; }
.tog .off { display: none; }
#tSound[aria-pressed="false"] .on { display: none; }
#tSound[aria-pressed="false"] .off { display: inline; }
.pill:hover, .tog:hover { border-color: #fff; }

/* ---------- shelf ---------- */
main { flex: 1; display: flex; flex-direction: column; }
#shelf {
  flex: 1; padding: 8px 20px 40px; text-align: center;
  background:
    radial-gradient(2px 2px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 82% 12%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 30% 8%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 64% 22%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 93% 34%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 5% 40%, #fff 50%, transparent 51%),
    linear-gradient(var(--night), var(--night-2));
}
h1 {
  margin: 0; font: 800 clamp(2.6rem, 8vw, 5.2rem)/.95 var(--display); letter-spacing: -.01em; color: var(--paper);
  text-shadow: 0 3px 0 var(--coral), 0 6px 0 #c2253a, 0 9px 0 rgba(0, 0, 0, .25);
}
.lede { margin: 18px auto 0; font-size: clamp(1.05rem, 2.2vw, 1.35rem); max-width: 34ch; color: #dcdcff; }
.books { display: grid; grid-template-columns: repeat(3, minmax(0, 300px)); justify-content: center; gap: clamp(18px, 4vw, 48px); margin: clamp(28px, 5vh, 56px) auto 28px; }
.book {
  position: relative; display: flex; flex-direction: column; padding: 0; border: 0; text-align: left;
  background: var(--paper); color: var(--ink); border-radius: 6px 18px 18px 6px;
  box-shadow: inset 12px 0 0 var(--ink), inset 15px 0 0 rgba(255, 255, 255, .35), 0 3px 0 #d9d2c0, 0 6px 0 #c2bba8, 0 22px 30px rgba(0, 0, 10, .45);
  rotate: var(--tilt); transition: rotate .25s, translate .25s;
  overflow: hidden;
}
.book:hover, .book:focus-visible { rotate: 0deg; translate: 0 -8px; }
.cover { display: block; aspect-ratio: 4 / 3.6; margin-left: 12px; overflow: hidden; }
.cover .scene { width: 100%; height: 100%; display: block; }
.label { display: block; padding: 14px 16px 6px 28px; }
.label .t { display: block; font: 800 1.45rem/1.05 var(--display); }
.label .p { display: block; margin-top: 6px; font-size: .92rem; opacity: .8; }
.progress { display: flex; align-items: center; gap: 4px; padding: 8px 16px 16px 28px; font-size: .82rem; }
.progress span { margin-left: 6px; opacity: .8; }
.medal { width: 22px; height: 22px; color: rgba(40, 40, 90, .22); flex: none; }
.medal.on { color: #f2a81d; }
.link { background: none; border: 0; padding: 12px; color: #dcdcff; text-decoration: underline; text-underline-offset: 4px; font-size: 1rem; }

/* ---------- reader ---------- */
#reader { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0 16px 12px; --sheet-h: min(calc(100dvh - 176px), calc((100vw - 32px) * .45)); }
.stage { display: grid; perspective: 3400px; width: fit-content; max-width: 100%; margin: auto; }
.sheet {
  grid-area: 1 / 1; display: grid; grid-template-columns: auto clamp(300px, 34vw, 500px);
  height: var(--sheet-h); background: var(--paper); color: var(--ink);
  border-radius: 10px 22px 22px 10px; overflow: hidden;
  box-shadow: 0 3px 0 rgba(255, 255, 255, .5), 0 7px 0 rgba(255, 255, 255, .25), 0 26px 40px rgba(0, 0, 0, .4);
  transform-origin: left center; backface-visibility: hidden; outline: none;
}
.pic { position: relative; height: 100%; aspect-ratio: 4 / 3; overflow: hidden; background: #cfe3e6; }
.scene { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.words {
  padding: clamp(18px, 2.2vw, 32px); overflow-y: auto; display: flex; flex-direction: column;
  font-size: clamp(.9rem, calc(var(--sheet-h) * .034), 1.5rem); line-height: 1.5;
  background: linear-gradient(90deg, rgba(0, 0, 0, .09), transparent 22px);
}
.words h2 { margin: 0 0 .5em; font: 800 1.7em/1 var(--display); color: var(--accent); outline: none; }
.words p { margin: 0 0 .55em; }
.tip { margin-top: .4em !important; padding: 10px 14px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 700; font-size: .9em; }
.ask { font: 800 1.2em/1.15 var(--display); margin-top: .3em !important; }
.choices { display: grid; gap: 12px; padding-bottom: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 6px; font-size: .85em; }
.choice, .btn {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 6px 16px 6px 8px; text-align: left;
  border: 0; border-radius: 18px; background: var(--accent, #7a5cd6); color: #fff; font: 800 1.05em/1.15 var(--display);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--accent, #7a5cd6) 60%, #000);
  transition: translate .1s, box-shadow .1s;
}
.choice:active, .btn:active { translate: 0 4px; box-shadow: 0 1px 0 color-mix(in srgb, var(--accent, #7a5cd6) 60%, #000); }
.choice svg { width: 46px; height: 46px; flex: none; background: rgba(0, 0, 0, .25); border-radius: 14px; }
.btn { padding: 6px 12px; justify-content: center; text-align: center; min-height: 50px; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2.5px currentColor; }
.btn.ghost:active { box-shadow: inset 0 0 0 2.5px currentColor; }
.theend { margin-top: auto; padding-top: .3em; display: grid; gap: 6px; }
.fin { font: 800 1.6em/1 var(--display); color: var(--accent); margin: 0 !important; }
.got { font-size: .88em; margin: 0 0 4px !important; }

.caption {
  position: absolute; left: 50%; top: 14px; translate: -50% -12px; margin: 0; max-width: 88%; width: max-content;
  padding: 10px 20px; border-radius: 22px; background: #fff; color: #232a66; text-align: center;
  font: 800 clamp(1rem, .7rem + .8vw, 1.35rem)/1.2 var(--display);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18); opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s;
}
.caption.show { opacity: 1; translate: -50% 0; }

/* ---------- page nav ---------- */
.nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(100%, 760px); padding-top: 14px; min-height: 86px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .16); display: grid; place-items: center; flex: none; }
.round svg { width: 32px; height: 32px; stroke-width: 3; }
.round.next { background: var(--sun); color: #2a2350; box-shadow: 0 5px 0 #c9971a; }
.round.next:active { translate: 0 4px; box-shadow: 0 1px 0 #c9971a; }
.round:disabled { opacity: .3; cursor: default; }
.round[hidden] { display: grid !important; visibility: hidden; }
.mid { display: grid; justify-items: center; gap: 6px; }
.dots { display: flex; gap: 7px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .28); }
.dots i.on { background: #fff; }
.finds { display: flex; align-items: center; gap: 3px; min-height: 44px; padding: 0 14px; border: 0; border-radius: 22px; background: rgba(255, 255, 255, .12); font-weight: 700; font-size: .95rem; }
.finds .medal { color: rgba(255, 255, 255, .3); }
.finds .medal.on { color: var(--sun); }
.finds span { margin-left: 6px; }

/* ---------- dialog ---------- */
dialog { max-width: min(640px, calc(100vw - 32px)); border: 0; border-radius: 22px; padding: 28px; color: var(--ink); background: var(--paper); font-size: 1.02rem; line-height: 1.55; }
dialog::backdrop { background: rgba(10, 10, 40, .7); }
dialog h2 { margin: 0 0 8px; font: 800 1.8rem/1 var(--display); }
dialog h3 { margin: 18px 0 2px; font: 800 1.15rem/1.1 var(--display); }
dialog p { margin: 0 0 10px; }
dialog form { display: flex; justify-content: flex-end; margin-top: 16px; }

/* ---------- page turning ---------- */
.turn-out { z-index: 2; animation: turn-out .85s ease-in-out forwards; }
.turn-in { z-index: 2; animation: turn-out .85s ease-in-out reverse both; }
@keyframes turn-out {
  0% { transform: rotateY(0); filter: brightness(1); }
  100% { transform: rotateY(-94deg); filter: brightness(.6); }
}

/* ---------- paper layers ---------- */
/* ponytail: one drop-shadow per layer (max 6); drop it first if a slow tablet stutters */
.layer { transform: translate(calc(var(--px, 0) * var(--z) * 3.500px), calc(var(--py, 0) * var(--z) * 1.500px)); transition: transform .5s cubic-bezier(.2, .8, .3, 1); }
.layer:not(:first-child) { filter: drop-shadow(0 4px 2px rgba(20, 20, 60, .28)); }
.cover .layer { filter: none; }
.pop { transform-origin: 400px 640px; animation: pop .75s cubic-bezier(.2, .9, .3, 1.25) both; animation-delay: calc(var(--i) * 110ms + 300ms); }
.layer:first-child .pop, .cover .pop { animation: none; }
@keyframes pop { from { transform: translateY(70px) scaleY(.55); opacity: 0; } }

/* ---------- things to find ---------- */
.find { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.find-in, .blink, .ripple, .flap, .flame, .boil, .fan, .spin-slow, .twinkle, .bob, .zzz { transform-box: fill-box; transform-origin: center; }
.find:focus-visible .find-in { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 7px #ffd24d) drop-shadow(0 0 2px #ffd24d); }
.find:hover .find-in { filter: brightness(1.08); }
.find.hint .find-in { animation: hint 1s ease 2; }
.find.go .find-in { animation: wiggle .8s ease; }
.find.go[data-anim="hop"] .find-in { animation-name: hop; }
.find.go[data-anim="jump"] .find-in { animation: jump 1s ease; }
.find.go[data-anim="spin"] .find-in { animation: spin .9s ease; }
.find.go[data-anim="shake"] .find-in { animation: shake .7s linear; }
.find.go[data-anim="pop"] .find-in, .find.go[data-anim="grow"] .find-in { animation: grow .8s ease; }
.find.go[data-anim="shrink"] .find-in { animation: shrink 1.2s ease; }
.find.go[data-anim="fly"] .find-in { animation: fly 1.6s ease; }
.find.go[data-anim="drop"] .find-in { animation: drop 1.6s ease-in; }
.find.go[data-anim="dance"] .find-in { animation: dance 1.6s ease; }
.find.go[data-anim="row"] .find-in { animation: row 1s ease; }
@keyframes hint { 50% { transform: scale(1.14); filter: drop-shadow(0 0 8px #fff); } }
@keyframes wiggle { 20% { transform: rotate(-7deg); } 40% { transform: rotate(7deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(4deg); } }
@keyframes hop { 30% { transform: translateY(-34px) scale(1.06, .96); } 55% { transform: translateY(0) scale(.96, 1.05); } 75% { transform: translateY(-12px); } }
@keyframes jump { 40% { transform: translateY(-90px) rotate(-30deg); } 80% { transform: translateY(6px) rotate(10deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 15% { transform: translateX(-9px); } 30% { transform: translateX(9px); } 45% { transform: translateX(-7px); } 60% { transform: translateX(7px); } 80% { transform: translateX(-3px); } }
@keyframes grow { 45% { transform: scale(1.35); } }
@keyframes shrink { 50% { transform: scale(.72); } }
@keyframes fly { 50% { transform: translate(60px, -60px); } }
@keyframes drop { 55% { transform: translateY(240px); opacity: 1; } 70% { transform: translateY(240px); opacity: 0; } 71% { transform: none; opacity: 0; } }
@keyframes dance { 15% { transform: rotate(-9deg) translateY(-12px); } 35% { transform: rotate(9deg); } 55% { transform: rotate(-9deg) translateY(-12px); } 75% { transform: rotate(9deg); } }
@keyframes row { 50% { transform: rotate(-22deg) translateX(-14px); } }

/* ---------- ambient motion ---------- */
.wave { animation: wave 5s ease-in-out infinite alternate; }
@keyframes wave { to { transform: translateX(34px); } }
.ripple { animation: ripple 2.4s ease-out infinite; }
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.rain { animation: rain 1.1s linear infinite; }
@keyframes rain { to { transform: translateY(600px); } }
.twinkle { animation: twinkle 3s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .25; transform: scale(.7); } }
.spin-slow { animation: spin 50s linear infinite; }
.sway { animation: sway 5s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-2.500deg); } to { transform: rotate(2.500deg); } }
.blink { animation: blink 4.500s infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
.bob { animation: bob 3.600s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-6px); } to { transform: translateY(6px); } }
.flap { animation: flap .5s ease-in-out infinite alternate; }
@keyframes flap { to { transform: scaleY(.3); } }
.oar { animation: oar 1s ease-in-out infinite alternate; }
@keyframes oar { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
.flame { transform-origin: center bottom; animation: flame .5s ease-in-out infinite alternate; }
@keyframes flame { to { transform: scale(.9, 1.12); } }
.glow { animation: twinkle 2.400s ease-in-out infinite; }
.boil { transform-origin: center bottom; animation: boil .7s ease-in-out infinite alternate; }
@keyframes boil { from { transform: scale(.9); } to { transform: scale(1.1) translateY(-4px); } }
.fan { transform-origin: center bottom; animation: fan 1.2s cubic-bezier(.2, .9, .3, 1.2) .9s both, sway 2.5s ease-in-out 2.1s infinite alternate; }
@keyframes fan { from { transform: scale(.1); } }
.zzz { animation: zzz 3s ease-in-out infinite; }
@keyframes zzz { from { opacity: 0; transform: translate(-10px, 14px) scale(.6); } 40% { opacity: 1; } to { opacity: 0; transform: translate(14px, -22px) scale(1.1); } }

.kloop { stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset 1s ease; }
.kloop.show { stroke-dashoffset: 0; }
.kborder { transition-duration: 2.200s; }

/* ---------- calm motion ---------- */
[data-motion="calm"] .scene *, [data-motion="calm"] .book { animation: none !important; transition: none !important; }
[data-motion="calm"] .layer { transform: none; }
[data-motion="calm"] .turn-out, [data-motion="calm"] .turn-in { animation: fade .25s linear forwards; }
[data-motion="calm"] .turn-in { animation-direction: reverse; }
@keyframes fade { to { opacity: 0; } }
[data-motion="calm"] .find.go .find-in, [data-motion="calm"] .find.hint .find-in { animation: flash .6s linear !important; }
@keyframes flash { 50% { opacity: .35; } }

/* ---------- small and tall screens ---------- */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .tog span, .pill span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tog, .pill { padding: 0 11px; }
  .bar-title { font-size: 1.05rem; text-align: left; }
  .books { grid-template-columns: minmax(0, 340px); }
  .book { rotate: 0deg; }
  #reader { padding-bottom: 100px; }
  .stage { width: 100%; max-width: 640px; margin-top: 0; }
  .sheet { grid-template-columns: 1fr; height: auto; border-radius: 18px; transform-origin: left top; }
  .pic { height: auto; width: 100%; }
  .words { overflow: visible; background: none; font-size: clamp(1.1rem, 4.4vw, 1.4rem); }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; width: 100%; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--ink) 88%, #000); z-index: 5; }
  .round { width: 56px; height: 56px; }
}
@media (min-width: 901px) and (max-height: 620px) {
  .words { font-size: 1rem; }
}
