/* ============================================================
   Math Practice — Design System
   Shares the same brand DNA as the Spelling Bee app (honey palette,
   Fredoka/Inter/JetBrains Mono) but adds operation chips and a
   digit-grid answer pad as the new signature elements.
   ============================================================ */

:root {
  --cream: #FFF8E7;
  --cream-deep: #FCEFD2;
  --ink: #1A1A2E;
  --ink-soft: #4A4A63;
  --honey: #F4A300;
  --honey-dk: #D98C00;
  --teal: #2D9596;
  --teal-dk: #237677;
  --coral: #E85D4E;
  --coral-dk: #C8483B;
  --soft-yl: #FFD166;ac
  --card-radius: 28px;
  --shadow-soft: 0 12px 32px rgba(26, 26, 46, 0.08);
  --shadow-lift: 0 18px 40px rgba(244, 163, 0, 0.25);
}

[data-bs-theme="dark"] {
  --cream: #15131C;
  --cream-deep: #1D1A26;
  --ink: #F4F1EA;
  --ink-soft: #C7C3D8;
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 18px 40px rgba(244, 163, 0, 0.18);
}

* { box-sizing: border-box; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background-color .35s ease, color .35s ease;
}

.hive-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(244,163,0,0.10) 0, transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(45,149,150,0.08) 0, transparent 40%),
    radial-gradient(circle at 92% 85%, rgba(244,163,0,0.08) 0, transparent 35%),
    radial-gradient(circle at 6% 80%, rgba(232,93,78,0.06) 0, transparent 35%);
}

.app-shell { position: relative; z-index: 1; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  background: var(--cream-deep);
  border-bottom: 2px solid rgba(244, 163, 0, 0.18);
}

.brand-hex-shape { fill: var(--honey); }
.brand-hex-letter {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 46px;
  fill: var(--ink);
}

.brand-title {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand-tagline {
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.btn-switch-view {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--cream);
  border: 1px solid rgba(26, 26, 46, 0.1);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  text-decoration: none;
}
.btn-switch-view:hover { background: rgba(244, 163, 0, 0.12); color: var(--ink); }

.btn-toggle-theme {
  border: 2px solid rgba(244, 163, 0, 0.3);
  background: transparent;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: transform .2s ease, background-color .2s ease;
}
.btn-toggle-theme:hover { background: rgba(244, 163, 0, 0.12); transform: rotate(15deg); }

/* ============================================================
   SHARED TEXT STYLES
   ============================================================ */
.eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--honey-dk);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

/* ============================================================
   SETUP PANEL
   ============================================================ */
.setup-panel { max-width: 600px; margin-top: 3rem; }

.setup-card {
  background: var(--cream-deep);
  border-radius: var(--card-radius);
  padding: 2.5rem 2.25rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(244, 163, 0, 0.12);
}

.setup-heading {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 1.9rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.setup-sub {
  color: var(--ink-soft);
  font-size: 0.97rem;
  margin-bottom: 1.75rem;
}

/* ----- operation chips (multi-select) ----- */
.operation-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.operation-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--cream);
  border: 2px solid rgba(26, 26, 46, 0.1);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, background-color .15s ease, transform .1s ease;
}
.operation-chip:hover { border-color: var(--honey); transform: translateY(-1px); }
.operation-chip.is-selected {
  background: rgba(244, 163, 0, 0.14);
  border-color: var(--honey);
}

.op-symbol {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--honey-dk);
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}
.operation-chip.is-selected .op-symbol { color: var(--ink); }

.op-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.form-select, .form-control {
  border-radius: 14px;
  border: 2px solid rgba(26, 26, 46, 0.1);
  background-color: var(--cream);
  color: var(--ink);
  padding: 0.65rem 1rem;
}
.form-select:focus, .form-control:focus {
  border-color: var(--honey);
  box-shadow: 0 0 0 4px rgba(244, 163, 0, 0.18);
  background-color: var(--cream);
  color: var(--ink);
}

.form-check-input:checked {
  background-color: var(--honey);
  border-color: var(--honey);
}

