:root,
[data-theme="light"] {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface2: #eef0f5;
  --surface3: #e2e6ef;
  --border: #dce0e8;
  --border2: #c6ccd8;
  --text: #171b2a;
  --text2: #485070;
  --text3: #858fa8;
  --accent: #2759d8;
  --accent-bg: rgba(39, 89, 216, .09);
  --green: #0d8a42;
  --green-bg: rgba(13, 138, 66, .09);
  --orange: #bd6907;
  --orange-bg: rgba(189, 105, 7, .1);
  --red: #c32828;
  --red-bg: rgba(195, 40, 40, .09);
  --purple: #6c2bd9;
  --purple-bg: rgba(108, 43, 217, .09);
  --cyan: #08758d;
  --cyan-bg: rgba(8, 117, 141, .09);
  --shadow: 0 10px 28px rgba(20, 28, 48, .08);
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0e1018;
  --surface: #181b26;
  --surface2: #222634;
  --surface3: #2c3046;
  --border: #2e3348;
  --border2: #3d4260;
  --text: #e3e7f3;
  --text2: #aab2ce;
  --text3: #70799a;
  --accent: #6d8dff;
  --accent-bg: rgba(109, 141, 255, .12);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, .12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, .12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, .12);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, .12);
  --cyan: #22d3ee;
  --cyan-bg: rgba(34, 211, 238, .12);
  --shadow: 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.learn-app {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 16px 13px;
  border-bottom: 1px solid var(--border);
}
.brand h1 { margin: 0; color: var(--accent); font-size: 18px; line-height: 1.2; }
.brand p { margin: 4px 0 0; color: var(--text3); font-size: 12px; }

.site-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.site-nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text2);
  text-decoration: none;
  font-size: 12px;
}
.site-nav a:hover { background: var(--surface2); }
.site-nav a.active {
  border-color: var(--border);
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 700;
}

