/* ==========================================================================
   mazpl.net/study-science — Cambridge IGCSE Combined Science Portal
   "Achromatic Ledger" restyle · cold blue-grey paper, ink-drawn precision
   ========================================================================== */

/*
   Google Fonts — wire these <link> tags in <head>:
   <link rel="preconnect" href="https://fonts.googleapis.com">
   <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
   <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
*/

/* ---- Design tokens ---- */
:root {
  /* dark ledger — same instrument, inverted paper */
  --ground: #101114;
  --surface: #17181c;
  --raised: #1e2023;
  --border: #2a2c31;
  --rule: #202225;
  --control: #33353a;
  --ink: #f2f3f5;
  --muted: #9aa0a8;
  --accent: #00a3a6;            /* teal — subject accent */
  --accent-2: #00cfd4;          /* gradient pair partner */
  --accent-bright: #3fd6da;
  --accent-light: #062d2f;
  --accent-soft: rgba(0, 163, 166, 0.10);
  --accent-soft-strong: rgba(0, 163, 166, 0.22);
  --accent-line: rgba(0, 163, 166, 0.45);
  --accent-grad: linear-gradient(135deg, #00a3a6, #00cfd4);
  --fx-rgb: 0, 163, 166;
  --fx-rgb-2: 0, 207, 212;
  --correct-bg: #0e2a1b;
  --correct-ink: #7ce3a1;
  --wrong-bg: #2e1414;
  --wrong-ink: #ff9a92;
  --warning-bg: #2f2410;
  --warning-ink: #f5c66f;
  --neutral-bg: #1e2023;
  --neutral-ink: #c6cad1;
  --primary-fill: #e9ecef;
  --primary-hover: #ffffff;
  --secondary-fill: #1e2023;
  --secondary-ink: #c6cad1;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;
  --radius-card: 8px;
  --radius-control: 6px;
  /* legacy var names still set inline by science.js (explanation titles) */
  --green-bright: #4ecf7d;
  --red-bright: #ff8b80;
  --transition-color: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

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

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

body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: 3rem;
}

/* ---- Background overlay: flat / transparent (no decorative gradient) ---- */
.bg-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: transparent;
  z-index: 0;
}

/* ---- Container: IS the ground, not a card ---- */
.container {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 1.5rem 24px;
}

/* ==========================================================================
   Header
   ========================================================================== */
header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding: 1.5rem 1rem;
}

.header-badge {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--raised);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-control);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

header h1 {
  font-family: var(--font-body);
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 700;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--accent);
  margin-bottom: 0.6rem;
  line-height: 1.3;
}

header p {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 650px;
  margin: 0 auto;
}

.source-badge {
  display: inline-block;
  margin-top: 0.9rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-control);
}

/* ==========================================================================
   Sticky Score Bar
   ========================================================================== */
.sticky-score-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.score-stats {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

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

.stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--ink);
}

.stat-value.total {
  color: var(--ink);
  font-weight: 700;
}

/* Progress bar */
.progress-bar-container {
  flex: 1 1 180px;
  min-width: 140px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 240ms ease;
}

/* ==========================================================================
   Score Actions (AI btn, reset, gear)
   ========================================================================== */
.score-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* AI button = secondary grey */
.ai-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--secondary-ink);
  background: var(--secondary-fill);
  border: 1px solid var(--control);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-control);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition: var(--transition-color);
}

.ai-btn:hover:not(.loading) {
  background: var(--control);
}

.ai-btn:active:not(.loading) {
  transform: scale(0.97);
}

.ai-btn.loading {
  cursor: wait;
  opacity: 0.55;
}

/* Spinner */
.spinner {
  width: 0.85em;
  height: 0.85em;
  border: 2px solid var(--control);
  border-top-color: var(--secondary-ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Reset button = secondary */
.reset-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8rem;
  background: var(--secondary-fill);
  color: var(--secondary-ink);
  border: 1px solid var(--control);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: var(--transition-color);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.reset-btn:hover {
  background: var(--control);
}

/* Gear button = ghost */
.gear-btn {
  font-size: 1rem;
  line-height: 1;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-control);
  transition: var(--transition-color);
}

.gear-btn:hover {
  border-color: var(--control);
  color: var(--ink);
  background: var(--raised);
}

/* ==========================================================================
   Mode Selector (MCQ / Theory / Both)
   ========================================================================== */
.mode-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.mode-btn {
  border-radius: 0;
  border: 1px solid var(--border);
  margin-left: -1px;
}

.mode-btn:first-child {
  border-radius: var(--radius-control) 0 0 var(--radius-control);
  margin-left: 0;
}

.mode-btn:last-child {
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
}

/* Unified active for segmented control — accent underline + ink text */
.mode-btn.mode-mcq.active,
.mode-btn.mode-theory.active,
.mode-btn.mode-both.active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* ==========================================================================
   AI Amount Pickers
   ========================================================================== */
.amount-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin: 0.2rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.amount-label {
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.68rem;
}

.amount-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  color: var(--ink);
}

