/* ==========================================================
   Quant Notes — shared notebook style
   Every page links this file. Change a token here and the
   whole notebook follows.
   ========================================================== */

:root {
  --paper:      #fbf9f4;
  --paper-2:    #f3efe5;
  --ink:        #1f2328;
  --ink-soft:   #555b63;
  --rule:       #e4ddcc;
  --margin:     #e8b4b0;
  --accent:     #2f5d8a;

  /* callout colours: [border, background] */
  --def-b:  #2f5d8a; --def-bg:  #eaf1f8;
  --thm-b:  #6a4c93; --thm-bg:  #f1ecf8;
  --ex-b:   #2e7d4f; --ex-bg:   #e9f5ee;
  --int-b:  #b7791f; --int-bg:  #fbf3e2;
  --fin-b:  #0f766e; --fin-bg:  #e6f5f3;
  --warn-b: #b42318; --warn-bg: #fcecea;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16181c; --paper-2: #1e2127; --ink: #e6e3dc; --ink-soft: #a3a7ad;
    --rule: #2c3038; --margin: #6b3a38; --accent: #8db8e3;
    --def-b: #6fa0d0; --def-bg: #1b2633;
    --thm-b: #a88bd4; --thm-bg: #241f30;
    --ex-b:  #5fbf87; --ex-bg:  #18291f;
    --int-b: #e0a84a; --int-bg: #2c2517;
    --fin-b: #4cc2b5; --fin-bg: #152a28;
    --warn-b:#ef7b70; --warn-bg:#2f1a19;
  }
}
:root[data-theme="dark"] {
  --paper: #16181c; --paper-2: #1e2127; --ink: #e6e3dc; --ink-soft: #a3a7ad;
  --rule: #2c3038; --margin: #6b3a38; --accent: #8db8e3;
  --def-b: #6fa0d0; --def-bg: #1b2633;
  --thm-b: #a88bd4; --thm-bg: #241f30;
  --ex-b:  #5fbf87; --ex-bg:  #18291f;
  --int-b: #e0a84a; --int-bg: #2c2517;
  --fin-b: #4cc2b5; --fin-bg: #152a28;
  --warn-b:#ef7b70; --warn-bg:#2f1a19;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 18px/1.7 var(--serif);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  font: 500 14px/1.4 var(--sans);
}
.topbar .crumbs { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.topbar .crumbs a { color: var(--ink-soft); }
.topbar .crumbs b { color: var(--ink); font-weight: 600; }
.theme-btn {
  border: 1px solid var(--rule); background: var(--paper-2); color: var(--ink);
  border-radius: 8px; padding: 4px 10px; font: inherit; cursor: pointer;
}

/* ---------- page layout ---------- */
.page { max-width: 820px; margin: 0 auto; padding: 32px 16px 96px; }
.page.wide { max-width: 1040px; }

/* notebook "margin line" on note pages */
.notes {
  position: relative;
  padding-left: 28px;
  border-left: 2px solid var(--margin);
}

h1, h2, h3, h4 { font-family: var(--sans); line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 6px; }
h2 { font-size: 1.4rem; margin: 48px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
h3 { font-size: 1.12rem; margin: 32px 0 8px; }
.subtitle { color: var(--ink-soft); font: 400 16px/1.5 var(--sans); margin: 0 0 28px; }
.meta { font: 500 13px/1.5 var(--sans); color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }

code { font-family: var(--mono); font-size: .88em; background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 14px; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; padding: 0; }
hr { border: 0; border-top: 1px dashed var(--rule); margin: 36px 0; }
table { border-collapse: collapse; width: 100%; font-size: 16px; margin: 16px 0; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--rule); padding: 6px 10px; text-align: left; }
th { background: var(--paper-2); font-family: var(--sans); font-size: 14px; }

/* math that overflows on phones scrolls instead of breaking the page */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ---------- callout boxes ---------- */
.box {
  --b: var(--def-b); --bg: var(--def-bg);
  margin: 20px 0; padding: 12px 16px 12px 16px;
  border-left: 4px solid var(--b); background: var(--bg);
  border-radius: 0 8px 8px 0;
}
.box > .label {
  display: block; margin-bottom: 4px;
  font: 700 12px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--b);
}
.box > :last-child { margin-bottom: 0; }
.box > p:first-of-type { margin-top: 0; }
.box.definition { --b: var(--def-b); --bg: var(--def-bg); }
.box.theorem    { --b: var(--thm-b); --bg: var(--thm-bg); }
.box.example    { --b: var(--ex-b);  --bg: var(--ex-bg); }
.box.intuition  { --b: var(--int-b); --bg: var(--int-bg); }
.box.finance    { --b: var(--fin-b); --bg: var(--fin-bg); }
.box.pitfall    { --b: var(--warn-b);--bg: var(--warn-bg); }

