:root {
  --bg: #fff7c8;
  --ink: #3d315b;
  --pink: #ff75a0;
  --green: #38c172;
  --red: #ff5252;
  --blue: #7bc7ff;
  --orange: #ffb84d;
  --panel: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 20px;
  color: var(--ink);
  font-family: "Comic Sans MS", "Marker Felt", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 20%, #ffb7d1 0 46px, transparent 48px),
    radial-gradient(circle at 88% 18%, #8ee5ff 0 42px, transparent 44px),
    radial-gradient(circle at 78% 84%, #b8f58d 0 56px, transparent 58px),
    linear-gradient(135deg, #fff7c8, #dff8ff);
}

.sound-button {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: #e8fbff;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 900;
}

.sound-button[aria-pressed="true"] {
  background: var(--green);
}

.app {
  width: min(96vw, 820px);
  margin: 24px 0;
}

.panel {
  position: relative;
  overflow: hidden;
  min-height: 560px;
  padding: 34px;
  border: 5px solid #3d315b;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 14px 0 #3d315b22, 0 24px 38px #3d315b26;
  text-align: center;
}

.hidden {
  display: none !important;
}

h1,
h2 {
  margin: 14px 0 8px;
  font-size: clamp(2.2rem, 8vw, 4.4rem);
  line-height: 1;
}

h2 {
  font-size: clamp(2rem, 7vw, 4rem);
}

.subtitle,
.celebration p {
  margin: 0 0 26px;
  font-size: 1.2rem;
}

.celebration .elapsed-time {
  display: inline-block;
  margin: -8px 0 30px;
  padding: 10px 18px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: #e8fbff;
  font-size: 1.25rem;
  font-weight: 900;
}

.mascot {
  position: relative;
  width: 118px;
  height: 96px;
  margin: 0 auto;
  border: 5px solid var(--ink);
  border-radius: 45% 45% 50% 50%;
  background: #ffe7ef;
}

.ear {
  position: absolute;
  top: -28px;
  width: 36px;
  height: 50px;
  border: 5px solid var(--ink);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: #ffe7ef;
}

.ear.left {
  left: 18px;
  transform: rotate(-16deg);
}

.ear.right {
  right: 18px;
  transform: rotate(16deg);
}

.face {
  display: grid;
  height: 100%;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
}

.category-list {
  display: grid;
  gap: 14px;
  margin: 28px auto;
  max-width: 480px;
}

.category-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 86px;
  padding: 14px 18px;
  border: 4px solid var(--ink);
  border-radius: 20px;
  background: #fff9e8;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, background 0.15s ease;
}

.category-card:hover,
.category-card:has(input:checked) {
  transform: translateY(-3px);
  background: #e8fbff;
}

.category-card input {
  width: 20px;
  height: 20px;
  accent-color: var(--pink);
}

.icon {
  display: grid;
  flex: 0 0 46px;
  height: 46px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--orange);
  font-size: 2rem;
  font-weight: 900;
}

.category-card strong,
.category-card small {
  display: block;
}

.category-card strong {
  font-size: 1.18rem;
}

.category-card small {
  margin-top: 4px;
  color: #6e6388;
}

.home-actions,
.story-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

button,
input {
  font: inherit;
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 4px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  padding: 14px 30px;
  color: var(--ink);
  background: var(--pink);
  box-shadow: 0 7px 0 var(--ink);
}

.secondary-button {
  padding: 14px 30px;
  color: var(--ink);
  background: #e8fbff;
  box-shadow: 0 7px 0 var(--ink);
}

.primary-button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--ink);
}

.secondary-button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--ink);
}

.ghost-button {
  padding: 8px 15px;
  background: #e8fbff;
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.story-jump-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 900;
}

.story-jump-form input {
  width: 82px;
  min-width: 0;
  padding: 8px 10px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: #fff9e8;
  color: var(--ink);
  text-align: center;
  font-weight: 900;
}

