:root {
  --bg: #16161A;
  --surface: #1E1E23;
  --card: #24242B;
  --border: #3A3A42;
  --text: #E8E6E1;
  --text-dim: #8B8B93;
  --accent: #FF6B4A;
  --accent-dim: #7A3326;
  --success: #4ADE80;
  --success-dim: #1F4A30;
  --fail: #E85D5D;
  --fail-dim: #4A1F1F;
  --amber: #FFC15E;
  --mono: 'SF Mono', 'Roboto Mono', 'Courier New', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body.light {
  --bg: #F5F3EE;
  --surface: #ECEAE4;
  --card: #FFFFFF;
  --border: #D4D0C8;
  --text: #1A1A1E;
  --text-dim: #6B6B73;
  --accent: #FF6B4A;
  --accent-dim: #FFD5CC;
  --success: #16A34A;
  --success-dim: #DCFCE7;
  --fail: #DC2626;
  --fail-dim: #FEE2E2;
  --amber: #B8860B;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px 64px;
  transition: background 0.2s ease, color 0.2s ease;
}

.wrap { width: 100%; max-width: 420px; }

header { text-align: center; margin-bottom: 28px; position: relative; }

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}

h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
  text-align: center;
  margin: 0 0 24px;
}

.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--sans);
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
}
.btn-secondary:hover { color: var(--text); }

/* --- HUD --- */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.hud-item { display: flex; flex-direction: column; }
.hud-item--right { align-items: flex-end; }
.hud-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.hud-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
}
.hud-value.warn { color: var(--fail); }

/* Question-count progress (distinct from the time track below) */
.progress-track {
  height: 6px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}
.question-number {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 16px;
  text-align: center;
}

/* --- Time track: Math Sprint's signature element — a race-lane
   style bar with a marker running left to right as time drains --- */
.track {
  position: relative;
  height: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: 24px;
  overflow: hidden;
}
.track-line {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  border-top: 1px dashed var(--border);
  transform: translateY(-50%);
}
.track-marker {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  margin-left: -8px;
  background: var(--amber);
  border-radius: 50%;
  transition: left 1s linear, background 0.2s ease;
}

.problem-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 16px;
  margin-bottom: 20px;
  text-align: center;
}

.problem {
  font-family: var(--mono);
  font-size: 2.1rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}

.answer-input {
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.4rem;
  text-align: center;
  padding: 14px;
  outline: none;
}
.answer-input:focus { border-color: var(--accent); }
.answer-input.correct {
  border-color: var(--success);
  background: var(--success-dim);
}
.answer-input.wrong {
  border-color: var(--fail);
  background: var(--fail-dim);
  animation: shake 0.3s ease;
}

.answer-submit {
  margin-top: 12px;
}

.answer-input:disabled {
  opacity: 0.7;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* --- Result --- */
.result { text-align: center; padding: 4px 0; }

.result-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--accent);
}

.result-score {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 700;
  margin: 4px 0 4px;
}

.result-breakdown {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
  margin: 0 0 20px;
}
.result-breakdown .bonus { color: var(--amber); }

.share-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 20px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
}
.share-btn:hover { border-color: var(--accent); }

.share-wrap {
  position: relative;
}

.share-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
}
.share-menu[hidden] { display: none; }

.share-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  text-align: left;
  padding: 10px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.share-option:hover { background: var(--surface); }
.share-option-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

footer {
  text-align: center;
  margin-top: 28px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}
footer a { color: var(--text-dim); }
footer a:hover { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
