:root {
  --ink: #2B2D42;
  --muted: #6B7280;
  --card: #FFFFFF;
  --purple: #7C5CFF;
  --pink: #FF5D8F;
  --green: #2EC4B6;
  --good: #22C55E;
  --radius: 28px;
  --shadow: 0 6px 0 rgba(43, 45, 66, 0.10), 0 14px 28px rgba(43, 45, 66, 0.10);
  --gutter: clamp(12px, 2.5vw, 32px);
  /* Baloo 2 covers Devanagari, so Hindi keeps the same rounded, playful look. */
  --font: 'Fredoka', 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --c: #FFC94D;
  --c2: #FF9F1C;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 201, 77, 0.35) 0, transparent 32%),
    radial-gradient(circle at 88% 20%, rgba(91, 192, 235, 0.30) 0, transparent 34%),
    radial-gradient(circle at 70% 95%, rgba(255, 181, 232, 0.35) 0, transparent 36%),
    linear-gradient(160deg, #FFF8EC 0%, #F0F7FF 100%);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
}

#app {
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

h1, h2, h3 { margin: 0; font-weight: 700; }

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2vh, 20px);
  padding: clamp(10px, 2vh, 20px) var(--gutter);
  animation: screen-in 0.35s ease-out;
}

.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  flex-shrink: 0;
}

.brand {
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  color: var(--purple);
}

.screen-title {
  font-size: clamp(22px, 3.2vw, 36px);
  text-align: center;
  flex: 1;
}

.topbar-spacer { width: 64px; }

.icon-btn {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 30px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.12s;
}
.icon-btn:active { transform: translateY(3px); }

/* Hold-to-activate: a bar fills while the button is pressed. */
.hold-btn::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 7px;
  height: 5px;
  border-radius: 3px;
  background: var(--purple);
  transform: scaleX(0);
  transform-origin: left;
}
.hold-btn.holding::after {
  transform: scaleX(1);
  transition: transform var(--hold, 700ms) linear;
}
.hold-tip {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
}
.hold-btn.nudge .hold-tip { animation: tip 1.6s ease; }

.pill-btn {
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.12s;
}
.pill-btn:active { transform: translateY(3px) scale(0.98); }
.pill-btn.play {
  background: linear-gradient(145deg, var(--c), var(--c2));
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.pill-btn.big { padding: 16px 28px; font-size: clamp(18px, 2.4vw, 26px); }

.top-actions { display: flex; gap: 10px; }

/* ---------- Start ---------- */

.start {
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.logo {
  display: flex;
  flex-direction: column;
  line-height: 0.95;
  font-size: clamp(54px, 11vw, 120px);
  color: var(--purple);
  text-shadow: 0 6px 0 rgba(124, 92, 255, 0.18);
  z-index: 1;
}
.logo span:last-child { color: var(--pink); }

.big-play {
  width: clamp(140px, 22vw, 200px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(145deg, #FFD166, #FF8C42);
  color: #fff;
  font-size: clamp(56px, 9vw, 84px);
  padding-left: 0.15em;
  box-shadow: 0 10px 0 #E06D1F, 0 22px 40px rgba(255, 140, 66, 0.45);
  animation: breathe 1.8s ease-in-out infinite;
  z-index: 1;
}
.big-play:active { transform: translateY(6px); box-shadow: 0 4px 0 #E06D1F; }

.start-hint {
  font-size: clamp(16px, 2vw, 22px);
  color: var(--muted);
  z-index: 1;
}

.floaters span {
  position: absolute;
  font-size: clamp(40px, 7vw, 76px);
  animation: float 6s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.6s);
  opacity: 0.9;
}

/* ---------- Home ---------- */

.module-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 17vw, 230px), 1fr));
  gap: clamp(12px, 2vw, 22px);
  align-content: start;
  padding: 6px 4px 24px;
}