.story-jump-form input:disabled {
  opacity: 0.48;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-text {
  font-size: 1.1rem;
  font-weight: 900;
}

.timer-text {
  padding: 7px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff0a6;
  font-size: 1rem;
  font-weight: 900;
  white-space: nowrap;
}

.progress-bar {
  height: 20px;
  margin: 20px 0 34px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: #f2edf7;
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 0.25s ease;
}

.question-card {
  position: relative;
  margin: 0 auto 26px;
  padding: 36px 28px;
  width: 100%;
  max-width: 740px;
  border: 5px solid var(--ink);
  border-radius: 26px;
  background: #fff0a6;
}

.question-label {
  margin: 0 0 8px;
  color: #6e6388;
  font-weight: 900;
}

.question-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.question {
  font-size: clamp(2.4rem, 9vw, 5.6rem);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  overflow-wrap: anywhere;
}

.formula-hint {
  width: min(100%, 320px);
  padding: 12px 14px;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: #e8fbff;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1.25;
}

.star {
  position: absolute;
  width: 22px;
  height: 22px;
  background: var(--pink);
  clip-path: polygon(50% 0, 62% 36%, 100% 36%, 70% 58%, 82% 96%, 50% 72%, 18% 96%, 30% 58%, 0 36%, 38% 36%);
}

.star-one {
  top: 18px;
  left: 22px;
}

.star-two {
  right: 28px;
  bottom: 20px;
  background: var(--blue);
}

.answer-area {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 0 auto;
  max-width: 430px;
}

.answer-area input {
  min-width: 0;
  width: 170px;
  padding: 12px 16px;
  border: 4px solid var(--ink);
  border-radius: 18px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
}

.number-pad {
  display: none;
}

.number-pad-enabled .number-pad:not(.hidden) {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 440px);
  margin: 14px auto 0;
}

.number-pad button {
  min-height: 48px;
  padding: 8px 10px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: #e8fbff;
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 900;
}

.number-pad button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.choice-area {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 auto;
  max-width: 520px;
}

.choice-button {
  min-height: 66px;
  padding: 12px 10px;
  border: 4px solid var(--ink);
  border-radius: 20px;
  background: #e8fbff;
  color: var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
  font-size: 2rem;
  font-weight: 900;
}

.choice-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.feedback {
  min-height: 58px;
  margin-top: 22px;
  font-size: 1.4rem;
  font-weight: 900;
}

.feedback.correct {
  color: var(--green);
}

.feedback.wrong {
  color: var(--red);
  animation: shake 0.28s ease;
}

.story-card {
  margin: 28px auto 24px;
  padding: 26px;
  max-width: 720px;
  border: 5px solid var(--ink);
  border-radius: 26px;
  background: #fff9e8;
  text-align: left;
}

.story-card .question-label {
  text-align: center;
}

.story-card h2 {
  margin: 8px 0 22px;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.15;
  text-align: center;
}

.story-content {
  font-size: clamp(1.1rem, 3.8vw, 1.38rem);
  font-weight: 700;
  line-height: 1.85;
}

.story-content p {
  margin: 0 0 0.85em;
}

.story-content p:last-child {
  margin-bottom: 0;
}

.addition-table-card {
  margin: 28px auto 0;
  max-width: 740px;
  text-align: left;
}

.addition-table-card .question-label,
.addition-table-card h2 {
  text-align: center;
}

.addition-table-card h2 {
  margin: 8px 0 16px;
  font-size: clamp(1.9rem, 5vw, 3.2rem);
  line-height: 1.12;
}

.memory-tips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 20px;
}

.memory-tips span {
  display: grid;
  min-height: 58px;
  place-items: center;
  padding: 10px 14px;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: #e8fbff;
  font-size: 1.04rem;
  font-weight: 900;
  line-height: 1.3;
  text-align: center;
}

.addition-table {
  display: grid;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.addition-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  align-items: stretch;
  min-width: 690px;
}

.addition-row-label {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: var(--orange);
  font-size: 1.35rem;
  font-weight: 900;
}

.addition-facts {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  justify-items: stretch;
}

