/* ==========================================================================
   mazpl.net/study-economics — Cambridge IGCSE Economics 0455 Quiz portal
   "Achromatic Ledger" restyle — cold paper, ink-drawn precision.
   TWIN FILE:  - byte-twin of ../study-ict/ict.css EXCEPT the accent token block.
   Change one -> mirror in the other.
   ========================================================================== */

/*
   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: #ff3e63;            /* raspberry — Susan Grant CUP Economics cover */
  --accent-2: #ff5b7e;          /* gradient pair partner */
  --accent-bright: #ff7b98;
  --accent-light: #2e1219;
  --accent-soft: rgba(255, 62, 99, 0.10);
  --accent-soft-strong: rgba(255, 62, 99, 0.22);
  --accent-line: rgba(255, 62, 99, 0.45);
  --accent-grad: linear-gradient(135deg, #ff3e63, #ff5b7e);
  --fx-rgb: 255, 62, 99;
  --fx-rgb-2: 255, 91, 126;
  --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 {
  position: relative;
  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);
}

/* Cohesion: subject-accent top hairline appears on hover, like the hub cards */
.question-card::before {
  content: "";
  position: absolute;
  left: 20px; right: 20px; top: -1px;
  height: 2px;
  background: var(--accent-grad);
  opacity: 0;
  transform: scaleX(0.4);
  transform-origin: center;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
.question-card:hover::before { opacity: 0.85; transform: scaleX(1); }

.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: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent);
  text-underline-offset: 3px;
}

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

/* ==========================================================================
   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;
  }
}

/* ---- Remove unwanted pink aurora canvas on Economics page ---- */
.fx-aurora { display: none !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; }
.unit-chip.preset { border-style: dashed; border-color: var(--accent-line); }
.unit-chip.preset.active { color: var(--accent); border-style: solid; border-color: var(--accent-line); background: var(--accent-soft-strong); font-weight: 700; }


/* ==========================================================================
   Top-level view selector (Key facts / Quiz) — v10
   ========================================================================== */
.view-selector {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 1.7rem 0 1.15rem;
}
.view-tab {
  appearance: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 22px;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.view-tab:hover { color: var(--ink); border-color: var(--rule, var(--border)); transform: translateY(-1px); }
.view-tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.view-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Key facts (notes view) - textbook fact cards - v10
   ========================================================================== */
.notes-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  padding: 1.1rem 1.3rem 1.25rem;
  margin-bottom: 1rem;
}
.notes-card-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.notes-card-count {
  margin-left: 10px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  vertical-align: middle;
  white-space: nowrap;
}
.note-facts {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
}
.note-fact {
  position: relative;
  padding: 0.55rem 0 0.55rem 1.25rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink);
}
.note-fact + .note-fact {
  border-top: 1px solid var(--rule);
}
.note-fact::before {
  content: '▸';
  position: absolute;
  left: 0.1rem;
  top: 0.55rem;
  color: var(--accent);
  font-size: 0.85em;
}

/* Score numbers use fixed-width digits so the count-up doesn't jitter */
.stat-value { font-variant-numeric: tabular-nums; }

/* ---- Device fit: phones, small phones, wide screens ---------------------- */
@media (max-width: 640px) {
  .view-selector { gap: 8px; margin-top: 1.2rem; }
  .view-tab {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.8rem;
  }
  .notes-card { padding: 0.95rem 0.9rem 1rem; border-radius: 12px; }
  .note-fact { font-size: 0.9rem; padding-left: 1.1rem; }
  .notes-card-count { display: inline-block; margin-left: 0; margin-top: 6px; }
}
@media (max-width: 380px) {
  .view-tab { font-size: 0.74rem; padding: 9px 12px; }
}
@media (min-width: 1200px) {
  .view-selector { margin-top: 2rem; }
}