.module-tile {
  position: relative;
  aspect-ratio: 1 / 1.05;
  border-radius: var(--radius);
  background: linear-gradient(150deg, var(--c), var(--c2));
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.14), 0 16px 30px rgba(0, 0, 0, 0.10);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  overflow: hidden;
  container-type: inline-size;
  transition: transform 0.12s;
}
.module-tile::before {
  content: '';
  position: absolute;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  top: -18%;
  right: -18%;
}
.module-tile:active { transform: translateY(5px) scale(0.98); }
.tile-emoji {
  font-size: 64px;
  font-size: 44cqi;
  line-height: 1.1;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.18));
}
.tile-title {
  font-size: 20px;
  font-size: clamp(16px, 11cqi, 26px);
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  text-align: center;
  line-height: 1.1;
}
.tile-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 80%;
  font-size: clamp(12px, 8cqi, 16px);
  font-weight: 600;
}
.tile-stars { white-space: nowrap; }

.meter {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  background: #fff;
  border-radius: inherit;
  min-width: 6%;
  transition: width 0.6s ease;
}
.meter.wide { background: rgba(43, 45, 66, 0.08); }
.meter.wide i { background: linear-gradient(90deg, var(--c), var(--c2)); }

/* ---------- Module (learn) ---------- */

.module .screen-title { color: var(--ink); }

.item-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(120px, 16vw, 190px), 1fr));
  gap: clamp(12px, 2vw, 20px);
  align-content: start;
  padding: 6px 4px 24px;
}

.item-card {
  position: relative;
  aspect-ratio: 1 / 1.12;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 7px 0 var(--c), 0 14px 26px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  container-type: inline-size;
  transition: transform 0.12s, box-shadow 0.2s;
}
.item-card:active { transform: translateY(4px); }
.item-card.spot { box-shadow: 0 0 0 6px var(--c), 0 0 0 12px rgba(255, 255, 255, 0.8), 0 14px 26px rgba(0, 0, 0, 0.12); transform: scale(1.05); }
.item-visual { display: grid; place-items: center; height: 100px; height: 66cqi; }
.item-visual .emoji { font-size: 84px; font-size: 56cqi; }
.item-visual .swatch { width: 88px; width: 58cqi; }
.item-name {
  font-size: 20px;
  font-size: clamp(16px, 13cqi, 26px);
  font-weight: 600;
  text-transform: capitalize;
}
.badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 13cqi;
}

.emoji { line-height: 1; display: inline-block; }

.swatch {
  display: inline-block;
  aspect-ratio: 1;
  background: var(--sw);
  border-radius: 46% 54% 52% 48% / 52% 46% 54% 48%;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.12), inset 8px 8px 0 rgba(255, 255, 255, 0.35), 0 0 0 3px rgba(43, 45, 66, 0.08);
}

/* ---------- Quiz ---------- */

.dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(43, 45, 66, 0.10);
  display: grid;
  place-items: center;
  font-size: 18px;
}
.dot.now { background: var(--c); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9); }
.dot.ok { background: #FFF3C4; animation: pop 0.4s; }
.dot.meh { background: #FFF3C4; opacity: 0.65; }

.prompt {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  padding: 14px 28px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: clamp(24px, 4.2vw, 46px);
  font-weight: 700;
  flex-shrink: 0;
}
.prompt-ear { font-size: 0.85em; animation: wiggle 2.4s ease-in-out infinite; }
.prompt-text { text-align: left; }

.choices {
  --cols: 2;
  --rows: 1;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: clamp(14px, 3vw, 36px);
  align-content: center;
  justify-items: center;
  padding-bottom: 10px;
}
.choices[data-n="3"] { --cols: 3; }
.choices[data-n="4"] { --cols: 4; }
@media (orientation: portrait) {
  .choices[data-n="4"] { --cols: 2; --rows: 2; }
}

.choice {
  width: 100%;
  max-width: min(420px, calc((100dvh - 290px) / var(--rows) - 20px));
  aspect-ratio: 1;
  border-radius: 36px;
  background: var(--card);
  box-shadow: 0 9px 0 var(--c), 0 18px 34px rgba(0, 0, 0, 0.10);
  display: grid;
  place-items: center;
  container-type: inline-size;
  transition: transform 0.15s, opacity 0.3s, box-shadow 0.3s;
  animation: deal 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) backwards;
}
.choice:nth-child(2) { animation-delay: 0.08s; }
.choice:nth-child(3) { animation-delay: 0.16s; }
.choice:nth-child(4) { animation-delay: 0.24s; }
.choice:active { transform: scale(0.96); }
.choice .emoji { font-size: 150px; font-size: 62cqi; }
.choice .swatch { width: 160px; width: 66cqi; }
.choice.correct {
  box-shadow: 0 0 0 8px var(--good), 0 0 40px rgba(34, 197, 94, 0.5);
  animation: celebrate 0.9s ease;
  z-index: 2;
}
.choice.fade { opacity: 0.25; transform: scale(0.92); }
.choice.wrong { opacity: 0.6; }
.choice.hint:not(.correct) { animation: hint 1.1s ease-in-out infinite; }

/* ---------- Round done ---------- */

.done {
  align-items: center;
  justify-content: center;
  text-align: center;
}
.trophy {
  font-size: clamp(90px, 18vh, 170px);
  line-height: 1;
  animation: trophy 1s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.done-title { font-size: clamp(36px, 7vw, 72px); color: var(--purple); }
.done-stars { display: flex; gap: 10px; font-size: clamp(48px, 9vh, 84px); }
.star { opacity: 0.18; filter: grayscale(1); }
.star.on { opacity: 1; filter: none; animation: star-in 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) backwards; animation-delay: calc(0.4s + var(--d)); }
.done-score { margin: 0; color: var(--muted); font-size: clamp(16px, 2vw, 22px); }
.unlock {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px 12px 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 700;
  animation: pop 0.6s 1.2s backwards;
}
.unlock-label {
  background: var(--pink);
  color: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.7em;
}
.unlock-visual .emoji { font-size: 1.8em; }
.unlock-visual .swatch { width: 1.6em; }
.unlock-name { text-transform: capitalize; }
.done-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 8px; }

/* ---------- Parent dashboard ---------- */

