/* ═══════════════════════════════════════════
   CalcForge — Design System & Styles
   ═══════════════════════════════════════════ */
* {
  font-family: "Outfit", sans-serif;
}

/* ── CSS Custom Properties ── */
:root {
  /* Use dynamic viewport height to account for mobile browser chrome */
  --vh-full: 100dvh;
  /* Surface */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.8);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(99, 102, 241, 0.4);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Accents */
  --accent: #818cf8;
  --accent-vivid: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, 0.12);
  --blue: #60a5fa;
  --blue-bg: rgba(96, 165, 250, 0.12);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.12);
  --pink: #f472b6;
  --pink-bg: rgba(244, 114, 182, 0.12);
  --yellow: #fbbf24;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Shadows */
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--border-subtle);
  --shadow-glow: 0 0 40px var(--accent-glow);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.2s var(--ease-out);
  --transition-med: 0.35s var(--ease-out);
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: var(--vh-full, 100vh);
  overflow-x: hidden;
  line-height: 1.6;
  width: 100%;
  max-width: 100vw;
}

/* Animated gradient background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(167, 139, 250, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse 40% 40% at 50% 50%, rgba(52, 211, 153, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── Glassmorphism Card ── */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 2rem;
  position: relative;
  z-index: 1;
}

/* ══════════════════════════
   Navigation
   ══════════════════════════ */

#top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  max-width: 100vw;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-logo {
  height: 50px;
  width: auto;
  border-radius: 6px;
  filter: drop-shadow(0 0 8px var(--accent-glow));
  object-fit: contain;
  /* Prevent the large logo from pushing nav height */
  margin-top: -34px;
  margin-bottom: -34px;
}

.brand-text {
  font-weight: 800;
  font-size: 1.25rem;
  background: rgb(255, 215, 0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.nav-tabs {
  display: flex;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 4px;
}

.nav-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.5rem 1.25rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav-tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  color: var(--text-primary);
  background: var(--accent-vivid);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.nav-streak {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.2);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--yellow);
}

.streak-icon {
  font-size: 1.1rem;
}

/* ══════════════════════════
   Tab Content
   ══════════════════════════ */

.tab-content {
  display: none;
  max-width: 960px;
  margin: 1rem auto;
  padding: 0 1.5rem;
  animation: fadeUp 0.4s var(--ease-out);
}

.tab-content.active {
  display: block;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ══════════════════════════
   Config Panel
   ══════════════════════════ */

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.config-grid {
  display: grid;
  gap: 1.75rem;
}

.config-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Operation Buttons */
.operation-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.op-btn {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.op-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.op-btn.active {
  border-color: var(--accent-vivid);
  background: var(--accent-vivid);
  color: #fff;
  box-shadow: 0 2px 14px var(--accent-glow);
}

/* Range Inputs */
.range-inputs {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.input-wrapper {
  position: relative;
  flex: 1;
}

.input-prefix {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.input-wrapper input {
  width: 100%;
  padding: 0.65rem 0.75rem 0.65rem 3rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color var(--transition-fast);
}

.input-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.range-dash {
  color: var(--text-muted);
  font-weight: 600;
}

/* Count Control */
.count-control {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.count-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.count-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}

.count-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.75rem;
  font-weight: 700;
  min-width: 3ch;
  text-align: center;
  color: var(--accent);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  transition: background var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--accent-vivid);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(22px);
  background: #fff;
}

/* Practice Mode Row */
.practice-mode-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.practice-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  font-style: italic;
  transition: color var(--transition-fast);
}

.practice-hint.active {
  color: var(--accent);
  font-style: normal;
}

/* Timer hidden state */
.timer-bar.hidden {
  display: none;
}

/* Practice mode badge (in result screen) */
.practice-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.9rem;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-md);
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.2);
  color: var(--purple);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Practice mode bar (above expression card) */
.practice-badge-bar {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  margin-bottom: 0;
  border-radius: var(--radius-sm);
  background: rgba(167, 139, 250, 0.08);
  border: 1px solid rgba(167, 139, 250, 0.15);
  color: var(--purple);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Start Button */
.start-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  margin-top: 1.5rem;
  padding: 1rem;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-vivid), #7c3aed);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all var(--transition-med);
  position: relative;
  overflow: hidden;
}

