/* Active Equity Management — reference site
 * Style: "Bloomberg Terminal" — near-black, amber + phosphor-green, mono numerics.
 * Dark is the canonical look; a light "day" theme is provided for daytime reading.
 * Components read ONLY design tokens, so the buddy widget inherits the palette. */

/* ============================ TOKENS ============================ */
:root {
  --bg: #0a0e14;
  --surface: #11161f;
  --surface-2: #1a212e;
  --surface-3: #232c3b;
  --ink: #e8e8e8;
  --muted: #8a94a6;
  --accent: #ffb000;          /* amber */
  --on-accent: #0a0e14;
  --accent-2: #00d26a;        /* phosphor green (positive) */
  --accent-dim: rgba(255, 176, 0, 0.14);
  --green-dim: rgba(0, 210, 106, 0.13);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --radius: 4px;
  --radius-lg: 6px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  --font-display: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, monospace;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  --ok: #00d26a;
  --warn: #ffb000;
  --err: #ff5c5c;
  --paper: #f7f4ea;           /* "paper chip" bg for formula/figure images */
  --sidebar-w: 300px;
}

/* Light "day" theme — auto for light OS, or via toggle (data-theme wins) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef0ee;
    --surface: #ffffff;
    --surface-2: #f2f4f3;
    --surface-3: #e6e9e7;
    --ink: #14181f;
    --muted: #5a6472;
    --accent: #9a6a00;
    --on-accent: #ffffff;
    --accent-2: #0a8f4d;
    --accent-dim: rgba(154, 106, 0, 0.12);
    --green-dim: rgba(10, 143, 77, 0.12);
    --border: rgba(0, 0, 0, 0.12);
    --border-strong: rgba(0, 0, 0, 0.22);
    --shadow: 0 4px 18px rgba(20, 24, 31, 0.14);
    --ok: #0a8f4d;
    --err: #c0392b;
  }
}
:root[data-theme="light"] {
  --bg: #eef0ee;
  --surface: #ffffff;
  --surface-2: #f2f4f3;
  --surface-3: #e6e9e7;
  --ink: #14181f;
  --muted: #5a6472;
  --accent: #9a6a00;
  --on-accent: #ffffff;
  --accent-2: #0a8f4d;
  --accent-dim: rgba(154, 106, 0, 0.12);
  --green-dim: rgba(10, 143, 77, 0.12);
  --border: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.22);
  --shadow: 0 4px 18px rgba(20, 24, 31, 0.14);
  --ok: #0a8f4d;
  --err: #c0392b;
}

/* ============================ BASE ============================ */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
code, kbd { font-family: var(--font-mono); }
::selection { background: var(--accent-dim); }

/* thin phosphor scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }

/* ============================ TOP BAR ============================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  height: 52px; padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--font-display); font-weight: 700; letter-spacing: .02em;
  color: var(--ink); cursor: pointer; white-space: nowrap;
}
.brand .tick { color: var(--accent-2); }
.brand .prompt { color: var(--accent); }
.brand .name { font-size: 15px; }
@media (max-width: 640px) { .brand .name { display: none; } }
.topbar-spacer { flex: 1; }

.search-wrap { position: relative; width: min(340px, 42vw); }
.search-input {
  width: 100%; height: 34px; padding: 0 12px 0 30px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 13px;
}
.search-input::placeholder { color: var(--muted); }
.search-wrap::before {
  content: "⌕"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px; pointer-events: none;
}
.search-results {
  position: absolute; top: 40px; left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto; display: none;
}
.search-results.open { display: block; }
.search-item { display: block; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.active { background: var(--accent-dim); }
.search-item .si-ch { font-family: var(--font-mono); font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.search-item .si-title { font-size: 14px; color: var(--ink); }
.search-item .si-kind { font-size: 11px; color: var(--muted); }
.search-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

.iconbtn {
  height: 34px; min-width: 34px; padding: 0 10px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); }
.menu-toggle { display: none; }
@media (max-width: 900px) { .menu-toggle { display: inline-flex; } }

/* ============================ LAYOUT ============================ */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: 52px; align-self: flex-start;
  width: var(--sidebar-w); flex-shrink: 0;
  height: calc(100vh - 52px); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 8px 40px;
}
.main { flex: 1; min-width: 0; padding: 34px clamp(18px, 5vw, 64px) 100px; }
.container { max-width: 760px; margin: 0 auto; }

