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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0f1f14;
  font-family: system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* === CHALKBOARD THEME === */
#app {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, #1e3d2e 0%, #0f1f14 70%),
    radial-gradient(ellipse at 80% 50%, #1a3628 0%, #0f1f14 70%);
}

.board-frame {
  position: relative;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      rgba(240,240,232,0.015) 1px,
      transparent 2px
    ),
    linear-gradient(160deg, #1e3d2e, #162b20);
  border: 3px solid #5c3a1e;
  border-radius: 4px;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.4),
    0 0 0 8px #4a2e16,
    0 0 0 11px #6b4a2a,
    0 8px 32px rgba(0,0,0,0.5);
  padding: 24px;
  width: min(560px, 94vw);
}

.chalk-border {
  position: absolute;
  inset: -2px;
  border: 1px solid rgba(240,240,232,0.08);
  border-radius: 2px;
  pointer-events: none;
}

/* === TYPOGRAPHY === */
.chalk-text {
  color: #f0f0e8;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5), 0 0 20px rgba(240,240,232,0.1);
  font-family: "Georgia", "Cambria", serif;
}

.game-title {
  font-family: "Georgia", "Cambria", serif;
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 700;
  text-align: center;
  color: #f0f0e8;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.6), 0 0 30px rgba(240,240,232,0.08);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.game-title .accent {
  color: #ffe44d;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.6), 0 0 30px rgba(255,228,77,0.2);
}

.subtitle {
  text-align: center;
  color: #8a9a8a;
  font-size: 0.85rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 20px;
  font-weight: 400;
}

/* === SELECTORS === */
.selector-group {
  margin-bottom: 16px;
}

.selector-label {
  display: block;
  color: #b0b0a8;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
  font-weight: 600;
}

.mode-selector {
  display: flex;
  gap: 6px;
}

.mode-btn {
  flex: 1;
  padding: 10px 0;
  background: rgba(240,240,232,0.06);
  border: 1px solid rgba(240,240,232,0.12);
  border-radius: 6px;
  color: #b0b0a8;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  font-family: system-ui, sans-serif;
}

.mode-btn:hover { background: rgba(240,240,232,0.1); }
.mode-btn.active {
  background: rgba(255,228,77,0.12);
  border-color: #ffe44d;
  color: #ffe44d;
  box-shadow: 0 0 12px rgba(255,228,77,0.15);
}

.type-selector {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  padding: 12px;
  background: rgba(240,240,232,0.06);
  border: 1px solid rgba(240,240,232,0.12);
  border-radius: 8px;
  color: #b0b0a8;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: system-ui, sans-serif;
}

.type-btn:hover { background: rgba(240,240,232,0.1); }
.type-btn.active {
  background: rgba(255,228,77,0.08);
  border-color: #ffe44d;
  color: #ffe44d;
  box-shadow: 0 0 12px rgba(255,228,77,0.1);
}

.type-icon { font-size: 1.1rem; display: block; margin-bottom: 2px; }
.type-label { font-size: 0.85rem; font-weight: 700; display: block; }
.type-desc { font-size: 0.65rem; color: #8a9a8a; display: block; margin-top: 2px; }
.type-btn.active .type-desc { color: #c0c0a8; }

/* === BUTTONS === */
.chalk-btn {
  font-family: system-ui, sans-serif;
  width: 100%;
  padding: 14px;
  border: 1px solid rgba(240,240,232,0.15);
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.chalk-btn.primary {
  background: linear-gradient(135deg, rgba(255,228,77,0.2), rgba(255,228,77,0.1));
  color: #ffe44d;
  border-color: rgba(255,228,77,0.3);
  text-shadow: 0 0 12px rgba(255,228,77,0.2);
}

.chalk-btn.primary:hover {
  background: linear-gradient(135deg, rgba(255,228,77,0.3), rgba(255,228,77,0.15));
  box-shadow: 0 0 20px rgba(255,228,77,0.15);
  transform: translateY(-1px);
}

.chalk-btn.primary:active {
  transform: translateY(0);
  box-shadow: none;
}

.chalk-btn.secondary {
  background: rgba(240,240,232,0.06);
  color: #b0b0a8;
  border-color: rgba(240,240,232,0.12);
}

.chalk-btn.secondary:hover {
  background: rgba(240,240,232,0.1);
  color: #d0d0c8;
}

.best-badge {
  text-align: center;
  color: #8a9a8a;
  font-size: 0.7rem;
  margin-top: 8px;
  min-height: 1.2em;
}

/* === SCREENS === */
.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
}

/* === GAME SCREEN === */
#game-screen.active {
  display: flex;
}

.game-frame {
  padding: 16px 20px 12px;
}

/* HUD */
#game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.2);
  padding: 4px 10px;
  border-radius: 6px;
  color: #f0f0e8;
  font-weight: 700;
  font-size: 0.85rem;
}

