:root {
  --paper: #fff3d8;
  --ink: #17212b;
  --panel: #1c2a36;
  --button: #ffd45a;
  --danger: #ff5a52;
  --ok: #5bd06c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #dff7ff, #7ab3e4 40%, #456b96 100%);
  min-height: 100vh;
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  color: white;
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

h1 { margin: 0; font-size: clamp(2rem, 5vw, 4rem); letter-spacing: .03em; }
p { margin: .35rem 0 0; }

.game-card {
  position: relative;
  border: 6px solid #111;
  border-radius: 20px;
  overflow: hidden;
  background: #a7d974;
  box-shadow: 0 14px 0 rgba(0,0,0,.28), 0 24px 42px rgba(0,0,0,.34);
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 31, 47, .76);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.start-overlay[hidden] { display: none; }

.start-card {
  width: min(900px, 96%);
  padding: clamp(22px, 4vw, 38px);
  border: 5px solid #111;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 10px 0 rgba(0,0,0,.38);
  text-align: center;
}

.start-card h2 {
  margin: 0;
  color: #263d57;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  line-height: 1.1;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0 12px;
}

.topic-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 92px;
  padding: 9px 6px;
  border: 4px solid #263d57;
  border-radius: 15px;
  color: #263d57;
  background: #fff;
  box-shadow: 0 5px 0 rgba(38,61,87,.35);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.topic-button span {
  font-size: clamp(1.65rem, 4vw, 2.4rem);
  line-height: 1;
}

.topic-button strong {
  font-size: .95rem;
  line-height: 1.05;
}

.topic-button.selected {
  border-color: #5133a5;
  background: #e9e1ff;
  box-shadow: 0 5px 0 #8d77cc;
  transform: translateY(-2px);
}

.topic-button:focus-visible {
  outline: 4px solid var(--button);
  outline-offset: 3px;
}

.start-card p {
  margin: 12px 0 22px;
  font-size: clamp(.95rem, 2vw, 1.15rem);
  font-weight: 700;
}

.start-button {
  min-height: 64px;
  padding: 12px 30px;
  border: 4px solid #111;
  border-radius: 16px;
  color: #111;
  background: var(--button);
  box-shadow: 0 7px 0 #7c5520;
  font: inherit;
  font-size: clamp(1.25rem, 3vw, 1.7rem);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.start-button:active {
  box-shadow: 0 2px 0 #7c5520;
  transform: translateY(5px);
}

.start-button:focus-visible {
  outline: 5px solid #6c4bd3;
  outline-offset: 4px;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #95d0ff;
}

.question-panel {
  position: static;
  background: var(--paper);
  border-top: 5px solid #111;
  padding: 14px;
}

.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: clamp(1rem, 2.5vw, 2rem);
  margin-bottom: 12px;
}

#question {
  flex: 1;
  text-align: center;
  font-size: clamp(1.8rem, 4vw, 4.5rem);
}

#question.capital-question {
  font-size: clamp(1.35rem, 3.4vw, 3rem);
  line-height: 1.05;
}

.visual-prompt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .12em;
  min-height: 1.2em;
  font-size: clamp(2rem, 5vw, 4rem);
  letter-spacing: .04em;
}

.listen-button {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border: 3px solid #111;
  border-radius: 50%;
  background: #dff7ff;
  box-shadow: 0 4px 0 #4f7895;
  font-size: 1.65rem;
  cursor: pointer;
  touch-action: manipulation;
}

.listen-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #4f7895; }
.listen-button[hidden], #timerText[hidden] { display: none; }

#levelBadge, #timerText {
  min-width: 110px;
  text-align: center;
  background: var(--panel);
  color: white;
  border: 3px solid #111;
  border-radius: 999px;
  padding: 8px 12px;
  box-shadow: inset 0 -4px rgba(0,0,0,.22);
}

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

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

.answer-btn.visual-answer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 92px;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1;
}

.quantity-visual {
  font-size: clamp(1.55rem, 4.2vw, 3.4rem);
  letter-spacing: -.12em;
  white-space: nowrap;
}

