:root {
  --paper: #e4edf2;
  --paper-2: #f5f8fa;
  --ink: #122033;
  --ink-soft: #3c5166;
  --line: #c5d3de;
  --copper: #b4532a;
  --copper-deep: #8c3e1c;
  --copper-soft: #f8ebe4;
  --teal: #0e6b66;
  --teal-soft: #e4f3f1;
  --navy: #17364d;
  --navy-2: #102838;
  --gold: #8a5a10;
  --gold-soft: #f8f1e2;
  --danger: #9b2c2c;
  --danger-soft: #fbecec;
  --shadow: 0 16px 40px rgba(18, 32, 51, 0.08);
  --radius: 12px;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --nav: 232px;
  --header: 64px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 54, 77, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 54, 77, 0.045) 1px, transparent 1px);
  background-size: 24px 24px;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible {
  outline: 3px solid var(--copper);
  outline-offset: 2px;
}
.skip {
  position: absolute;
  left: 16px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { top: 8px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--navy-2);
  color: #f4f7f8;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.mark {
  width: 36px;
  height: 36px;
  flex: none;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 560;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand p {
  margin: 2px 0 0;
  color: #b7c6d2;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.progress-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}
.progress-chip span {
  font-size: 0.82rem;
  color: #d5e0e8;
  white-space: nowrap;
}
.track {
  flex: 1;
  height: 8px;
  background: #2a455c;
  border-radius: 99px;
  overflow: hidden;
}
.track > i {
  display: block;
  height: 100%;
  width: 0%;
  background: #e7a07a;
  border-radius: 99px;
}

.shell {
  display: grid;
  grid-template-columns: var(--nav) minmax(0, 1fr);
  min-height: calc(100vh - var(--header));
}
.sidenav {
  position: sticky;
  top: var(--header);
  height: calc(100vh - var(--header));
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: rgba(245, 248, 250, 0.86);
  backdrop-filter: blur(8px);
}
.sidenav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--ink-soft);
}
.sidenav button svg { flex: none; }
.sidenav button[aria-current="page"] {
  background: white;
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--copper);
}
.sidenav button:hover { background: rgba(255, 255, 255, 0.7); }
.nav-label {
  margin: 18px 12px 6px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

main { padding: 28px 28px 64px; max-width: 1180px; }
.kicker {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--copper-deep);
}
h2.page-title {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 560;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.lede { margin: 0 0 24px; max-width: 68ch; color: var(--ink-soft); font-size: 1.05rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 20px;
  align-items: start;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h3 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 560;
}
.card p { margin: 0; color: var(--ink-soft); }
.pillar {
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  min-height: 132px;
  box-shadow: var(--shadow);
}
.pillar:hover { border-color: var(--copper); }
.pillar.mastered { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.dot.half { background: var(--gold); border-color: var(--gold); }
.pillar .idx {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--copper-deep);
}
.pillar strong { display: block; margin: 6px 0; font-family: var(--display); font-size: 1.15rem; }
.pillar span { color: var(--ink-soft); font-size: 0.92rem; }

.map-wrap { overflow-x: auto; }
.map-wrap svg { width: 100%; height: auto; min-width: 640px; display: block; }
.node-btn { cursor: pointer; }
.node-btn:hover rect { stroke: var(--copper); }

.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 64px;
  padding: 12px 14px;
}
.lesson-row:hover { border-color: #8aa0b3; }
.dot {
  width: 14px;
  height: 14px;
  border-radius: 99px;
  border: 2px solid var(--line);
}
.dot.on { background: var(--teal); border-color: var(--teal); }
.meta { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-soft); }

.prose { max-width: 72ch; }
.prose h3 {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 560;
  margin: 28px 0 8px;
}
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 1.2rem; }
.prose li { margin: 4px 0; }
.callout {
  border-left: 4px solid var(--copper);
  background: var(--copper-soft);
  border-radius: 0 12px 12px 0;
  padding: 12px 14px;
  margin: 14px 0;
}
.callout.teal { border-color: var(--teal); background: var(--teal-soft); }
.callout.gold { border-color: var(--gold); background: var(--gold-soft); }
.callout strong { display: block; margin-bottom: 4px; }
pre.code {
  background: var(--navy-2);
  color: #e7eef3;
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  margin: 12px 0 16px;
}
.table-wrap { overflow-x: auto; margin: 12px 0 16px; }
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.95rem;
}
th, td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
th { background: #e7eef3; font-weight: 650; }

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.btn {
  min-height: 44px;
  border-radius: 10px;
  padding: 8px 16px;
  border: 1.5px solid transparent;
}
.btn.primary { background: var(--copper); color: white; }
.btn.primary:hover { background: var(--copper-deep); }
.btn.secondary { background: white; border-color: #b7c6d2; }
.btn.secondary:hover { border-color: var(--navy); }
.btn.ghost { background: transparent; color: var(--ink-soft); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sim-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
}
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice-list button, .option {
  text-align: left;
  background: white;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  min-height: 48px;
  padding: 10px 12px;
}
.choice-list button[aria-pressed="true"], .option.picked {
  border-color: var(--navy);
  background: #eef4f8;
}
.option.good { border-color: var(--teal); background: var(--teal-soft); }
.option.bad { border-color: var(--danger); background: var(--danger-soft); }
.step-rail { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.step-pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 6px 8px;
  border-radius: 99px;
  background: white;
  border: 1px solid var(--line);
}
.step-pill.on { background: var(--navy); color: white; border-color: var(--navy); }
.step-pill.done { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }

.q-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.exam-meta { text-align: right; }
.live-score { font-family: var(--display); font-size: 1.45rem; line-height: 1; }
.timer { font-family: var(--mono); font-size: 1rem; }
.score-big {
  font-family: var(--display);
  font-size: 3.2rem;
  line-height: 1;
  margin: 8px 0;
}
.study-card {
  width: 100%;
  min-height: 220px;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}
.study-card:hover { border-color: var(--copper); }
.study-card.flipped {
  background: var(--teal-soft);
  border-color: var(--teal);
}
.study-q {
  display: block;
  font-family: var(--display);
  font-size: clamp(1.35rem, 2vw, 1.7rem);
  font-weight: 560;
  line-height: 1.3;
  margin: 8px 0;
}
.study-hint { font-size: 0.85rem; color: var(--ink-soft); }
.opt-key {
  font-family: var(--mono);
  font-size: 0.75rem;
  margin-right: 8px;
  color: var(--copper-deep);
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters button[aria-pressed="true"] { background: var(--navy); color: white; border-color: var(--navy); }

.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.pair.locked { border-color: var(--teal); background: var(--teal-soft); }
.pair.selected { border-color: var(--copper); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav {
    position: sticky;
    top: var(--header);
    height: auto;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    z-index: 5;
  }
  .nav-label { display: none; }
  .sidenav button { width: auto; white-space: nowrap; }
  .grid-2, .sim-layout, .match-grid { grid-template-columns: 1fr; }
  main { padding: 18px 14px 48px; }
  .progress-chip { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
