/* FL 2-20 General Lines — design tokens & base styles
   Identity: a study manual crossed with an instrument panel.
   Precise, legible under pressure, not playful. */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Palette */
  --navy: #0F1B2D;
  --navy-light: #1B2D47;
  --paper: #FAF7F0;
  --paper-raised: #FFFFFF;
  --forest: #1D5C4A;
  --forest-light: #E3EEE9;
  --rust: #B5482E;
  --rust-light: #F7E8E3;
  --slate: #5B6470;
  --slate-light: #8C94A0;
  --gold: #C99A3C;
  --gold-light: #F5EBD3;
  --line: #DDD7C9;
  --line-strong: #C2BBA8;

  /* Type */
  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Layout */
  --radius: 3px;
  --max-width: 1180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--navy);
  line-height: 1.6;
  font-size: 16px;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  color: var(--navy);
  line-height: 1.25;
}

a { color: var(--forest); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

/* Visible keyboard focus everywhere */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

/* ===== Top nav ===== */
.topnav {
  background: var(--navy);
  color: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--gold);
}
.topnav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--paper);
}
.brand .brand-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--gold);
  letter-spacing: 0.06em;
  border: 1px solid var(--gold);
  padding: 2px 7px;
  border-radius: var(--radius);
}
.navlinks { display: flex; gap: 4px; align-items: center; }
.navlinks a {
  color: var(--slate-light);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
.navlinks a:hover { color: var(--paper); text-decoration: none; background: var(--navy-light); }
.navlinks a.active { color: var(--paper); background: var(--navy-light); }
.navlinks a.active::after { content: ''; }

.mobile-nav-toggle { display: none; background: none; border: none; color: var(--paper); font-size: 22px; padding: 4px; }

@media (max-width: 720px) {
  .navlinks { display: none; gap: 2px; }
  .navlinks.open { display: flex; flex-direction: column; align-items: stretch; position: absolute; top: 100%; left: 0; right: 0; background: var(--navy); padding: 8px; border-bottom: 1px solid var(--gold); }
  .mobile-nav-toggle { display: block; }
}

/* ===== Ledger strip (signature element) ===== */
.ledger {
  background: var(--navy-light);
  border-bottom: 1px solid rgba(201, 154, 60, 0.35);
}
.ledger-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}
.ledger-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--slate-light);
}
.ledger-item .ledger-value {
  font-size: 16px;
  font-weight: 500;
  color: var(--gold);
}
.ledger-item.alert .ledger-value { color: #E08A6F; }
.ledger-setdate {
  font-size: 12px;
  color: var(--slate-light);
  background: none;
  border: 1px solid var(--slate-light);
  padding: 3px 10px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
}
.ledger-setdate:hover { border-color: var(--gold); color: var(--gold); }

/* ===== Page shell ===== */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 36px 24px 80px;
}
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 30px; margin-bottom: 6px; }
.page-header p.lede { color: var(--slate); font-size: 15px; max-width: 640px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
  display: block;
}

/* ===== Cards ===== */
.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.card + .card { margin-top: 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .stat-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate);
  margin-bottom: 6px;
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--navy);
}
.stat-card .stat-sub { font-size: 12px; color: var(--slate-light); margin-top: 2px; }

/* ===== Unit weight badge ===== */
.weight-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: var(--radius);
  background: var(--gold-light);
  color: #6B4E1C;
  font-weight: 500;
  white-space: nowrap;
}

/* ===== Progress bars ===== */
.progress-track {
  background: var(--line);
  border-radius: 99px;
  height: 7px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--forest);
  transition: width 0.4s ease;
}
.progress-fill.weak { background: var(--rust); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  font-size: 14px;
  font-weight: 500;
  color: var(--navy);
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--paper); border-color: var(--slate); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--forest); border-color: var(--forest); color: var(--paper); }
.btn-primary:hover { background: #164939; border-color: #164939; }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover { background: var(--line); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== Lesson list / sidebar (lessons page) ===== */
.lesson-layout { display: grid; grid-template-columns: 280px 1fr; gap: 0; align-items: start; }
.lesson-nav {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky;
  top: 88px;
}
.unit-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--slate);
  padding: 14px 16px 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-top: 1px solid var(--line);
}
.unit-label:first-child { border-top: none; }
.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 13.5px;
  color: var(--slate);
  transition: background 0.15s;
}
.lesson-item:hover { background: var(--paper); }
.lesson-item.active { background: var(--forest-light); border-left-color: var(--forest); color: var(--navy); font-weight: 500; }
.lesson-item.weak { border-left-color: var(--rust); }
.lesson-icon { font-size: 16px; min-width: 18px; color: var(--slate-light); }
.lesson-item.active .lesson-icon { color: var(--forest); }
.lesson-item.done .lesson-icon { color: var(--forest); }
.lesson-content { padding: 0 0 0 28px; }

@media (max-width: 880px) {
  .lesson-layout { grid-template-columns: 1fr; }
  .lesson-nav { position: static; }
  .lesson-content { padding: 24px 0 0; }
}

/* ===== Concept cards ===== */
.key-concepts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin: 20px 0 24px;
}
.concept-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.concept-card .concept-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.concept-card .concept-val { font-size: 14px; font-weight: 500; color: var(--navy); }