.quantity-equation {
  font-size: clamp(1.45rem, 4vw, 3.1rem);
  letter-spacing: -.06em;
  white-space: nowrap;
}

.shape-visual {
  color: #6c4bd3;
  text-shadow: 0 3px 0 #312068;
}

.pattern-token {
  display: inline-block;
  min-width: .8em;
  text-align: center;
  text-shadow: 0 2px 0 rgba(17, 24, 39, .45);
}

.answer-btn, .secondary {
  border: 4px solid #111;
  border-radius: 14px;
  background: var(--button);
  color: #111;
  font-weight: 900;
  font-size: clamp(1.2rem, 3vw, 2.8rem);
  padding: 12px 8px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 0 #7c5520;
  transform: translateY(0);
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
}

.answer-btn:focus-visible, .secondary:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
}

@media (hover: hover) {
  .answer-btn:hover, .secondary:hover { filter: brightness(1.05); }
}
.answer-btn:active, .secondary:active { transform: translateY(5px); box-shadow: 0 1px 0 #7c5520; }
.answer-btn.correct { background: var(--ok); }
.answer-btn.wrong { background: var(--danger); }
.answer-btn:disabled { cursor: not-allowed; opacity: .75; }

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  padding: 10px 14px;
  background: #f7f7f7;
  box-shadow: 0 5px 0 rgba(0,0,0,.35);
}

.home-link { text-decoration: none; }

.help {
  margin-top: 18px;
  background: rgba(255,255,255,.78);
  border: 3px solid rgba(0,0,0,.2);
  border-radius: 16px;
  padding: 14px 18px;
}

.help h2 { margin: 0 0 6px; }

@media (max-height: 850px) and (min-width: 701px) {
  body { overflow: hidden; }

  .shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    padding: 8px 0;
  }

  .topbar {
    flex: 0 0 auto;
    margin-bottom: 8px;
  }

  .topbar h1 { font-size: clamp(1.8rem, 5vh, 2.6rem); }
  .topbar p { display: none; }

  .game-card {
    display: grid;
    flex: 1 1 auto;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    border-width: 4px;
    border-radius: 15px;
    box-shadow: 0 7px 0 rgba(0,0,0,.28), 0 12px 25px rgba(0,0,0,.25);
  }

  canvas {
    width: 100%;
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
    object-fit: contain;
  }

  .question-panel {
    padding: 7px 10px 9px;
    border-top-width: 4px;
  }

  .question-row {
    min-height: 42px;
    margin-bottom: 6px;
  }

  #question { font-size: clamp(1.8rem, 6vh, 2.8rem); }
  #question.capital-question { font-size: clamp(1.35rem, 4.6vh, 2.2rem); }

  #levelBadge, #timerText {
    min-width: 96px;
    padding: 5px 10px;
  }

  .answers { gap: 8px; }

  .answer-btn {
    min-height: 50px;
    padding: 5px 8px;
    border-width: 3px;
    font-size: clamp(1.4rem, 5vh, 2.2rem);
    box-shadow: 0 4px 0 #7c5520;
  }

  .help { display: none; }

  .start-card {
    width: min(900px, 92%);
    padding: 14px 20px 18px;
  }

  .start-card h2 { font-size: 1.8rem; }
  .topic-grid { margin: 12px 0 8px; gap: 8px; }
  .topic-button { min-height: 70px; border-width: 3px; }
  .topic-button span { font-size: 1.8rem; }
  .start-card p { margin: 6px 0 12px; }
  .start-button { min-height: 56px; }

  .listen-button { width: 46px; height: 46px; font-size: 1.25rem; }
  .answer-btn.visual-answer { min-height: 54px; font-size: clamp(1.8rem, 6vh, 2.8rem); }
  .quantity-visual { font-size: clamp(1.25rem, 4.5vh, 2.2rem); }
}

@media (max-width: 700px) {
  .answers { grid-template-columns: repeat(2, 1fr); }
  .answers.preschool { grid-template-columns: repeat(3, 1fr); }
  .topbar { align-items: flex-start; }
  .answer-btn { min-height: 64px; }
  .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topic-button { min-height: 76px; }
}
