/* Mobile-first. Sizing uses clamp() so characters/buttons/text scale fluidly
   from phone (~360px) through tablet to desktop without media-query jumps.
   Layout: 3-row grid (topbar / stage / bottombar) using 100dvh so iOS Safari's
   address bar doesn't push the bottombar off screen. */

:root {
  --bg: #fff8e6;
  --panel: #ffffff;
  --ink: #2d2a4a;
  --accent: #ff7ab6;
  --accent-2: #6ec6ff;
  --good: #6dd58c;
  --bad: #ff7676;
  --radius: 20px;
  --shadow: 0 4px 0 rgba(45, 42, 74, 0.12);
  --tap: 52px;
  font-family: "Comic Sans MS", "Comic Neue", "Quicksand", system-ui, -apple-system, sans-serif;
  font-size: clamp(14px, 2.6vw, 17px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- top + bottom bars ---------- */
.topbar, .bottombar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  flex-wrap: nowrap;
}
.topbar {
  justify-content: space-between;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left:  max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}
.bottombar {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left:  max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.logo { font-size: clamp(1.4rem, 5vw, 1.8rem); }
.brand .title {
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* On tiny phones, drop the wordmark to free space for badges + controls. */
@media (max-width: 420px) {
  .brand .title { display: none; }
}

.badges { display: flex; gap: 6px; flex-wrap: nowrap; }
.badge {
  width: clamp(34px, 9vw, 44px);
  height: clamp(34px, 9vw, 44px);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  background: #eee;
  filter: grayscale(1) opacity(0.5);
  transition: transform 0.4s, filter 0.4s, background 0.4s;
}
.badge.earned {
  filter: none;
  background: linear-gradient(135deg, #fff2a8, #ffd166);
  transform: scale(1.1) rotate(-6deg);
  box-shadow: var(--shadow);
}

.controls { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.icon-btn {
  min-width: 38px; min-height: 38px;
  border: 2px solid var(--ink);
  background: var(--panel);
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.icon-btn[aria-pressed="true"] {
  background: var(--ink); color: #fff;
}
.icon-btn.presenter-btn[aria-pressed="true"] {
  background: #312e81; color: #fde047; border-color: #312e81;
}
.lang { display: flex; gap: 4px; }
.lang-btn {
  min-width: 40px; min-height: 40px;
  border: 2px solid var(--ink);
  background: var(--panel);
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0 8px;
}
.lang-btn[aria-pressed="true"] {
  background: var(--accent);
  color: white;
}

.nav {
  min-height: var(--tap);
  padding: 0 clamp(14px, 4vw, 24px);
  font-size: clamp(0.95rem, 3vw, 1.1rem);
  font-weight: 700;
  border-radius: var(--radius);
  border: none;
  background: var(--accent-2);
  color: white;
  cursor: pointer;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.nav:disabled { opacity: 0.4; cursor: not-allowed; }
.nav.next { background: var(--accent); }
.progress { flex: 1; display: flex; gap: 6px; justify-content: center; }
.progress span {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #e3dffb;
}
.progress span.done { background: var(--accent); }
.progress span.current { background: var(--accent-2); transform: scale(1.3); }

/* ---------- stage ---------- */
.stage {
  position: relative;
  padding: 12px;
  display: grid;
  place-items: start center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0; /* allow shrink in grid */
}
.scene {
  width: 100%;
  max-width: 760px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: clamp(12px, 3vw, 24px);
  box-shadow: var(--shadow);
  display: grid;
  gap: clamp(10px, 2vw, 16px);
  text-align: center;
}
.scene h2 {
  margin: 0;
  font-size: clamp(1.2rem, 4.5vw, 1.6rem);
}
.scene p.dialog {
  font-size: clamp(0.95rem, 3.2vw, 1.2rem);
  line-height: 1.45;
  padding: clamp(10px, 2.5vw, 14px) clamp(12px, 3vw, 18px);
  background: #fff3fb;
  border-radius: 16px;
  border: 2px dashed var(--accent);
  margin: 0 auto;
  max-width: 620px;
}
.scene .cta {
  min-height: var(--tap);
  padding: 0 clamp(18px, 5vw, 28px);
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  justify-self: center;
}

/* ---------- characters (emoji) ---------- */
.zubko {
  font-size: clamp(3.5rem, 18vw, 6.5rem);
  line-height: 1;
  display: inline-block;
  transform-origin: center bottom;
}
.zubko.has-cape { animation: zubko-bob 2.4s ease-in-out infinite; }
.zubko.has-cape::after {
  content: "🦸";
  font-size: 0.35em;
  vertical-align: super;
  margin-left: -0.2em;
  display: inline-block;
  transform-origin: 50% 100%;
  animation: cape-flap 1.2s ease-in-out infinite;
}
.zubko.bounce { animation: zubko-bounce 0.55s cubic-bezier(.32,1.5,.4,1); }
.zubko.shake { animation: zubko-shake 0.45s ease-in-out; }
.monster { font-size: clamp(2.8rem, 12vw, 4rem); display: inline-block; transition: transform 0.5s; }
.monster.grew { transform: scale(1.6); filter: drop-shadow(0 0 8px var(--bad)); }

@keyframes zubko-bounce {
  0%   { transform: translateY(0) scale(1); }
  35%  { transform: translateY(-18px) scale(1.12); }
  65%  { transform: translateY(2px)   scale(0.94); }
  100% { transform: translateY(0)     scale(1); }
}
@keyframes zubko-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-8px) rotate(-4deg); }
  40% { transform: translateX(8px)  rotate(4deg); }
  60% { transform: translateX(-6px) rotate(-2deg); }
  80% { transform: translateX(6px)  rotate(2deg); }
}
@keyframes zubko-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
@keyframes cape-flap {
  0%, 100% { transform: rotate(-10deg) translateY(0); }
  50%      { transform: rotate(10deg)  translateY(-3px); }
}

/* ---------- drag/drop ---------- */
.draggables {
  display: flex; gap: clamp(8px, 2vw, 16px); flex-wrap: wrap; justify-content: center;
}
.drag-item {
  width:  clamp(64px, 18vw, 90px);
  height: clamp(64px, 18vw, 90px);
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: clamp(2.2rem, 9vw, 3rem);
  background: #f6f1ff;
  cursor: grab;
  touch-action: none;
  box-shadow: var(--shadow);
}
.drag-item.dragging { opacity: 0.65; cursor: grabbing; z-index: 5; }
.drag-item.used { visibility: hidden; }
.drop-zone {
  min-height: clamp(110px, 28vw, 160px);
  border-radius: var(--radius);
  border: 3px dashed var(--accent-2);
  display: grid; place-items: center;
  padding: 10px;
}
.drop-zone.hover { background: #e8f6ff; }

/* ---------- snack stage: stack on phones, two columns on wider screens ---------- */
.snack-stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: center;
}
@media (min-width: 520px) {
  .snack-stage { grid-template-columns: 1fr 1fr; }
}
.monster-side { display: grid; place-items: center; gap: 4px; }
.monster-side small { font-size: 0.85rem; opacity: 0.7; }

/* ---------- brushing ---------- */
.paste-row {
  display: flex; justify-content: center; align-items: center;
  gap: clamp(12px, 4vw, 24px); flex-wrap: wrap;
}
.drop-zone--brush {
  min-width: clamp(100px, 30vw, 140px);
  min-height: clamp(80px, 22vw, 120px);
  display: grid; place-items: center; gap: 4px;
}
.brush-emoji { font-size: clamp(2.5rem, 9vw, 3.5rem); display: block; }
.pea { font-size: clamp(1rem, 4vw, 1.4rem); display: block; margin-top: -8px; }
.tooth-area {
  width:  clamp(180px, 60vw, 240px);
  height: clamp(180px, 60vw, 240px);
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff, #ffe6f1);
  position: relative;
  touch-action: none;
  display: grid; place-items: center;
  font-size: clamp(4rem, 22vw, 6rem);
  overflow: hidden;
}
.tooth-area .plaque {
  position: absolute; inset: 0;
  background: radial-gradient(circle, #c9c19b 0%, #c9c19b 60%, transparent 70%);
  opacity: 1;
  transition: opacity 0.2s;
  pointer-events: none;
}
.meter {
  height: 14px;
  background: #eee;
  border-radius: 8px;
  overflow: hidden;
  max-width: 320px;
  width: 80%;
  margin: 0 auto;
}
.meter > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--good));
  transition: width 0.2s;
}

/* ---------- plan (if-then) ---------- */
.bed-scene { font-size: clamp(2.5rem, 10vw, 3.5rem); }
.plan-row {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: stretch;
}
.plan-card {
  flex: 1 1 200px;
  min-height: 90px;
  border-radius: 16px;
  padding: 12px;
  background: #f6f1ff;
  font-size: clamp(0.9rem, 3vw, 1.05rem);
  display: grid; place-items: center;
  border: 3px solid transparent;
  cursor: pointer;
}
.plan-card.if { background: #fff7d6; cursor: default; }
.plan-card.then { transition: transform 0.15s, border-color 0.15s; }
.plan-card.then:hover { transform: translateY(-3px); }
.plan-card.then.correct { border-color: var(--good); background: #e9fbef; }
.plan-card.then.wrong { border-color: var(--bad); background: #ffe9e9; }

/* ---------- dentist ---------- */
.dentist-row {
  display: flex; justify-content: center; align-items: center;
  gap: clamp(8px, 3vw, 18px); flex-wrap: wrap;
}
.dentist-figure, .mirror-figure { font-size: clamp(2.5rem, 10vw, 4rem); }
.tooth-with-stars {
  position: relative;
  width:  clamp(180px, 50vw, 240px);
  height: clamp(180px, 50vw, 240px);
}
.tooth-with-stars .zubko {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: clamp(5rem, 22vw, 7rem);
}
.star {
  position: absolute;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  cursor: pointer;
  filter: drop-shadow(0 0 8px gold);
  animation: twinkle 1.4s ease-in-out infinite;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  transform: translate(-50%, -50%);
}
.star.found { animation: none; filter: none; opacity: 0.3; pointer-events: none; }
@keyframes twinkle {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.25); }
}

/* ---------- victory ---------- */
.victory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin: 8px 0;
}
.victory-badge {
  background: linear-gradient(135deg, #fff2a8, #ffd166);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
  display: grid; gap: 4px; place-items: center;
}
.victory-badge .icon { font-size: clamp(1.8rem, 6vw, 2.4rem); }
.victory-badge .name { font-weight: 700; font-size: clamp(0.8rem, 2.6vw, 0.95rem); }
.victory-badge.missed { opacity: 0.35; filter: grayscale(1); }

/* ---------- feedback toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: clamp(0.9rem, 3vw, 1.05rem);
  max-width: 92vw;
  text-align: center;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-8px);
}
.toast.good { background: var(--good); }
.toast.bad { background: var(--bad); }

/* ---------- confetti (victory) ---------- */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 35;
}
.confetti span {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-24px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(var(--spin, 540deg)); opacity: 0.4; }
}

/* Respect users who prefer no motion — disable all decorative loops. */
@media (prefers-reduced-motion: reduce) {
  .zubko.bounce, .zubko.shake, .zubko.has-cape, .zubko.has-cape::after,
  .star, .monster, .confetti span {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- presenter / teacher panel ---------- */
.presenter-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(380px, 100vw);
  background: #1e1b4b;
  color: #fff;
  padding: 18px;
  padding-top:    max(18px, env(safe-area-inset-top));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 40;
  box-shadow: -8px 0 24px rgba(0,0,0,0.25);
}
.presenter-panel[aria-hidden="false"] { transform: translateX(0); }
.presenter-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 1.15rem; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 10px; margin-bottom: 14px;
}
.presenter-panel__close {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.4);
  width: 36px; height: 36px; border-radius: 50%; font-size: 1rem; cursor: pointer;
}
.presenter-section { margin-bottom: 16px; }
.presenter-label {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #c4b5fd; margin-bottom: 4px;
}
.presenter-value { font-size: 0.98rem; line-height: 1.45; color: #f5f3ff; }

/* On wide screens, shift the stage left so the panel doesn't cover content. */
@media (min-width: 1100px) {
  body.presenter-open .stage { padding-right: 400px; }
}