.hud-icon { color: #ffe44d; font-size: 0.9rem; }

.operation-badge {
  font-size: 0.9rem;
  color: #38bdf8;
  background: rgba(56,189,248,0.1);
  border: 1px solid rgba(56,189,248,0.2);
  min-width: 32px;
  justify-content: center;
}

.hud-timer {
  font-size: 1.5rem;
  font-weight: 800;
  color: #f0f0e8;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: center;
  transition: color 0.3s;
}

.hud-timer.warning {
  color: #ef4444;
  animation: timerPulse 0.5s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
}

.hud-lives {
  font-size: 1.2rem;
  letter-spacing: 3px;
  color: #ef4444;
}

/* Streak */
.streak-badge {
  transition: all 0.3s;
}

.streak-badge.hot {
  color: #fbbf24;
  background: rgba(251,191,36,0.15);
  border: 1px solid rgba(251,191,36,0.3);
  box-shadow: 0 0 12px rgba(251,191,36,0.15);
}

.streak-fire {
  display: inline-block;
  transition: transform 0.3s;
}

.streak-fire.pulse {
  animation: flamePulse 0.6s ease-in-out infinite;
}

@keyframes flamePulse {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.2) rotate(-5deg); }
  75% { transform: scale(1.2) rotate(5deg); }
}

/* Question Area */
#question-area {
  text-align: center;
  margin: 8px 0 10px;
  padding: 16px 8px;
  border-radius: 8px;
  position: relative;
  transition: background 0.15s;
}

#question-area.flash-correct {
  background: rgba(74,222,128,0.1);
}

#question-area.flash-wrong {
  background: rgba(239,68,68,0.1);
  animation: shake 0.3s ease-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.q-label {
  font-size: 0.65rem;
  color: #8a9a8a;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.question-text {
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 800;
  color: #f0f0e8;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
  letter-spacing: 2px;
  margin-bottom: 8px;
  font-family: "Georgia", "Cambria", serif;
}

.answer-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 40px;
  border-bottom: 2px solid rgba(240,240,232,0.2);
  margin: 0 auto;
  width: min(200px, 80%);
  padding: 4px 8px;
}

.answer-display {
  font-size: 1.6rem;
  font-weight: 700;
  color: #38bdf8;
  font-variant-numeric: tabular-nums;
  letter-spacing: 3px;
  min-height: 1.8rem;
}

.cursor {
  font-size: 1.6rem;
  font-weight: 300;
  color: rgba(56,189,248,0.6);
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.feedback-area {
  min-height: 24px;
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.feedback-area.correct { color: #4ade80; }
.feedback-area.wrong { color: #ef4444; }

/* Score Popup */
.score-popup {
  position: absolute;
  left: 50%;
  top: 20%;
  transform: translateX(-50%);
  font-size: 1.5rem;
  font-weight: 800;
  color: #ffe44d;
  pointer-events: none;
  animation: scoreFloat 0.9s ease-out forwards;
  text-shadow: 0 0 12px rgba(255,228,77,0.4);
}

@keyframes scoreFloat {
  0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.2); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(1); }
}

/* === KEYPAD === */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  max-width: 280px;
  margin: 0 auto;
}

.key-btn {
  padding: 12px 0;
  font-size: 1.3rem;
  font-weight: 700;
  background: rgba(240,240,232,0.07);
  border: 1px solid rgba(240,240,232,0.12);
  border-radius: 8px;
  color: #f0f0e8;
  cursor: pointer;
  transition: all 0.1s;
  font-family: system-ui, sans-serif;
  min-height: 44px;
  touch-action: manipulation;
}

.key-btn:hover { background: rgba(240,240,232,0.14); }
.key-btn:active {
  background: rgba(240,240,232,0.2);
  transform: scale(0.95);
}

.key-clear {
  color: #f59e0b;
  font-weight: 800;
}

.key-submit {
  background: rgba(74,222,128,0.12);
  border-color: rgba(74,222,128,0.25);
  color: #4ade80;
  font-size: 1.4rem;
}

.key-submit:active {
  background: rgba(74,222,128,0.2);
}

/* === RESULTS SCREEN === */
.results-title {
  font-family: "Georgia", "Cambria", serif;
  text-align: center;
  font-size: clamp(1.5rem, 5vw, 2rem);
  color: #f0f0e8;
  margin-bottom: 16px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.result-card {
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(240,240,232,0.08);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.4s ease-out;
}

.result-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.result-icon { font-size: 1rem; margin-bottom: 2px; }
.correct-icon { color: #4ade80; }
.wrong-icon { color: #ef4444; }

.result-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: #f0f0e8;
  font-variant-numeric: tabular-nums;
}

.score-card .result-value { color: #ffe44d; }
.accuracy-card .result-value { color: #38bdf8; }
.speed-card .result-value { color: #c084fc; }
.streak-card .result-value { color: #fbbf24; }

.result-label {
  font-size: 0.6rem;
  color: #8a9a8a;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

.personal-best-badge {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fbbf24;
  min-height: 1.2em;
  margin-bottom: 12px;
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions .chalk-btn {
  flex: 1;
}

/* === FX CANVAS === */
#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* === RESPONSIVE === */
@media (max-width: 480px) {
  .board-frame { padding: 16px 14px; }
  .mode-btn { font-size: 1rem; padding: 8px 0; }
  .type-btn { padding: 10px; }
  .key-btn { padding: 10px 0; font-size: 1.2rem; min-height: 40px; }
  .question-text { font-size: clamp(1.6rem, 6vw, 2.2rem); }
  .results-grid { gap: 6px; }
}

/* === CONFETTI (results screen) === */
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100px) rotate(720deg); opacity: 0; }
}

.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 101;
  animation: confettiFall 1.5s ease-in forwards;
}
