:root {
  --bg: #fff6e5;
  --card: #ffffff;
  --ink: #2a2733;
  --muted: #7a7386;
  --line: #efe3cc;
  --teal: #12a594;
  --teal-dark: #0c7d70;
  --orange: #ff8a3d;
  --orange-dark: #d96a1f;
  --pink: #ef5da8;
  --pink-dark: #c63f86;
  --yellow: #ffc83d;
  --green: #35b36b;
  --green-soft: #dff5e7;
  --amber-soft: #ffe9c7;
  --red: #e5484d;
  /* Noto Sans Malayalam joins conjuncts the way the textbook prints them.
     The fallbacks are system Malayalam fonts that also join them. */
  --ui: 'Noto Sans Malayalam', 'Malayalam Sangam MN', 'Nirmala UI', sans-serif;
  --read: var(--ui);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

button,
a {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
  opacity: 0.4;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

#app {
  max-width: 640px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.hero {
  text-align: center;
  padding: 20px 16px 24px;
  border-radius: 32px;
  background: linear-gradient(180deg, #bfeee6 0%, #e4f8f3 70%);
  border: 2px solid #a8e2d8;
}

.hero-emoji {
  font-size: 84px;
  line-height: 1.1;
  animation: bob 3s ease-in-out infinite;
}

.eyebrow {
  margin: 4px 0 0;
  font-weight: 700;
  color: var(--teal-dark);
}

.hero h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.35;
  font-weight: 800;
}

.menu {
  display: grid;
  gap: 14px;
}

.tile {
  --c: var(--teal);
  --d: var(--teal-dark);
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  min-height: 92px;
  border-radius: 26px;
  background: var(--c);
  color: #fff;
  text-decoration: none;
  text-align: left;
  width: 100%;
  box-shadow: 0 6px 0 var(--d);
  transition: transform 0.08s, box-shadow 0.08s;
}

.tile:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--d);
}

.tile-speak {
  --c: var(--orange);
  --d: var(--orange-dark);
}

.tile-games {
  --c: var(--pink);
  --d: var(--pink-dark);
}

.tile-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  font-size: 36px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 20px;
}

.tile b {
  display: block;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
}

.tile small {
  display: block;
  font-size: 15px;
  font-weight: 600;
  opacity: 0.9;
}

.stars {
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--yellow);
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.stars .off {
  color: rgba(255, 255, 255, 0.45);
  text-shadow: none;
}

.stars.dark .off {
  color: #e6dcc8;
}

.sticker {
  text-align: center;
  padding: 14px;
  border-radius: 24px;
  background: #fff3c4;
  border: 2px dashed var(--yellow);
  font-weight: 700;
  font-size: 20px;
}

.sticker span {
  font-size: 40px;
  display: block;
}

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

.bar {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  gap: 8px;
}

.bar h2 {
  margin: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 800;
}

.chip {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--card);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 var(--line);
  font-size: 24px;
  text-decoration: none;
}

.chip svg {
  width: 26px;
  height: 26px;
}

.chip.on {
  background: #d6f5ef;
  border-color: var(--teal);
  box-shadow: 0 3px 0 var(--teal);
}

/* ---------- Reading stage ---------- */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px 16px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 32px;
  text-align: center;
  min-height: 300px;
}

.scene {
  font-size: 64px;
  line-height: 1.2;
  letter-spacing: 6px;
}

.sentence {
  margin: 0;
  font-family: var(--read);
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 600;
  line-height: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
}

.w {
  padding: 0 8px;
  border-radius: 14px;
  font-family: var(--read);
  font-weight: 600;
  line-height: 1.7;
  transition: background 0.12s, transform 0.12s;
}

.w.on {
  background: var(--yellow);
  transform: scale(1.06);
}

.w.picked {
  background: #d6f5ef;
}

.w.good {
  background: var(--green-soft);
  color: #1c7a45;
}

.w.again {
  background: var(--amber-soft);
  color: #a35a00;
  text-decoration: underline wavy var(--orange);
  text-underline-offset: 8px;
}

.meaning {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-radius: 999px;
  background: #eefaf7;
  color: var(--teal-dark);
  font-weight: 700;
  font-size: 20px;
}