.start-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 30%, rgba(255, 255, 255, 0.15) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s;
}

.start-btn:hover::before {
  transform: translateX(100%);
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
}

.start-btn:active {
  transform: translateY(0);
}

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

.pulse-glow {
  animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {

  0%,
  100% {
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
  }

  50% {
    box-shadow: 0 4px 30px rgba(99, 102, 241, 0.45);
  }
}

.config-btn {
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.config-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ══════════════════════════
   Challenge Area
   ══════════════════════════ */

.challenge-area {
  animation: fadeUp 0.4s var(--ease-out);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Timer Bar */
.timer-bar {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  margin-bottom: 0;
  border-radius: var(--radius-md);
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.15);
}

.timer-icon {
  font-size: 1.1rem;
}

.timer-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--yellow);
  min-width: 6ch;
}

/* Expression Card */
.expression-card {
  text-align: center;
  padding: 1.5rem 2rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.expression-numbers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.expr-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  animation: slideIn 0.3s var(--ease-out) both;
}

.expr-row .expr-op {
  color: var(--accent);
  font-size: 1.4rem;
  min-width: 1.5ch;
  text-align: center;
}

.expr-row .expr-num {
  min-width: 4ch;
  text-align: right;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.expression-line {
  width: 60%;
  max-width: 260px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 0.75rem auto;
  border-radius: 2px;
}

/* ── Circular Layout Mode ── */
.expression-card.scattered {
  padding: 1.5rem 1.5rem 2.5rem;
}

.expression-card.scattered .expression-numbers {
  position: relative;
  width: 380px;
  height: 380px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto 0.5rem;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(99, 102, 241, 0.06) 0%, transparent 70%);
  overflow: visible;
}

/* Orbit ring */
.expression-card.scattered .expression-numbers::before {
  content: '';
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.06);
  animation: orbitSpin 30s linear infinite;
  pointer-events: none;
}

/* Center glow dot */
.expression-card.scattered .expression-numbers::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent-vivid);
  box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-glow);
  pointer-events: none;
}

@keyframes orbitSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.expression-card.scattered .expression-line {
  display: none;
}

.scattered-number {
  position: absolute;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 1.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  cursor: default;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  animation: circleAppear 0.5s var(--ease-out) both;
  user-select: none;
  white-space: nowrap;
  /* position via transform, set by JS inline */
  transform: translate(-50%, -50%);
}

.scattered-number:hover {
  transform: translate(-50%, -50%) scale(1.15) !important;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 0 24px var(--accent-glow);
  z-index: 10;
}

@keyframes circleAppear {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }

  60% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }

  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.scattered-op-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  opacity: 0.6;
  z-index: 2;
}

/* Color variations for circular numbers */
.scattered-number.color-0 {
  border-color: rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.08);
}

.scattered-number.color-1 {
  border-color: rgba(52, 211, 153, 0.35);
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.08);
}

.scattered-number.color-2 {
  border-color: rgba(251, 146, 60, 0.35);
  color: #fdba74;
  background: rgba(251, 146, 60, 0.08);
}

.scattered-number.color-3 {
  border-color: rgba(244, 114, 182, 0.35);
  color: #f9a8d4;
  background: rgba(244, 114, 182, 0.08);
}

.scattered-number.color-4 {
  border-color: rgba(167, 139, 250, 0.35);
  color: #c4b5fd;
  background: rgba(167, 139, 250, 0.08);
}

.scattered-number.color-5 {
  border-color: rgba(96, 165, 250, 0.35);
  color: #93c5fd;
  background: rgba(96, 165, 250, 0.08);
}

.scattered-number.color-6 {
  border-color: rgba(251, 191, 36, 0.35);
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.08);
}

.scattered-number.color-7 {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.08);
}

@media (max-width: 640px) {
  .expression-card.scattered .expression-numbers {
    width: 300px;
    height: 300px;
  }

  .scattered-number {
    font-size: 1.1rem;
    padding: 0.4rem 0.75rem;
  }
}

