* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI Rounded", system-ui, sans-serif;
  background: linear-gradient(135deg, #aee9ff 0%, #d9c6ff 35%, #ffd6ec 70%, #fff3b0 100%);
  min-height: 100vh;
  overflow-x: hidden;
  color: #3a2d5c;
  touch-action: manipulation; /* no double-tap zoom delay on phones */
  overscroll-behavior-y: none;
}
button { touch-action: manipulation; user-select: none; -webkit-user-select: none; }

/* floating bg emojis */
.bg-shapes { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-shapes span {
  position: absolute; font-size: 2.4rem; opacity: .35;
  animation: float 9s ease-in-out infinite;
}
.bg-shapes span:nth-child(1){ left:4%; top:8%; }
.bg-shapes span:nth-child(2){ right:8%; top:12%; animation-delay:1s; }
.bg-shapes span:nth-child(3){ left:10%; bottom:14%; animation-delay:2s; }
.bg-shapes span:nth-child(4){ right:12%; bottom:20%; animation-delay:.5s; }
.bg-shapes span:nth-child(5){ left:45%; top:4%; animation-delay:1.5s; }
.bg-shapes span:nth-child(6){ left:30%; bottom:6%; animation-delay:2.5s; }
.bg-shapes span:nth-child(7){ right:30%; top:40%; animation-delay:3s; }
.bg-shapes span:nth-child(8){ left:6%; top:45%; animation-delay:.8s; }
.bg-shapes span:nth-child(9){ right:5%; top:60%; animation-delay:1.8s; }
.bg-shapes span:nth-child(10){ left:48%; bottom:3%; animation-delay:2.2s; }
@keyframes float { 0%,100%{ transform: translateY(0) rotate(-6deg);} 50%{ transform: translateY(-18px) rotate(6deg);} }

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  z-index: 1;
}
.screen.active { display: flex; }

/* full-page quiz — locked, no page scroll */
#screen-quiz.active { justify-content: center; padding: 0; height: 100dvh; max-height: 100dvh; overflow: hidden; }
.quiz-layout {
  display: flex; flex-direction: column;
  width: 100%; height: 100dvh; max-height: 100dvh; /* complete full-height layout */
  margin: 0 auto; /* centered block; desktop width set below */
}
/* side panel: horizontal top strip on phones, vertical sidebar on wide screens */
.quiz-side {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  padding: 12px 12px 0;
  flex-shrink: 0;
}
#screen-quiz .quiz-card {
  flex: 1; min-height: 0; width: auto; max-width: none; /* fill the row — base .card caps at 560px */
  border-radius: 32px 32px 0 0; margin: 10px 12px 0;
  display: flex; flex-direction: column;
  overflow-y: auto; /* safety valve for very small screens */
  scrollbar-gutter: stable both-edges; /* symmetric gutters: a scrollbar can never shift content left */
}
/* question + options: natural flow, sized in vh so it always fits */
.quiz-body {
  flex: 0 1 auto; min-height: 0;
}
/* reserved bottom space: feedback + Next always occupy room → no jump, no scroll */
.quiz-foot {
  margin-top: auto;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  min-height: 2.5rem; /* feedback line only — no big reserve eating option space */
  display: flex; flex-direction: column; justify-content: flex-end;
}
/* celebration popup on correct answer */
.celebrate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(58, 45, 92, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
  padding: 16px;
}
.celebrate.show { opacity: 1; pointer-events: auto; }
.celebrate-pop {
  background: #fff; border-radius: 32px; border: 4px solid #ffde59;
  padding: 26px 40px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  transform: scale(.5);
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
  max-width: 90vw;
}
.celebrate.show .celebrate-pop { transform: scale(1); }
.celebrate-emoji { font-size: 4.5rem; line-height: 1; animation: bounce 1s ease infinite; }
.celebrate-title { font-size: 2.6rem; font-weight: 900; color: #16a34a; margin: 4px 0 0; }
.celebrate-sub { font-size: 1.2rem; font-weight: 800; opacity: .8; margin: 2px 0 6px; }
.celebrate-count {
  font-size: 3.5rem; font-weight: 900; color: #2563eb; line-height: 1.1;
  animation: pop .3s ease;
}
/* restored-after-reload rendering: zero motion until she taps Stay */
.quiz-card.no-anim, .quiz-card.no-anim * { animation: none !important; transition: none !important; }
/* new question card slides in */
.quiz-card.enter { animation: slideIn .35s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: none; } }