/* ---- Key facts cards: word -> definition pairings (v10) ------------------- */
.notes-subhead {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.notes-terms {
  margin: 0.45rem 0 0.2rem;
  padding: 0;
}
.note-term {
  display: grid;
  grid-template-columns: minmax(150px, 200px) 1fr;
  gap: 0 0.9rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed var(--rule, var(--border));
}
.note-term:last-child { border-bottom: none; }
.note-term dt {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.note-term dd {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
}
@media (max-width: 640px) {
  .note-term {
    grid-template-columns: 1fr;
    gap: 0.05rem 0;
  }
  .note-term dd { font-size: 0.9rem; }
}


/* ---- [hidden] must always win: several of these containers set their own
   display (flex), which would otherwise defeat the UA's [hidden] rule and
   leak the key-facts picker into the quiz view ---------------------------- */
[hidden] { display: none !important; }


/* ---- Subunit headers dominate the card; word->def pairs stay quiet (v10) -- */
.notes-subhead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 1.35rem 0 0.2rem;
  padding: 0.5rem 0.9rem;
  background: var(--accent-soft, rgba(88, 214, 238, 0.08));
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}
.notes-card > .notes-subhead:first-of-type { margin-top: 0.9rem; }
.subhead-id {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--accent-line, var(--accent));
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}
.subhead-name {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* Quiet the term pairs: ink words (not accent), smaller defs */
.note-term dt {
  color: var(--ink);
  font-weight: 600;
  font-size: 0.78rem;
}
.note-term dd {
  font-size: 0.88rem;
  color: var(--ink);
}

@media (max-width: 640px) {
  .notes-subhead { flex-wrap: wrap; row-gap: 4px; padding: 0.45rem 0.7rem; }
  .subhead-name { font-size: 0.95rem; }
  .note-term dt { font-size: 0.74rem; }
  .note-term dd { font-size: 0.86rem; }
}


/* ---- First-run AI guide modal (v10) -------------------------------------- */
.guide-modal {
  max-width: 540px;
}
.guide-body {
  margin: 0.4rem 0 0.2rem;
}
.guide-body p {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--ink);
}
.guide-lead {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  color: var(--ink);
}
.guide-actions {
  margin-top: 0.6rem;
}
.guide-actions .save-btn {
  flex: 1;
}

/* ---- AI re-check button on theory feedback (student-mark-dispute path) ---- */
.ai-recheck-btn {
  appearance: none;
  cursor: pointer;
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-soft, transparent);
  border: 1px dashed var(--accent-line, var(--accent));
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.ai-recheck-btn:hover:enabled {
  border-style: solid;
  background: var(--raised, rgba(88, 214, 238, 0.08));
}
.ai-recheck-btn:disabled {
  cursor: progress;
  opacity: 0.75;
}

@media (max-width: 640px) {
  .guide-actions {
    flex-direction: column;
  }
}


/* ---- Resume / fresh-start modal (v11) ------------------------------------- */
.resume-modal {
  max-width: 470px;
}
.resume-text {
  margin: 0.4rem 0 0.9rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink);
}
.resume-text b {
  color: var(--accent);
}
.resume-modal .settings-actions {
  margin-top: 0.2rem;
}


/* ---- Gear button: sleek inline SVG icon (v-bump) -------------------------- */
.gear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.48rem 0.55rem;
}
.gear-btn svg {
  display: block;
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}
.gear-btn:hover svg {
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  .gear-btn svg { transition: none; }
  .gear-btn:hover svg { transform: none; }
}

/* ==========================================================================
   Touch + small-device feedback (phones, Samsung Watch / Wear OS browser)
   ========================================================================== */

/* Press feedback: :active fires on tap, so every control visibly responds
   on touch devices that have no hover. Scale-down on press, snap back on
   release — the same motion hover gives the mouse. */
.unit-chip:active,
.view-tab:active,
.nav-tab:active,
.ai-btn:active:not(.loading),
.reset-btn:active,
.check-btn:active,
.gear-btn:active,
.close-btn:active,
.save-btn:active,
.clear-btn:active,
.subject-link:active,
.tut-tabs button:active,
.ai-recheck-btn:active:enabled {
  transform: scale(0.97);
}
.mcq-option:active:not(:disabled) {
  transform: scale(0.985);
}

/* Coarse pointers (touch): 44px tap targets, and 16px form text so iOS
   does not zoom the page when a select or textarea takes focus. */
@media (pointer: coarse) {
  .unit-chip { min-height: 44px; }
  .view-tab { min-height: 44px; }
  .amount-item select { font-size: 16px; }
  .theory-textarea { font-size: 16px; }
}

/* Samsung Watch (Watch 8 Classic etc. — Wear OS browser): tiny width AND
   tiny height AND coarse pointer. Phones are always tall, so they never
   match; the watch page stays fully scrollable, only chrome compresses. */