.answer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.answer-eq {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.answer-input {
  width: 200px;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-accent);
  border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, 0.06);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: all var(--transition-fast);
}

.answer-input:focus {
  border-color: var(--accent-vivid);
  box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow-glow);
}

.answer-input::placeholder {
  color: var(--text-muted);
}

/* Challenge Controls */
.challenge-controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.submit-btn {
  flex: 1;
  padding: 0.9rem;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--green), #059669);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(52, 211, 153, 0.35);
}

.quit-btn {
  padding: 0.9rem 1.5rem;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-md);
  background: var(--red-bg);
  color: var(--red);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quit-btn:hover {
  background: rgba(248, 113, 113, 0.2);
  border-color: var(--red);
}

/* ── Virtual Numpad (mobile only) ── */
.virtual-numpad {
  display: none;
  /* hidden on desktop */
}

/* ── Correct Flash Overlay ── */
.correct-flash {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(16, 185, 129, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  animation: flashPop 0.4s var(--ease-out);
  pointer-events: none;
}

.correct-flash.show {
  display: flex;
}

.correct-flash-icon {
  font-size: 3rem;
}

.correct-flash-text {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--green);
  text-shadow: 0 0 20px rgba(52, 211, 153, 0.5);
}

@keyframes flashPop {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }

  50% {
    opacity: 1;
    transform: scale(1.05);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── Wrong Answer Shake ── */
.answer-input.shake-wrong {
  animation: shakeWrong 0.5s ease;
  border-color: var(--red) !important;
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.25) !important;
}

@keyframes shakeWrong {

  0%,
  100% {
    transform: translateX(0);
  }

  15% {
    transform: translateX(-8px);
  }

  30% {
    transform: translateX(8px);
  }

  45% {
    transform: translateX(-6px);
  }

  60% {
    transform: translateX(6px);
  }

  75% {
    transform: translateX(-3px);
  }

  90% {
    transform: translateX(3px);
  }
}

/* Round Info */
.round-info {
  text-align: center;
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ══════════════════════════
   Result Splash
   ══════════════════════════ */

.result-splash {
  text-align: center;
  padding: 3rem 2rem;
  animation: popIn 0.4s var(--ease-out);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

.result-title {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 1rem;
}

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

.result-title.wrong {
  color: var(--red);
}

.result-details {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.8;
  margin-bottom: 1.5rem;
}

.result-details strong {
  color: var(--text-primary);
  font-weight: 600;
}

.result-details .mono {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
}

.result-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ══════════════════════════
   History Table
   ══════════════════════════ */

.history-section {
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.history-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.filter-select {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.filter-select option {
  background: var(--bg-secondary);
}

.clear-btn {
  padding: 0.45rem 0.9rem;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  background: var(--red-bg);
  color: var(--red);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.clear-btn:hover {
  background: rgba(248, 113, 113, 0.2);
}

.table-wrapper {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table thead th {
  text-align: left;
  padding: 0.75rem 0.6rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.history-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

.history-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.history-table td {
  padding: 0.7rem 0.6rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.history-table td.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.75rem;
}

.badge-correct {
  background: var(--green-bg);
  color: var(--green);
}

.badge-wrong {
  background: var(--red-bg);
  color: var(--red);
}

.badge-skip {
  background: var(--orange-bg);
  color: var(--orange);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ══════════════════════════
   Statistics
   ══════════════════════════ */

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  text-align: center;
  padding: 1.5rem 1rem;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.3rem;
  color: var(--accent);
}

.stat-card.accent-green .stat-value {
  color: var(--green);
}

.stat-card.accent-blue .stat-value {
  color: var(--blue);
}

.stat-card.accent-purple .stat-value {
  color: var(--purple);
}

.stat-card.accent-orange .stat-value {
  color: var(--orange);
}

.stat-card.accent-pink .stat-value {
  color: var(--pink);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Breakdown Grid */
.stats-breakdown {
  margin-bottom: 1.5rem;
}

.breakdown-grid {
  display: grid;
  gap: 0.75rem;
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
}

.breakdown-label {
  font-weight: 600;
  min-width: 100px;
  font-size: 0.9rem;
}

.breakdown-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.breakdown-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-vivid), var(--purple));
  transition: width 0.6s var(--ease-out);
}

.breakdown-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 180px;
  justify-content: flex-end;
}

.breakdown-stats span {
  white-space: nowrap;
}

.breakdown-stats .stat-highlight {
  color: var(--text-primary);
  font-weight: 600;
}

/* Operation group in combined breakdown */
.breakdown-op-group {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.breakdown-op-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: default;
}

.breakdown-op-header .breakdown-label {
  font-size: 1rem;
  font-weight: 700;
  min-width: 120px;
}

.breakdown-count-group {
  margin-top: 0.5rem;
  padding-left: 1rem;
}

.breakdown-count-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
}

.breakdown-count-header .breakdown-label {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 100px;
  color: var(--text-primary);
}

.breakdown-sub-rows {
  display: grid;
  gap: 0;
  padding-left: 1.5rem;
  margin-top: 0.35rem;
}

.breakdown-sub-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.breakdown-sub-row .breakdown-label {
  font-weight: 500;
  font-size: 0.8rem;
  min-width: 90px;
  color: var(--text-muted);
}

.breakdown-sub-row .breakdown-stats {
  min-width: 160px;
  font-size: 0.75rem;
}

.breakdown-no-data {
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  padding-left: 2.5rem;
}

/* Daily Chart */
.chart-container {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 200px;
  padding: 1rem 0;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 40px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent-vivid), var(--purple));
  transition: height 0.6s var(--ease-out);
  min-height: 4px;
  position: relative;
}

.chart-bar:hover {
  filter: brightness(1.2);
}

.chart-bar-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
}

