/* Baby Talk Stories - app styles. Same design system as Baby Talk First Words:
   cream canvas, coral accent, big rounded cards, Fredoka for the words children
   see, Nunito for grown-up text. The reader adds a scene stage with lightly
   animated emoji actors and a story text panel with tappable words. */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/fredoka-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/nunito-latin.woff2') format('woff2');
}

:root {
  --canvas: #FFF8EE;
  --card: #FFFFFF;
  --ink: #2B2440;
  --muted: #6E6A80;
  --line: #EFE6DA;
  --primary: #FF6B6B;
  --primary-dark: #E85555;
  --sun: #FFD166;
  --sky: #4ECDC4;
  --lav: #A78BFA;
  --radius: 28px;
  --radius-sm: 18px;
  --shadow: 0 6px 0 rgba(43, 36, 64, .06), 0 14px 32px rgba(43, 36, 64, .10);
  --shadow-press: 0 2px 0 rgba(43, 36, 64, .06), 0 6px 14px rgba(43, 36, 64, .10);
  --display: 'Fredoka', 'Segoe UI Rounded', system-ui, -apple-system, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --top-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; padding-right: 12px;
  background: rgba(255, 248, 238, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--ink);
  font-family: var(--display); font-weight: 600; font-size: 24px;
  padding: 4px 8px 4px 4px; border-radius: 16px;
}
.brand .mark { width: 40px; height: 40px; background: var(--primary); border-radius: 14px; padding: 3px; flex: none; }
.brand-t { display: flex; flex-direction: column; line-height: 1; white-space: nowrap; }
.brand-t small { font-size: 11px; font-weight: 600; color: var(--primary-dark); letter-spacing: .12em; text-transform: uppercase; margin-top: 3px; }
.title {
  margin: 0; flex: 1; min-width: 0;
  font-family: var(--display); font-weight: 600; font-size: 22px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title small { display: block; font-size: 14px; font-weight: 500; color: var(--muted); line-height: 1.1; }
.tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.iconbtn {
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); box-shadow: var(--shadow-press); color: var(--ink);
  transition: transform .12s ease;
}
.iconbtn svg { width: 24px; height: 24px; }
.iconbtn:active { transform: scale(.92); }