.card {
  background: rgba(255,255,255,.96);
  border-radius: 32px;
  padding: 26px 22px 22px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(90,60,160,.25);
  border: 4px solid #fff;
  text-align: center;
}
.logo {
  display: inline-block;
  font-size: 1.6rem; font-weight: 900;
  background: #ffde59; border-radius: 999px;
  padding: 8px 20px; transform: rotate(-2deg);
  box-shadow: 0 4px 0 #e0a800;
}
h1 { font-size: 2rem; line-height: 1.15; margin: 14px 0 6px; }
.subtitle { font-size: 1.05rem; opacity: .85; margin: 0 0 12px; }

.panel {
  background: #f4f0ff; border-radius: 20px;
  padding: 12px; margin: 12px 0; text-align: left;
}
.panel-label { font-weight: 800; display: block; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 3px solid #ddd6ff; background: #fff;
  border-radius: 999px; padding: 8px 12px;
  font-size: .95rem; font-weight: 800; cursor: pointer;
}
.chip.active { background: #7c5cff; color: #fff; border-color: #7c5cff; }

.count-row { display: flex; flex-direction: column; gap: 10px; }
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 56px; border: 3px solid #ddd6ff;
  background: #fff; border-radius: 14px; padding: 10px 0;
  font-weight: 900; font-size: 1rem; cursor: pointer;
}
.seg-btn.active { background: #22c55e; color: #fff; border-color: #22c55e; }
/* answer modes: 2 per row so all four stay big and readable */
#mode-segmented { display: grid; grid-template-columns: 1fr 1fr; }
#mode-segmented .seg-btn { min-width: 0; padding: 14px 0; font-size: 1.1rem; }
.custom-count { display: flex; align-items: center; gap: 8px; justify-content: center; font-weight: 700; }
.custom-count input {
  width: 90px; font-size: 1.2rem; font-weight: 900; text-align: center;
  border-radius: 12px; border: 3px solid #ddd6ff; padding: 6px;
}
.hint { font-size: .9rem; margin: 8px 2px 0; opacity: .8; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.answered-line { font-size: 1.05rem; }
.sub-hint { font-size: .85rem; opacity: .7; }

.toggles { display: flex; gap: 12px; justify-content: center; margin: 6px 0 12px; flex-wrap: wrap; }
.toggle { background: #fff7d6; border-radius: 999px; padding: 8px 14px; font-weight: 800; border: 2px solid #ffe27a; cursor: pointer; }

.btn {
  border: none; border-radius: 20px; cursor: pointer;
  font-family: inherit; font-weight: 900;
}
.btn-big {
  width: 100%; font-size: 1.7rem; padding: 18px;
  background: linear-gradient(180deg, #34d399, #16a34a);
  color: #fff; letter-spacing: 1px;
  box-shadow: 0 6px 0 #0d7a36;
  margin-top: 6px;
}
.btn-big:active { transform: translateY(4px); box-shadow: 0 2px 0 #0d7a36; }
.btn-secondary { background: #7c5cff; color: #fff; padding: 12px 18px; font-size: 1rem; box-shadow: 0 4px 0 #4c2fd6; }
.btn-block { width: 100%; margin-top: 10px; padding: 15px 18px; font-size: 1.2rem; }
.btn-ghost { background: #fff; border: 3px solid #ffd0d0; padding: 10px 14px; font-size: .95rem; }
.btn-ghost.on { border-color: #22c55e; background: #d3f9d8; }
.tiny { font-size: .8rem; opacity: .6; margin-top: 10px; }

/* Quiz side panel contents */
.quiz-side {
  width: 100%;
}
.icon-btn {
  width: 52px; height: 52px; font-size: 1.5rem;
  border-radius: 16px; border: none; background: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.12); cursor: pointer;
}
.progress-wrap { flex: 1; }
.progress-text { font-weight: 900; margin-bottom: 4px; }
.progress-bar { height: 16px; background: rgba(255,255,255,.8); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg,#ff9f1c,#ff4d6d,#7c5cff); transition: width .4s; border-radius: 999px; }
.score-pill { background: #fff; border-radius: 999px; padding: 10px 16px; font-weight: 900; font-size: 1.1rem; }

.quiz-card { padding-bottom: 18px; }
.q-category { display: inline-block; background: #eef2ff; border-radius: 999px; padding: 4px 14px; font-weight: 800; }
.q-text { font-size: 1.5rem; margin: 4px 0 2px; }
.q-emoji {
  /* viewport-relative: the whole quiz always fits, zero scrolling for kids */
  font-size: clamp(4.5rem, 19vh, 7rem);
  line-height: 1;
  background: radial-gradient(circle, #fff7d6 0%, #ffe9f3 70%);
  border-radius: 28px; padding: 8px; margin: 4px 0 6px;
  animation: pop .35s ease;
  cursor: pointer;
  height: clamp(120px, 22vh, 200px);
  min-height: unset;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  flex-shrink: 0;
}
/* ABC mode: giant letter instead of a picture */
.q-emoji.big-letter {
  color: #6d28d9; font-weight: 900;
  font-size: clamp(5rem, 22vh, 8rem);
  background: radial-gradient(circle, #ede9fe 0%, #fce7f3 70%);
}
@keyframes pop { from { transform: scale(.6);} to { transform: scale(1);} }

.q-options { display: flex; flex-direction: column; gap: 8px; }
.opt-btn {
  font-size: 1.5rem; font-weight: 900; padding: 12px 16px;
  min-height: 64px;
  border-radius: 24px; border: 5px solid #e5e0ff; background: #fff;
  cursor: pointer; transition: transform .15s ease, background-color .2s ease, border-color .2s ease;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  line-height: 1.2;
}
.opt-btn:active { transform: scale(.97); }
.opt-btn .opt-sound {
  font-size: 1.6rem; background: #eef2ff; border-radius: 12px;
  padding: 6px 10px; flex-shrink: 0;
  min-width: 48px; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.opt-btn .opt-name { flex: 1; text-align: center; }
/* picture-answer mode: big emoji + small word label (no reading needed) */
.opt-btn.pic { flex-direction: row; gap: 10px; align-items: center; padding: 8px 12px; }
.opt-btn .opt-mid { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0; }
.opt-btn .opt-emoji { font-size: 2.6rem; line-height: 1.1; }
.opt-btn .opt-word { font-size: .95rem; font-weight: 800; opacity: .6; }
.opt-btn.pic .opt-sound {
  font-size: 1.1rem; background: #eef2ff; border-radius: 10px;
  padding: 4px 8px; min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.opt-btn.wrong { background: #ffe1e1; border-color: #ff6b6b; transform: scale(.98); }
.opt-btn.correct { background: #d3f9d8; border-color: #22c55e; animation: bounce .5s; }
.opt-btn:disabled { opacity: .95; cursor: default; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-10px)} 75%{transform:translateX(10px)} }
@keyframes bounce { 0%{transform:scale(1)} 40%{transform:scale(1.08)} 100%{transform:scale(1)} }

.feedback { min-height: 2rem; font-size: 1.4rem; font-weight: 900; margin: 6px 0 2px; }
.feedback.good { color: #16a34a; }
.feedback.bad { color: #e11d48; }
.hidden { display: none !important; }

.center { text-align: center; }
.big-score { font-size: 4rem; font-weight: 900; }
.big-score small { font-size: 1.2rem; display: block; opacity: .7; }
.row-gap { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.confetti { font-size: 2rem; margin: 8px 0 14px; animation: float 2s ease-in-out infinite; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(100px);
  background: #3a2d5c; color: #fff; padding: 12px 20px; border-radius: 999px;
  font-weight: 800; opacity: 0; transition: all .3s; z-index: 99; max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* resume modal after a refresh mid-quiz */
.resume {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  background: rgba(58, 45, 92, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
  padding: 16px;
}
.resume.show { opacity: 1; pointer-events: auto; }
.resume-pop {
  background: #fff; border-radius: 32px; border: 4px solid #7c5cff;
  padding: 26px 30px; text-align: center;
  max-width: 430px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  transform: scale(.9); transition: transform .25s ease;
}
.resume.show .resume-pop { transform: scale(1); }
.resume-emoji { font-size: 3.5rem; line-height: 1; }
.resume-title { font-size: 2rem; font-weight: 900; margin-top: 4px; }
.resume-sub { font-size: 1rem; font-weight: 700; opacity: .7; margin: 4px 0 14px; }
.resume-btns { display: flex; flex-direction: column; gap: 10px; }
.resume-btns .btn-big { font-size: 1.3rem; }

/* on-page speech debug log, only visible with ?debug=1 */
.debuglog {
  display: none;
  position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 200;
  max-height: 32vh; overflow-y: auto;
  background: rgba(20,10,40,.92); color: #b6ff9e;
  font-family: monospace; font-size: 11px; line-height: 1.5;
  border-radius: 12px; padding: 8px 10px;
  pointer-events: auto; cursor: pointer; /* tap to dismiss */
}

.hear-row { margin: 0 0 8px; }
.btn-hear {
  background: #fff7d6; border: 3px solid #ffe27a;
  padding: 10px 18px; font-size: 1.05rem; border-radius: 999px;
}
.hear-hint { font-size: .8rem; opacity: .65; margin: 0 0 8px; }
.sound-test-row { align-items: center; margin-top: 4px; }
.debug-details summary { cursor: pointer; }
.debug-details summary small { font-weight: 400; opacity: .6; }
.debug-details .sound-test-row { margin-top: 10px; }
.voice-status { font-size: .85rem; font-weight: 700; opacity: .8; }
.voice-warn {
  background: #ffe1e1; border: 2px solid #ff6b6b; color: #a00;
  border-radius: 12px; padding: 8px 12px; font-size: .85rem; font-weight: 700;
  margin-top: 8px;
}

@media (min-width: 700px) {
  .q-emoji { height: clamp(140px, 24vh, 210px); }
  .opt-btn { font-size: 1.6rem; }
  /* keep single column — predictable height, no scroll surprises */
  /* side panel becomes a true vertical sidebar */
  .quiz-layout { flex-direction: row; align-items: stretch; width: 88%; max-width: 1400px; gap: 12px; }
  .quiz-side {
    flex-direction: column; align-items: stretch;
    width: 140px; flex-shrink: 0;
    padding: 16px 0 16px 16px; gap: 12px;
  }
  .quiz-side .icon-btn { width: 100%; height: 56px; font-size: 1.6rem; }
  .quiz-side .progress-wrap { width: 100%; }
  .quiz-side .progress-text { text-align: center; }
  .quiz-side .score-pill { text-align: center; font-size: 1.2rem; }
  #screen-quiz .quiz-card { margin: 16px 16px 0 0; }
  /* start page uses the same wide centered block: 15% air each side */
  #screen-start .start-card { width: 70%; max-width: 1200px; }
}

/* answers stay stacked (single column) on all screens — predictable, no squeeze */

/* ---- short screens (laptop windows, landscape phones): shrink to fit, no inner scroll ---- */
@media (max-height: 760px) {
  #screen-quiz .quiz-card { border-radius: 24px 24px 0 0; }
  .quiz-side { padding: 8px 10px 0; }
  .icon-btn { width: 44px; height: 44px; }
  .q-text { font-size: 1.3rem; margin: 4px 0 2px; }
  .q-emoji { height: clamp(96px, 20vh, 150px); font-size: clamp(3.8rem, 16vh, 5.5rem); margin: 4px 0 6px; padding: 6px; }
  .hear-row { margin: 0 0 6px; }
  .btn-hear { padding: 8px 14px; font-size: .95rem; }
  .hear-hint { display: none; }
  .q-options { gap: 8px; }
  .opt-btn { font-size: 1.3rem; min-height: 60px; padding: 10px 12px; border-width: 4px; }
  .feedback { min-height: 2rem; font-size: 1.25rem; margin: 6px 0 2px; }
}

/* ---- small phones: compact top bar, safe-area notch, still big touch targets ---- */
@media (max-width: 480px) {
  .screen { padding: 10px; }
  .card { padding: 18px 14px 16px; border-radius: 24px; }
  h1 { font-size: 1.6rem; }
  .quiz-side {
    gap: 8px; padding: 10px 10px 0;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .icon-btn { width: 48px; height: 48px; font-size: 1.3rem; }
  .score-pill { padding: 8px 12px; font-size: 1rem; }
  .q-text { font-size: 1.45rem; }
  .q-emoji { border-radius: 22px; height: clamp(110px, 20vh, 160px); font-size: clamp(4rem, 16vh, 5.5rem); }
  .opt-btn { font-size: 1.4rem; min-height: 64px; padding: 12px; border-width: 4px; }
  .quiz-foot { min-height: 76px; }
  .btn-big { font-size: 1.4rem; padding: 16px; }
  .hear-hint { display: none; } /* saves vertical space; 🔊 badges + Hear button remain */
}
