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

:root {
  --bg:         #0b0f1a;
  --surface:    #111827;
  --card:       #161e2e;
  --border:     #1f2d42;
  --text:       #e2e8f0;
  --muted:      #94a3b8;
  --white:      #ffffff;
  --primary:    #0ea5e9;
  --primary-h:  #0284c7;
  --primary-bg: rgba(14,165,233,0.1);
  --correct:    #34d399;
  --correct-bg: rgba(52,211,153,0.12);
  --wrong:      #f87171;
  --wrong-bg:   rgba(248,113,113,0.12);
  --warn:       #f97316;
  --weak-bg:    rgba(249,115,22,0.08);
  --violet:     #a78bfa;
  --radius:     8px;
  --shadow:     0 1px 4px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.2);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Nav ──────────────────────────────────────────────────────────────── */
nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(11,15,26,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.nav-brand {
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 0.5rem;
  text-decoration: none;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand img { height: 32px; width: auto; border-radius: 4px; }
.nav-links { display: flex; gap: 2rem; }
.nav-links a { color: var(--muted); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--text); }
.nav-cta {
  background: var(--primary); color: #050d18;
  padding: 0.4rem 1.1rem; border-radius: 6px;
  font-size: 0.9rem; font-weight: 600;
}
.nav-cta:hover { opacity: 0.85; text-decoration: none; }

/* ── Layout ───────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

/* ── Site header (quiz-internal title) ───────────────────────────────── */
.site-header {
  padding: 40px 0 24px;
  text-align: center;
}
.site-header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--white);
}
.tagline {
  margin-top: 6px;
  color: var(--muted);
  font-size: .95rem;
}

/* ── Write-up intro ───────────────────────────────────────────────────── */
.writeup-section {
  padding: 1.5rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  font-size: 0.97rem;
  line-height: 1.75;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.writeup-section a { color: var(--primary); }

/* ── Card ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 16px;
}

/* ── Topic list ───────────────────────────────────────────────────────── */
.topic-controls {
  margin-bottom: 12px;
  font-size: .875rem;
  color: var(--muted);
}
.sep { margin: 0 6px; }
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}
.btn-link:hover { color: var(--primary-h); }

.topic-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 8px;
}
.topic-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background .1s;
}
.topic-label:hover { background: rgba(255,255,255,0.04); }
.topic-label input { flex-shrink: 0; accent-color: var(--primary); }
.topic-name { flex: 1; font-size: .9rem; }
.topic-count { font-size: .8rem; color: var(--muted); }

/* ── Count selector ───────────────────────────────────────────────────── */
.count-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.count-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 20px;
  font-weight: 500;
  color: var(--text);
  transition: border-color .1s, background .1s;
}
.count-label:hover { background: rgba(255,255,255,0.04); }
.count-label input { accent-color: var(--primary); }
.count-label input:checked + span { color: var(--primary); }
.count-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.pool-note {
  font-size: .85rem;
  color: var(--muted);
}
.pool-note.warn { color: var(--warn); }

/* ── Start button row ─────────────────────────────────────────────────── */
.start-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  background: var(--primary);
  color: #050d18;
  border: none;
  border-radius: var(--radius);
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; text-decoration: none; }
.btn-primary:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.btn-secondary {
  display: inline-block;
  background: var(--card);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--primary-bg); text-decoration: none; }

/* ── Quiz header ──────────────────────────────────────────────────────── */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  gap: 12px;
}
.back-link {
  font-size: .875rem;
  color: var(--primary);
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

.scoreboard {
  display: flex;
  gap: 16px;
  font-size: .95rem;
  font-weight: 600;
}
.score-correct   { color: var(--correct); }
.score-incorrect { color: var(--wrong); }
.score-remaining { color: var(--muted); }

/* ── Progress bar ─────────────────────────────────────────────────────── */
.progress-bar-wrap {
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  width: 0;
  transition: width .3s ease;
}

/* ── Question card ────────────────────────────────────────────────────── */
.quiz-main { padding-bottom: 32px; }

.question-meta {
  font-size: .8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 12px;
}

.question-image-wrap {
  margin-bottom: 20px;
  text-align: center;
}
.question-image-wrap img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.question-text {
  font-size: 1.15rem;
  line-height: 1.55;
  margin-bottom: 20px;
  font-weight: 500;
  color: var(--white);
}

/* ── Options ──────────────────────────────────────────────────────────── */
.options-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.option-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .97rem;
  line-height: 1.5;
  transition: border-color .1s, background .1s;
  background: var(--surface);
  color: var(--text);
}
.option-label:hover { border-color: var(--primary); background: var(--primary-bg); }
.option-label input { flex-shrink: 0; margin-top: 3px; accent-color: var(--primary); }

.option-label.opt-correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: var(--correct);
  font-weight: 500;
}
.option-label.opt-wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: var(--wrong);
}

/* ── Feedback block ───────────────────────────────────────────────────── */
.feedback-block { margin-top: 20px; }