/* ============================ SIDEBAR TOC ============================ */
.toc-progress { padding: 4px 10px 12px; }
.toc-progress .bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.toc-progress .bar > i { display: block; height: 100%; background: var(--accent-2); width: 0; transition: width .3s ease; }
.toc-progress .lbl { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 5px; letter-spacing: .03em; }

.part { margin-bottom: 4px; }
.part-head {
  width: 100%; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  padding: 8px 10px; background: none; border: none;
  color: var(--muted); font-family: var(--font-display);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.part-head:hover { color: var(--ink); }
.part-head .caret { transition: transform .18s ease; font-size: 10px; color: var(--accent); }
.part.collapsed .caret { transform: rotate(-90deg); }
.part.collapsed .chapters { display: none; }
.chapters { list-style: none; margin: 0 0 6px; padding: 0; }
.chapters a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 22px; color: var(--ink);
  font-size: 13.5px; border-left: 2px solid transparent; border-radius: 0 var(--radius) var(--radius) 0;
}
.chapters a:hover { background: var(--surface-2); text-decoration: none; }
.chapters a.active { background: var(--accent-dim); border-left-color: var(--accent); color: var(--ink); }
.chapters a .num { font-family: var(--font-mono); font-size: 11px; color: var(--muted); min-width: 20px; }
.chapters a.active .num { color: var(--accent); }
.chapters a .ct { flex: 1; }
.chapters a .check { color: var(--accent-2); font-size: 12px; opacity: 0; }
.chapters a.visited .check { opacity: 1; }
.chapters a .qz { font-family: var(--font-mono); font-size: 10px; color: var(--on-accent); background: var(--accent-2); padding: 1px 5px; border-radius: 8px; }

