* { box-sizing: border-box; }

:root {
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  color: #25231f;
  background: #f5f2ea;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.9), transparent 36%),
    #f5f2ea;
}

button, input { font: inherit; }

.app-shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 28px 18px 48px;
}

header { text-align: center; margin-bottom: 24px; }

[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 6px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .58;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.25rem);
  line-height: 1;
}

.subtitle {
  margin: 10px auto 24px;
  max-width: 36ch;
  font-size: 1.05rem;
  opacity: .72;
}

.view-subtitle {
  margin: -8px auto 20px;
  text-align: center;
  font-size: 1.05rem;
  opacity: .72;
}

.view h2 {
  margin: 0 0 22px;
  text-align: center;
  font-size: clamp(1.7rem, 6vw, 2.4rem);
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.mode-card,
.category-card {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 28px;
  padding: 22px;
  box-shadow: 0 9px 0 rgba(96,84,65,.2), 0 18px 35px rgba(66,56,38,.1);
  color: #25231f;
  cursor: pointer;
}

.mode-make { background: #ffe49a; }
.mode-spell { background: #bfe5ff; }
.mode-read { background: #d8f2c3; }
.mode-icon { font-size: 4.5rem; }
.mode-card strong { font-size: 1.45rem; }
.mode-card small { max-width: 18ch; font-size: .95rem; line-height: 1.35; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.category-card {
  min-height: 180px;
  background: #fff;
}

.category-card span { font-size: 3.8rem; }
.category-card strong { font-size: 1.25rem; }
.category-card:disabled { opacity: .52; cursor: default; box-shadow: none; }

.game-card {
  position: relative;
  background: rgba(255,255,255,.82);
  border: 1px solid rgba(37,35,31,.09);
  border-radius: 28px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(66,56,38,.1);
}

.animal-card {
  position: relative;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(37,35,31,.09);
  border-radius: 28px;
  padding: 24px 22px;
  box-shadow: 0 18px 50px rgba(66,56,38,.1);
}

.reading-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 390px;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(37,35,31,.09);
  border-radius: 28px;
  padding: 38px 22px 28px;
  box-shadow: 0 18px 50px rgba(66,56,38,.1);
}

.reading-word {
  font-size: clamp(3.4rem, 14vw, 6.5rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.reading-picture-frame {
  position: relative;
  width: min(280px, 70vw);
  margin: 30px 0 10px;
}

.reading-picture { margin: 0; }

.microphone-button {
  width: 76px;
  height: 76px;
  margin-top: 44px;
  border: 0;
  border-radius: 50%;
  background: #d94c3d;
  color: #fff;
  box-shadow: 0 7px 0 #a93227, 0 12px 24px rgba(37,35,31,.18);
  font-size: 2.4rem;
  cursor: pointer;
}

.microphone-button:disabled { opacity: .5; cursor: wait; }
.microphone-button.listening { animation: microphone-pulse .8s ease-in-out infinite alternate; }
.reading-status-failure { color: #c52c20; }

.reading-debug {
  width: 100%;
  margin-top: 22px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eeeae2;
  color: #5c554b;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: .78rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.spell-progress {
  margin-bottom: 12px;
  text-align: center;
  font-size: 1.05rem;
}

.animal-picture {
  min-height: 115px;
  display: grid;
  place-items: center;
  font-size: 6.5rem;
  line-height: 1;
  margin-bottom: 18px;
}

.spelling-image {
  grid-area: 1 / 1;
  width: min(230px, 58vw);
  height: 170px;
  object-fit: contain;
  border-radius: 18px;
}

.spelling-image-fallback {
  grid-area: 1 / 1;
  font-size: 6.5rem;
  line-height: 1;
}

.spelling-slots {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  margin-bottom: 24px;
}

.spelling-slot {
  width: 58px;
  height: 62px;
  display: grid;
  place-items: center;
  border-bottom: 5px solid #403b34;
  border-radius: 8px 8px 0 0;
  font-size: 2.2rem;
  font-weight: 900;
}

.spelling-slot.correct { background: #dbf4dc; }
.spelling-slot.incorrect { background: #ffd7d2; color: #a9271b; border-color: #d94c3d; }

.spelling-tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.spelling-tile {
  min-height: 68px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 0 #d6d0c5;
  font-size: 2rem;
  font-weight: 900;
  cursor: pointer;
}

.spelling-tile:disabled { opacity: .25; cursor: default; }
.spelling-tile.hint-vowel { background: #ffe77a; border-color: #e7c520; }
.spelling-tile.hint-consonant { background: #b9e0ff; border-color: #4a9bda; }

.spell-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.hint-button,
.next-animal,
.restart-button {
  min-width: 110px;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  background: #25231f;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.hint-button:disabled { opacity: .35; cursor: default; }
.next-animal { min-width: 62px; font-size: 1.8rem; background: #23864d; }

.completion-view { text-align: center; }
.completion-image { font-size: clamp(8rem, 30vw, 14rem); animation: celebrate .7s ease-out; }
.completion-view h2 { margin-bottom: 8px; }
.completion-view p { font-size: 1.2rem; }
.restart-button { min-width: 72px; font-size: 2rem; margin-top: 12px; }

.bottom-navigation {
  display: flex;
  justify-content: center;
  padding-top: 28px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.home-button {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  background: #25231f;
  color: #fff;
  box-shadow: 0 6px 18px rgba(37,35,31,.25);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.update-notice {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 28px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 18px;
  border-radius: 16px;
  background: #25231f;
  color: #fff;
  box-shadow: 0 10px 28px rgba(37,35,31,.3);
  font-weight: 800;
}

.update-notice button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: #ffe49a;
  color: #25231f;
  font-weight: 900;
  cursor: pointer;
}

.update-notice button:disabled { opacity: .7; cursor: wait; }

.curriculum-label {
  margin: 0 0 12px;
  text-align: center;
  font-size: .95rem;
  opacity: .72;
}

.picture {
  text-align: center;
  font-size: 5rem;
  line-height: 1;
  margin: 8px 0 20px;
}

.picture.celebrate {
  animation: celebrate .55s ease-out;
}

.word-slots {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-height: 76px;
  margin-bottom: 24px;
}

.word-slots:empty::after {
  content: "Build a 2- or 3-letter word";
  align-self: center;
  color: #817a70;
  font-weight: 750;
}

.slot {
  width: 68px;
  height: 72px;
  border-bottom: 5px solid #403b34;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  font-weight: 900;
  text-transform: uppercase;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.tile {
  min-height: 92px;
  border: 0;
  border-radius: 22px;
  background: #fff;
  box-shadow:
    0 6px 0 #d6d0c5,
    0 12px 22px rgba(40,35,28,.08);
  font-size: 2.7rem;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}

.tile:active {
  transform: translateY(5px);
  box-shadow:
    0 1px 0 #d6d0c5,
    0 5px 10px rgba(40,35,28,.08);
}

.tile.used {
  opacity: .35;
  pointer-events: none;
}

.tile.wrong {
  animation: shake .24s linear 1;
}

.status {
  min-height: 34px;
  margin: 22px 0 12px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 750;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls button {
  min-height: 50px;
  border-radius: 16px;
  border: 0;
  font-weight: 800;
  cursor: pointer;
}

.word-counter {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(37,35,31,.1);
  font-weight: 800;
}

.milestone-border {
  position: absolute;
  inset: -13px;
  z-index: 2;
  pointer-events: none;
  animation: celebrate .55s ease-out;
}

.milestone-edge {
  position: absolute;
  font-size: 1.35rem;
  line-height: 1.25;
  white-space: nowrap;
  filter: drop-shadow(0 2px 2px rgba(66,56,38,.18));
}

.milestone-top,
.milestone-bottom {
  left: 50%;
  transform: translateX(-50%);
  letter-spacing: .25em;
}

.milestone-top { top: -9px; }
.milestone-bottom { bottom: -9px; }
.milestone-left { left: -7px; top: 28%; }
.milestone-right { right: -7px; top: 28%; }

.counter-reset {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #ebe6dc;
  color: #25231f;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
}

.counter-reset:focus-visible {
  outline: 3px solid #786f62;
  outline-offset: 2px;
}

.primary {
  background: #25231f;
  color: #fff;
}

.secondary {
  background: #ebe6dc;
  color: #25231f;
}

.parent-panel {
  margin-top: 18px;
  padding: 0 6px;
}

summary {
  cursor: pointer;
  font-weight: 750;
}

details label {
  display: block;
  margin-top: 14px;
}

.checkbox-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.note {
  font-size: .9rem;
  line-height: 1.45;
  opacity: .68;
}

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

@keyframes celebrate {
  0% { transform: scale(.55) rotate(-8deg); }
  65% { transform: scale(1.18) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes microphone-pulse {
  to { transform: scale(1.1); box-shadow: 0 7px 0 #a93227, 0 0 0 12px rgba(217,76,61,.16); }
}

@media (max-width: 520px) {
  .app-shell { padding-bottom: 28px; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 170px; }
  .category-grid { grid-template-columns: 1fr; }
  .category-card { min-height: 120px; flex-direction: row; }
  .category-card span { font-size: 3rem; }
  .game-card { padding: 18px 14px; border-radius: 22px; }
  .animal-card { padding: 20px 12px; }
  .tile { min-height: 82px; }
  .slot { width: 58px; height: 64px; }
  .spelling-slot { width: 44px; height: 54px; font-size: 1.8rem; }
  .spelling-tiles { gap: 7px; }
  .spelling-tile { min-height: 58px; font-size: 1.65rem; }
  .controls { grid-template-columns: 1fr 1fr; }
}
