/* ============================================================
   Math Challenge – Style Sheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0F1117;
  --surface:   #1A1D27;
  --surface2:  #22263A;
  --accent:    #305CDE;
  --accent2:   #4A7AFF;
  --green:     #22C55E;
  --red:       #EF4444;
  --yellow:    #EAB308;
  --text:      #E8EAF0;
  --text-dim:  #7A7F9A;
  --radius:    12px;
}

html, body {
  min-height: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  overflow: hidden;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── Shared Buttons ─────────────────────────────────────── */
.btn {
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover  { background: var(--accent2); }
.btn:active { transform: scale(0.96); }

.btn-big {
  font-size: 1.2rem;
  padding: 14px 40px;
  border-radius: 14px;
  width: 100%;
  max-width: 280px;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--surface2);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* ══════════════════════════════════════════════════════════
   START SCREEN
   ══════════════════════════════════════════════════════════ */
.start-box {
  background: var(--surface);
  border-radius: 22px;
  padding: 32px 28px 28px;
  width: 90%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--surface2);
}

.start-icon { font-size: 3rem; }

.start-box h1 {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -1px;
}

.sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Difficulty selector */
.difficulty-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.diff-btns {
  display: flex;
  gap: 8px;
}

.diff-btn {
  flex: 1;
  padding: 10px 6px;
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text-dim);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1.4;
  text-align: center;
  transition: all 0.15s;
}
.diff-btn small { font-weight: 400; font-size: 0.72rem; }
.diff-btn.active {
  border-color: var(--accent2);
  background: rgba(48, 92, 222, 0.22);
  color: var(--accent2);
}
.diff-btn:hover:not(.active) { border-color: var(--text-dim); color: var(--text); }

/* Highscores mini row */
.highscores {
  display: flex;
  gap: 14px;
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-wrap: wrap;
  justify-content: center;
}
.highscores b { color: var(--yellow); }

/* ══════════════════════════════════════════════════════════
   GAME SCREEN
   ══════════════════════════════════════════════════════════ */
#screen-game {
  padding: 16px 12px 12px;
  justify-content: flex-start;
  gap: 0;
}

/* Top bar */
.top-bar {
  display: flex;
  width: 100%;
  max-width: 420px;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.stat-pill {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
}
.streak-pill { background: rgba(234,179,8,0.12); }

.stat-label {
  font-size: 0.58rem;
  letter-spacing: 1px;
  font-weight: 700;
  color: var(--text-dim);
}

.stat-val {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.2;
}

/* Timer bar */
.timer-track {
  width: 100%;
  max-width: 420px;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 22px;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent2);
  border-radius: 4px;
  transform-origin: left;
  transition: width 0.5s linear, background 0.4s;
}
.timer-bar.urgent { background: var(--red); }

/* Question */
.question-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  width: 100%;
  max-width: 420px;
}

.question-display {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: clamp(2.2rem, 12vw, 3.8rem);
  font-weight: 900;
  line-height: 1;
  flex-wrap: nowrap;
}

.q-eq { color: var(--text-dim); }

.answer-display {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  padding: 12px 24px;
  min-width: 160px;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s;
}
.answer-display.correct { border-color: var(--green); }
.answer-display.wrong   { border-color: var(--red);   }

#answer-text {
  font-size: clamp(1.6rem, 8vw, 2.4rem);
  font-weight: 900;
  min-width: 40px;
  text-align: center;
}

.cursor {
  font-size: 1.6rem;
  color: var(--accent2);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Feedback */
.feedback {
  font-size: 1.1rem;
  font-weight: 800;
  padding: 6px 20px;
  border-radius: 20px;
  text-align: center;
}
.feedback.hidden  { visibility: hidden; }
.feedback.correct { color: var(--green); }
.feedback.wrong   { color: var(--red); }

/* Speed bonus */
.speed-bonus {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--yellow);
  text-align: center;
  margin-bottom: 8px;
  animation: pop-badge 0.4s ease;
}
.speed-bonus.hidden { visibility: hidden; }

@keyframes pop-badge {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* Number pad */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.num-btn {
  background: var(--surface);
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 800;
  padding: 16px 0;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.num-btn:hover  { background: var(--surface2); border-color: var(--accent); }
.num-btn:active { transform: scale(0.92); background: rgba(48,92,222,0.25); }

.num-wide { grid-column: span 2; }
.num-back { color: var(--red); }

/* Diff badge */
.diff-badge {
  margin-top: 12px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-dim);
  border: 1px solid var(--surface2);
  border-radius: 20px;
  padding: 3px 12px;
}

/* ══════════════════════════════════════════════════════════
   GAME OVER SCREEN
   ══════════════════════════════════════════════════════════ */
#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

.gameover-box {
  background: var(--surface);
  border-radius: 22px;
  padding: 32px 28px;
  width: 90%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  border: 1px solid var(--surface2);
  position: relative;
  z-index: 10;
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#go-trophy { font-size: 3rem; }

.gameover-box h2 {
  font-size: 1.8rem;
  font-weight: 900;
}

.go-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.go-stat {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.go-stat-val {
  display: block;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent2);
}

.go-stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 2px;
}

.new-hs {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--yellow);
  text-align: center;
  animation: pop-badge 0.5s ease;
}
.new-hs.hidden { display: none; }

.go-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: center;
}

/* Shake animation for wrong answer */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}
.shake { animation: shake 0.35s ease; }