/* ---- views ---- */
.view { padding: 16px 16px calc(24px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }
.loading { text-align: center; padding: 60px 20px; color: var(--muted); font-family: var(--display); font-size: 22px; }

/* ---- shelf (home) ---- */
.shelf-head { margin: 4px 4px 14px; }
.shelf-head h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; }
.shelf-head p { margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.shelf {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
@media (max-width: 380px) { .shelf { grid-template-columns: repeat(2, 1fr); gap: 10px; } .book { aspect-ratio: 1 / 1.34; } }
@media (min-width: 700px) { .shelf { gap: 18px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
.book {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px;
  aspect-ratio: 1 / 1.22;
  padding: 12px 10px 14px;
  border-radius: var(--radius);
  background: var(--tint, var(--card));
  box-shadow: var(--shadow);
  text-align: center; color: var(--ink); text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease;
  -webkit-user-select: none; user-select: none;
  overflow: hidden;
}
.book:active { transform: scale(.96); box-shadow: var(--shadow-press); }
/* the hero sits in the flex column above the text and shrinks when a two-line
   title and subtitle need the room (narrow phones), so they never overlap */
.book .hero { position: relative; flex: 0 1 auto; min-height: 0; width: 52%; aspect-ratio: 1; margin: 6% 0 auto; pointer-events: none; }
.book .hero img { width: 100%; height: 100%; object-fit: contain; }
.book .hero.two img:first-child { position: absolute; left: -22%; top: 10%; width: 78%; }
.book .hero.two img:last-child { position: absolute; right: -22%; top: 0; width: 78%; }
.book .l1, .book .l2 { font-family: var(--display); line-height: 1.15; max-width: 100%; overflow-wrap: anywhere; }
.book .l1 { font-weight: 600; font-size: clamp(17px, 4.6vw, 21px); }
.book .l2 { font-weight: 500; font-size: clamp(14px, 3.8vw, 16px); color: rgba(43, 36, 64, .62); }
.book .meta { font-size: 12px; font-weight: 700; color: rgba(43, 36, 64, .55); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.book .lock {
  position: absolute; top: 10px; right: 10px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px; border-radius: 999px; background: var(--ink); color: var(--sun);
  font-size: 11px; font-weight: 800; letter-spacing: .06em;
}
.book .lock svg { width: 12px; height: 12px; }
.book.locked .hero { filter: saturate(.55); opacity: .75; }
.book .saved { position: absolute; top: 12px; left: 12px; width: 22px; height: 22px; border-radius: 50%; background: var(--sky); color: #fff; display: flex; align-items: center; justify-content: center; }
.book .saved svg { width: 14px; height: 14px; }

/* ---- scene stage ---- */
.scene {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 100%);
  box-shadow: var(--shadow);
  -webkit-user-select: none; user-select: none;
  touch-action: pan-y;
  --sky1: #BDE8FF; --sky2: #E9F7FF; --gnd1: #9BD77A; --gnd2: #6FBF5A; --gnd-h: 34%;
}
.scene .ground {
  position: absolute; left: -10%; right: -10%; bottom: 0; height: var(--gnd-h);
  background: linear-gradient(180deg, var(--gnd1), var(--gnd2));
  border-radius: 50% 50% 0 0 / 28% 28% 0 0;
}
.scene.flat .ground { border-radius: 0; left: 0; right: 0; }
.scene .actors, .scene .fx { position: absolute; inset: 0; }
.scene .fx { pointer-events: none; overflow: hidden; }
.actor {
  position: absolute; transform: translate(-50%, -50%);
  width: 16%; aspect-ratio: 1;
}
.actor.tap { cursor: pointer; }
.actor-in { width: 100%; height: 100%; will-change: transform; }
.actor img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.actor img.flip { transform: scaleX(-1); }
/* a soft contact shadow under everything that stands on the ground */
.actor::after {
  content: ""; position: absolute; left: 14%; right: 14%; bottom: -2%; height: 11%; border-radius: 50%; z-index: -1;
  background: radial-gradient(ellipse at center, rgba(43, 36, 64, .22), rgba(43, 36, 64, 0) 70%);
}
.actor.noshadow::after { display: none; }
/* actors pop into the scene one after another when a page opens */
.actor.in { animation: actorEnter .55s cubic-bezier(.2, .9, .3, 1.25) both; }
@keyframes actorEnter {
  from { transform: translate(-50%, -50%) scale(.2); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.actor.pop { animation: actorPop .5s ease; }
@keyframes actorPop {
  0% { transform: translate(-50%, -50%) scale(1); }
  35% { transform: translate(-50%, -50%) scale(1.22) rotate(-4deg); }
  70% { transform: translate(-50%, -50%) scale(.97) rotate(2deg); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
/* tapping an actor: it says its word in a little bubble and throws sparkles */
.actor .say {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -6px);
  background: #fff; color: var(--ink); font-family: var(--display); font-weight: 600;
  font-size: clamp(13px, 2.8vw, 19px); line-height: 1.2; padding: 4px 11px; border-radius: 999px; white-space: nowrap;
  box-shadow: var(--shadow-press); pointer-events: none; z-index: 5;
  animation: sayIn 1.5s ease both;
}
.actor .say::after { content: ""; position: absolute; left: 50%; top: 100%; width: 9px; height: 9px; background: #fff; transform: translate(-50%, -5px) rotate(45deg); }
@keyframes sayIn {
  0% { opacity: 0; transform: translate(-50%, 4px) scale(.6); }
  14% { opacity: 1; transform: translate(-50%, -6px) scale(1.04); }
  22% { transform: translate(-50%, -6px) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -6px); }
  100% { opacity: 0; transform: translate(-50%, -16px); }
}
.actor .burst {
  position: absolute; left: 50%; top: 50%; width: 12%; aspect-ratio: 1; pointer-events: none;
  background: var(--sun); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: burst .65s ease-out both;
}
@keyframes burst {
  from { transform: translate(-50%, -50%) scale(.6); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0); opacity: 0; }
}

/* backgrounds */
.bg-meadow { --sky1: #A8DDFF; --sky2: #E8F6FF; --gnd1: #A3DC7E; --gnd2: #72C061; }
.bg-hill { --sky1: #A8DDFF; --sky2: #EAF7FF; --gnd1: #9FD87A; --gnd2: #5FB24E; --gnd-h: 52%; }
.bg-forest { --sky1: #9ED3B3; --sky2: #E3F4E6; --gnd1: #7FBF66; --gnd2: #4E9A44; --gnd-h: 38%; }
.bg-farm { --sky1: #BFE3FF; --sky2: #FFF4D6; --gnd1: #D7C27A; --gnd2: #B99A4F; --gnd-h: 36%; }
.bg-sunset { --sky1: #FFB37A; --sky2: #FFE2B5; --gnd1: #C9B06A; --gnd2: #9A7F3F; --gnd-h: 36%; }
.bg-night { --sky1: #2B2A5C; --sky2: #4A4A8C; --gnd1: #3E6B4C; --gnd2: #2C4D36; --gnd-h: 34%; }
.bg-road { --sky1: #A8DDFF; --sky2: #E8F6FF; --gnd1: #8E8E9A; --gnd2: #6E6E7A; --gnd-h: 30%; }
.bg-road .ground { border-radius: 0; left: 0; right: 0; }
.bg-road .ground::after { content: ""; position: absolute; left: 0; right: 0; top: 48%; height: 6%; background: repeating-linear-gradient(90deg, #FFF 0 8%, transparent 8% 16%); opacity: .8; }
.bg-park { --sky1: #A8DDFF; --sky2: #E8F6FF; --gnd1: #9BDB7A; --gnd2: #63B853; --gnd-h: 40%; }
.bg-beach { --sky1: #9ED9FF; --sky2: #E6F6FF; --gnd1: #F6E2A8; --gnd2: #E8CD83; --gnd-h: 30%; }
.bg-beach .ground::before { content: ""; position: absolute; left: 0; right: 0; top: -36%; height: 36%; background: linear-gradient(180deg, #5FC4E8, #8FD9F4); border-radius: 0; }
.bg-beach .ground { border-radius: 0; left: 0; right: 0; }
.bg-room { --sky1: #FFE9D6; --sky2: #FFF4E8; --gnd1: #D9A878; --gnd2: #C08C5C; --gnd-h: 32%; }
.bg-room .ground { border-radius: 0; left: 0; right: 0; }
.bg-kitchen { --sky1: #E6F3F1; --sky2: #FFFFFF; --gnd1: #E0C9A8; --gnd2: #C6A880; --gnd-h: 32%; }
.bg-kitchen .ground { border-radius: 0; left: 0; right: 0; }
.bg-bedroom { --sky1: #3F3A7A; --sky2: #6B5FB0; --gnd1: #8E6CC7; --gnd2: #6F52A6; --gnd-h: 32%; }
.bg-bedroom .ground { border-radius: 0; left: 0; right: 0; }
.bg-bathroom { --sky1: #D6F1FF; --sky2: #F2FBFF; --gnd1: #BFE6F5; --gnd2: #93D0EA; --gnd-h: 32%; }
.bg-bathroom .ground { border-radius: 0; left: 0; right: 0; }
.bg-bathroom .ground::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, rgba(255,255,255,.35) 0 12%, transparent 12% 12.6%), repeating-linear-gradient(0deg, rgba(255,255,255,.35) 0 30%, transparent 30% 31.5%); }
.bg-rain { --sky1: #8FA3B8; --sky2: #CFD9E2; --gnd1: #8FC97A; --gnd2: #5FAE52; --gnd-h: 40%; }
.bg-rainbow { --sky1: #B5E3FF; --sky2: #F2FBFF; --gnd1: #9BDB7A; --gnd2: #63B853; --gnd-h: 40%; }

/* effects */
.fx span { position: absolute; display: block; }
.fx .star { width: 2.2%; aspect-ratio: 1; border-radius: 50%; background: #FFF6C2; box-shadow: 0 0 6px #FFF6C2; animation: twinkle 2.4s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .25; transform: scale(.7); } 50% { opacity: 1; transform: scale(1.15); } }
.fx .drop { width: .8%; height: 5%; border-radius: 999px; background: rgba(255,255,255,.75); animation: fall 1.1s linear infinite; }
@keyframes fall { from { transform: translateY(-20%); opacity: 0; } 15% { opacity: 1; } to { transform: translateY(2600%); opacity: .4; } }
.fx .bub { aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255,255,255,.9); background: radial-gradient(circle at 35% 35%, rgba(255,255,255,.9), rgba(255,255,255,.1) 60%); animation: rise 4s ease-in infinite; }
@keyframes rise { from { transform: translateY(0) scale(.7); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(-900%) scale(1.1); opacity: 0; } }
.fx .zz { font-family: var(--display); font-weight: 700; color: rgba(255,255,255,.95); font-size: clamp(14px, 4vw, 26px); animation: drift 3s ease-out infinite; }
@keyframes drift { from { transform: translate(0, 0) scale(.6); opacity: 0; } 25% { opacity: 1; } to { transform: translate(60%, -260%) scale(1.2); opacity: 0; } }
.fx .heart { width: 4%; aspect-ratio: 1; background: #FF8FA3; clip-path: path('M12 21s-7-4.6-9.5-9C.6 8.4 2.6 4 6.5 4c2 0 3.6 1.2 5.5 3 1.9-1.8 3.5-3 5.5-3 3.9 0 5.9 4.4 4 8-2.5 4.4-9.5 9-9.5 9z'); animation: rise 3.2s ease-in infinite; }
.fx .sunray { left: 50%; top: 50%; width: 180%; aspect-ratio: 1; margin: -90% 0 0 -90%; background: repeating-conic-gradient(rgba(255,255,255,.18) 0 6deg, transparent 6deg 18deg); animation: spin 48s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* ambient life: clouds, birds, butterflies, grass, fireflies, smoke, waves, leaves, sparkles, splashes */
.fx .cloud { height: 7%; aspect-ratio: 2.8 / 1; border-radius: 999px; background: rgba(255, 255, 255, .88); }
.fx .cloud::before, .fx .cloud::after { content: ""; position: absolute; bottom: 36%; border-radius: 50%; background: inherit; aspect-ratio: 1; }
.fx .cloud::before { left: 14%; width: 46%; }
.fx .cloud::after { left: 44%; width: 58%; bottom: 40%; }
.bg-sunset .fx .cloud { background: rgba(255, 236, 214, .9); }
.bg-rain .fx .cloud { background: rgba(236, 240, 245, .85); }
.bg-night .fx .cloud, .bg-bedroom .fx .cloud { background: rgba(255, 255, 255, .14); }
.fx .bird { width: 4.2%; aspect-ratio: 2 / 1; }
.fx .bird svg { width: 100%; height: 100%; display: block; animation: flap .5s ease-in-out infinite alternate; transform-origin: 50% 70%; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(.45); } }
.fx .fly { width: 6%; aspect-ratio: 1; }
.fx .fly img { width: 100%; height: 100%; display: block; animation: flapX .28s ease-in-out infinite alternate; }
@keyframes flapX { from { transform: scaleX(1); } to { transform: scaleX(.55); } }
.fx .firefly { width: 1.5%; aspect-ratio: 1; border-radius: 50%; background: #F6FF9A; box-shadow: 0 0 8px 2px rgba(246, 255, 154, .8); animation: blink 2.2s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: .15; } 50% { opacity: 1; } }
.fx .puff { width: 5%; aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .6); animation: puffUp 3.2s ease-out infinite; }
.fx .puff.smoke { background: rgba(130, 128, 140, .4); }
.fx .puff.dust { background: rgba(190, 170, 130, .45); }
@keyframes puffUp { 0% { transform: translate(0, 0) scale(.5); opacity: 0; } 18% { opacity: .9; } 100% { transform: translate(40%, -520%) scale(1.9); opacity: 0; } }
.fx .wave { left: -12%; width: 124%; height: 5%; border-radius: 50%; background: rgba(255, 255, 255, .32); }
.fx .tuft { width: 3.2%; aspect-ratio: 1; background: var(--tuft, #5FAE52); clip-path: polygon(50% 0, 62% 55%, 82% 18%, 76% 70%, 100% 50%, 86% 100%, 14% 100%, 0 56%, 24% 68%, 20% 20%, 40% 58%); transform-origin: 50% 100%; animation: sway 2.4s ease-in-out infinite; }
.bg-farm { --tuft: #9A8140; } .bg-sunset { --tuft: #7A6630; } .bg-night { --tuft: #2C4D36; } .bg-forest { --tuft: #3F8A38; } .bg-hill { --tuft: #4FA442; }
.fx .leaf { width: 4%; aspect-ratio: 1; animation: leafFall linear infinite; }
.fx .leaf img { width: 100%; height: 100%; display: block; }
@keyframes leafFall { 0% { transform: translate(0, -120%) rotate(0deg); opacity: 0; } 8% { opacity: 1; } 50% { transform: translate(180%, 1100%) rotate(200deg); } 100% { transform: translate(-60%, 2400%) rotate(380deg); opacity: .6; } }
.fx .spark { width: 3%; aspect-ratio: 1; background: #FFF6C2; clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%); animation: sparkle 1.8s ease-in-out infinite; }
@keyframes sparkle { 0%, 100% { transform: scale(0) rotate(0); opacity: 0; } 50% { transform: scale(1) rotate(45deg); opacity: 1; } }
.fx .splashdrop { width: 1.6%; aspect-ratio: 1; border-radius: 50% 50% 50% 0; background: rgba(255, 255, 255, .9); animation: jump 1.3s ease-out infinite; }
@keyframes jump { 0% { transform: translate(0, 0) rotate(-45deg); opacity: 0; } 10% { opacity: 1; } 50% { transform: translate(var(--dx), -420%) rotate(-45deg); } 100% { transform: translate(calc(var(--dx) * 2), 60%) rotate(-45deg); opacity: 0; } }
.fx .bow { left: -10%; width: 120%; aspect-ratio: 2 / 1; top: 30%; border-radius: 100% 100% 0 0 / 200% 200% 0 0; background: conic-gradient(from 270deg at 50% 100%, #F25C5C 0 30deg, #FFA62B 30deg 60deg, #FFD166 60deg 90deg, #6FCF7A 90deg 120deg, #4FA3F7 120deg 150deg, #A78BFA 150deg 180deg, transparent 180deg); opacity: .8; -webkit-mask: radial-gradient(circle at 50% 100%, transparent 0 58%, #000 60%); mask: radial-gradient(circle at 50% 100%, transparent 0 58%, #000 60%); }

/* actor loops */
.an-bob { animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6%); } }
.an-sway { animation: sway 2.6s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.an-float { animation: floaty 4.2s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(3%, -10%); } }
.an-wiggle { animation: wiggle .55s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
.an-hop { animation: hop 1s cubic-bezier(.3, 0, .2, 1) infinite; transform-origin: 50% 100%; }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 30% { transform: translateY(-22%) scale(.96, 1.06); } 60% { transform: translateY(0) scale(1.06, .94); } 75% { transform: translateY(0) scale(1, 1); } }
.an-spin { animation: spin 30s linear infinite; }
.an-shake { animation: shakeX .5s ease-in-out infinite; }
@keyframes shakeX { 0%, 100% { transform: translateX(-3%); } 50% { transform: translateX(3%); } }
.an-walk { animation: walk .5s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes walk { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-5%) rotate(3deg); } }
.an-breathe { animation: breathe 3.4s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04, 1.06); } }
.an-fly { animation: fly 2.8s ease-in-out infinite; }
@keyframes fly { 0%, 100% { transform: translate(0, 0) rotate(-6deg); } 50% { transform: translate(-4%, -12%) rotate(6deg); } }
.an-puff { animation: puff 1.6s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes puff { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.18, .9); } 60% { transform: scale(.94, 1.08); } }
.an-pull { animation: pull 1.2s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes pull { 0%, 100% { transform: rotate(0) translateX(0); } 40% { transform: rotate(-10deg) translateX(-5%); } 60% { transform: rotate(-8deg) translateX(-4%); } }
.an-tumble { animation: tumble .9s ease-in-out infinite alternate; }
@keyframes tumble { from { transform: rotate(-18deg); } to { transform: rotate(18deg); } }
.an-idle { animation: idle 3.4s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes idle { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.022, 1.03) translateY(-.6%); } }
.an-peek { animation: peek 2.8s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes peek { 0%, 100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(3deg) translateY(-4%); } }

/* ---- cover ---- */
.cover { display: grid; gap: 16px; max-width: 640px; margin: 0 auto; }
.cover h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: clamp(28px, 7vw, 40px); line-height: 1.1; text-align: center; }
.cover h2 small { display: block; font-size: .58em; font-weight: 500; color: var(--muted); margin-top: 4px; }
.cover .blurb { margin: 0; text-align: center; color: var(--muted); font-weight: 600; font-size: 16px; }
.cover .cta { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cover .meta { text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; }
.cover .meta button { color: var(--primary-dark); font-weight: 800; text-decoration: underline; }
.cover .locked-card { background: #FFFBEB; border: 2px solid var(--sun); border-radius: var(--radius-sm); padding: 14px 16px; text-align: center; font-weight: 600; }
.cover .locked-card p { margin: 0 0 10px; }

/* ---- reader ---- */
.reader {
  display: grid; gap: 10px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
  min-height: calc(100dvh - var(--top-h) - env(safe-area-inset-top, 0px) - 32px - var(--safe-b));
  max-width: 720px; margin: 0 auto;
}
.reader .stagewrap { position: relative; min-width: 0; }
.story-text {
  display: flex; flex-direction: column; justify-content: flex-start; gap: 8px;
  padding: 10px 8px 6px; min-height: 0; min-width: 0; text-align: center;
}
.line {
  margin: 0; font-family: var(--display); line-height: 1.3; overflow-wrap: anywhere;
}
.line.l1 { font-weight: 600; font-size: clamp(22px, 5.6vw, 30px); }
.line.l2 { font-weight: 500; font-size: clamp(17px, 4.4vw, 22px); color: var(--muted); }
.line .t { display: inline-block; border-radius: 8px; padding: 0 2px; transition: background .12s ease, color .12s ease, transform .12s ease; }
.line .t.hot { background: var(--sun); color: var(--ink); transform: scale(1.08); }
.line.now .t { color: var(--ink); }
.line.l2.now .t { color: #574f6e; }
.line .w { text-decoration: underline dotted; text-decoration-color: var(--primary); text-underline-offset: 4px; text-decoration-thickness: 2px; cursor: pointer; }
.line .w.pop { display: inline-block; animation: pop .45s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.14) rotate(-2deg); }
  70% { transform: scale(.98) rotate(1deg); }
  100% { transform: scale(1); }
}
@media (orientation: landscape) and (min-width: 700px) {
  .reader { grid-template-columns: minmax(0, 58%) minmax(0, 1fr); grid-template-rows: 1fr auto auto; max-width: 1100px; align-items: center; column-gap: 20px; }
  .reader .stagewrap { grid-column: 1; grid-row: 1; }
  .reader .dots { grid-column: 1; grid-row: 2; }
  .reader .story-text { grid-column: 2; grid-row: 1 / 3; text-align: left; padding: 12px 16px; }
  .reader .bar { grid-column: 1 / -1; grid-row: 3; }
  .line.l1 { font-size: clamp(26px, 3.2vw, 38px); }
  .line.l2 { font-size: clamp(18px, 2.2vw, 26px); }
}
.dots { display: flex; justify-content: center; gap: 6px; padding: 2px 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--primary); width: 22px; border-radius: 999px; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding-bottom: 4px; min-width: 0;
}
.bar .bigbtn { min-width: 0; }
.bar .bigbtn span { overflow: hidden; text-overflow: ellipsis; }
.bigbtn {
  height: 60px; padding: 0 22px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 10px; white-space: nowrap;
  font-family: var(--display); font-weight: 600; font-size: 20px;
  background: var(--primary); color: #fff; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.bigbtn svg { width: 26px; height: 26px; }
.bigbtn:active { transform: scale(.95); }
.bigbtn.alt { background: var(--card); color: var(--ink); }
.bigbtn.alt.on { background: var(--sky); color: #fff; }
.bigbtn.xl { height: 68px; padding: 0 30px; font-size: 24px; }
.bigbtn:disabled { opacity: .5; }
@media (max-width: 420px) {
  .bigbtn { height: 54px; padding: 0 16px; font-size: 18px; gap: 8px; }
  .bigbtn svg { width: 22px; height: 22px; }
  .bigbtn.xl { height: 62px; padding: 0 24px; font-size: 22px; }
}
.arrowbtn {
  width: 60px; height: 60px; border-radius: 50%; flex: none;
  background: var(--card); box-shadow: var(--shadow); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
}
.arrowbtn svg { width: 28px; height: 28px; }
.arrowbtn:active { transform: scale(.92); }
.arrowbtn:disabled { opacity: .35; }
@media (max-width: 420px) { .arrowbtn { width: 54px; height: 54px; } }
@keyframes inRight { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes inLeft { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
.from-right { animation: inRight .3s ease; }
.from-left { animation: inLeft .3s ease; }

/* ---- the end ---- */
.end { display: grid; gap: 18px; justify-items: center; text-align: center; max-width: 640px; margin: 0 auto; }
.end .scene { width: 100%; }
.end h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: clamp(36px, 10vw, 56px); line-height: 1; }
.end h2 small { display: block; font-size: .5em; color: var(--muted); font-weight: 500; margin-top: 6px; }
.end .cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ---- overlays: gate + settings ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(43, 36, 64, .45);
  display: flex; align-items: flex-end; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
@media (min-width: 700px) { .overlay { align-items: center; } }
.gate {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 24px calc(28px + var(--safe-b)); width: 100%; max-width: 480px; text-align: center;
}
@media (min-width: 700px) { .gate { border-radius: var(--radius); } }
.gate-kicker { margin: 0; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.gate h2 { font-family: var(--display); font-weight: 600; font-size: 30px; margin: 8px 0 18px; }
.gate-opts { display: flex; gap: 12px; justify-content: center; margin-bottom: 14px; }
.gate-opts button {
  width: 76px; height: 64px; border-radius: 20px;
  background: var(--canvas); border: 2px solid var(--line);
  font-family: var(--display); font-size: 26px; font-weight: 600;
}
.gate-opts button:active { background: var(--sun); }
.gate-opts button.wrong { animation: shake .35s ease; border-color: var(--primary); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.linkbtn { color: var(--muted); font-weight: 700; padding: 10px 14px; border-radius: 12px; text-decoration: underline; }

.sheet {
  background: var(--canvas); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 560px; max-height: calc(100dvh - 24px);
  display: flex; flex-direction: column;
}
@media (min-width: 700px) { .sheet { border-radius: var(--radius); max-height: min(90vh, 860px); } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px 24px;
}
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; }
.sheet-body { overflow-y: auto; padding: 0 16px calc(24px + var(--safe-b)); }
.set { background: var(--card); border-radius: var(--radius-sm); padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow-press); }
.set h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 600; font-size: 19px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-weight: 600; }
.row + .row { border-top: 1px solid var(--line); }
.row span { flex: 1; }
select {
  font: inherit; font-weight: 700; color: var(--ink);
  padding: 10px 36px 10px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--canvas);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%232B2440' stroke-width='3' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
  max-width: 60%;
}
.toggle input { appearance: none; -webkit-appearance: none; width: 54px; height: 32px; border-radius: 999px; background: #D9D3C8; position: relative; flex: none; margin: 0; transition: background .2s; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.toggle input:checked { background: var(--sky); }
.toggle input:checked::after { transform: translateX(22px); }
.hint { margin: 6px 0 4px; color: var(--muted); font-size: 14px; }
.hint.note { background: #FFF6DA; border-radius: 10px; padding: 8px 10px; color: var(--ink); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 20px; border-radius: 999px; margin-top: 6px;
  background: var(--primary); color: #fff; font-weight: 800; box-shadow: var(--shadow-press);
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink); border: 2px solid var(--line); }
.about p { margin: 6px 0; font-size: 14px; color: var(--muted); }
.about a { color: var(--ink); font-weight: 700; }

.voices { display: flex; flex-direction: column; gap: 8px; }
.voice {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px 8px 12px; border-radius: 16px; border: 2px solid var(--line); background: var(--canvas);
  cursor: pointer;
}
.voice.on { border-color: var(--primary); background: #FFF1F1; }
.voice .av {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 600; font-size: 18px; color: #fff;
}
.voice .av.f { background: var(--lav); }
.voice .av.m { background: var(--sky); }
.voice .vn { flex: 1; min-width: 0; }
.voice .vn b { display: block; font-family: var(--display); font-weight: 600; font-size: 17px; }
.voice .vn small { color: var(--muted); font-weight: 600; }
.voice .play {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--card); box-shadow: var(--shadow-press);
  display: flex; align-items: center; justify-content: center;
}
.voice .play svg { width: 20px; height: 20px; }
.voice input { position: absolute; opacity: 0; width: 0; height: 0; }

/* ---- Pro ---- */
.pill { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; background: var(--sun); color: var(--ink); vertical-align: middle; margin-left: 4px; }
.pro-card { border: 2px solid var(--sun); background: #FFFBEB; border-radius: var(--radius-sm); padding: 14px 16px; margin: 8px 0 14px; }
.pro-price { display: flex; align-items: baseline; gap: 6px; font-family: var(--display); }
.pro-price b { font-size: 34px; font-weight: 600; }
.pro-price span { color: var(--muted); font-weight: 600; }
.pro-list { margin: 8px 0 12px; padding-left: 20px; font-weight: 600; }
.pro-list li { margin: 2px 0; }
.row-title { margin: 8px 0 6px; font-weight: 700; }
.code-entry { display: flex; gap: 8px; }
.code-entry input { flex: 1; min-width: 0; font: inherit; font-family: var(--display); font-weight: 600; font-size: 20px; letter-spacing: .08em; text-transform: uppercase; padding: 8px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--canvas); color: var(--ink); }
.code-entry .btn { margin-top: 0; flex: none; }
.pro-badge { display: inline-block; margin: 0 0 6px; padding: 6px 12px; border-radius: 999px; background: var(--sky); color: #fff; font-weight: 800; }
.pro-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
@keyframes flash { 0%, 100% { box-shadow: var(--shadow-press); } 50% { box-shadow: 0 0 0 4px var(--sun); } }
.set.flash { animation: flash .9s ease 2; }
select option:disabled { color: #9a96a8; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  z-index: 60; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.toast button { color: var(--sun); font-weight: 800; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .actor-in, .actor.in, .fx span, .fx svg, .fx img { animation: none !important; }
  .from-right, .from-left { animation: none !important; }
}