.addition-fact {
  display: grid;
  min-height: 46px;
  place-items: center;
  padding: 8px 10px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #ffffff;
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.addition-fact .equals {
  color: var(--red);
}

.trophy {
  margin: 68px auto 18px;
  display: grid;
  width: 150px;
  height: 150px;
  place-items: center;
  border: 6px solid var(--ink);
  border-radius: 50%;
  background: var(--orange);
  color: #fff7c8;
  font-size: 6rem;
  animation: pop 0.8s ease infinite alternate;
}

.confetti span {
  position: absolute;
  top: -24px;
  width: 14px;
  height: 24px;
  border-radius: 6px;
  background: var(--pink);
  animation: fall 2.4s linear infinite;
}

.confetti span:nth-child(2n) {
  background: var(--green);
}

.confetti span:nth-child(3n) {
  background: var(--blue);
}

.confetti span:nth-child(4n) {
  background: var(--orange);
}

.confetti span:nth-child(1) { left: 8%; animation-delay: 0s; }
.confetti span:nth-child(2) { left: 18%; animation-delay: 0.3s; }
.confetti span:nth-child(3) { left: 28%; animation-delay: 0.6s; }
.confetti span:nth-child(4) { left: 38%; animation-delay: 0.1s; }
.confetti span:nth-child(5) { left: 48%; animation-delay: 0.9s; }
.confetti span:nth-child(6) { left: 58%; animation-delay: 0.4s; }
.confetti span:nth-child(7) { left: 68%; animation-delay: 0.7s; }
.confetti span:nth-child(8) { left: 78%; animation-delay: 0.2s; }
.confetti span:nth-child(9) { left: 88%; animation-delay: 1s; }
.confetti span:nth-child(10) { left: 94%; animation-delay: 0.5s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-10px); }
  70% { transform: translateX(10px); }
}

@keyframes pop {
  from { transform: scale(0.96) rotate(-3deg); }
  to { transform: scale(1.05) rotate(3deg); }
}

@keyframes fall {
  from {
    transform: translateY(-30px) rotate(0deg);
    opacity: 1;
  }
  to {
    transform: translateY(650px) rotate(360deg);
    opacity: 0;
  }
}

.number-pad-enabled .answer-area {
  max-width: 260px;
}

.number-pad-enabled .answer-area .primary-button {
  display: none;
}

.number-pad-enabled .answer-area input {
  width: 100%;
}

@media (orientation: landscape) and (max-height: 820px) {
  body {
    padding: 10px;
  }

  .app {
    width: min(98vw, 900px);
    margin: 0;
  }

  #quiz-screen.panel {
    min-height: auto;
    padding: 18px 24px;
    border-radius: 22px;
  }

  #quiz-screen .progress-bar {
    height: 16px;
    margin: 12px 0 16px;
  }

  #quiz-screen .question-card {
    margin-bottom: 14px;
    padding: 22px 24px;
    border-radius: 22px;
  }

  #quiz-screen .question {
    font-size: clamp(2.4rem, 8vh, 4.4rem);
  }

  #quiz-screen .formula-hint {
    padding: 8px 12px;
    font-size: 1rem;
  }

  #quiz-screen .feedback {
    min-height: 38px;
    margin-top: 12px;
    font-size: 1.15rem;
  }

  .number-pad-enabled #quiz-screen .number-pad:not(.hidden) {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    max-width: 620px;
    margin-top: 10px;
  }

  .number-pad-enabled #quiz-screen .number-pad button {
    min-height: 42px;
    border-radius: 14px;
    font-size: 1.15rem;
  }
}

@media (max-width: 560px) {
  body {
    padding: 12px;
  }

  .panel {
    min-height: auto;
    padding: 24px 16px;
    border-radius: 22px;
  }

  .app {
    width: 100%;
    margin: 8px 0;
  }

  .answer-area {
    display: grid;
  }

  .answer-area input {
    width: 100%;
  }

  .question-content {
    gap: 14px;
  }

  .formula-hint {
    width: min(100%, 280px);
  }

  .choice-area {
    grid-template-columns: 1fr;
  }

  .top-row {
    flex-wrap: wrap;
  }

  .timer-text {
    order: 3;
    width: 100%;
  }

  .home-actions,
  .story-actions {
    display: grid;
  }

  .memory-tips {
    grid-template-columns: 1fr;
  }

  .addition-table-card {
    margin-top: 22px;
  }

  .addition-table {
    gap: 8px;
  }

  .addition-row {
    grid-template-columns: 34px 1fr;
    gap: 6px;
    min-width: 580px;
  }

  .addition-row-label {
    min-height: 40px;
    border-width: 3px;
    border-radius: 14px;
    font-size: 1.1rem;
  }

  .addition-fact {
    min-height: 40px;
    padding: 7px 5px;
    border-width: 3px;
    border-radius: 14px;
    font-size: 0.93rem;
  }

  .story-jump-form {
    display: grid;
    grid-template-columns: auto minmax(72px, 1fr) auto auto;
  }

  .story-card {
    padding: 20px 16px;
  }
}