.feedback-verdict {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.feedback-verdict.correct  { color: var(--correct); }
.feedback-verdict.incorrect { color: var(--wrong); }
.feedback-verdict.study    { color: var(--primary); }

.feedback-explanation {
  font-size: .92rem;
  line-height: 1.6;
  background: var(--surface);
  border-left: 3px solid var(--primary);
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 8px;
  color: var(--text);
}
.feedback-source {
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 16px;
}

/* ── btn-row ──────────────────────────────────────────────────────────── */
.btn-row { margin-top: 16px; }

/* ── Results ──────────────────────────────────────────────────────────── */
.results-screen { padding-bottom: 48px; }
.results-card h2 { font-size: 1.5rem; margin-bottom: 12px; color: var(--white); }
.results-score { font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; color: var(--primary); }

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  margin-bottom: 24px;
}
.results-table th,
.results-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.results-table th { font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.results-table tr.weak td { background: var(--weak-bg); }
.results-table tbody tr:hover td { background: rgba(255,255,255,0.03); }

.results-card h3 { font-size: 1.05rem; margin: 20px 0 12px; color: var(--white); }

/* ── Missed questions list ────────────────────────────────────────────── */
.wrong-list { list-style: none; display: flex; flex-direction: column; gap: 16px; }
.wrong-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.wrong-q { font-weight: 500; margin-bottom: 6px; color: var(--text); }
.wrong-answer { font-size: .875rem; margin-bottom: 6px; color: var(--muted); }
.wrong-answer b { color: var(--primary); }
.wrong-expl {
  font-size: .85rem;
  color: var(--muted);
  border-left: 3px solid var(--border);
  padding-left: 10px;
}

/* ── Mode badge (Study Mode indicator) ───────────────────────────────── */
.mode-badge {
  background: var(--violet);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 99px;
}

/* ── Mode selector (index page) ──────────────────────────────────────── */
.mode-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mode-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  transition: border-color .1s, background .1s;
}
.mode-label:hover { background: rgba(255,255,255,0.04); }
.mode-label input { flex-shrink: 0; margin-top: 3px; accent-color: var(--primary); }
.mode-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.mode-label span { display: flex; flex-direction: column; gap: 2px; }
.mode-label strong { font-size: .95rem; color: var(--white); }
.mode-label small { font-size: .82rem; color: var(--muted); }

/* ── Flag button ──────────────────────────────────────────────────────── */
.feedback-btn-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-flag {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s, color .15s, background .15s;
}
.btn-flag:hover {
  border-color: var(--warn);
  color: var(--warn);
}
.btn-flag--active {
  border-color: var(--warn);
  background: rgba(249,115,22,0.1);
  color: var(--warn);
}

/* ── Site nav (quiz-internal links row) ──────────────────────────────── */
.site-nav {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 20px;
}
.nav-link {
  font-size: .875rem;
  color: var(--primary);
  text-decoration: none;
}
.nav-link:hover { text-decoration: underline; }

/* ── Acronym dictionary page ──────────────────────────────────────────── */
.acr-search-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.acr-search {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.acr-search:focus { border-color: var(--primary); }
.acr-search::placeholder { color: var(--muted); }
.acr-count {
  font-size: .82rem;
  color: var(--muted);
}
.acr-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: .95rem;
}

.acr-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.acr-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.acr-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}
.acr-abbr {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}
.acr-expansion {
  font-size: .95rem;
  font-weight: 500;
  flex: 1;
  color: var(--white);
}
.acr-topic-tag {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--primary);
  background: var(--primary-bg);
  border: 1px solid rgba(14,165,233,0.3);
  border-radius: 99px;
  padding: 2px 10px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.acr-topic-tag:hover { background: rgba(14,165,233,0.2); text-decoration: none; }
.acr-def {
  font-size: .9rem;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 4px;
}
.acr-source {
  font-size: .75rem;
  color: var(--muted);
}

/* ── Acronym tooltip (quiz page) ──────────────────────────────────────── */
abbr.acr-tooltip {
  text-decoration: underline dotted var(--primary);
  cursor: help;
  text-underline-offset: 3px;
}

/* ── History page ─────────────────────────────────────────────────────── */
.history-empty {
  color: var(--muted);
  text-align: center;
  padding: 16px 0 20px;
}

/* Stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}
.stat-label {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Bar chart */
.chart-wrap {
  display: grid;
  grid-template-columns: 36px 1fr;
  grid-template-rows: 1fr 28px;
  gap: 0 8px;
  height: 200px;
  margin-top: 12px;
}
.chart-y-labels {
  position: relative;
  grid-column: 1;
  grid-row: 1;
}
.chart-y-label {
  position: absolute;
  right: 0;
  font-size: .7rem;
  color: var(--muted);
  transform: translateY(50%);
  white-space: nowrap;
}
.chart-bars {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  padding: 8px 4px 0;
}
.chart-pass-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--warn) 0, var(--warn) 6px, transparent 6px, transparent 10px);
  pointer-events: none;
}
.chart-bar-wrap {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
}
.chart-bar {
  width: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  transition: opacity .15s;
  cursor: default;
  min-height: 2px;
}
.chart-bar:hover { opacity: .8; }
.chart-bar--fail { background: var(--wrong); }
.chart-x-labels {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  gap: 4px;
  padding: 4px 4px 0;
}
.chart-x-label {
  flex: 1;
  font-size: .65rem;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Log table */
.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.log-header h2 { margin-bottom: 0; }
.btn-danger-sm {
  background: none;
  border: 1px solid var(--wrong);
  color: var(--wrong);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger-sm:hover { background: var(--wrong-bg); }

.table-scroll { overflow-x: auto; }
.topics-cell {
  font-size: .78rem;
  color: var(--muted);
  max-width: 260px;
}

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

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .nav-links { display: none; }
}
@media (max-width: 540px) {
  .site-header h1 { font-size: 1.5rem; }
  .topic-list { grid-template-columns: 1fr; }
  .scoreboard { gap: 10px; font-size: .85rem; }
  .question-text { font-size: 1.05rem; }
  .count-options { gap: 8px; }
  .count-label { padding: 8px 14px; }
}