/* proofs / worked solutions fold away */
details.proof { margin: 12px 0 20px; border: 1px dashed var(--rule); border-radius: 8px; padding: 8px 14px; }
details.proof > summary { cursor: pointer; font: 600 14px/1.6 var(--sans); color: var(--ink-soft); }
details.proof[open] > summary { margin-bottom: 8px; }

/* key-takeaways list at the end of a note */
.summary { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 18px; margin-top: 40px; }
.summary h3 { margin-top: 0; }

/* ---------- home + subject listings ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: block; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px;
  padding: 18px 20px; transition: transform .12s ease, border-color .12s ease;
}
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.card .num { font: 700 13px/1 var(--mono); color: var(--accent); }
.card h3 { margin: 8px 0 6px; }
.card p { margin: 0; font-size: 15px; line-height: 1.5; color: var(--ink-soft); font-family: var(--sans); }
.card .count { margin-top: 12px; font: 500 13px/1 var(--sans); color: var(--ink-soft); }

.toc { list-style: none; padding: 0; margin: 0; counter-reset: lec; }
.toc li {
  display: flex; gap: 14px; align-items: baseline;
  padding: 12px 0; border-bottom: 1px solid var(--rule);
  font-family: var(--sans); font-size: 16px;
}
.toc li .n { font: 600 13px/1 var(--mono); color: var(--accent); min-width: 28px; }
.toc li .t { flex: 1; }
.toc li .s { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.toc li.todo .t { color: var(--ink-soft); }
.empty { color: var(--ink-soft); font: italic 16px/1.6 var(--serif); padding: 16px 0; }

/* prev / next at the bottom of note pages */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; font: 500 15px/1.4 var(--sans); }
.pager a { padding: 10px 14px; border: 1px solid var(--rule); border-radius: 8px; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  h1 { font-size: 1.6rem; }
  .notes { padding-left: 14px; }
}

@media print {
  .topbar, .pager, .theme-btn { display: none; }
  body { background: #fff; }
  details.proof { border: none; }
}

/* exam / review rows in a lecture list */
.toc li.exam .n { color: var(--warn-b); }
.toc li.exam .t { font-style: italic; }
.toc li.exam .s { color: var(--warn-b); font-weight: 600; }

/* ---------- figures (inline SVG diagrams) ---------- */
.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin: 20px 0; }
figure.fig { margin: 0; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 12px; }
figure.fig svg { display: block; width: 100%; height: auto; }
figure.fig figcaption { font: 400 14px/1.5 var(--sans); color: var(--ink-soft); margin-top: 8px; }
.fig .axis  { stroke: var(--ink-soft); stroke-width: 1; opacity: .55; }
.fig .grid  { stroke: var(--rule); stroke-width: 1; }
.fig .tick  { fill: var(--ink-soft); font: 11px var(--sans); }
.fig .l1    { stroke: var(--def-b); stroke-width: 2.5; fill: none; }
.fig .l2    { stroke: var(--ex-b);  stroke-width: 2.5; fill: none; }
.fig .l3    { stroke: var(--warn-b);stroke-width: 2.5; fill: none; }
.fig .dash  { stroke-dasharray: 5 4; }
.fig .pt    { fill: var(--ink); }
.fig .hit   { fill: var(--warn-b); }
.fig .lbl   { font: 600 13px var(--sans); }
.fig .c1 { fill: var(--def-b); } .fig .c2 { fill: var(--ex-b); } .fig .c3 { fill: var(--warn-b); } .fig .ci { fill: var(--ink); }