/* ============================ HERO / LANDING ============================ */
.hero-eyebrow { font-family: var(--font-mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
h1.display { font-family: var(--font-display); font-size: clamp(28px, 5vw, 42px); line-height: 1.1; margin: 8px 0 10px; letter-spacing: -.01em; }
.lede { font-size: 18px; color: var(--muted); margin: 0 0 26px; max-width: 60ch; }
.why {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 16px 18px; margin: 0 0 30px;
}
.section-label { font-family: var(--font-display); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 34px 0 14px; display: flex; align-items: center; gap: 8px; }
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.starts { display: grid; gap: 10px; margin-bottom: 8px; }
.start-card { display: flex; gap: 12px; align-items: center; padding: 13px 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.start-card:hover { border-color: var(--accent); text-decoration: none; }
.start-card .k { font-family: var(--font-mono); font-size: 12px; color: var(--on-accent); background: var(--accent); padding: 3px 8px; border-radius: var(--radius); }
.start-card .t { color: var(--ink); font-weight: 600; }
.start-card .d { color: var(--muted); font-size: 13px; }

.chgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.chcard { position: relative; display: block; padding: 14px 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chcard:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.chcard .cnum { font-family: var(--font-mono); font-size: 11px; color: var(--accent); letter-spacing: .05em; }
.chcard .ctitle { color: var(--ink); font-weight: 600; margin: 3px 0 2px; line-height: 1.25; }
.chcard .cpages { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.chcard .cdone { position: absolute; top: 12px; right: 12px; color: var(--accent-2); font-size: 13px; opacity: 0; }
.chcard.visited .cdone { opacity: 1; }
.chcard.visited { border-left: 3px solid var(--accent-2); }

/* ============================ CHAPTER PAGE ============================ */
.crumbs { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
h2.chtitle { font-family: var(--font-display); font-size: clamp(24px, 4vw, 34px); line-height: 1.12; margin: 2px 0 6px; }
.ch-meta { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.ch-summary { font-size: 17px; color: var(--ink); margin: 0 0 22px; }

.keyideas { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 16px 20px; margin: 0 0 30px; border-left: 3px solid var(--accent-2); }
.keyideas h3 { margin: 0 0 10px; font-family: var(--font-display); font-size: 12px; letter-spacing: .07em; text-transform: uppercase; color: var(--accent-2); }
.keyideas ul { margin: 0; padding-left: 18px; }
.keyideas li { margin: 6px 0; }

section.ch-section { margin: 0 0 14px; padding-top: 10px; }
section.ch-section > h3.sec-title { font-family: var(--font-display); font-size: 20px; margin: 24px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); scroll-margin-top: 64px; }
.sec-title .anchor { color: var(--muted); font-size: 14px; opacity: 0; margin-left: 8px; }
.sec-title:hover .anchor { opacity: 1; }

/* content blocks */
.blk-p { margin: 12px 0; }
.blk-p code, .blk-def code { background: var(--surface-2); padding: 1px 6px; border-radius: 3px; font-size: .9em; }

.def {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 15px; margin: 16px 0; border-left: 3px solid var(--accent);
}
.def .term { font-family: var(--font-display); font-weight: 700; color: var(--accent); font-size: 15px; }
.def .term::before { content: "▹ "; color: var(--muted); }
.def .body { margin: 5px 0 0; }
.def .plain { margin-top: 6px; font-size: 13.5px; color: var(--muted); font-style: italic; }
.def .plain::before { content: "in plain words — "; text-transform: uppercase; font-family: var(--font-mono); font-style: normal; font-size: 10px; letter-spacing: .05em; color: var(--accent-2); }

.formula {
  margin: 18px 0; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto;
}
.formula .katex-holder { text-align: center; font-size: 1.12em; overflow-x: auto; }
.formula .tex-fallback { font-family: var(--font-mono); font-size: 14px; color: var(--ink); background: var(--surface-2); padding: 10px 12px; border-radius: var(--radius); white-space: pre-wrap; text-align: center; }
.formula .fx-plain { margin-top: 9px; font-size: 13.5px; color: var(--muted); }
.formula .fx-plain b { color: var(--accent-2); font-family: var(--font-mono); font-weight: 400; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
.formula .fx-note { margin-top: 6px; font-size: 12.5px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 6px; }
/* formula/figure images sit on a light "paper chip" so scans read in dark mode */
.paper-chip { background: var(--paper); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 10px 12px; display: inline-block; max-width: 100%; }
.paper-chip img { display: block; max-width: 100%; height: auto; }

figure.fig { margin: 20px 0; }
figure.fig figcaption { font-size: 12.5px; color: var(--muted); margin-top: 8px; font-family: var(--font-mono); }
figure.fig figcaption .ref { color: var(--accent); }

.callout { margin: 18px 0; padding: 13px 15px 13px 44px; border-radius: var(--radius); position: relative; border: 1px solid var(--border); background: var(--surface); }
.callout::before { position: absolute; left: 13px; top: 12px; font-size: 18px; }
.callout .ctag { font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; display: block; margin-bottom: 3px; }
.callout.intuition { border-left: 3px solid var(--accent-2); } .callout.intuition::before { content: "💡"; } .callout.intuition .ctag { color: var(--accent-2); }
.callout.warning   { border-left: 3px solid var(--err); }      .callout.warning::before { content: "⚠️"; }  .callout.warning .ctag { color: var(--err); }
.callout.example   { border-left: 3px solid var(--accent); }   .callout.example::before { content: "🧮"; }  .callout.example .ctag { color: var(--accent); }

.tbl-wrap { overflow-x: auto; margin: 18px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.data th { font-family: var(--font-display); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); background: var(--surface-2); position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td { font-variant-numeric: tabular-nums; }

blockquote.bq { margin: 18px 0; padding: 8px 16px; border-left: 3px solid var(--accent); color: var(--ink); font-style: italic; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
blockquote.bq .ref { display: block; font-style: normal; font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ============================ QUIZ ============================ */
.quiz { margin: 40px 0 0; padding-top: 20px; border-top: 1px solid var(--border); }
.quiz h3, .flash h3, .refs h3 { font-family: var(--font-display); font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.qscore { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.qcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; margin: 14px 0; }
.qcard .q { font-weight: 600; margin-bottom: 10px; }
.qcard .q .qn { font-family: var(--font-mono); color: var(--accent); margin-right: 6px; }
.qopts { display: grid; gap: 7px; }
.qopt { text-align: left; padding: 9px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--ink); cursor: pointer; font: inherit; font-size: 14px; display: flex; gap: 9px; }
.qopt:hover:not(:disabled) { border-color: var(--accent); }
.qopt .mk { font-family: var(--font-mono); color: var(--muted); }
.qopt:disabled { cursor: default; }
.qopt.correct { border-color: var(--ok); background: var(--green-dim); color: var(--ink); }
.qopt.correct .mk { color: var(--ok); }
.qopt.wrong { border-color: var(--err); background: rgba(255, 92, 92, .10); }
.qopt.wrong .mk { color: var(--err); }
.qwhy { margin-top: 10px; padding: 10px 12px; font-size: 13.5px; background: var(--surface-2); border-radius: var(--radius); border-left: 3px solid var(--accent-2); display: none; }
.qwhy.show { display: block; }
.qwhy .verdict { font-family: var(--font-mono); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; }

/* ============================ FLASHCARDS ============================ */
.flash { margin: 40px 0 0; padding-top: 20px; border-top: 1px solid var(--border); }
.flash-tools { display: flex; gap: 8px; align-items: center; margin: 12px 0 14px; }
.flash-count { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-left: auto; }
.fcard { perspective: 1200px; background: none; border: none; padding: 0; width: 100%; cursor: pointer; margin: 0 0 10px; }
.fcard-inner { position: relative; transform-style: preserve-3d; transition: transform .4s ease; min-height: 96px; }
.fcard.flipped .fcard-inner { transform: rotateY(180deg); }
.fcard-face { position: absolute; inset: 0; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.fcard-front { border-left: 3px solid var(--accent); }
.fcard-front .lbl, .fcard-back .lbl { position: absolute; top: 8px; left: 12px; font-family: var(--font-mono); font-size: 10px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.fcard-front .txt { font-family: var(--font-display); font-size: 17px; color: var(--accent); }
.fcard-back { transform: rotateY(180deg); border-left: 3px solid var(--accent-2); }
.fcard-back .txt { font-size: 14px; color: var(--ink); }
.fcard-static .fcard-inner { position: static; }              /* reduced-motion fallback set in JS */

/* ============================ REFS / PAGER ============================ */
.refs { margin: 40px 0 0; padding-top: 18px; border-top: 1px solid var(--border); }
.refs ul { list-style: none; margin: 10px 0 0; padding: 0; }
.refs li { font-size: 13.5px; color: var(--muted); padding: 4px 0; }
.refs li .pg { font-family: var(--font-mono); color: var(--accent); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--border); }
.pager a { flex: 1; padding: 12px 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a.next { text-align: right; }
.pager .dir { font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pager .pt { color: var(--ink); font-weight: 600; }
.pager a.disabled { visibility: hidden; }

/* mark-as-read */
.readrow { margin-top: 28px; }
.readbtn { padding: 10px 16px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); color: var(--ink); font-family: var(--font-mono); font-size: 13px; cursor: pointer; }
.readbtn:hover { border-color: var(--accent-2); color: var(--accent-2); }
.readbtn.done { background: var(--green-dim); border-color: var(--accent-2); color: var(--accent-2); }

/* ============================ MOBILE ============================ */
.scrim { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 52px; left: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .22s ease;
    width: min(300px, 82vw); box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.open { display: block; position: fixed; inset: 52px 0 0; background: rgba(0,0,0,.5); z-index: 44; }
  .search-wrap { width: 40vw; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .fcard-inner, .chcard, .toc-progress .bar > i { transition: none !important; }
}

/* ============================ PRINT ============================ */
@media print {
  .topbar, .sidebar, .scrim, .pager, .buddy-fab, .buddy-panel, .readrow, .quiz .qopts { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; color: #000; }
  .def, .formula, .callout, .keyideas, .why, table.data { break-inside: avoid; }
}