.panel { padding: 12px; border-bottom: 1px solid var(--border); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-title, .eyebrow {
  color: var(--text3);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
}
.panel-title { margin-bottom: 9px; }

.route-list, .lesson-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lesson-list { overflow: auto; padding-right: 2px; }
.route-item, .lesson-item, .topic-chip {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.route-item { padding: 10px; }
.route-item strong, .lesson-item strong, .topic-chip strong {
  display: block;
  overflow: hidden;
  color: var(--accent);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.route-item span, .lesson-item span, .topic-chip span {
  display: block;
  margin-top: 2px;
  color: var(--text3);
  font-size: 11px;
}
.route-item:hover, .lesson-item:hover, .topic-chip:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.route-item.active, .lesson-item.active, .topic-chip.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.lesson-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  padding: 9px;
}
.lesson-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text2);
  font-size: 12px;
  font-weight: 800;
}
.lesson-item.done .lesson-index {
  background: var(--green-bg);
  color: var(--green);
}

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.top-title { min-width: 0; }
.top-title strong { display: block; font-size: 15px; }
.top-title span {
  display: block;
  overflow: hidden;
  color: var(--text3);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-actions { display: flex; gap: 8px; }

.workspace {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}
.overview-band {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, .8fr);
  gap: 10px;
  margin-bottom: 12px;
}
.metric-card {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.metric-card span { display: block; color: var(--text3); font-size: 11px; }
.metric-card strong { display: block; margin-top: 2px; color: var(--accent); font-size: 24px; line-height: 1.15; }
.progress {
  height: 5px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface3);
}
.progress div { width: 0; height: 100%; border-radius: 99px; background: var(--accent); transition: width .2s ease; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(260px, .9fr) minmax(360px, 1.25fr) minmax(300px, .9fr);
  gap: 12px;
  align-items: start;
}
.lesson-column, .study-column, .right-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lesson-column, .topic-card, .graph-card, .practice-card, .evidence-card, .map-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(20, 28, 48, .04);
}
.lesson-column { padding: 14px; }
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.section-head h2, .section-head h3 {
  margin: 2px 0 0;
  line-height: 1.22;
}
.section-head h2 { font-size: 21px; }
.section-head h3 { font-size: 15px; }
.section-head.compact { padding: 12px 12px 0; }
.outcome {
  min-height: 44px;
  margin: 10px 0 12px;
  color: var(--text2);
  font-size: 13px;
}
.lesson-guide {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.guide-block {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.guide-block strong {
  display: block;
  margin-bottom: 5px;
  color: var(--text3);
  font-size: 11px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.guide-block ul {
  margin: 0;
  padding-left: 17px;
  color: var(--text2);
  font-size: 12.5px;
}
.guide-block li + li { margin-top: 3px; }
.guide-block p {
  margin: 0;
  color: var(--text2);
  font-size: 12.5px;
}
.topic-deck {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}
.topic-chip { min-height: 72px; padding: 9px; }
.topic-chip.done strong::after { content: " ✓"; color: var(--green); }

.topic-card { padding: 14px; }
.topic-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.topic-head h2 {
  margin: 6px 0 2px;
  font-size: 26px;
  line-height: 1.2;
}
.topic-head p {
  margin: 0;
  color: var(--text3);
  font-size: 12px;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--purple-bg);
  color: var(--purple);
  font-size: 11px;
  font-weight: 800;
}
.topic-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.learning-block {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.learning-block h3 {
  margin: 0 0 6px;
  color: var(--text3);
  font-size: 11px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.learning-block p {
  margin: 0;
  color: var(--text);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}
.learning-block.highlight {
  border-color: transparent;
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
}
.metric-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 7px;
}
.metric-item {
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--surface2);
  font-size: 12px;
}
.metric-item strong { display: block; color: var(--text3); font-size: 10px; }

.graph-card, .practice-card, .evidence-card, .map-card { overflow: hidden; }
.graph-wrap {
  position: relative;
  height: 330px;
  margin: 10px 12px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
#miniGraph, #routeMap {
  display: block;
  width: 100%;
  height: 100%;
}
.graph-wrap .empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.relation-list {
  max-height: 180px;
  overflow: auto;
  padding: 10px 12px 12px;
}
.relation-item {
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-size: 12px;
}
.relation-item + .relation-item { margin-top: 7px; }
.relation-item strong { color: var(--accent); }
.relation-item p {
  margin: 4px 0 0;
  color: var(--text3);
  overflow-wrap: anywhere;
}
.term-link {
  display: inline;
  padding: 0 2px;
  border-radius: 4px;
  color: var(--accent);
  background: var(--accent-bg);
  text-decoration: none;
  font-weight: 650;
  text-underline-offset: 2px;
}
.term-link:hover,
.term-link:focus {
  outline: none;
  text-decoration: underline;
}
.term-popover {
  position: fixed;
  z-index: 100;
  width: min(340px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12.5px;
  pointer-events: none;
}
.term-popover strong {
  display: block;
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 14px;
}
.term-popover span {
  display: inline-flex;
  margin-bottom: 7px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--purple-bg);
  color: var(--purple);
  font-size: 10px;
  font-weight: 800;
}
.term-popover p {
  margin: 0;
  color: var(--text2);
  line-height: 1.65;
}

.quiz-box, .evidence-list { padding: 12px; }
.quiz-question {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.quiz-option {
  display: block;
  width: 100%;
  min-height: 38px;
  margin-top: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  font-size: 12.5px;
}
.quiz-option:hover { border-color: var(--accent); color: var(--accent); }
.quiz-option.correct { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.quiz-option.wrong { border-color: var(--red); background: var(--red-bg); color: var(--red); }
.quiz-feedback {
  margin-top: 9px;
  color: var(--text2);
  font-size: 12px;
}
.evidence-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-size: 12px;
}
.evidence-item + .evidence-item { margin-top: 8px; }
.evidence-item strong { color: var(--accent); }
.evidence-item p {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
}
.source-line { margin-top: 6px; color: var(--text3); font-size: 11px; }
.map-card { height: 250px; }
.map-card .section-head { position: relative; z-index: 1; }
#routeMap { height: 202px; }

.btn, .icon-btn {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  text-decoration: none;
  transition: border-color .14s, background .14s, color .14s;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 13px;
}
.btn:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 800; }
.btn.primary:hover { filter: brightness(1.05); color: #fff; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex-shrink: 0;
}
.icon-btn.check {
  border-color: var(--border2);
  font-size: 16px;
  font-weight: 900;
}
.icon-btn.check.active {
  border-color: var(--green);
  background: var(--green-bg);
  color: var(--green);
}
.mobile-only { display: none; }
.mobile-scrim { display: none; }
.empty-state {
  color: var(--text3);
  font-size: 12.5px;
  text-align: center;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateY(0); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

@media (max-width: 1240px) {
  .content-grid { grid-template-columns: minmax(250px, .85fr) minmax(360px, 1.15fr); }
  .right-column { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .map-card { height: auto; min-height: 230px; }
}

@media (max-width: 860px) {
  body { overflow: hidden; }
  .learn-app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 330px);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform .18s ease;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .mobile-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(10, 14, 24, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }
  body.menu-open .mobile-scrim { opacity: 1; pointer-events: auto; }
  .topbar { min-height: 54px; padding: 10px; }
  .top-actions .btn { padding: 6px 9px; }
  .workspace { padding: 10px; }
  .overview-band { grid-template-columns: 1fr 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .right-column { display: flex; }
  .topic-head h2 { font-size: 23px; }
  .graph-wrap { height: 290px; }
}

@media (max-width: 520px) {
  .overview-band { grid-template-columns: 1fr; }
  .topic-deck { grid-template-columns: 1fr 1fr; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head.compact { flex-direction: row; align-items: flex-start; }
  .top-title span { max-width: 190px; }
}
