:root {
  --bg-top: #a2d9ff;
  --bg-bottom: #ffffff;
  --panel: #ffef96;
  --panel-border: rgba(0, 0, 0, 0.05);
  --btn: #7bdc8d;
  --btn-pressed: #63c377;
  --text: #0f172a;
  --muted: #334155;
  --shadow: 0 10px 40px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.6), transparent 50%),
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.5), transparent 45%),
    linear-gradient(to bottom, var(--bg-top), var(--bg-bottom));
  font-family: "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

.game-container {
  width: min(480px, 100%);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  padding: 28px 20px 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  text-align: center;
  position: relative;
}

/* ── Screen management ─────────────────────────────────── */

.screen {
  display: none;
}

.screen--active {
  display: block;
}

/* ── Typography ─────────────────────────────────── */

.title {
  font-size: clamp(28px, 6vw, 36px);
  margin: 0 0 8px;
}

.subtitle {
  font-size: clamp(16px, 4.5vw, 20px);
  margin: 0 0 24px;
  color: var(--muted);
}

.label {
  font-size: 14px;
  color: var(--muted);
}

/* ── Start screen ─────────────────────────────────── */

.grade-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

.grade-select {
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 600;
  background: #fff;
  color: var(--text);
}

.generate-btn {
  font-size: clamp(17px, 4.5vw, 20px);
  font-weight: 700;
  padding: 14px;
  background: var(--btn);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  box-shadow: 0 10px 20px rgba(123, 220, 141, 0.35);
  touch-action: manipulation;
  color: var(--text);
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.generate-btn:active:not(:disabled) {
  transform: translateY(0);
  background: var(--btn-pressed);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Quiz header & score ─────────────────────────────────── */

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.score-bar {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: clamp(18px, 4.5vw, 22px);
  font-weight: 700;
  margin-bottom: 18px;
}

#correctCount {
  color: #16a34a;
}

#wrongCount {
  color: #dc2626;
}

/* ── Loading & error states ─────────────────────────────────── */

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: clamp(16px, 4vw, 18px);
  color: var(--muted);
  padding: 28px 0;
}

.quiz-error {
  color: #c0392b;
  font-size: clamp(14px, 3.8vw, 16px);
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  text-align: left;
}

.retry-btn {
  margin-bottom: 12px;
}

/* ── Question & choices ─────────────────────────────────── */

.problem-box {
  font-size: clamp(28px, 7vw, 34px);
  padding: 18px 16px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  color: var(--text);
  display: inline-block;
  margin-bottom: 22px;
  min-width: 70%;
  box-shadow: 0 8px 24px rgba(255, 239, 150, 0.5);
}

.quiz-question-box {
  display: block;
  width: 100%;
  min-width: unset;
  font-size: clamp(16px, 4.2vw, 21px);
  text-align: left;
  line-height: 1.4;
}

.choices-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.choice-btn {
  font-size: clamp(20px, 5vw, 24px);
  padding: 14px;
  background: var(--btn);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  box-shadow: 0 10px 20px rgba(123, 220, 141, 0.35);
  width: 100%;
  touch-action: manipulation;
}

.choice-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.choice-btn:active:not(:disabled) {
  transform: translateY(0);
  background: var(--btn-pressed);
}

/* Quiz choices — always stacked, left-aligned text */
.quiz-choices {
  flex-direction: column;
  margin-top: 4px;
}

.quiz-choice {
  font-size: clamp(15px, 4vw, 18px);
  text-align: left;
  padding: 14px 16px;
}

.quiz-choice--correct {
  background: #bbf7d0 !important;
  box-shadow: 0 0 0 2px #16a34a !important;
}

.quiz-choice--wrong {
  background: #fecaca !important;
  box-shadow: 0 0 0 2px #dc2626 !important;
}

/* ── Feedback & explanation ─────────────────────────────────── */

.result-text {
  font-size: clamp(18px, 4.5vw, 22px);
  margin: 18px 0 10px;
  min-height: 28px;
}

.explanation-box {
  font-size: clamp(14px, 3.8vw, 17px);
  color: var(--muted);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 12px rgba(255, 239, 150, 0.4);
  text-align: left;
  line-height: 1.5;
}

.restart-btn {
  margin-top: 0;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: #f8fafc;
  font-weight: 700;
  font-size: clamp(17px, 5vw, 20px);
  cursor: pointer;
  width: 100%;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
  touch-action: manipulation;
}

.restart-btn:active {
  transform: translateY(1px);
}

.next-btn {
  background: var(--btn);
  border-color: transparent;
  box-shadow: 0 10px 20px rgba(123, 220, 141, 0.35);
  color: var(--text);
}

.next-btn:hover {
  transform: translateY(-2px);
}

.next-btn:active {
  transform: translateY(0);
  background: var(--btn-pressed);
}

/* ── Results screen ─────────────────────────────────── */

.results-score {
  font-size: clamp(48px, 12vw, 64px);
  font-weight: 700;
  margin: 12px 0 6px;
  line-height: 1;
}

/* ── Celebration animation ─────────────────────────────────── */

.celebration {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  overflow: hidden;
  border-radius: 18px;
}

.balloon {
  position: absolute;
  bottom: -60px;
  font-size: 32px;
  animation: float 4s ease-in forwards;
}

@keyframes float {
  0% {
    transform: translateY(0) scale(0.8);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(-120vh) scale(1.1);
    opacity: 0;
  }
}

/* ── Desktop overrides ─────────────────────────────────── */

@media (min-width: 520px) {
  /* Quiz choices stay stacked even on wide screens */
  .quiz-choices {
    flex-direction: column;
  }

  .quiz-choice {
    width: 100%;
    min-width: unset;
  }
}
