:root {
  --ink: #2b2318;
  --paper: #faf6ec;
  --paper-2: #f1e9d6;
  --line: #ddd0ac;
  --forest: #2f5d4f;
  --forest-dark: #1f4237;
  --amber: #c8842a;
  --amber-dark: #a3671a;
  --rust: #a8452f;
  --peak: #4a6fa5;
  --gold: #d9a441;
  --danger: #b0402f;
  --success: #3c7a4e;
  --shadow: 0 2px 10px rgba(43,35,24,0.12);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--forest-dark);
  color: #fff;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 12px; opacity: 0.75; }

.topnav { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.nav-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-btn:hover { background: rgba(255,255,255,0.12); }
.nav-btn.active { background: var(--amber); border-color: var(--amber); font-weight: 600; }

.badge {
  background: var(--rust);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  margin-left: 4px;
}
.badge.hidden { display: none; }

.xp-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
}
.xp-level { font-weight: 600; white-space: nowrap; }
.xp-bar-track { width: 90px; height: 6px; background: rgba(255,255,255,0.25); border-radius: 4px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: var(--gold); width: 0%; transition: width 0.4s ease; }
.xp-amount { white-space: nowrap; opacity: 0.85; }

/* ---------- Main layout ---------- */
main#app {
  flex: 1;
  padding: 28px 24px 60px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.footer {
  text-align: center;
  font-size: 12px;
  color: #8a7d5f;
  padding: 14px;
  border-top: 1px solid var(--line);
}
.footer code { background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }

h1.view-title { font-size: 22px; margin: 0 0 4px; }
p.view-sub { color: #6b5f45; margin: 0 0 24px; font-size: 14px; }

/* ---------- Region map ---------- */
.trail {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 32px;
}
.region-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.region-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(43,35,24,0.16); }
.region-icon {
  font-size: 34px;
  width: 62px; height: 62px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-2);
  border-radius: 50%;
  flex-shrink: 0;
}
.region-card.explored .region-icon { background: #e3f0e6; }
.region-info { flex: 1; min-width: 0; }
.region-name { font-weight: 700; font-size: 17px; margin-bottom: 2px; }
.region-meta { font-size: 12.5px; color: #6b5f45; }
.region-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  color: #8a7d5f;
  white-space: nowrap;
}
.region-card.explored .region-status { background: #dff2e3; color: var(--success); }
.region-best {
  font-size: 11.5px;
  color: #8a7d5f;
  margin-top: 4px;
}

.global-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:hover { background: var(--forest-dark); }
.btn-secondary { background: var(--paper-2); color: var(--ink); }
.btn-secondary:hover { background: var(--line); }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover { background: var(--amber-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---------- Panels / cards ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.back-link {
  background: none;
  border: none;
  color: var(--forest);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
  font-size: 13.5px;
}
.back-link:hover { text-decoration: underline; }

/* ---------- Guide reader ---------- */
.guide-body h2 { color: var(--forest-dark); border-bottom: 2px solid var(--paper-2); padding-bottom: 6px; margin-top: 32px; }
.guide-body h3 { color: var(--amber-dark); margin-top: 26px; }
.guide-body table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.guide-body th, .guide-body td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.guide-body th { background: var(--paper-2); }
.guide-body p { line-height: 1.6; font-size: 14.5px; }
.guide-body { max-width: 780px; }

/* ---------- Quiz setup ---------- */
.quiz-setup { display: flex; flex-direction: column; gap: 18px; max-width: 520px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--paper-2);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.chip.selected { background: var(--forest); color: #fff; border-color: var(--forest); }
.field-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: #6b5f45; margin-bottom: 6px; }

/* ---------- Quiz question ---------- */
.quiz-progress { font-size: 12.5px; color: #6b5f45; margin-bottom: 10px; }
.trap-pill {
  display: inline-block;
  background: var(--peak);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.question-text { font-size: 17px; font-weight: 600; margin: 0 0 20px; line-height: 1.45; }
.option-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  text-align: left;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  transition: all 0.12s ease;
}
.option-btn:hover:not(:disabled) { border-color: var(--forest); background: #f4f9f5; }
.option-btn.correct { border-color: var(--success); background: #e5f5e9; }
.option-btn.incorrect { border-color: var(--danger); background: #fbe9e6; }
.option-btn:disabled { cursor: default; }
.option-letter { font-weight: 700; margin-right: 8px; color: var(--forest); }

.explanation-box {
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--paper-2);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.55;
}
.explanation-box.wrong { border-left-color: var(--danger); }
.quiz-nav { margin-top: 20px; display: flex; justify-content: flex-end; }

/* ---------- Quiz results ---------- */
.results-score { font-size: 42px; font-weight: 800; color: var(--forest); }
.results-sub { color: #6b5f45; margin-bottom: 20px; }
.trap-breakdown { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 24px; }
.trap-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.trap-name { width: 90px; font-weight: 600; text-transform: capitalize; }
.trap-bar-track { flex: 1; height: 10px; background: var(--paper-2); border-radius: 6px; overflow: hidden; }
.trap-bar-fill { height: 100%; background: var(--forest); }
.trap-bar-fill.weak { background: var(--danger); }
.trap-frac { width: 46px; text-align: right; color: #6b5f45; }

/* ---------- Flashcards ---------- */
.flash-controls { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 22px; align-items: flex-end; }
.flash-count { font-size: 13px; color: #6b5f45; margin-bottom: 14px; }
.flashcard-stage { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.flashcard {
  width: 100%;
  max-width: 560px;
  height: 220px;
  perspective: 1200px;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.flashcard-front { background: #fff; }
.flashcard-back { background: var(--forest); color: #fff; transform: rotateY(180deg); }
.flashcard-region-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--amber-dark); margin-bottom: 10px; font-weight: 700; }
.flashcard-back .flashcard-region-tag { color: var(--gold); }
.flashcard-figure-name { font-size: 17px; font-weight: 700; line-height: 1.4; }
.flashcard-amount { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.flashcard-marker { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,0.2); margin-bottom: 10px; }
.flashcard-source { font-size: 12px; opacity: 0.85; }
.flash-controls-row { display: flex; gap: 10px; }
.flash-hint { font-size: 12px; color: #8a7d5f; }

/* ---------- Vault table ---------- */
.vault-controls { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; align-items: center; }
.vault-search {
  padding: 9px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-size: 13.5px;
  flex: 1;
  min-width: 200px;
}
table.vault-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.vault-table th, table.vault-table td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; }
table.vault-table th { background: var(--paper-2); position: sticky; top: 0; }
.vault-table-wrap { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.marker-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.marker-tag.annual { background: #fdeecd; color: var(--amber-dark); }
.marker-tag.law { background: #f6dcd6; color: var(--danger); }
.marker-tag.stable { background: #dcecf6; color: var(--peak); }
.marker-tag.other { background: var(--paper-2); color: #6b5f45; }
.region-tag-inline { font-size: 11.5px; color: #8a7d5f; }

/* ---------- Missed ---------- */
.missed-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.missed-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.missed-q-text { font-size: 13.5px; }
.missed-meta { font-size: 11.5px; color: #8a7d5f; margin-top: 3px; }
.empty-state { text-align: center; padding: 50px 20px; color: #8a7d5f; }
.empty-state .emoji { font-size: 40px; display: block; margin-bottom: 12px; }

@media (max-width: 640px) {
  .topbar { gap: 12px; }
  .xp-chip { order: 3; width: 100%; justify-content: center; }
  .region-card { flex-wrap: wrap; }
}

/* ── question-bank drill integration ── */
.drill-bar { margin: 10px 0 18px; }
.btn-drill {
  background: #2e5339; color: #eaf5ec; border: 1.5px solid #4d7f5c;
  border-radius: 10px; padding: 8px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: background .15s, transform .15s;
}
.btn-drill:hover { background: #3a6a49; transform: translateY(-1px); }
.bank-pill {
  display: inline-block; margin-left: 8px; padding: 3px 10px; border-radius: 99px;
  background: #2e5339; color: #cfe8d6; font-size: 11px; letter-spacing: .04em;
}
.case-setup {
  background: #f2ecdc; border: 1px solid #d8cba6; border-left: 4px solid #b09a5e;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;
  font-size: 13.5px; line-height: 1.55; color: #4d4227;
}
.ref-line { margin-top: 8px; font-size: 12px; opacity: .75; }
.anchor-flash { animation: anchorFlash 2.2s ease-out; }
@keyframes anchorFlash {
  0% { background: #ffe9a8; box-shadow: 0 0 0 6px #ffe9a8; }
  100% { background: transparent; box-shadow: none; }
}