.parent { display: block; padding-bottom: 40px; }
.parent > * + * { margin-top: 18px; }
.parent h3 { font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.parent p { margin: 6px 0 0; line-height: 1.4; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat, .panel, .mod-card {
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 4px 0 rgba(43, 45, 66, 0.06), 0 10px 22px rgba(43, 45, 66, 0.06);
}
.stat { padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 34px; color: var(--purple); }
.stat b small { font-size: 18px; color: var(--muted); }
.stat span { color: var(--muted); font-weight: 500; }

.mod-progress {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
  gap: 12px;
}
.mod-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.mod-head { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.mod-emoji { font-size: 28px; }
.mod-pct { margin-left: auto; font-weight: 700; color: var(--purple); }
.mod-sub { font-size: 13px; color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.chip { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.chip-visual .emoji { font-size: 22px; }
.chip-visual .swatch { width: 20px; }
.chip-bar { width: 100%; height: 5px; border-radius: 3px; background: rgba(43, 45, 66, 0.1); overflow: hidden; }
.chip-bar i { display: block; height: 100%; background: #F59E0B; }
.chip.learning .chip-bar i { background: #3B82F6; }
.chip.knows .chip-bar i { background: var(--good); }
.chip.locked { opacity: 0.35; }

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 12px;
}
.panel { padding: 16px; }
.mixups, .recent { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mixups li { display: flex; align-items: center; gap: 10px; }
.mixups .emoji { font-size: 28px; }
.mixups .swatch { width: 26px; }
.mix-arrow { font-size: 13px; color: var(--muted); }
.recent li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; font-size: 15px; }

.settings { display: flex; flex-direction: column; gap: 4px; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(43, 45, 66, 0.07);
  font-size: 17px;
}
.setting input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--purple); }
.setting input[type="range"] { width: min(220px, 45%); accent-color: var(--purple); }
.setting select {
  font: inherit;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid rgba(43, 45, 66, 0.12);
  background: #fff;
  color: var(--ink);
}
.settings .pill-btn { align-self: flex-start; margin-top: 10px; }

.how summary { font-weight: 700; font-size: 18px; cursor: pointer; }
.how ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.5; display: flex; flex-direction: column; gap: 6px; }

.danger { display: flex; justify-content: center; padding-top: 6px; }
.danger-btn { background: #FFE4E6; color: #BE123C; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(43, 45, 66, 0.4);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
  animation: screen-in 0.2s;
}
.modal-card {
  background: #fff;
  border-radius: 26px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Language ---------- */

.lang-btn {
  padding: 10px 18px;
  font-family: 'Baloo 2', var(--font);
  font-weight: 700;
  color: var(--purple);
  border: 2px solid rgba(124, 92, 255, 0.25);
}
.lang-btn.corner {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 2;
  font-size: 20px;
}
.voice-warning {
  margin: 4px 0 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #FFF4D6;
  color: #8A4B00;
  font-size: 15px;
}

/* Devanagari has taller marks above and below the line: give it room. */
:lang(hi) body { font-family: 'Baloo 2', 'Fredoka', ui-rounded, system-ui, sans-serif; }
:lang(hi) .logo { line-height: 1.12; }
:lang(hi) .tile-title,
:lang(hi) .item-name,
:lang(hi) .prompt,
:lang(hi) .done-title { line-height: 1.3; }
:lang(hi) .item-name { text-transform: none; }

/* ---------- Problems and recovery ---------- */

.help-btn {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: #FFF4D6;
  color: #8A4B00;
  border: 2px solid #F5B942;
  box-shadow: var(--shadow);
  font-size: 16px;
  font-weight: 600;
  animation: pop 0.5s;
}
.help-btn b {
  background: #E8590C;
  color: #fff;
  border-radius: 999px;
  min-width: 24px;
  padding: 0 7px;
  font-size: 14px;
}
.problems { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.problems li { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 14px; background: #FFF7E8; font-size: 14px; -webkit-user-select: text; user-select: text; }
.problems li b { color: #8A4B00; }
.row-actions, .modal-actions.wrap { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.modal-actions.wrap { justify-content: flex-end; }
.report-text {
  width: 100%;
  min-height: 140px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid rgba(43, 45, 66, 0.15);
  font: 12px/1.4 ui-monospace, Menlo, monospace;
  -webkit-user-select: text;
  user-select: text;
}
.oops { align-items: center; justify-content: center; text-align: center; }

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .top-actions .pill-btn { padding: 10px 14px; }
  .module .screen-title { font-size: 20px; }
  .prompt { padding: 12px 20px; }
}
@media (max-width: 420px) {
  .listen { display: none; }
}

/* ---------- Motion ---------- */

.pop { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
.shake { animation: shake 0.5s ease; }

@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.15) rotate(-3deg); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-12px) rotate(-3deg); } 40% { transform: translateX(10px) rotate(3deg); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } }
@keyframes celebrate { 0% { transform: scale(1); } 30% { transform: scale(1.14) rotate(-4deg); } 55% { transform: scale(1.08) rotate(4deg); } 100% { transform: scale(1.06); } }
@keyframes hint { 0%, 100% { transform: scale(1); box-shadow: 0 9px 0 var(--c), 0 0 0 0 rgba(255, 209, 102, 0.0); } 50% { transform: scale(1.06); box-shadow: 0 9px 0 var(--c), 0 0 0 14px rgba(255, 209, 102, 0.7); } }
@keyframes deal { from { opacity: 0; transform: translateY(40px) scale(0.8); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-22px) rotate(6deg); } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-12deg); } 90% { transform: rotate(12deg); } 95% { transform: rotate(-6deg); } }
@keyframes trophy { from { transform: scale(0) rotate(-30deg); } }
@keyframes star-in { from { transform: scale(0) rotate(-90deg); opacity: 0; } }
@keyframes tip { 0% { opacity: 0; } 15%, 75% { opacity: 1; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