.btn-honey {
  background: var(--honey);
  border: none;
  color: var(--ink);
  font-weight: 700;
  font-family: 'Fredoka', sans-serif;
  border-radius: 16px;
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-lift);
  transition: transform .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.btn-honey:hover:not(:disabled) {
  background: var(--honey-dk);
  transform: translateY(-2px);
  box-shadow: 0 22px 44px rgba(244, 163, 0, 0.32);
  color: var(--ink);
}
.btn-honey:active:not(:disabled) { transform: translateY(0); }
.btn-honey:disabled { background: rgba(244, 163, 0, 0.35); box-shadow: none; cursor: not-allowed; }

.setup-hint { font-size: 0.85rem; color: var(--coral-dk); font-weight: 600; min-height: 1.2em; }

/* ============================================================
   QUIZ PANEL
   ============================================================ */
.quiz-panel { max-width: 640px; margin-top: 2.5rem; }

.quiz-progress-row { display: flex; align-items: center; margin-bottom: 1.75rem; }

.progress-pill {
  background: var(--cream-deep);
  border-radius: 14px;
  padding: 0.5rem 1rem;
  text-align: center;
  border: 1px solid rgba(244, 163, 0, 0.15);
  min-width: 84px;
}
.progress-pill .progress-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-weight: 600;
}
.progress-pill .progress-value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
}
.score-pill .progress-value { color: var(--teal-dk); }

.progress { height: 10px; border-radius: 8px; background-color: rgba(244, 163, 0, 0.15); }
.progress-bar { background: linear-gradient(90deg, var(--soft-yl), var(--honey)); transition: width .4s ease; }

/* ----- question card ----- */
.question-stage { display: flex; justify-content: center; margin-bottom: 2rem; }

.question-card {
  background: var(--cream-deep);
  border-radius: 24px;
  border: 3px solid var(--honey);
  box-shadow: var(--shadow-soft);
  padding: 1.5rem 2rem 2rem;
  text-align: center;
  min-width: 280px;
  position: relative;
}
.question-card.is-speaking { animation: cardPulse 1.1s ease-in-out infinite; }
@keyframes cardPulse {
  0%, 100% { background: var(--cream-deep); }
  50% { background: rgba(244, 163, 0, 0.18); }
}

.question-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.question-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ----- vertical question grid: numbers stacked, right-aligned by place value ----- */
.question-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto 0;
  width: max-content;
}

.question-row {
  display: flex;
  align-items: center;
}

.question-op-cell {
  width: 36px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.7rem;
  color: var(--honey-dk);
  flex-shrink: 0;
}

.question-digit-cell {
  width: 48px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.9rem;
  color: var(--ink);
  flex-shrink: 0;
}
.question-digit-cell.is-empty { visibility: hidden; }

.question-rule {
  height: 3px;
  background: var(--ink);
  border-radius: 2px;
  margin-top: 0.35rem;
  width: 100%;
  opacity: 0.85;
}

.speaker-btn-top {
  background: var(--honey);
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(244, 163, 0, 0.4);
  transition: transform .15s ease;
  cursor: pointer;
}
.speaker-btn-top:hover { transform: scale(1.08); }
.speaker-btn-top:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ----- digit grid (the signature element) -----
   Mirrors the question grid exactly: same cell widths, same spacer
   column on the left, laid out left-to-right so it sits directly
   underneath the question's digit columns. */
.answer-form { max-width: 480px; }

.digit-grid {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  flex-wrap: nowrap;
}

.digit-box-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: 48px;
  flex-shrink: 0;
}
.digit-box-wrap.is-spacer { width: 36px; }

.digit-box-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.digit-box-spacer-cell {
  width: 36px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--honey-dk);
}

.digit-box {
  width: 44px;
  height: 64px;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  border: 3px solid rgba(26, 26, 46, 0.15);
  border-radius: 14px;
  background: #FFFFFF;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.digit-box:focus {
  outline: none;
  border-color: var(--honey);
  box-shadow: 0 0 0 4px rgba(244, 163, 0, 0.22);
}
.digit-box.is-correct { border-color: var(--teal); background: rgba(45, 149, 150, 0.1); }
.digit-box.is-incorrect { border-color: var(--coral); background: rgba(232, 93, 78, 0.08); }
.digit-box:disabled { background: rgba(26,26,46,0.04); cursor: not-allowed; }