.intro-text {
  font-size: 14.5px;
  color: var(--slate);
  line-height: 1.7;
  background: var(--paper);
  border-left: 3px solid var(--gold);
  border-radius: 0;
  padding: 12px 16px;
  margin-bottom: 4px;
}

/* ===== Quiz ===== */
.quiz-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.q-num { font-family: var(--font-mono); font-size: 12px; color: var(--slate-light); margin-bottom: 10px; }
.q-text { font-size: 16px; color: var(--navy); margin-bottom: 18px; line-height: 1.55; }
.options-list { display: flex; flex-direction: column; gap: 8px; }
.opt-btn {
  text-align: left;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  font-size: 14.5px;
  color: var(--navy);
  transition: background 0.15s, border-color 0.15s;
}
.opt-btn:hover:not(:disabled) { background: var(--paper); border-color: var(--slate); }
.opt-btn.correct { background: var(--forest-light); border-color: var(--forest); color: #0D3A2E; }
.opt-btn.wrong { background: var(--rust-light); border-color: var(--rust); color: #6B2A1A; }
.opt-btn:disabled { cursor: default; }
.feedback-box { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius); font-size: 14px; line-height: 1.6; }
.feedback-box.correct { background: var(--forest-light); color: #0D3A2E; border: 1px solid var(--forest); }
.feedback-box.wrong { background: var(--rust-light); color: #6B2A1A; border: 1px solid var(--rust); }
.quiz-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; }
.score-pill {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--slate);
  border: 1px solid var(--line);
}

.loading-msg { font-size: 14px; color: var(--slate); padding: 20px 0; display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--forest);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.summary-card {
  background: var(--forest-light);
  border: 1px solid var(--forest);
  border-radius: var(--radius);
  padding: 24px 28px;
  text-align: center;
}
.summary-card .big-score { font-family: var(--font-display); font-size: 44px; font-weight: 600; color: var(--forest); }
.summary-card .score-label { font-size: 14px; color: var(--slate); margin: 4px 0 18px; }

/* ===== Flashcards ===== */
.flashcard-stage {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
}
.flashcard {
  perspective: 1200px;
  height: 280px;
  margin-bottom: 20px;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  font-size: 18px;
  line-height: 1.5;
  color: var(--navy);
}
.flashcard-face.back { transform: rotateY(180deg); background: var(--forest-light); border-color: var(--forest); }
.flashcard-hint { font-size: 12px; color: var(--slate-light); font-family: var(--font-mono); margin-top: -10px; margin-bottom: 18px; }
.flashcard-controls { display: flex; justify-content: center; gap: 12px; }
.fc-btn-know { background: var(--forest-light); border-color: var(--forest); color: #0D3A2E; }
.fc-btn-know:hover { background: #CCE3D9; }
.fc-btn-dontknow { background: var(--rust-light); border-color: var(--rust); color: #6B2A1A; }
.fc-btn-dontknow:hover { background: #F0D2C7; }
.flashcard-progress { font-family: var(--font-mono); font-size: 13px; color: var(--slate); margin-bottom: 24px; }
.flashcard-deck-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.deck-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s;
  text-align: left;
}
.deck-card:hover { border-color: var(--gold); }
.deck-card .deck-title { font-size: 14.5px; font-weight: 500; color: var(--navy); margin-bottom: 8px; }
.deck-card .deck-meta { font-family: var(--font-mono); font-size: 12px; color: var(--slate); display: flex; justify-content: space-between; }
.deck-card .deck-due { color: var(--gold); font-weight: 500; }
.empty-deck { text-align: center; padding: 40px 20px; color: var(--slate); }
.empty-deck i { font-size: 36px; color: var(--forest); margin-bottom: 12px; display: block; }

/* ===== Progress page ===== */
.unit-block { margin-bottom: 28px; }
.unit-block-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.unit-block-header h3 { font-size: 16px; }
.lesson-row {
  display: grid;
  grid-template-columns: 1fr 100px 120px 80px;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  margin-bottom: 6px;
  font-size: 13.5px;
}
.lesson-row .lr-title { color: var(--navy); font-weight: 500; }
.lesson-row .lr-accuracy { font-family: var(--font-mono); color: var(--slate); }
.lesson-row .lr-accuracy.weak { color: var(--rust); font-weight: 500; }
.lesson-row .lr-accuracy.strong { color: var(--forest); font-weight: 500; }
.lesson-row .lr-status { font-family: var(--font-mono); font-size: 12px; }
@media (max-width: 640px) {
  .lesson-row { grid-template-columns: 1fr; gap: 4px; }
}

.weak-callout {
  background: var(--rust-light);
  border: 1px solid var(--rust);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 24px;
}
.weak-callout h3 { color: #6B2A1A; font-size: 15px; margin-bottom: 8px; }
.weak-callout ul { margin: 0; padding-left: 20px; font-size: 14px; color: #6B2A1A; }
.weak-callout li { margin-bottom: 4px; }

/* ===== Data management (export/import/reset) ===== */
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
textarea.data-blob {
  width: 100%;
  height: 120px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  resize: vertical;
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--slate-light);
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}
