/* Misbah — bright, big, touch-first. */

:root {
  --bg: #FFF8E7;
  --paper: #FFFFFF;
  --ink: #23305A;
  --ink-soft: #5B6690;
  --red: #E63946;
  --blue: #1D7FD8;
  --yellow: #FFC93C;
  --green: #2BB673;
  --purple: #8E5CF7;
  --orange: #FF8C42;
  --line: #F0E3C2;
  --radius: 24px;
  --shadow: 0 6px 0 rgba(35, 48, 90, 0.12);
  --tap: 64px;
  --font: 'Andika', 'Comic Sans MS', 'Chalkboard SE', 'Trebuchet MS', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 20px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button, a { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { text-decoration: none; touch-action: manipulation; }
:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }

.screen {
  max-width: 960px;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 700;
  transition: transform 0.1s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(35, 48, 90, 0.12); }
.btn-primary { background: var(--accent, var(--red)); color: #fff; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 28px;
}
.icon-btn:active { transform: translateY(4px); }

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

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.star-count {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 22px;
}

.hero { text-align: center; margin: 8px 0 16px; }

/* A striped hat, drawn in CSS */
.hero-hat {
  width: 92px;
  height: 104px;
  margin: 0 auto -6px;
  position: relative;
  background: repeating-linear-gradient(180deg, var(--red) 0 20px, #fff 20px 40px);
  border-radius: 14px 14px 4px 4px;
  transform: rotate(-6deg);
  box-shadow: inset 0 0 0 4px rgba(35, 48, 90, 0.08);
  animation: wobble 3s ease-in-out infinite;
}
.hero-hat::after {
  content: '';
  position: absolute;
  left: -26px;
  right: -26px;
  bottom: -12px;
  height: 22px;
  border-radius: 999px;
  background: var(--red);
}
@keyframes wobble {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(4deg); }
}

.logo {
  margin: 14px 0 0;
  font-size: clamp(56px, 14vw, 96px);
  line-height: 1;
  color: var(--red);
  letter-spacing: 1px;
  text-shadow: 4px 4px 0 var(--yellow);
}
.tagline { margin: 6px 0 0; font-size: 24px; color: var(--ink-soft); }

.section-label {
  margin: 24px 4px 12px;
  font-size: 22px;
  color: var(--ink-soft);
}

.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.level-chip {
  min-height: 56px;
  padding: 0 20px;
  border: 3px solid var(--chip);
  border-radius: 999px;
  background: var(--paper);
  color: var(--chip);
  font-weight: 700;
  font-size: 20px;
}
.level-chip[aria-checked='true'] { background: var(--chip); color: #fff; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.game-tile:first-child { grid-column: span 2; }
@media (min-width: 760px) {
  .game-grid { grid-template-columns: repeat(5, 1fr); }
  .game-tile:first-child { grid-column: auto; }
}

.game-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 170px;
  padding: 16px 10px;
  border-radius: var(--radius);
  background: var(--tile);
  color: #fff;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.1s;
}
.game-tile:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.game-icon { font-size: 56px; line-height: 1.1; }
.game-name { font-size: 22px; font-weight: 700; }
.game-blurb { font-size: 16px; opacity: 0.92; }

/* ---------- Game chrome ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.topbar-title {
  flex: 1;
  margin: 0;
  font-size: clamp(22px, 5vw, 32px);
  color: var(--accent);
  text-align: center;
}

.game-body { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.game-body > .levels { justify-content: center; }

.prompt { margin: 4px 0 0; font-size: 24px; font-weight: 700; text-align: center; }

.progress-dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); }

.speaker {
  width: 120px;
  height: 120px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 56px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
  animation: pulse 2s ease-in-out infinite;
}
.speaker:active { transform: translateY(6px); }
@keyframes pulse {
  0%, 100% { scale: 1; }
  50% { scale: 1.06; }
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 640px;
}
.choice-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 420px) { .choice-grid.three { grid-template-columns: 1fr; } }

.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 110px;
  padding: 12px;
  border: 4px solid transparent;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: clamp(34px, 8vw, 48px);
  font-weight: 700;
  overflow-wrap: anywhere;
  transition: transform 0.1s;
}
.choice:active { transform: translateY(4px); }
.choice-emoji { font-size: 44px; line-height: 1; }
.choice.right { border-color: var(--green); background: #E5F8EE; animation: bounce 0.5s; }
.choice.wrong { border-color: var(--red); opacity: 0.45; animation: shake 0.4s; }

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

.target-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.18);
}
.target-emoji { font-size: 64px; line-height: 1; }
.target-word { font-size: clamp(48px, 12vw, 72px); font-weight: 700; }
.target-hint { font-size: 28px; }

/* ---------- Word Explorer ---------- */

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  width: 100%;
}
.word-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 120px;
  padding: 10px;
  border: 0;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.word-card:active { transform: translateY(4px); }
