:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --grid: #e7e6e2;
  --axis: #a9a8a2;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --good: #0a7d45; --bad: #c62f2f; --warn: #a86400;
  --gain-tint: rgba(27, 175, 122, 0.07);
  --loss-tint: rgba(227, 73, 72, 0.07);
  --callout: #eef4fc; --callout-border: #b7d3f6;
  --warnbox: #fdf4e3; --warnbox-border: #f0d29a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --grid: #2a2a27; --axis: #5b5a55;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --good: #3cc47f; --bad: #ff7b7b; --warn: #e2a33a;
    --gain-tint: rgba(25, 158, 112, 0.10); --loss-tint: rgba(230, 103, 103, 0.10);
    --callout: #172435; --callout-border: #24456d;
    --warnbox: #2c2414; --warnbox-border: #5c4718;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --grid: #2a2a27; --axis: #5b5a55;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --good: #3cc47f; --bad: #ff7b7b; --warn: #e2a33a;
  --gain-tint: rgba(25, 158, 112, 0.10); --loss-tint: rgba(230, 103, 103, 0.10);
  --callout: #172435; --callout-border: #24456d;
  --warnbox: #2c2414; --warnbox-border: #5c4718;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.8rem; margin: 0 0 .4rem; }
h2 { font-size: 1.35rem; margin: 2.2rem 0 .6rem; }
h3 { font-size: 1.08rem; margin: 1.6rem 0 .4rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .92em; }
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar / layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
#topnav { margin-left: auto; display: flex; gap: 6px; align-items: center; min-width: 0; }
#topnav a, #topnav button { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; background: none; border: 0; cursor: pointer; font-size: .95rem; }
#topnav a:hover, #topnav button:hover { background: var(--surface-2); color: var(--text); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 2px 9px; cursor: pointer; font-size: 1.1rem; }

.layout { flex: 1; display: flex; width: 100%; max-width: 1240px; margin: 0 auto; }
#sidebar {
  width: 280px; flex-shrink: 0; padding: 20px 12px 40px 16px; border-right: 1px solid var(--border);
  position: sticky; top: 53px; align-self: flex-start; max-height: calc(100vh - 53px); overflow-y: auto;
}
#sidebar h4 { margin: 18px 8px 6px; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#sidebar a { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 6px; color: var(--text-2); text-decoration: none; font-size: .92rem; line-height: 1.35; }
#sidebar a:hover { background: var(--surface-2); color: var(--text); }
#sidebar a.active { background: var(--callout); color: var(--text); font-weight: 600; }
#sidebar .tick { flex-shrink: 0; width: 1.1em; color: var(--good); font-weight: 700; }
#main { flex: 1; min-width: 0; padding: 28px 32px 64px; }
.footer { text-align: center; font-size: .8rem; color: var(--muted); padding: 18px 16px 24px; border-top: 1px solid var(--border); }
.loading { color: var(--muted); padding: 40px 0; }

@media (max-width: 860px) {
  #sidebar { position: fixed; left: 0; top: 53px; bottom: 0; z-index: 15; background: var(--surface); max-height: none; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  #sidebar.open { transform: none; }
  #main { padding: 20px 16px 48px; }
  #topnav .hide-sm { display: none; }
}

/* ---------- auth ---------- */
.auth-wrap { max-width: 920px; margin: 24px auto; display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; }
.auth-wrap .pitch h1 { font-size: 2.1rem; }
.auth-wrap .pitch ul { padding-left: 1.2em; color: var(--text-2); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--surface-2); padding: 4px; border-radius: 8px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 6px; cursor: pointer; color: var(--text-2); }
.tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: 4px; }
.field input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.error { color: var(--bad); font-size: .9rem; min-height: 1.3em; margin: 4px 0 10px; }
.ok { color: var(--good); font-size: .9rem; }
@media (max-width: 760px) { .auth-wrap { grid-template-columns: 1fr; gap: 20px; margin-top: 0; } .auth-wrap .pitch h1 { font-size: 1.6rem; } }

/* ---------- dashboard ---------- */
.hero { margin-bottom: 28px; }
.hero p { color: var(--text-2); max-width: 70ch; }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; max-width: 420px; }
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 99px; }
.module { margin-bottom: 30px; }
.module h2 { margin: 0 0 4px; font-size: 1.2rem; }
.module > p { color: var(--text-2); margin: 0 0 12px; }
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.lesson-card { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: border-color .15s, transform .15s; }
.lesson-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lesson-card .num { font-size: .78rem; color: var(--muted); font-weight: 600; }
.lesson-card h3 { margin: 2px 0 6px; font-size: 1.02rem; }
.lesson-card p { margin: 0; font-size: .88rem; color: var(--text-2); line-height: 1.45; }
.lesson-card .meta { margin-top: 10px; font-size: .8rem; color: var(--muted); display: flex; gap: 10px; }
.lesson-card .done { color: var(--good); font-weight: 600; }
.lesson-card.featured { border-left: 4px solid var(--series-2); }