.pager .off { padding: 10px 14px; border: 1px dashed var(--rule); border-radius: 8px; color: var(--ink-soft); }

/* ---------- Notes / Examples tabs on lecture pages ---------- */
/* Desktop: tabs are a sidebar fixed to the very left edge of the window. */
.page.tabbed { max-width: none; padding-left: 288px; padding-right: 48px; }
.page.tabbed .tab-body { max-width: none; margin: 0; }  /* start right after the sidebar, use the full width */
.tabs {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 9;
  width: 240px; padding: 68px 12px 24px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--paper-2); border-right: 1px solid var(--rule);
  font: 600 14px/1.3 var(--sans);
}
.tabs .tabs-title { font: 600 11px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin: 4px 0 6px 12px; }
.tabs button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid transparent; background: none; color: var(--ink-soft); font: inherit;
}
.tabs button:hover { background: var(--paper); color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--accent); border-color: var(--rule); box-shadow: inset 3px 0 0 var(--accent); }
.tabs button .ct { margin-left: auto; font: 600 11px/1 var(--mono); color: var(--ink-soft); background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; padding: 3px 6px; }
.tab-panel[hidden] { display: none; }

@media (max-width: 860px) {
  .page.tabbed { padding-left: 16px; }
  .tabs {
    position: sticky; top: 45px; bottom: auto; z-index: 5;
    width: auto; flex-direction: row;
    margin: 0 -16px 20px; padding: 8px 16px;
    background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px);
    border-right: 0; border-bottom: 1px solid var(--rule);
  }
  .tabs .tabs-title { display: none; }
  .tabs button { width: auto; flex: 1; justify-content: center; }
  .tabs button[aria-selected="true"] { box-shadow: inset 0 -3px 0 var(--accent); }
}

/* worked example: problem statement + visible step-by-step solution */
.worked { margin: 24px 0 36px; }
.worked .steps { margin: 8px 0 0; padding-left: 16px; border-left: 2px dotted var(--rule); }
.worked .steps > p:first-child { margin-top: 0; }
.answer { font-family: var(--sans); font-weight: 600; color: var(--ex-b); }