.wc-emoji { font-size: 32px; line-height: 1.1; }
.wc-word { font-size: 32px; font-weight: 700; }
.wc-stars, .stars { color: var(--yellow); letter-spacing: 2px; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15); }
.wc-stars { font-size: 18px; }

.card-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(35, 48, 90, 0.45);
  animation: fade 0.2s;
}
@keyframes fade { from { opacity: 0; } }

.card-big {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 20px 20px;
  border-radius: 32px;
  background: var(--paper);
  text-align: center;
}
.close-btn { position: absolute; top: 12px; right: 12px; width: 52px; height: 52px; font-size: 22px; }
.card-emoji { font-size: 80px; line-height: 1; }
.big-word {
  border: 0;
  background: none;
  font-size: clamp(64px, 18vw, 110px);
  font-weight: 700;
  line-height: 1.05;
  color: var(--accent);
}
.stars { font-size: 30px; }

.letters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.letter {
  width: 56px;
  height: 64px;
  border: 0;
  border-radius: 14px;
  background: var(--yellow);
  font-size: 34px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.letter:active { transform: translateY(4px); }

.sentence { margin: 8px 0; font-size: 30px; line-height: 1.6; }
.say-word {
  padding: 0 4px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: inherit;
}
.say-word.target { color: var(--accent); font-weight: 700; text-decoration: underline 3px; text-underline-offset: 6px; }
.say-word.reading { background: var(--yellow); }

.card-actions { display: flex; align-items: center; gap: 12px; }
.card-actions .btn { padding: 0 20px; white-space: nowrap; }

/* ---------- First Words ---------- */

.fw-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 720px;
  padding: 28px 16px;
  border-radius: 32px;
  background: var(--paper);
  box-shadow: var(--shadow);
  touch-action: pan-y;
}
/* Plain, familiar print: the most common typeface, always lowercase. */
.fw-word {
  max-width: 100%;
  padding: 0 8px;
  border: 0;
  background: none;
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(72px, 24vw, 180px);
  font-weight: 700;
  line-height: 1.1;
  text-transform: lowercase;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.fw-word.pop { animation: bounce 0.5s; }
.fw-pic {
  width: 160px;
  height: 160px;
  border: 4px dashed var(--line);
  border-radius: 28px;
  background: var(--bg);
  font-size: 56px;
  line-height: 1;
  opacity: 0.8;
}
.fw-pic.revealed {
  border: 4px solid var(--accent);
  background: var(--paper);
  font-size: 110px;
  opacity: 1;
  animation: bounce 0.5s;
}
.fw-nav { display: flex; align-items: center; gap: 20px; }
.fw-count { min-width: 80px; margin: 0; text-align: center; font-size: 22px; font-weight: 700; color: var(--ink-soft); }

/* ---------- Memory Match ---------- */

.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 640px;
}
@media (min-width: 700px) and (orientation: landscape) { .memory-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 820px; } }

.mem-card {
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  background: none;
  perspective: 800px;
}
.mem-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.35s;
}
.mem-card.flipped .mem-inner { transform: rotateY(180deg); }
.mem-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-weight: 700;
}
.mem-back {
  background: repeating-linear-gradient(45deg, var(--accent) 0 14px, #A37BFA 14px 28px);
  color: #fff;
  font-size: 44px;
}
.mem-front {
  transform: rotateY(180deg);
  background: var(--paper);
  font-size: clamp(26px, 7vw, 40px);
  overflow-wrap: anywhere;
}
.mem-card.matched .mem-front { background: #E5F8EE; outline: 4px solid var(--green); outline-offset: -4px; }

/* ---------- Finish & confetti ---------- */

.finish { text-align: center; padding: 24px 0; }
.finish-badge { font-size: 96px; animation: bounce 0.8s; }
.finish h2 { margin: 8px 0; font-size: 44px; color: var(--accent); }
.finish p { font-size: 24px; }
.finish-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti span {
  position: absolute;
  top: -60px;
  animation: fall 2.6s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(540deg); }
}

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