.amount-item select {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0.3rem 0.5rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition-color);
}

.amount-item select:hover,
.amount-item select:focus {
  border-color: var(--accent);
}

.amount-item select option {
  background: var(--surface);
  color: var(--ink);
}

/* ==========================================================================
   Navigation Tabs
   ========================================================================== */
.nav-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 0;
  margin-bottom: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--control) transparent;
  border-bottom: 1px solid var(--rule);
}

.nav-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0 1rem;
  height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-color), border-color 180ms ease;
  position: relative;
}

/* 1px vertical rules between tabs */
.nav-tab + .nav-tab {
  border-left: 1px solid var(--rule);
}

.nav-tab:hover {
  color: var(--ink);
}

.nav-tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* ==========================================================================
   Section Headers
   ========================================================================== */
.quiz-section {
  margin-bottom: 1rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-count {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--muted);
}

/* ==========================================================================
   Question Cards
   ========================================================================== */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 12px;
  animation: fadeIn 160ms ease-out;
}

.question-card:hover {
  border-color: var(--control);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  gap: 0.5rem;
}

.badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.ch-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--raised);
  color: var(--neutral-ink);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.marks-badge {
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--warning-bg);
  color: var(--warning-ink);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.question-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 1rem;
  line-height: 1.5;
}

/* ==========================================================================
   MCQ Options
   ========================================================================== */
.mcq-options {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.mcq-option {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 0.5rem 1rem;      /* room for wrapped lines */
  min-height: 44px;          /* grows to fit long option text, stays 44px at rest */
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: -1px;
}

.mcq-option:first-child {
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.mcq-option:last-child {
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  margin-bottom: 0;
}

.mcq-option:only-child {
  border-radius: var(--radius-card);
}

.mcq-option:hover:not(:disabled) {
  background: var(--raised);
}

.mcq-option:disabled {
  cursor: default;
}

/* Selected state: accent left bar + tinted bg */
.mcq-option.selected {
  border-left: 2px solid var(--accent);
  background: var(--accent-light);
}

/* Correct / Wrong feedback */
.mcq-option.correct {
  background: var(--correct-bg) !important;
  border-color: var(--correct-bg) !important;
  color: var(--correct-ink) !important;
  font-weight: 600;
}

.mcq-option.wrong {
  background: var(--wrong-bg) !important;
  border-color: var(--wrong-bg) !important;
  color: var(--wrong-ink) !important;
  opacity: 0.85;
}

.option-letter {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  min-width: 20px;
  flex-shrink: 0; /* letter keeps its width when the option text wraps */
  color: var(--muted);
}

.mcq-option.correct .option-letter { color: var(--correct-ink); }
.mcq-option.wrong .option-letter   { color: var(--wrong-ink); }

/* ==========================================================================
   Explanation Box
   ========================================================================== */
.explanation-box {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-control);
  font-size: 0.88rem;
  line-height: 1.5;
  background: var(--raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  animation: fadeIn 160ms ease-out;
}

.explanation-box.correct {
  border-left-color: #4ecf7d;
  background: var(--correct-bg);
}

.explanation-box.wrong {
  border-left-color: #ff8b80;
  background: var(--wrong-bg);
}

.explanation-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ==========================================================================
   Theory: Textarea + Check Button
   ========================================================================== */
.theory-input-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.theory-textarea {
  width: 100%;
  min-height: 110px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0.85rem;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem; /* 16px — prevents iOS auto-zoom on focus */
  line-height: 1.5;
  resize: vertical;
  transition: var(--transition-color);
}

.theory-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

/* Check button = subject-accent ghost gradient (calm, never bright white) */
.check-btn {
  align-self: flex-start;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  background: linear-gradient(135deg, var(--accent-soft-strong), var(--accent-soft));
  color: var(--accent-bright);
  border: 1px solid var(--accent-line);
  padding: 0 1.1rem;
  height: 44px;
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: var(--transition-color);
}

.check-btn:hover {
  background: linear-gradient(135deg, rgba(var(--fx-rgb), 0.30), rgba(var(--fx-rgb-2), 0.20));
  border-color: var(--accent);
}

/* ==========================================================================
   Theory Feedback
   ========================================================================== */
.theory-feedback {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  animation: fadeIn 160ms ease-out;
}

.feedback-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.predicted-marks {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
}

.predicted-marks.full {
  background: var(--correct-bg);
  color: var(--correct-ink);
}

.predicted-marks.partial {
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.predicted-marks.zero {
  background: var(--wrong-bg);
  color: var(--wrong-ink);
}

.marking-points-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.marking-points-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.marking-point-item {
  font-size: 0.88rem;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  line-height: 1.4;
}

.marking-point-item.hit {
  background: var(--correct-bg);
  border-left: 3px solid #4ecf7d;
  color: var(--correct-ink);
}

.marking-point-item.missed {
  background: var(--wrong-bg);
  border-left: 3px solid #ff8b80;
  color: var(--wrong-ink);
}

.mp-icon {
  font-weight: bold;
  font-size: 0.95rem;
}

.mp-icon.hit  { color: var(--correct-ink); }
.mp-icon.missed { color: var(--wrong-ink); }

.model-answer-box {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0.85rem;
  margin-top: 0.75rem;
}

.model-answer-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.model-answer-text {
  font-size: 0.88rem;
  color: var(--ink);
  line-height: 1.5;
}

/* Key Term Highlights */
mark.key-term {
  background: var(--correct-bg);
  color: var(--correct-ink);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-weight: 600;
}

/* ==========================================================================
   Footer
   ========================================================================== */
footer {
  margin-top: 3rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Settings Modal (BYOK)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none;
}

.settings-modal {
  width: min(520px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.4rem;
}

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.settings-head h3 {
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.close-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  transition: var(--transition-color);
}

.close-btn:hover {
  border-color: var(--control);
  color: var(--ink);
}

.settings-sub {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 1.1rem;
}

.settings-sub b {
  color: var(--ink);
}

.field-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
}

#provider-select,
#api-key-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0.65rem 0.75rem;
  outline: none;
  transition: var(--transition-color);
}

#provider-select:focus,
#api-key-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

#provider-select option {
  background: var(--surface);
  color: var(--ink);
}

/* Tutorial tabs + body */
.tut-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 1.2rem;
}