@media (max-width: 480px) and (max-height: 480px) and (pointer: coarse) {
  body { font-size: 13px; }
  .container { padding: 0.6rem 10px; }
  .nav-tab { height: 40px; font-size: 0.72rem; padding: 0 0.6rem; }
  .unit-chip { font-size: 0.78rem; padding: 8px 11px; }
  .view-tab { font-size: 0.72rem; padding: 10px 12px; }
  .view-selector { gap: 7px; margin-top: 1rem; }
  .question-card { padding: 0.85rem 0.75rem; }
  .mcq-option { padding: 0.55rem 0.6rem; font-size: 0.85rem; }
  .ai-btn, .reset-btn, .check-btn { font-size: 0.82rem; }
  .amount-row { flex-wrap: wrap; gap: 0.3rem; }
  .notes-card { padding: 0.8rem 0.75rem 0.9rem; }
  .notes-subcard { padding: 0.3rem 0.7rem 0.8rem; }
  .note-fact { font-size: 0.8rem; }
  /* Watches: never pin the score bar — it eats the tiny viewport */
  .sticky-score-bar { position: static; z-index: auto; }
}

/* ==========================================================================
   Question graphs (inline SVG diagrams keyed by q.diagram) — economics only
   ========================================================================== */
.diagram-box { margin: 0 0 1rem; background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 0.7rem 0.7rem 0.5rem; max-width: 340px; }
.diagram-box svg { display: block; width: 100%; height: auto; }
.diagram-box .dg-axis { stroke: var(--muted); stroke-width: 1.5; fill: none; stroke-linecap: round; }
.diagram-box .dg-curve { stroke: var(--accent); stroke-width: 2.5; fill: none; stroke-linecap: round; }
.diagram-box .dg-curve2 { stroke: var(--accent-bright); stroke-width: 2.5; fill: none; stroke-dasharray: 6 4; stroke-linecap: round; }
.diagram-box .dg-guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; fill: none; }
.diagram-box .dg-arrow { fill: var(--accent-bright); }
.diagram-box .dg-point { fill: var(--accent); }
.diagram-box .dg-label { font-family: var(--font-mono), monospace; font-size: 10px; fill: var(--muted); }
.diagram-box .dg-label-strong { font-family: var(--font-mono), monospace; font-size: 11px; font-weight: 700; fill: var(--ink); }
@media (max-width: 640px) { .diagram-box { max-width: 100%; } }

/* ==========================================================================
   Theory working pad: optional symbol keys + graph sketch — economics only
   ========================================================================== */
.theory-symbols { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin: 0.15rem 0 0.2rem; }
.theory-symbols-label { font: 600 0.62rem var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-right: 0.15rem; }
.symbol-btn { min-width: 32px; height: 32px; padding: 0 0.45rem; font: 600 0.9rem/1 var(--font-mono); color: var(--ink); background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-control); cursor: pointer; transition: var(--transition-color); }
.symbol-btn:hover { color: var(--accent-bright); border-color: var(--accent-line); background: var(--accent-soft); }
.symbol-btn:active { transform: scale(0.94); }
.theory-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.graph-toggle { font-family: var(--font-body); font-weight: 600; font-size: 0.8rem; color: var(--secondary-ink); background: var(--secondary-fill); border: 1px solid var(--control); padding: 0 0.9rem; height: 36px; border-radius: var(--radius-control); cursor: pointer; transition: var(--transition-color); }
.graph-toggle:hover { color: var(--ink); background: var(--control); }
.graph-pad { margin-top: 0.55rem; padding: 0.6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); max-width: 470px; }
.graph-pad[hidden] { display: none; }
.graph-tools { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.45rem; }
.graph-tool { font-family: var(--font-body); font-weight: 600; font-size: 0.72rem; color: var(--muted); background: var(--raised); border: 1px solid var(--border); padding: 0 0.6rem; height: 30px; border-radius: var(--radius-control); cursor: pointer; transition: var(--transition-color); }
.graph-tool:hover { color: var(--ink); border-color: var(--control); }
.graph-tool.active { color: var(--accent-bright); background: var(--accent-soft); border-color: var(--accent-line); }
.graph-canvas { display: block; width: 100%; height: 210px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-control); touch-action: none; cursor: crosshair; }
.graph-hint { margin: 0.45rem 0 0; font: 400 0.72rem/1.4 var(--font-body); color: var(--muted); }
@media (max-width: 640px) {
  .graph-pad { max-width: 100%; }
  .graph-canvas { height: 180px; }
  .symbol-btn { min-width: 34px; height: 34px; }
}