/* ----- feedback alert ----- */
.feedback-alert {
  max-width: 480px;
  border-radius: 16px;
  padding: 0.9rem 1.2rem;
  font-weight: 600;
  text-align: center;
  font-size: 1.02rem;
  animation: feedbackIn .25s ease;
}
@keyframes feedbackIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.feedback-alert.correct { background: rgba(45, 149, 150, 0.14); color: var(--teal-dk); border: 2px solid rgba(45, 149, 150, 0.35); }
.feedback-alert.incorrect { background: rgba(232, 93, 78, 0.12); color: var(--coral-dk); border: 2px solid rgba(232, 93, 78, 0.32); }
.feedback-alert .feedback-correction { display: block; font-size: 0.85rem; font-weight: 500; margin-top: 0.25rem; opacity: 0.9; }

/* ============================================================
   RESULTS PANEL
   ============================================================ */
.results-panel { max-width: 480px; margin-top: 3rem; }

.results-card {
  background: var(--cream-deep);
  border-radius: var(--card-radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(244, 163, 0, 0.12);
}

.results-heading { font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 2rem; margin-bottom: 0; }

.results-score-ring {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--honey) calc(var(--pct, 0) * 1%), rgba(244,163,0,0.14) 0);
  position: relative;
}
.results-score-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--cream-deep); }
.results-percent { position: relative; z-index: 1; font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 1.7rem; color: var(--ink); }

.results-fraction { font-family: 'JetBrains Mono', monospace; font-size: 1.1rem; font-weight: 600; color: var(--ink-soft); }
.results-message { color: var(--ink-soft); font-size: 0.95rem; }

.missed-words .badge-word {
  background: rgba(232, 93, 78, 0.12);
  color: var(--coral-dk);
  border: 1px solid rgba(232, 93, 78, 0.3);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-weight: 600;
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   HISTORY PANEL
   ============================================================ */
.history-panel { max-width: 760px; }

.history-heading { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.5rem; }

.btn-clear-history {
  background: transparent;
  border: 2px solid rgba(232, 93, 78, 0.4);
  color: var(--coral-dk);
  border-radius: 999px;
  font-weight: 600;
  padding: 0.35rem 1rem;
}
.btn-clear-history:hover { background: rgba(232, 93, 78, 0.1); color: var(--coral-dk); }

.history-table-wrap {
  background: var(--cream-deep);
  border-radius: 20px;
  padding: 0.5rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(244, 163, 0, 0.12);
}

.table-history { margin-bottom: 0; background: transparent; color: var(--ink); }
.table-history thead th {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  border-bottom: 2px solid rgba(244, 163, 0, 0.2);
  padding: 0.9rem 1rem;
}
.table-history tbody td { padding: 0.85rem 1rem; border-bottom: 1px solid rgba(26, 26, 46, 0.06); font-size: 0.9rem; }
.table-history tbody tr:last-child td { border-bottom: none; }

.history-score-good { color: var(--teal-dk); font-weight: 700; }
.history-score-mid { color: var(--honey-dk); font-weight: 700; }
.history-score-low { color: var(--coral-dk); font-weight: 700; }

.history-empty { text-align: center; color: var(--ink-soft); font-size: 0.92rem; margin-top: 1.5rem; }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer { color: var(--ink-soft); font-size: 0.82rem; }
.app-disclaimer { font-size: 0.72rem; opacity: 0.7; max-width: 480px; margin-left: auto; margin-right: auto; line-height: 1.5; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 576px) {
  .setup-card, .results-card { padding: 2rem 1.5rem; }
  .operation-grid { grid-template-columns: 1fr; }
  .question-card { padding: 1.5rem 1.5rem; min-width: 0; width: 100%; }
  .question-digit-cell { width: 38px; height: 48px; font-size: 1.5rem; }
  .question-op-cell { width: 30px; height: 48px; font-size: 1.4rem; }
  .digit-box { width: 46px; height: 56px; font-size: 1.5rem; }
  .brand-title { font-size: 1.25rem; }
  .quiz-progress-row { flex-wrap: wrap; row-gap: 0.5rem; }
  .quiz-progress-row .progress { order: 3; flex-basis: 100%; margin: 0.5rem 0 0; }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .question-card.is-speaking, .feedback-alert, .btn-toggle-theme { animation: none !important; transition: none !important; }
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}