.chart-bar-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ══════════════════════════
   Responsive
   ══════════════════════════ */

@media (max-width: 640px) {
  #top-nav {
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    position: relative;
  }

  /* Row 1: logo left, brand-text center, streak right */
  .nav-brand {
    order: 1;
    flex: 0 0 auto;
  }

  /* Hide brand text from normal flow; position it in the center */
  .brand-text {
    position: absolute;
    left: 50%;
    top: 0.55rem;
    transform: translateX(-50%);
    font-size: 1.55rem;
    font-family: "Jost", sans-serif;
  }

  .nav-streak {
    order: 2;
    margin-left: auto;
  }

  .nav-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .nav-tab {
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
  }

  .brand-logo {
    height: 60px;
    margin-top: 0;
    margin-bottom: 0;
  }

  .tab-content {
    padding: 0 0.75rem;
    margin: 1rem auto;
  }

  .glass-card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }

  /* Make config panel fit mobile screen without scroll */
  .config-panel {
    padding: 0.85rem;
  }

  .section-title {
    font-size: 1rem;
    margin-bottom: 1rem;
  }

  .config-grid {
    gap: 1rem;
  }

  .config-label {
    font-size: 0.7rem;
    margin-bottom: 0.4rem;
  }

  .op-btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
  }

  .count-display {
    font-size: 1.3rem;
  }

  .count-btn {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  .toggle-switch {
    width: 42px;
    height: 24px;
  }

  .toggle-slider::before {
    width: 18px;
    height: 18px;
  }

  .toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(18px);
  }

  .practice-hint {
    font-size: 0.7rem;
  }

  .start-btn {
    margin-top: 1rem;
    padding: 0.75rem;
    font-size: 0.95rem;
  }

  .input-wrapper input {
    padding: 0.5rem 0.6rem 0.5rem 2.5rem;
    font-size: 0.9rem;
  }

  .input-prefix {
    font-size: 0.65rem;
    left: 10px;
  }

  .expr-row {
    font-size: 1.4rem;
  }

  .answer-input {
    width: 160px;
    font-size: 1.3rem;
  }

  .expression-card {
    padding: 1.5rem 1rem;
  }

  /* ── Challenge page: fill viewport without scroll ── */
  #tab-practice.tab-content.active {
    display: flex;
    flex-direction: column;
  }

  .challenge-area {
    flex: 1;
    min-height: 0;
    /* Fill remaining viewport after nav */
    height: calc(var(--vh-full, 100vh) - var(--nav-height, 110px) - 2rem);
  }

  .challenge-area .expression-card {
    flex: 1;
    min-height: 0;
    padding: 0.5rem 0.5rem;
    margin-bottom: 0.25rem;
  }

  /* Make timer small and absolute positioned on mobile to save space */
  .timer-bar {
    position: absolute;
    top: 4px;
    left: 4px;
    right: auto;
    padding: 0.1rem 0.3rem;
    gap: 0.2rem;
    margin: 0;
    z-index: 10;
    background: rgba(251, 191, 36, 0.08);
    border: none;
    /* Make it unnoticeable */
    border-radius: var(--radius-sm);
  }

  .timer-icon {
    font-size: 0.75rem;
  }

  .timer-display {
    font-size: 0.85rem;
    min-width: 3ch;
  }

  .challenge-area .expression-numbers {
    gap: 0.15rem;
    margin-bottom: 0.5rem;
  }

  .challenge-area .expr-row {
    gap: 0.5rem;
    font-size: 1.3rem;
  }

  .challenge-area .expr-row .expr-op {
    font-size: 1.1rem;
  }

  .challenge-area .expression-line {
    margin: 0.4rem auto;
  }

  .challenge-area .answer-row {
    margin-top: 0.5rem;
  }

  .challenge-area .answer-eq {
    font-size: 1.5rem;
  }

  .challenge-area .answer-input {
    width: 140px;
    font-size: 1.2rem;
    padding: 0.5rem 0.75rem;
    /* Prevent native keyboard from opening */
    caret-color: var(--accent);
  }

  /* Hide challenge controls on mobile (numpad has quit, auto-detect has submit) */
  .challenge-controls {
    display: none;
  }

  .challenge-area .round-info {
    margin-top: 0.5rem;
    font-size: 0.75rem;
  }

  /* Make challenge area relative for the flash overlay */
  .challenge-area {
    position: relative;
  }

  /* ── Virtual Numpad: show on mobile ── */
  .virtual-numpad {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 0.5rem 0.25rem 0;
    margin-top: auto;
  }

  .numpad-key {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.35rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.12s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .numpad-key:active {
    background: var(--accent-vivid);
    color: #fff;
    transform: scale(0.95);
    border-color: var(--accent-vivid);
  }

  .numpad-special {
    color: var(--accent);
    font-size: 1.4rem;
  }

  .numpad-quit {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.2);
    color: var(--red);
    font-size: 1rem;
  }

  .numpad-quit:active {
    background: rgba(248, 113, 113, 0.3);
  }

  .numpad-backspace {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.2);
    color: var(--red);
    font-size: 1.3rem;
  }

  .numpad-backspace:active {
    background: rgba(248, 113, 113, 0.3);
  }

  /* Practice mode badge on mobile: small icon */
  .practice-badge-bar {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 0.25rem;
    margin: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1rem;
    color: transparent;
    /* hide text */
    overflow: hidden;
  }

  .practice-badge-bar::before {
    content: '🧘';
    color: initial;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Correct flash: smaller on mobile */
  .correct-flash-icon {
    font-size: 2.5rem;
  }

  .correct-flash-text {
    font-size: 1.1rem;
  }

  /* Result splash: also fit viewport */
  .result-splash {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Fill remaining viewport after nav */
    min-height: calc(var(--vh-full, 100vh) - var(--nav-height, 110px) - 2rem);
  }

  .result-splash .result-icon {
    font-size: 2.5rem;
    margin-bottom: 0.3rem;
  }

  .result-splash .result-title {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
  }

  .result-splash .result-details {
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 1rem;
  }

  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .breakdown-stats {
    min-width: auto;
    width: 100%;
    justify-content: flex-start;
  }

  .history-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-actions .start-btn,
  .result-actions .config-btn {
    width: 100%;
  }
}

/* Extra-small screens (below 380px) */
@media (max-width: 380px) {
  .op-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.7rem;
  }

  .operation-buttons {
    gap: 0.35rem;
  }

  .config-grid {
    gap: 0.75rem;
  }

  .nav-tab {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }
}