.tut-tabs button {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  transition: var(--transition-color);
}

.tut-tabs button:hover {
  color: var(--ink);
  border-color: var(--control);
}

.tut-tabs button.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.tut-body {
  margin-top: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 0.9rem 1rem;
}

.tut-title {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

.tut-title a {
  color: var(--accent);
  text-decoration: none;
}

.tut-title a:hover {
  text-decoration: underline;
}

.tut-steps {
  margin: 0 0 0.6rem 1.1rem;
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--ink);
}

.tut-note {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Settings action buttons */
.settings-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}

/* Save = subject-accent ghost (matches the Check button) */
.save-btn {
  flex: 1;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent-bright);
  background: linear-gradient(135deg, var(--accent-soft-strong), var(--accent-soft));
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-control);
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: var(--transition-color);
}

.save-btn:hover {
  background: var(--primary-hover);
}

/* Clear = secondary */
.clear-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--wrong-ink);
  background: var(--wrong-bg);
  border: none;
  border-radius: var(--radius-control);
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: var(--transition-color);
}

.clear-btn:hover {
  background: #3d1f1f;
}

.settings-status {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding-top: 0.8rem;
  line-height: 1.5;
}

.settings-status b {
  color: var(--ink);
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.6rem;
  transform: translate(-50%, 16px);
  max-width: min(92vw, 480px);
  background: #1e2023;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  color: var(--ink);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 150;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Kind-variant left edge */
.toast.ok {
  border-left: 4px solid var(--accent);
}

.toast.warn {
  border-left: 4px solid var(--warning-ink);
}

.toast.err {
  border-left: 4px solid var(--wrong-ink);
}

/* ==========================================================================
   Accessibility: focus rings + disabled
   ========================================================================== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:disabled,
[disabled] {
  opacity: 0.55;
  cursor: default;
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */
@media (max-width: 640px) {
  .container {
    padding: 1rem 16px;
  }

  /* Touch/readability fixes */

  .unit-chip {
    min-height: 42px; /* thumb-sized tap target */
    font-size: 0.95rem;
  }

  .theory-textarea {
    min-height: 96px; /* one line grows on demand, still roomy at rest */
  }

  .sticky-score-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .score-stats {
    justify-content: space-between;
  }

  .score-actions {
    width: 100%;
    flex-direction: column;
  }

  .ai-btn {
    width: 100%;
    justify-content: center;
  }

  .reset-btn {
    width: 100%;
    justify-content: center;
  }

  .check-btn {
    width: 100%;
    text-align: center;
  }

  .nav-tabs {
    gap: 0;
  }
}

/* ---- Unit picker (dropdown selects which units are practised) ---- */
.unit-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 4px 0 20px;
  flex-wrap: wrap;
}
.unit-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.unit-picker select {
  appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%239aa0a8' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 40px 10px 14px;
  font: 600 0.95rem var(--font-body);
  cursor: pointer;
  min-width: min(320px, 74vw);
}
.unit-picker select:hover { border-color: var(--control); }
.unit-picker select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.subject-link {
  -webkit-text-fill-color: var(--muted); /* exempt from h1 gradient text */
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  vertical-align: middle;
  white-space: nowrap;
}
.subject-link:hover { color: var(--ink); border-color: var(--control); }

/* ---- Unit picker chips (v3-multiselect - multi-select) ---- */
.unit-chips {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.unit-chip {
  appearance: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 15px;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}
.unit-chip:hover { color: var(--ink); border-color: var(--rule, var(--border)); }
.unit-chip.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.unit-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
