/* Wonder Explorer — bubbly, chunky, cartoon-style UI for young learners. */

:root {
  --ink: #2b2d42;
  --ink-soft: #5d607c;
  --paper: #ffffff;
  --accent: #3ab7ef;
  --accent-deep: #137bb8;
  --accent-soft: #e1f5fe;
  --sky-top: #bde6ff;
  --sky-bottom: #fff4dc;
  --pink: #ff6fb5;
  --yellow: #ffd23f;
  --green: #6fd08c;
  --purple: #9b6cf0;
  --orange: #ff9f1c;
  --red: #ff5d73;
  --radius: 28px;
  --border: 3px solid var(--ink);
  --font-ui: "Fredoka", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-read: "Andika", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --read-size: 26px;
}

body[data-theme="sunny"]  { --accent: #ffb627; --accent-deep: #b86e00; --accent-soft: #fff3d1; --sky-top: #ffe5a0; --sky-bottom: #fff9ec; }
body[data-theme="forest"] { --accent: #4cbf6b; --accent-deep: #217a3a; --accent-soft: #e2f7e7; --sky-top: #c6efd1; --sky-bottom: #fbfff0; }
body[data-theme="ocean"]  { --accent: #1fc7c1; --accent-deep: #0b7480; --accent-soft: #dbf7f6; --sky-top: #b3edf0; --sky-bottom: #eafbff; }
body[data-theme="space"]  { --accent: #8b6cf0; --accent-deep: #5135b8; --accent-soft: #eee8ff; --sky-top: #cdc1ff; --sky-bottom: #f4efff; }
body[data-theme="candy"]  { --accent: #ff6fb5; --accent-deep: #b52d70; --accent-soft: #ffe6f2; --sky-top: #ffcbe5; --sky-bottom: #fff4fa; }
body[data-theme="fire"]   { --accent: #ff7a45; --accent-deep: #b93d0b; --accent-soft: #ffeadf; --sky-top: #ffcfb6; --sky-bottom: #fff6ec; }

body[data-size="s"] { --read-size: 22px; }
body[data-size="m"] { --read-size: 26px; }
body[data-size="l"] { --read-size: 33px; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--sky-bottom);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.2px; }
h2 { font-size: 30px; margin-bottom: 18px; }
button {
  margin: 0; padding: 0; font: inherit; color: inherit;
  -webkit-appearance: none; appearance: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.ico { display: block; flex: none; width: 1.15em; height: 1.15em; }
button, .chip, .mic-btn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---------- Sky decoration ---------- */
/* The sky is a fixed layer because iPad Safari ignores fixed page backgrounds. */
.sky {
  position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}
/* Clouds move with transform (smooth on older iPads) rather than by changing their position. */
.cloud {
  position: absolute; left: 0; width: 180px; height: 56px; background: #fff; border-radius: 60px; opacity: 0.85;
  animation: drift linear infinite; will-change: transform;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; top: -40px; left: 28px; }
.cloud::after { width: 104px; height: 104px; top: -56px; left: 72px; }
.c1 { top: 12%; animation-duration: 95s; animation-delay: -20s; }
.c2 { top: 34%; animation-name: drift70; animation-duration: 120s; animation-delay: -70s; }
.c3 { top: 62%; animation-name: drift85; animation-duration: 110s; animation-delay: -40s; }
.c4 { top: 82%; animation-name: drift60; animation-duration: 140s; animation-delay: -100s; }
@keyframes drift { from { transform: translateX(-280px); } to { transform: translateX(calc(100vw + 40px)); } }
@keyframes drift70 { from { transform: translateX(-280px) scale(0.7); } to { transform: translateX(calc(100vw + 40px)) scale(0.7); } }
@keyframes drift85 { from { transform: translateX(-280px) scale(0.85); } to { transform: translateX(calc(100vw + 40px)) scale(0.85); } }
@keyframes drift60 { from { transform: translateX(-280px) scale(0.6); } to { transform: translateX(calc(100vw + 40px)) scale(0.6); } }
.dot { position: absolute; bottom: -60px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.9); background: rgba(255,255,255,0.25); animation: rise linear infinite; }
.d1 { left: 8%;  width: 34px; height: 34px; animation-duration: 18s; }
.d2 { left: 22%; width: 18px; height: 18px; animation-duration: 13s; animation-delay: -6s; }
.d3 { left: 71%; width: 28px; height: 28px; animation-duration: 16s; animation-delay: -3s; }
.d4 { left: 86%; width: 20px; height: 20px; animation-duration: 12s; animation-delay: -9s; }
.d5 { left: 52%; width: 14px; height: 14px; animation-duration: 15s; animation-delay: -11s; }
@keyframes rise { to { transform: translateY(-115vh) translateX(30px); } }

/* ---------- Views ---------- */
.view {
  display: none; position: relative; z-index: 1; max-width: 1180px; margin: 0 auto;
  padding-block: calc(28px + env(safe-area-inset-top, 0px)) calc(80px + env(safe-area-inset-bottom, 0px));
  padding-left: max(28px, env(safe-area-inset-left, 0px));
  padding-right: max(28px, env(safe-area-inset-right, 0px));
}
body[data-view="home"] #home,
body[data-view="loading"] #loading,
body[data-view="lesson"] #lesson,
body[data-view="game"] #game,
body[data-view="notice"] #notice { display: block; animation: pop-in 0.35s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  min-height: 56px; padding: 10px 24px; font-size: 22px; font-weight: 600;
  background: var(--paper); border: var(--border); border-radius: 999px;
  box-shadow: 0 5px 0 var(--ink); cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}
.btn:active, .chip:active, .mic-btn:active, .choice:active, .seg button:active, .video-card:active, .history-card:active, .word-card:active {
  transform: translateY(4px); box-shadow: 0 1px 0 var(--ink);
}
.btn.primary { background: var(--accent); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-soft); }
:focus-visible { outline: 4px solid var(--accent-deep); outline-offset: 3px; }

.card {
  background: var(--paper); border: var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--ink); padding: 28px; margin: 0 0 32px;
}
.block { margin: 0 0 36px; }

/* ---------- Hoot ---------- */
.hoot { width: 100%; height: 100%; overflow: visible; }
.hoot-body { animation: bob 3.2s ease-in-out infinite; }
.hoot .eyes { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.hoot .wing-l { transform-box: view-box; transform-origin: 44px 112px; }
.hoot .wing-r { transform-box: view-box; transform-origin: 156px 112px; }
.hoot-shadow { transform-box: fill-box; transform-origin: center; animation: shadow 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes shadow { 50% { transform: scaleX(0.85); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
.thinking .hoot-body { animation: bob 0.9s ease-in-out infinite; }
.thinking .wing-l { animation: flap-l 0.45s ease-in-out infinite; }
.thinking .wing-r { animation: flap-r 0.45s ease-in-out infinite; }
.thinking .pupils { animation: look 3s ease-in-out infinite; }
@keyframes flap-l { 50% { transform: rotate(28deg); } }
@keyframes flap-r { 50% { transform: rotate(-28deg); } }
@keyframes look { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 70% { transform: translateX(6px); } }
.wave .wing-r { animation: wave 1.2s ease-in-out 2; }
@keyframes wave { 25%, 75% { transform: rotate(-40deg); } 50% { transform: rotate(-15deg); } }

/* ---------- Home ---------- */
.brand { text-align: center; margin: 4px 0 8px; }
.logo { font-size: 46px; font-weight: 700; color: var(--ink); text-shadow: 0 4px 0 #fff; }
.logo b { color: var(--accent-deep); }

.ask { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 40px; }
.ask-hoot { display: flex; align-items: center; gap: 18px; margin: 4px 0 18px; }
.ask-hoot .hoot-slot { width: 170px; height: 186px; flex: none; }
.speech {
  position: relative; max-width: 440px; margin: 0; padding: 18px 24px;
  font-size: 26px; font-weight: 600; line-height: 1.3; text-align: left;
  background: var(--paper); border: var(--border); border-radius: 26px; box-shadow: 0 6px 0 var(--ink);
}
.ask-hoot .speech::before {
  content: ""; position: absolute; left: -15px; top: 50%; width: 24px; height: 24px; margin-top: -12px;
  background: var(--paper); border-left: var(--border); border-bottom: var(--border); transform: rotate(45deg);
}
.speech.big { font-size: 30px; text-align: center; max-width: 640px; }

.mic-btn {
  position: relative; width: 156px; height: 156px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 35% 30%, #ff9fcf, var(--pink) 55%, #f0458f);
  border: 4px solid var(--ink); box-shadow: 0 8px 0 var(--ink);
  animation: breathe 2.6s ease-in-out infinite; transition: transform 0.08s, box-shadow 0.08s;
}
.mic-icon { width: 70px; height: 70px; filter: drop-shadow(0 3px 0 rgba(0,0,0,0.18)); }
@keyframes breathe { 50% { transform: scale(1.05); } }
.mic-label { margin: 18px 0 20px; font-size: 30px; font-weight: 700; color: var(--accent-deep); }

.type-form { display: flex; gap: 10px; width: min(560px, 100%); }
.type-form input {
  flex: 1; min-width: 0; min-height: 56px; padding: 0 22px; font: 500 21px var(--font-ui); color: var(--ink);
  background: rgba(255,255,255,0.85); border: var(--border); border-radius: 999px; outline: none;
}
.type-form input:focus { background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.go-btn { background: var(--yellow); }

.chips { display: flex; flex-wrap: wrap; gap: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px 22px;
  font-size: 22px; font-weight: 600; cursor: pointer; text-align: left;
  background: var(--paper); border: var(--border); border-radius: 999px; box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}
.chip .e { font-size: 30px; line-height: 1; }

.history { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 18px; }
.history-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 160px; padding: 16px; cursor: pointer; text-align: center;
  font-size: 19px; font-weight: 600; line-height: 1.2;
  border: var(--border); border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.history-card .e { font-size: 52px; line-height: 1; }
.history-card .when { font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.history-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 18px; }
.history-note { font-size: 16px; color: var(--ink-soft); }

/* ---------- Loading / notice ---------- */
.loading-box { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 6vh; }
.loading-box .hoot-slot { width: 220px; height: 240px; margin-bottom: 16px; }
.loading-q { margin: 0 0 8px; font-size: 36px; font-weight: 700; max-width: 820px; }
.loading-msg { margin: 0 0 18px; font-size: 26px; color: var(--ink-soft); min-height: 1.4em; }
.dots { display: flex; gap: 14px; margin-bottom: 28px; }
.dots i { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid var(--ink); animation: hop 1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; background: var(--pink); }
.dots i:nth-child(3) { animation-delay: 0.3s; background: var(--yellow); }
@keyframes hop { 30% { transform: translateY(-16px); } 60% { transform: translateY(0); } }
.notice-actions { display: flex; gap: 16px; margin-top: 30px; }

/* ---------- Lesson ---------- */
.topbar {
  position: sticky; top: calc(12px + env(safe-area-inset-top, 0px)); z-index: 5; display: flex; justify-content: space-between; gap: 12px; margin-bottom: 26px;
}
.ask-new { background: var(--pink); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.15); }

.hero { display: flex; align-items: center; gap: 26px; background: var(--accent-soft); }
.hero-emoji {
  flex: none; width: 128px; height: 128px; display: grid; place-items: center; font-size: 76px;
  background: var(--paper); border: var(--border); border-radius: 50%; box-shadow: 0 6px 0 var(--ink);
  animation: wiggle 3s ease-in-out infinite;
}
@keyframes wiggle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg) scale(1.04); } }
.hero h1 { font-size: 50px; line-height: 1.05; margin-bottom: 10px; }
.big-idea { margin: 0; font-family: var(--font-read); font-size: 26px; line-height: 1.45; }

.say {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; vertical-align: middle; line-height: 0;
  font-size: 22px; color: var(--ink); cursor: pointer; background: var(--yellow); border: 2.5px solid var(--ink); border-radius: 50%;
  box-shadow: 0 3px 0 var(--ink); transition: transform 0.08s, box-shadow 0.08s;
}
.big-idea .say { margin-left: 6px; position: relative; top: -2px; }
.say:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

.controls { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 22px 40px; padding: 22px 28px; }
.ctrl { display: flex; flex-direction: column; gap: 10px; }
.ctrl-label { font-size: 20px; font-weight: 600; color: var(--ink-soft); }
.seg { display: flex; gap: 10px; flex-wrap: wrap; }
.seg button {
  display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 8px 20px; cursor: pointer;
  background: var(--paper); border: var(--border); border-radius: 20px; box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }
.seg .lvl-e { font-size: 34px; line-height: 1; }
.seg .lvl-t { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; }
.seg .lvl-t b { font-size: 22px; }
.seg .lvl-t small { font-size: 15px; font-weight: 500; opacity: 0.85; }
.sizes button { width: 64px; justify-content: center; padding: 0; font-weight: 700; }

.lesson-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 32px; align-items: start; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.card-head h2 { margin: 0; }
.read-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.read-btn, .pause-btn { background: var(--yellow); }
.stop-btn { background: var(--red); color: #fff; }
.say[data-state="playing"] { background: var(--red); color: #fff; }
.ico-spin {
  display: block; flex: none; width: 1.05em; height: 1.05em; border-radius: 50%;
  border: 3px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}

.reading p {
  margin: 0 0 0.85em; padding: 6px 12px; margin-left: -12px; margin-right: -12px;
  font-family: var(--font-read); font-size: var(--read-size); line-height: 1.6;
  border-radius: 14px; transition: background 0.3s;
}
.reading .s { border-radius: 8px; transition: background 0.25s, box-shadow 0.25s; }
.reading .s.speaking { background: #fff3b0; box-shadow: 0 0 0 4px #fff3b0; }
.vocab {
  padding: 0 4px; font-family: inherit; font-size: inherit; font-weight: 700; cursor: pointer;
  color: var(--accent-deep); background: var(--accent-soft); border: none; border-radius: 8px;
  border-bottom: 3px dotted var(--accent-deep);
}
.sub { margin: 26px 0 14px; font-size: 24px; }
.sub small { font-size: 16px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; }
.word-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.word-card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; text-align: left; cursor: pointer;
  border: var(--border); border-radius: 20px; box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.word-card b { font-size: 24px; }
.word-card span { font-family: var(--font-read); font-size: 18px; line-height: 1.4; }
.wc0 { background: #fff3c4; } .wc1 { background: #ffe0ef; } .wc2 { background: #dcf6e4; } .wc3 { background: #e3f2ff; }

.pics { display: flex; flex-direction: column; }
.pic-card { padding: 16px; margin: 0 0 32px; }
.pic-card img { display: block; width: 100%; border-radius: 18px; border: var(--border); background: var(--accent-soft); }
.pic-card .photo { aspect-ratio: 4 / 3; object-fit: cover; }
.pic-card figcaption { padding: 12px 6px 2px; font-size: 19px; line-height: 1.35; }
.pic-card figcaption .label { display: block; font-weight: 700; font-size: 21px; margin-bottom: 2px; }
.pic-card figcaption .credit { display: block; margin-top: 4px; font-size: 14px; color: var(--ink-soft); }

.skeleton {
  display: grid; place-items: center; text-align: center; padding: 20px;
  min-height: 220px; border-radius: 18px; border: 3px dashed var(--ink-soft);
  font-size: 21px; font-weight: 600; color: var(--ink-soft);
  background: linear-gradient(100deg, var(--accent-soft) 30%, #fff 50%, var(--accent-soft) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite;
}
.skeleton .e { display: block; font-size: 44px; margin-bottom: 6px; animation: bob 1.2s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }
.empty { padding: 20px; text-align: center; font-size: 21px; color: var(--ink-soft); }

.video-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.video-card {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; cursor: pointer;
  background: var(--paper); border: var(--border); border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.08s;
}
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--accent-soft); border-bottom: var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play {
  position: absolute; left: 50%; top: 50%; width: 76px; height: 76px; margin: -38px 0 0 -38px;
  display: grid; place-items: center; border-radius: 50%; background: var(--yellow);
  border: var(--border); box-shadow: 0 5px 0 var(--ink);
}
.play::after { content: ""; margin-left: 6px; border-left: 26px solid var(--ink); border-top: 16px solid transparent; border-bottom: 16px solid transparent; }
.vnum {
  position: absolute; left: 12px; top: 12px; width: 44px; height: 44px; display: grid; place-items: center;
  font-size: 24px; font-weight: 700; color: #fff; background: var(--accent); border: var(--border); border-radius: 50%;
}
.dur {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 10px; font-size: 16px; font-weight: 600;
  color: #fff; background: rgba(43, 45, 66, 0.85); border-radius: 999px;
}
.vinfo { padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.vtitle { font-size: 20px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vwhy { font-family: var(--font-read); font-size: 17px; line-height: 1.4; color: var(--ink-soft); }
.badge {
  align-self: flex-start; padding: 4px 12px; font-size: 15px; font-weight: 600;
  background: #dcf6e4; border: 2px solid var(--ink); border-radius: 999px;
}

.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.fact {
  position: relative; padding: 30px 24px 22px; font-family: var(--font-read); font-size: 22px; line-height: 1.45;
  border: var(--border); border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
}
.fact:nth-child(1) { background: #fff3c4; transform: rotate(-1.2deg); }
.fact:nth-child(2) { background: #ffe0ef; transform: rotate(0.8deg); }
.fact:nth-child(3) { background: #dcf6e4; transform: rotate(-0.6deg); }
.fact .n {
  position: absolute; top: -20px; left: 20px; width: 46px; height: 46px; display: grid; place-items: center;
  font-family: var(--font-ui); font-weight: 700; font-size: 24px; background: var(--paper); border: var(--border); border-radius: 50%;
}
/* The speaker sits on the card's top edge, mirroring the number badge. */
.fact .say { position: absolute; top: -21px; right: 18px; }

.q { padding: 18px 0 22px; border-bottom: 3px dashed #d9dbe8; }
.q:last-child { border-bottom: none; }
.q-text { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; font-size: 25px; font-weight: 600; line-height: 1.3; }
.q-num {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; color: #fff;
  background: var(--purple); border: var(--border); border-radius: 50%; font-size: 22px;
}
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.choice {
  min-height: 70px; padding: 12px 16px; font-family: var(--font-read); font-size: 21px; line-height: 1.3; cursor: pointer;
  background: var(--paper); border: var(--border); border-radius: 20px; box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}
.choice:disabled { cursor: default; }
.choice.right { background: var(--green); }
.choice.wrong { background: var(--red); color: #fff; animation: shake 0.4s; }
.choice.faded { opacity: 0.5; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.q-explain { margin: 14px 0 0; font-family: var(--font-read); font-size: 21px; line-height: 1.4; }
.quiz-end {
  display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 18px; padding: 18px;
  text-align: center; background: #fff3c4; border: var(--border); border-radius: 20px;
}
.score-line { margin: 0; font-size: 30px; font-weight: 700; }
.score-note { margin: 0; font-size: 21px; line-height: 1.35; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: rgba(43, 45, 66, 0.72); animation: fade 0.2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.listen-box {
  width: min(620px, 100%); padding: 44px 32px 26px; text-align: center;
  background: var(--paper); border: var(--border); border-radius: 36px; box-shadow: 0 10px 0 var(--ink);
}
.rings { position: relative; display: inline-grid; place-items: center; margin-bottom: 18px; }
.rings.active::before, .rings.active::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 4px solid var(--pink); animation: ring 1.6s ease-out infinite;
}
.rings.active::after { animation-delay: 0.8s; }
@keyframes ring { from { transform: scale(1); opacity: 0.9; } to { transform: scale(1.7); opacity: 0; } }
.mic-btn.on { animation: none; }
.rings:not(.active) .mic-btn { background: radial-gradient(circle at 35% 30%, #9fdcff, var(--accent) 55%, var(--accent-deep)); }
.listen-label { margin: 6px 0 8px; font-size: 32px; font-weight: 700; }
.transcript { min-height: 1.4em; margin: 0 0 18px; font-family: var(--font-read); font-size: 28px; color: var(--accent-deep); }

.video-box {
  width: min(1100px, 100%); padding: 18px; background: var(--paper);
  border: var(--border); border-radius: 30px; box-shadow: 0 10px 0 var(--ink);
}
.video-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; padding: 0 6px; }
.video-top h3 { min-width: 0; font-size: 24px; line-height: 1.2; }
.video-top .btn { flex: none; white-space: nowrap; }
.player {
  position: relative; aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden; border: var(--border);
  background: #000 center / cover no-repeat;
}
.player-loading {
  position: absolute; inset: 0; z-index: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  font-size: 24px; font-weight: 600; color: #fff; background: rgba(43, 45, 66, 0.55); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.35); border-top-color: var(--yellow); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#playerHost { position: relative; z-index: 1; }
.today {
  display: inline-block; margin-bottom: 12px; padding: 8px 18px; font-size: 22px; font-weight: 700;
  background: var(--yellow); border: var(--border); border-radius: 999px; box-shadow: 0 4px 0 var(--ink);
}
#playerHost, #playerHost iframe { width: 100%; height: 100%; border: 0; display: block; }
.end-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: var(--accent-soft); font-size: 40px; font-weight: 700;
}
.end-screen p { margin: 0; }
.end-screen div { display: flex; gap: 16px; }

.popover {
  position: absolute; z-index: 15; width: 320px; padding: 16px 18px;
  background: var(--paper); border: var(--border); border-radius: 22px; box-shadow: 0 6px 0 var(--ink);
  animation: pop-in 0.18s ease-out;
}
.popover b { display: block; font-size: 26px; margin-bottom: 4px; color: var(--accent-deep); }
.popover p { margin: 0 0 10px; font-family: var(--font-read); font-size: 20px; line-height: 1.4; }

.confetti { position: fixed; z-index: 30; width: 11px; height: 15px; border-radius: 3px; pointer-events: none; animation: confetti 1.15s ease-out forwards; }
@keyframes confetti {
  40% { transform: translate(calc(var(--dx) * 0.6), var(--dy)) rotate(calc(var(--r) * 0.5)); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) + 320px)) rotate(var(--r)); opacity: 0; }
}

/* ---------- Today's game: unlock card and reward ---------- */
.game-teaser {
  display: flex; align-items: center; gap: 18px; margin: 0 0 36px; padding: 18px 22px;
  background: var(--paper); border: var(--border); border-radius: 26px; box-shadow: 0 6px 0 var(--ink);
}
.game-teaser.unlocked { background: #fff3c4; }
.gt-icon { flex: none; font-size: 48px; line-height: 1; }
.gt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 19px; }
.gt-text b { font-size: 22px; }
.gt-step.done { color: #217a3a; font-weight: 600; }
.reward-box h2 { font-size: 32px; margin-bottom: 6px; }
.reward-trophy { margin: 0 0 6px; font-size: 76px; line-height: 1; animation: wiggle 1.6s ease-in-out infinite; }
.reward-game { margin: 0 0 18px; font-size: 22px; font-weight: 600; }

/* ---------- Today's game: playing ---------- */
.game-head { display: flex; align-items: center; gap: 22px; margin-bottom: 10px; }
.game-titles { min-width: 0; }
.game-kind { display: block; margin-bottom: 4px; font-size: 18px; font-weight: 600; color: var(--ink-soft); }
.game-titles h1 { font-size: 40px; line-height: 1.1; margin-bottom: 6px; }
.game-progress { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 18px; }
.gp-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 2.5px solid var(--ink); }
.gp-dot.done { background: var(--accent); }
.game-board { min-height: 320px; }

.pop-prompt { display: flex; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.pop-prompt p { margin: 0; font-size: 34px; font-weight: 700; line-height: 1.2; }
.pop-emoji { font-size: 56px; line-height: 1; }
.bubbles { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; padding: 34px 0 14px; }
.bubble {
  width: 150px; height: 150px; padding: 10px; border-radius: 50%; cursor: pointer;
  font-size: 28px; font-weight: 700; line-height: 1.1; overflow-wrap: anywhere;
  border: var(--border); box-shadow: 0 6px 0 var(--ink), inset -12px -14px 0 rgba(0, 0, 0, 0.07), inset 12px 12px 0 rgba(255, 255, 255, 0.55);
  animation: float 3.2s ease-in-out infinite;
}
.bubble.b0 { background: #ffd1e8; } .bubble.b1 { background: #fff0a8; } .bubble.b2 { background: #c9f2d6; } .bubble.b3 { background: #cdeaff; }
.bubble.popped { animation: popped 0.45s forwards; }
.bubble.nope { background: #d9dbe8; opacity: 0.55; animation: shake 0.4s; }
@keyframes float { 50% { transform: translateY(-14px); } }
@keyframes popped { 40% { transform: scale(1.25); } 100% { transform: scale(0); opacity: 0; } }

.match-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.mcard {
  display: flex; align-items: center; justify-content: center; min-height: 130px; padding: 10px; cursor: pointer;
  border: var(--border); border-radius: 20px; box-shadow: 0 5px 0 var(--ink); color: #fff;
  background: repeating-linear-gradient(45deg, var(--purple) 0 14px, #8a5ae6 14px 28px);
}
.mcard .mback { font-size: 54px; font-weight: 700; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.2); }
.mcard .mfront { display: none; font-size: 22px; font-weight: 700; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.mcard.open { background: var(--paper); color: var(--ink); animation: flip 0.3s ease-out; }
.mcard.open .mback { display: none; }
.mcard.open .mfront { display: block; }
.mcard.matched { background: #dcf6e4; }
@keyframes flip { from { transform: scaleX(0.1); } }

.sort-item {
  width: min(320px, 100%); margin: 6px auto 4px; padding: 22px; text-align: center;
  background: var(--paper); border: var(--border); border-radius: 28px; box-shadow: 0 8px 0 var(--ink); animation: pop-in 0.3s ease-out;
  transition: transform 0.6s ease-in, opacity 0.6s ease-in;
}
.si-emoji { display: block; font-size: 84px; line-height: 1.1; }
.si-label { font-size: 32px; font-weight: 700; }
.sort-item.fly-left { transform: translate(-45%, 130%) scale(0.35); opacity: 0; }
.sort-item.fly-right { transform: translate(45%, 130%) scale(0.35); opacity: 0; }
.sort-ask { margin: 14px 0 12px; text-align: center; font-size: 22px; font-weight: 600; color: var(--ink-soft); }
.baskets { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.basket {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 180px; padding: 14px; cursor: pointer;
  font-size: 26px; border: var(--border); border-radius: 26px 26px 44px 44px; box-shadow: 0 6px 0 var(--ink);
}
.basket.k0 { background: #ffe0ef; } .basket.k1 { background: #e3f2ff; }
.basket.nope { animation: shake 0.4s; }
.bk-emoji { font-size: 54px; line-height: 1; }
.bk-items { min-height: 1.4em; font-size: 22px; line-height: 1.3; }

.game-done { display: flex; flex-direction: column; align-items: center; text-align: center; }
.game-done .confirm-hoot { width: 150px; height: 165px; }
.gd-stars { margin: 4px 0; font-size: 60px; line-height: 1; }
.game-done h2 { margin-bottom: 16px; }

@media (max-width: 700px) {
  .match-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bubble { width: 120px; height: 120px; font-size: 22px; }
  .game-head { flex-direction: column; text-align: center; }
}

/* ---------- Listening: listen → confirm → (problem) ---------- */
.overlay { overflow-y: auto; }
.phase { display: none; flex-direction: column; align-items: center; }
.listen-box[data-phase="listening"] .phase-listening,
.listen-box[data-phase="confirm"] .phase-confirm,
.listen-box[data-phase="problem"] .phase-problem,
.listen-box[data-phase="thinking"] .phase-thinking { display: flex; animation: pop-in 0.25s ease-out; }
.phase-thinking .dots { margin: 6px 0 4px; }
#micToggle { transition: transform 0.08s linear; }
.listen-hint { margin: 0 0 10px; font-size: 20px; color: var(--ink-soft); }
.listen-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin: 4px 0 10px; }
.confirm-hoot { width: 120px; height: 132px; margin-bottom: 4px; }
.confirm-label { margin: 0 0 8px; font-size: 26px; font-weight: 600; color: var(--ink-soft); }
.phase-problem .confirm-label { max-width: 460px; color: var(--ink); line-height: 1.3; margin-bottom: 18px; }
.confirm-q {
  margin: 0 0 22px; padding: 14px 24px; max-width: 100%;
  font-family: var(--font-read); font-size: 34px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere;
  background: var(--accent-soft); border: var(--border); border-radius: 22px;
}
.btn.yes { min-height: 68px; padding: 12px 28px; font-size: 25px; background: var(--green); }
.btn.again { min-height: 68px; padding: 12px 28px; font-size: 25px; background: var(--pink); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.15); }

/* ---------- Grown-up settings ---------- */
.home-foot { display: flex; justify-content: center; margin-top: 8px; }
.settings-box {
  display: flex; flex-direction: column; gap: 10px; width: min(640px, 100%); padding: 26px 28px 28px;
  background: var(--paper); border: var(--border); border-radius: 30px; box-shadow: 0 10px 0 var(--ink);
}
.settings-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.settings-top h2 { margin: 0; font-size: 28px; }
.set-label { margin-top: 8px; font-size: 20px; font-weight: 600; }
.set-row { display: flex; align-items: center; gap: 12px; }
.set-row select {
  flex: 1; min-width: 0; min-height: 56px; padding: 0 16px; font: 500 19px var(--font-ui); color: var(--ink);
  background: var(--paper); border: var(--border); border-radius: 16px;
}
.set-row.speed { font-size: 17px; font-weight: 600; color: var(--ink-soft); }
.set-row input[type="range"] { flex: 1; min-width: 0; height: 40px; accent-color: var(--accent-deep); }
.set-note { margin: 0; font-size: 16px; color: var(--ink-soft); }
.set-tip {
  margin-top: 12px; padding: 16px 18px; font-size: 17px; line-height: 1.45;
  background: #fff3c4; border: 2px dashed var(--ink); border-radius: 18px;
}
.set-tip ul { margin: 8px 0; padding-left: 20px; }

/* ---------- Mouse hover (not on touch screens, where it sticks after a tap) ---------- */
@media (hover: hover) {
  .btn:hover { background: var(--accent-soft); }
  .btn.primary:hover { background: var(--accent-deep); }
  .btn.ghost:hover { background: rgba(255,255,255,0.6); }
  .mic-btn:hover { filter: brightness(1.05); }
  .chip:nth-child(4n+1):hover { background: #fff3c4; }
  .chip:nth-child(4n+2):hover { background: #ffe0ef; }
  .chip:nth-child(4n+3):hover { background: #dcf6e4; }
  .chip:nth-child(4n+4):hover { background: #e3f2ff; }
  .history-card:hover { transform: translateY(-3px) rotate(-1deg); }
  .ask-new:hover { background: #f0458f; }
  .seg button:hover { background: var(--accent-soft); }
  .video-card:hover { transform: translateY(-4px) rotate(-0.6deg); }
  .video-card:nth-child(2):hover { transform: translateY(-4px) rotate(0.6deg); }
  .choice:hover:not(:disabled) { background: var(--accent-soft); }
}

/* ---------- Smaller screens ---------- */
@media (max-width: 960px) {
  .lesson-grid { grid-template-columns: 1fr; }
  .video-grid, .facts { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .choices { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .hero { flex-direction: column; text-align: center; }
  .hero h1 { font-size: 40px; }
}
@media (max-width: 600px) {
  .view { padding: 20px 16px 60px; }
  .ask-hoot { flex-direction: column; }
  .ask-hoot .speech::before { display: none; }
  .logo { font-size: 36px; }
  .topbar .btn { font-size: 18px; padding: 8px 16px; }
}

/* Calm mode (the device's Reduce Motion setting, or the Grown-ups choice): gentle movement stays
   (drifting clouds, floating bubbles, Hoot blinking and bobbing); sudden or bouncy movement goes. */
body[data-motion="calm"] .confetti { display: none; }
body[data-motion="calm"] .view { animation-name: fade !important; }
body[data-motion="calm"] .hero-emoji,
body[data-motion="calm"] .reward-trophy,
body[data-motion="calm"] .mic-btn,
body[data-motion="calm"] .dots i,
body[data-motion="calm"] .thinking .wing-l,
body[data-motion="calm"] .thinking .wing-r,
body[data-motion="calm"] .wave .wing-r,
body[data-motion="calm"] .choice.wrong,
body[data-motion="calm"] .basket.nope,
body[data-motion="calm"] .bubble.nope,
body[data-motion="calm"] .skeleton .e { animation: none; }
body[data-motion="calm"] .thinking .hoot-body { animation-duration: 3.2s; }
body[data-motion="calm"] .rings.active::before,
body[data-motion="calm"] .rings.active::after { animation-duration: 2.6s; }
body[data-motion="calm"] .bubble { animation-duration: 5s; }