/* ---------- study-chapter helpers ---------- */
.notes h2 { scroll-margin-top: 70px; }
.contents { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 18px; margin: 8px 0 32px; font-family: var(--sans); }
.contents .label { display: block; font: 700 12px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.contents ol { margin: 0; padding-left: 22px; columns: 2 240px; column-gap: 28px; font-size: 15px; line-height: 1.9; }
.goals { margin: 0 0 8px; }
.goals li { margin: 4px 0; }
dl.vocab { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 0; margin: 16px 0; border-top: 1px solid var(--rule); }
dl.vocab dt, dl.vocab dd { margin: 0; padding: 10px 8px; border-bottom: 1px solid var(--rule); }
dl.vocab dt { font: 600 15px/1.5 var(--sans); }
@media (max-width: 600px) { dl.vocab { grid-template-columns: 1fr; } dl.vocab dt { border-bottom: 0; padding-bottom: 0; } }
.figs.three { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.step-list { counter-reset: st; list-style: none; padding-left: 0; }
.step-list > li { counter-increment: st; position: relative; padding-left: 36px; margin: 10px 0; }
.step-list > li::before { content: counter(st); position: absolute; left: 0; top: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--paper); font: 700 13px/24px var(--sans); text-align: center; }

/* section links under a tab in the sidebar (built by notebook.js from the page's Contents box) */
.tabs .subnav { margin: 2px 0 10px; padding: 0 0 0 10px; }
.tabs .subnav[hidden] { display: none; }
.tabs .subnav ol { list-style: none; margin: 0; padding: 0; counter-reset: sn; border-left: 1px solid var(--rule); }
.tabs .subnav li { counter-increment: sn; }
.tabs .subnav a {
  display: block; position: relative; padding: 5px 8px 5px 34px; margin-left: -1px;
  border-left: 2px solid transparent;
  font: 500 13px/1.4 var(--sans); color: var(--ink-soft); text-decoration: none;
}
.tabs .subnav a::before { content: counter(sn); position: absolute; left: 12px; top: 5px; font: 600 11px/1.7 var(--mono); color: var(--ink-soft); opacity: .7; }
.tabs .subnav a:hover { color: var(--ink); }
.tabs .subnav a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.tabs .subnav .katex { font-size: 1em; }

/* on desktop the sidebar carries the contents, so hide the in-page box */
@media (min-width: 861px) { .page.tabbed .contents { display: none; } }
@media (max-width: 860px) { .tabs .subnav { display: none !important; } }

/* interactive 3D plots (Plotly) */
figure.fig.plot3d { max-width: 760px; margin: 20px auto; }
.plot3d-box { width: 100%; height: 520px; }
@media (max-width: 600px) { .plot3d-box { height: 360px; } }

/* slider controls for interactive graphs */
.mixer { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 16px; margin: 12px 0; font: 500 15px/1.6 var(--sans); }
.mixer label { display: flex; align-items: center; gap: 12px; margin: 4px 0; flex-wrap: wrap; }
.mixer input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.mixer-out { margin: 8px 0 0; font-family: var(--serif); }

/* Options Replication Lab */
.lab-controls { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 16px; margin: 12px 0 20px; font: 500 14px/1.6 var(--sans); }
.lab-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 8px 0; }
.lab-controls input[type=number], .lab-controls input[type=text] { width: 7em; padding: 3px 6px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; }
.lab-controls select { padding: 3px 6px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; max-width: 100%; }
.lab-table { font-size: 14px; }
.lab-table td, .lab-table th { vertical-align: middle; }
.lab-btn { border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 8px; padding: 4px 12px; font: 600 14px var(--sans); cursor: pointer; }
.lab-btn:hover { border-color: var(--accent); color: var(--accent); }
.lab-lvl { white-space: nowrap; }
.lab-warn { color: var(--warn-b); font-family: var(--sans); }
#labout h4 { margin-top: 28px; }
.lab-emat { background: var(--paper-2); border-left: 3px solid var(--accent); padding: 6px 12px; border-radius: 0 6px 6px 0; }

/* Study log (home page) */
.log-progress { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px 24px; margin-bottom: 28px; font-family: var(--sans); }
.log-bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.log-bar-top a { color: var(--ink); font-weight: 600; }
.log-bar-top span { color: var(--ink-soft); white-space: nowrap; }
.log-track { height: 8px; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 6px; margin-top: 4px; overflow: hidden; }
.log-fill { height: 100%; background: var(--accent); }
.log { border-left: 2px solid var(--rule); margin-left: 6px; }
.log-day { position: relative; padding: 0 0 20px 22px; }
.log-day::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.log-date { font: 500 14px/1.4 var(--sans); color: var(--ink-soft); margin-bottom: 8px; }
.log-date b { color: var(--ink); }
.log-day ul { list-style: none; margin: 0; padding: 0; }
.log-day li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--rule); font: 15px/1.5 var(--sans); }
.log-kind { font: 700 11px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; padding: 4px 7px; border-radius: 5px; background: var(--paper-2); color: var(--ink-soft); }
.log-lecture { background: var(--def-bg); color: var(--def-b); }
.log-extra { background: var(--fin-bg); color: var(--fin-b); }
.log-plan { background: var(--int-bg); color: var(--int-b); }
.log-subj { font-size: 13px; color: var(--ink-soft); }
.log-num { font: 600 13px var(--mono); color: var(--accent); }
.log-title { flex: 1; min-width: 200px; }

/* child-style solving: each step says what / why / how / what we have now */
.kid-step > li { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px 10px 44px; }
.kid-step > li::before { left: 12px; top: 12px; }
.kid-step p.k { margin: 4px 0; position: relative; padding-left: 142px; }
.kid-step p.k .kl { position: absolute; left: 0; top: 3px; width: 132px; }
@media (max-width: 600px) { .kid-step p.k { padding-left: 0; } .kid-step p.k .kl { position: static; display: block; } }
.kid-step .kl { display: inline-block; font: 600 11px/1.6 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.kid-step table { margin: 6px 0; }