.meaning:empty {
  visibility: hidden;
}

.meaning .en {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--muted);
}

.status {
  min-height: 34px;
  font-weight: 700;
  font-size: 20px;
  color: var(--muted);
}

.status .stars {
  font-size: 34px;
}

.dots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

.dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e9dcc2;
}

.dots i.done {
  background: var(--teal);
}

.dots i.here {
  background: var(--orange);
  transform: scale(1.3);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding-bottom: 6px;
}

.round,
.big {
  --c: var(--card);
  --d: var(--line);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 5px 0 var(--d);
  transition: transform 0.08s, box-shadow 0.08s;
}

.round {
  width: 64px;
  height: 64px;
  border: 2px solid var(--line);
}

.big {
  --c: var(--teal);
  --d: var(--teal-dark);
  width: 96px;
  height: 96px;
  color: #fff;
}

.big.mic {
  --c: var(--orange);
  --d: var(--orange-dark);
}

.big.mic.rec {
  --c: var(--red);
  --d: #b0282d;
  animation: pulse 1.1s ease-in-out infinite;
}

.round:active:not(:disabled),
.big:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--d);
}

.round svg {
  width: 30px;
  height: 30px;
}

.big svg {
  width: 46px;
  height: 46px;
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.cta {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 22px;
  background: var(--teal);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 5px 0 var(--teal-dark);
}

.cta.alt {
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 0 5px 0 var(--line);
}

.cta:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--teal-dark);
}

.notice {
  padding: 12px 16px;
  border-radius: 18px;
  background: var(--amber-soft);
  color: #7a4400;
  font-family: system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- Games ---------- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.game-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 10px 14px;
  border-radius: 26px;
  background: var(--card);
  border: 2px solid var(--line);
  box-shadow: 0 5px 0 var(--line);
  text-decoration: none;
  text-align: center;
}

.game-tile:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--line);
}

.game-tile .ge {
  font-size: 44px;
  line-height: 1.2;
}

.game-tile b {
  /* Sized so the longest title fits on one line: a word must never be
     broken in the middle of a conjunct. */
  font-size: clamp(15px, 4.5vw, 20px);
  font-weight: 800;
  line-height: 1.5;
}

.game-tile small {
  font-family: system-ui, sans-serif;
  font-size: 13px;
  color: var(--muted);
}

.progress {
  height: 14px;
  border-radius: 999px;
  background: #eadfc8;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.3s;
}

.prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 16px;
  border-radius: 28px;
  background: var(--card);
  border: 2px solid var(--line);
  text-align: center;
}

.prompt-text {
  margin: 0;
  font-family: var(--read);
  font-weight: 700;
  font-size: clamp(26px, 7.5vw, 40px);
  line-height: 1.6;
}

.prompt-text.long {
  font-size: clamp(22px, 6vw, 28px);
}

.options {
  display: grid;
  gap: 12px;
}

.options.pictures {
  grid-template-columns: repeat(3, 1fr);
}

.opt {
  padding: 14px 12px;
  min-height: 72px;
  border-radius: 22px;
  background: var(--card);
  border: 2px solid var(--line);
  box-shadow: 0 5px 0 var(--line);
  font-family: var(--read);
  font-weight: 700;
  font-size: clamp(21px, 5.8vw, 27px);
  line-height: 1.6;
  transition: transform 0.08s, box-shadow 0.08s;
}

.pictures .opt {
  font-size: 54px;
  min-height: 110px;
  line-height: 1.2;
}

.opt:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--line);
}

.opt.right {
  background: var(--green-soft);
  border-color: var(--green);
  box-shadow: 0 5px 0 var(--green);
  opacity: 1;
  animation: pop 0.35s;
}

.opt.wrong {
  background: #f3ece0;
  color: var(--muted);
  box-shadow: none;
  animation: shake 0.3s;
}

.result {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.result .trophy {
  font-size: 96px;
  animation: pop 0.5s;
}

.result .stars {
  font-size: 54px;
}

.result p {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
}

.stack {
  display: grid;
  gap: 12px;
}

@keyframes bob {
  50% {
    transform: translateY(-6px) rotate(-3deg);
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.08);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pop {
  40% {
    transform: scale(1.12);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