/* ---------- lesson ---------- */
.lesson { max-width: 820px; }
.lesson .crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.lesson .lede { font-size: 1.1rem; color: var(--text-2); }
.lesson p, .lesson li { max-width: 72ch; }
.lesson table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: .92rem; }
.lesson th, .lesson td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.lesson th { background: var(--surface-2); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.callout, .warn, .keyidea { border-radius: var(--radius); padding: 12px 16px; margin: 18px 0; border: 1px solid; }
.callout { background: var(--callout); border-color: var(--callout-border); }
.warn { background: var(--warnbox); border-color: var(--warnbox-border); }
.keyidea { background: var(--surface); border-color: var(--border); border-left: 4px solid var(--accent); }
.callout > :first-child, .warn > :first-child, .keyidea > :first-child { margin-top: 0; }
.callout > :last-child, .warn > :last-child, .keyidea > :last-child { margin-bottom: 0; }
.formula { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); padding: 10px 14px; border-radius: 8px; overflow-x: auto; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.complete-bar { display: flex; align-items: center; gap: 14px; margin-top: 28px; flex-wrap: wrap; }

/* ---------- widgets ---------- */
.widget { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 22px 0; box-shadow: var(--shadow); }
.widget > .w-title { font-weight: 700; margin: 0 0 2px; display: flex; align-items: center; gap: 8px; }
.widget > .w-title::before { content: "▶"; font-size: .7em; color: var(--accent); }
.widget > .w-sub { color: var(--text-2); font-size: .9rem; margin: 0 0 14px; }
.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 16px; margin-bottom: 14px; }
.ctl { display: flex; flex-direction: column; font-size: .85rem; color: var(--text-2); gap: 3px; }
.ctl .val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctl select, .ctl input[type=number] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: .86rem; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.stat .k { font-size: .76rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.stat .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.explain { font-size: .93rem; background: var(--surface-2); border-radius: 8px; padding: 10px 14px; margin-top: 12px; }
.explain:empty { display: none; }
.wtable { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.wtable th, .wtable td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.wtable th:first-child, .wtable td:first-child { text-align: left; }
.wtable th { color: var(--text-2); font-weight: 600; font-size: .8rem; }
.wtable i.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* charts */
.chart { position: relative; margin: 6px 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick, .chart .chart-note { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .chart-note { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.chart .axis-label { fill: var(--text-2); font-size: 11.5px; }
.chart .row-label { fill: var(--text); font-size: 12.5px; }
.chart .refline { stroke: var(--axis); stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart .ref-label, .chart .marker-label { fill: var(--text-2); font-size: 11.5px; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.chart .marker-label { fill: var(--text); font-weight: 600; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .82rem; color: var(--text-2); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-tip { position: absolute; display: none; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; z-index: 5; color: var(--text); }
.chart-tip .tip-x { color: var(--text-2); margin-bottom: 2px; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* order book */
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-variant-numeric: tabular-nums; font-size: .9rem; }
.book table { width: 100%; border-collapse: collapse; }
.book td, .book th { padding: 3px 8px; text-align: right; position: relative; }
.book th { font-size: .78rem; color: var(--text-2); }
.book .bar { position: absolute; top: 2px; bottom: 2px; right: 0; border-radius: 3px; opacity: .22; z-index: 0; }
.book td span { position: relative; z-index: 1; }
.book tr.hit td { font-weight: 700; }
.book tr.hit td:first-child::before { content: "●"; color: var(--accent); position: absolute; left: 0; }

/* quiz + scenario */
.quiz { margin-top: 36px; border-top: 2px solid var(--border); padding-top: 8px; }
.q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.q .qtext { font-weight: 600; margin-bottom: 10px; }
.q label { display: flex; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.q label:hover { background: var(--surface-2); }
.q input { margin-top: .35em; accent-color: var(--accent); }
.q label.right { border-color: var(--good); background: var(--gain-tint); }
.q label.wrong { border-color: var(--bad); background: var(--loss-tint); }
.q .why { font-size: .9rem; color: var(--text-2); margin-top: 8px; display: none; }
.q.answered .why { display: block; }
.score { font-size: 1.1rem; font-weight: 700; }
.scenario .step { margin-top: 10px; }
.scenario .choice { display: block; width: 100%; text-align: left; margin: 6px 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; }
.scenario .choice:hover:not(:disabled) { border-color: var(--accent); }
.scenario .choice.picked { border-color: var(--accent); background: var(--callout); }
.scenario .feedback { margin-top: 8px; padding: 10px 14px; border-radius: 8px; background: var(--surface-2); font-size: .93rem; }
.scenario .grade { font-weight: 700; margin-right: 6px; }
.scenario .grade.good { color: var(--good); } .scenario .grade.ok { color: var(--warn); } .scenario .grade.bad { color: var(--bad); }

/* glossary */
.glossary dt { font-weight: 700; margin-top: 14px; }
.glossary dd { margin: 2px 0 0; color: var(--text-2); max-width: 72ch; }
.search { width: 100%; max-width: 420px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin: 8px 0 12px; }

#topnav a[title="Account"] { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .brand { font-size: .95rem; } #topnav a, #topnav button { padding: 6px 7px; } }
