/* ============================================================
   DESIGN TOKENS & GLOBAL STYLES
   ============================================================ */

:root {
  /* Backgrounds */
  --bg-primary: hsl(230, 25%, 9%);
  --bg-secondary: hsl(230, 20%, 14%);
  --bg-tertiary: hsl(230, 18%, 19%);
  --bg-elevated: hsl(230, 22%, 17%);

  /* Accent colors */
  --accent-primary: hsl(265, 90%, 65%);
  --accent-primary-dim: hsl(265, 60%, 40%);
  --accent-secondary: hsl(190, 90%, 55%);
  --accent-secondary-dim: hsl(190, 60%, 35%);
  --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));

  /* Semantic colors */
  --success: hsl(145, 70%, 50%);
  --success-dim: hsl(145, 50%, 25%);
  --error: hsl(0, 80%, 60%);
  --error-dim: hsl(0, 50%, 25%);
  --warning: hsl(40, 90%, 60%);
  --warning-dim: hsl(40, 60%, 30%);

  /* Text */
  --text-primary: hsl(0, 0%, 95%);
  --text-secondary: hsl(230, 15%, 60%);
  --text-tertiary: hsl(230, 12%, 42%);

  /* Borders */
  --border-subtle: hsl(230, 18%, 22%);
  --border-medium: hsl(230, 18%, 28%);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  --shadow-glow-primary: 0 0 20px hsla(265, 90%, 65%, 0.3);
  --shadow-glow-secondary: 0 0 20px hsla(190, 90%, 55%, 0.3);
  --shadow-glow-success: 0 0 20px hsla(145, 70%, 50%, 0.3);
  --shadow-glow-error: 0 0 20px hsla(0, 80%, 60%, 0.3);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
  --transition-screen: 350ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

body.gameplay-active {
  overflow: hidden;
  height: 100%;
  position: fixed;
  width: 100%;
}

/* Subtle background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, hsla(265, 90%, 65%, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, hsla(190, 90%, 55%, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent-secondary); text-decoration: none; }
@media (hover: hover) {
  a:hover { text-decoration: underline; }
}

input[type="number"] {
  font-family: 'JetBrains Mono', monospace;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Prevent double-tap zoom delays, text selection, and sticky hovers on touch devices */
.btn,
.numpad-btn,
.pill-opt,
.op-toggle,
.dir-toggle,
.difficulty-card,
.specific-chip,
.gaps-toggle-btn,
.gaps-mode-tab,
.gaps-spinner-arrow,
.gaps-diff-btn,
.legend-item,
.vmt-btn,
.gameplay-pause-btn,
.gameplay-input-btn,
.btc-pause-btn,
.btc-input-btn,
.gaps-close-btn,
.boundary-op-badge,
.triumph-op-symbol,
.question-display,
.q-operand,
.q-operator,
.q-equals,
.q-answer-preview {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ============================================================
   APP & SCREEN SYSTEM
   ============================================================ */

#app {
  position: relative;
  min-height: 100vh;
  z-index: 1;
}

.screen {
  display: none;
  animation: screenFadeIn var(--transition-screen) forwards;
}

.screen.active {
  display: block;
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  padding-bottom: var(--space-3xl);
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  padding: var(--space-md) var(--space-xl);
  font-size: 1rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow-primary);
}

@media (hover: hover) {
  .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px hsla(265, 90%, 65%, 0.45);
  }
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

@media (hover: hover) {
  .btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-color: var(--border-medium);
  }
}

.btn-icon-only {
  padding: var(--space-sm);
  min-width: 36px;
  justify-content: center;
}

/* Tooltip */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

@media (hover: hover) {
  [data-tooltip]:hover::after {
    opacity: 1;
  }
}

.btn-tiny {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

@media (hover: hover) {
  .btn-tiny:hover {
    color: var(--text-primary);
    background: var(--border-medium);
  }
}

.btn-stepper {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.875rem;
  font-family: 'JetBrains Mono', monospace;
  border-radius: var(--radius-sm);
  min-width: 36px;
  justify-content: center;
}

@media (hover: hover) {
  .btn-stepper:hover {
    background: var(--accent-primary-dim);
    color: var(--text-primary);
  }
}

/* ============================================================
   HEADINGS & TEXT HELPERS
   ============================================================ */

h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.hint-text {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

.validation-msg {
  font-size: 0.875rem;
  color: var(--error);
  margin-top: var(--space-sm);
  min-height: 1.3em;
}

/* ============================================================
   LIGHT THEME
   ============================================================ */

body[data-theme="light"] {
  --bg-primary:   hsl(220, 20%, 96%);
  --bg-secondary: hsl(0, 0%, 100%);
  --bg-tertiary:  hsl(220, 10%, 96%);
  --bg-elevated:  hsl(220, 10%, 93%);

  --text-primary:   hsl(230, 30%, 10%);
  --text-secondary: hsl(230, 15%, 35%);
  --text-tertiary:  hsl(230, 12%, 52%);

  --border-subtle: hsl(220, 15%, 84%);
  --border-medium: hsl(220, 15%, 72%);

  --accent-primary-dim:   hsl(265, 60%, 88%);
  --accent-secondary-dim: hsl(190, 60%, 85%);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.09);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.13);
  --shadow-glow-primary:   0 0 20px hsla(265, 90%, 65%, 0.18);
  --shadow-glow-secondary: 0 0 20px hsla(190, 90%, 55%, 0.18);
  --shadow-glow-success:   0 0 20px hsla(145, 70%, 50%, 0.18);
  --shadow-glow-error:     0 0 20px hsla(0,   80%, 60%, 0.18);
}

body[data-theme="light"]::before {
  background:
    radial-gradient(ellipse at 20% 0%,   hsla(265, 90%, 65%, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, hsla(190, 90%, 55%, 0.04) 0%, transparent 50%);
}

/* Overlay backdrops are always dark regardless of theme */
body[data-theme="light"] .answer-reveal-overlay,
body[data-theme="light"] .gaps-popup,
body[data-theme="light"] #plug-gaps-confirm {
  background: rgba(0, 0, 0, 0.45);
}

/* Session-card-mode badges: accent-primary/secondary text on their respective light pastel
   backgrounds has too little contrast — use dark text in light mode instead */
body[data-theme="light"] .session-card-mode,
body[data-theme="light"] .session-card-mode.btc {
  color: var(--text-primary);
}

/* Progress-bar tracks sit on the page background (not a white card), so bg-tertiary
   at near-page-background lightness would be invisible — give them an explicit track colour */
body[data-theme="light"] .gameplay-timer-wrap,
body[data-theme="light"] .btc-bar-wrap {
  background: hsl(220, 12%, 88%);
}

/* Theme toggle icon visibility */
.icon-moon { display: none; }
body[data-theme="light"] .icon-sun  { display: none; }
body[data-theme="light"] .icon-moon { display: block; }

/* Platinum symbol: match the filled diamond progress segment palette */
body[data-theme="light"] .triumph-op-symbol--tier-4 {
  background: linear-gradient(155deg, #E4E8FF 0%, #B0B8F0 35%, #9098D8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter:
    drop-shadow(0 0 4px hsla(228, 80%, 82%, 0.9))
    drop-shadow(0 0 14px hsla(228, 70%, 70%, 0.6))
    drop-shadow(0 0 28px hsla(228, 60%, 60%, 0.35));
}

/* Platinum sparkle ✦ glyphs: match the same palette */
body[data-theme="light"] .triumph-plat-sym-wrap::before,
body[data-theme="light"] .triumph-plat-sym-wrap::after {
  color: hsl(228, 70%, 65%);
  filter: drop-shadow(0 0 4px hsla(228, 80%, 75%, 0.8));
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-medium);
}

/* ============================================================
   NAV TOGGLE BAR
   ============================================================ */

.nav-toggle-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-lg);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
}

.nav-toggle-bar.hidden {
  display: none;
}

.nav-theme-btn {
  position: absolute;
  right: var(--space-lg);
}

.nav-logo-group {
  position: absolute;
  left: var(--space-lg);
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-logo {
  height: 46px;
  width: auto;
}

.nav-logo-text {
  font-size: 1.35rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.pill-toggle {
  position: relative;
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  padding: 3px;
}

.pill-opt {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 88px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 100px;
  transition: color var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  text-align: center;
}

.pill-opt.active {
  color: white;
}

.pill-indicator {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(33.333% - 2px);
  bottom: 3px;
  background: var(--accent-gradient);
  border-radius: 100px;
  transition: transform var(--transition-normal);
  z-index: 0;
  box-shadow: var(--shadow-glow-primary);
}

.pill-indicator.at-track {
  transform: translateX(100%);
}

.pill-indicator.at-triumphs {
  transform: translateX(200%);
}

/* ============================================================
   SLIDER TRACK
   ============================================================ */

.slider-viewport {
  overflow-x: hidden;
  width: 100%;
}

.slider-track {
  display: flex;
  width: 300%;
  transform: translateX(0);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider-track.at-track {
  transform: translateX(-33.333%);
}

.slider-track.at-triumphs {
  transform: translateX(-66.667%);
}

.screen-slide {
  width: 33.333%;
  visibility: hidden;
  pointer-events: none;
  max-height: 0;
  overflow: hidden;
}

.screen-slide.slide-visible {
  visibility: visible;
  pointer-events: auto;
  max-height: none;
  overflow: visible;
}

/* Layout adjustments for smaller screens */
@media (max-width: 600px) {
  .screen-inner {
    padding: var(--space-md) var(--space-sm);
    padding-bottom: var(--space-2xl);
  }

  .nav-toggle-bar {
    padding: var(--space-sm) var(--space-md);
  }

  .nav-logo-text {
    display: none;
  }

  .nav-logo {
    height: 34px;
  }

  .nav-logo-group {
    left: var(--space-md);
  }

  .nav-theme-btn {
    right: var(--space-md);
  }

  .pill-opt {
    min-width: 68px;
    padding: 6px 8px;
    font-size: 0.8rem;
  }
}
