/* ==========================================================
   Valuation Basics — shared styles
   Colors are tokens on :root. Dark mode overrides below.
   ========================================================== */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1c1b19;
  --muted: #5f5c55;
  --border: #e3e0d8;
  --accent: #1f6f5c;        /* deep green */
  --accent-soft: #e3f0ec;
  --cash-in: #1f7a4d;
  --cash-out: #b4442f;
  --warn: #9a6a00;
  --warn-soft: #fbf1d9;
  --link: #1d5fa8;
  --code-bg: #f1efe9;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  --sidebar-w: 270px;
  --content-w: 760px;
  --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141513; --surface: #1b1c1a; --surface-2: #232421; --text: #ebe9e4;
    --muted: #a6a39b; --border: #33342f; --accent: #5cc4a6; --accent-soft: #1d2f29;
    --cash-in: #5cc48a; --cash-out: #e9826d; --warn: #e6b955; --warn-soft: #2e2716;
    --link: #7fb2ec; --code-bg: #232421; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141513; --surface: #1b1c1a; --surface-2: #232421; --text: #ebe9e4;
  --muted: #a6a39b; --border: #33342f; --accent: #5cc4a6; --accent-soft: #1d2f29;
  --cash-in: #5cc48a; --cash-out: #e9826d; --warn: #e6b955; --warn-soft: #2e2716;
  --link: #7fb2ec; --code-bg: #232421; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 18px; line-height: 1.65;
}
a { color: var(--link); text-underline-offset: 2px; }
img { max-width: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  font-family: var(--font-ui);
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.icon-btn {
  font: inherit; font-size: 14px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
#menu-btn { display: none; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; border-right: 1px solid var(--border);
  padding: 20px 14px 40px; position: sticky; top: 56px; height: calc(100vh - 56px);
  overflow-y: auto; font-family: var(--font-ui); font-size: 14px; background: var(--bg);
}
.sidebar h4 {
  margin: 18px 8px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600;
}
.sidebar h4:first-child { margin-top: 0; }
.sidebar a, .sidebar .soon {
  display: block; padding: 6px 8px; border-radius: 6px; color: var(--text);
  text-decoration: none; line-height: 1.35;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .soon { color: var(--muted); opacity: .7; }
.sidebar .soon::after { content: " · soon"; font-size: 11px; }

main { flex: 1; min-width: 0; padding: 40px 32px 80px; }
.content { max-width: var(--content-w); margin: 0 auto; }

/* ---------- Typography ---------- */
h1, h2, h3 { font-family: var(--font-ui); letter-spacing: -.02em; line-height: 1.2; }
h1 { font-size: 2.1rem; margin: 0 0 .4em; }
h2 { font-size: 1.45rem; margin: 2em 0 .6em; padding-top: .4em; border-top: 1px solid var(--border); }
h3 { font-size: 1.15rem; margin: 1.6em 0 .4em; }
.eyebrow {
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px;
}
.lede { font-size: 1.15rem; color: var(--muted); margin-top: 0; }
code, .mono { font-family: var(--font-mono); font-size: .85em; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
ul, ol { padding-left: 1.3em; }
li { margin: .25em 0; }

/* ---------- Components ---------- */
.callout {
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: var(--radius); padding: 14px 18px; margin: 1.4em 0;
  box-shadow: var(--shadow);
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .label {
  font-family: var(--font-ui); font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--accent); display: block; margin-bottom: 4px;
}
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout.warn .label { color: var(--warn); }
.callout.key { border-left-color: var(--cash-in); }
.callout.key .label { color: var(--cash-in); }

.formula {
  font-family: var(--font-mono); font-size: 15px; background: var(--surface-2);
  border-radius: var(--radius); padding: 14px 18px; margin: 1.2em 0; text-align: center;
  overflow-x: auto;
}

.table-wrap { overflow-x: auto; margin: 1.2em 0; }
table {
  width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: 14.5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 700; }
.in { color: var(--cash-in); }
.out { color: var(--cash-out); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin: 1.2em 0; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
  font-family: var(--font-ui); transition: border-color .15s, transform .15s;
}
a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .tag { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .07em; }
.card h3 { margin: 4px 0 6px; font-size: 1.05rem; }
.card p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.card.disabled { opacity: .55; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 1.2em 0; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-family: var(--font-ui);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }

.asof { font-family: var(--font-ui); font-size: 13px; color: var(--muted); }

/* Glossary term + tooltip */
.term {
  border-bottom: 1px dotted var(--accent); cursor: help; position: relative;
}
.tip {
  position: absolute; z-index: 50; max-width: 300px; background: var(--text); color: var(--bg);
  font-family: var(--font-ui); font-size: 13.5px; line-height: 1.45; padding: 10px 12px;
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.2); pointer-events: none;
}
.tip strong { display: block; margin-bottom: 2px; }

/* Quiz */
.quiz { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 1.6em 0; font-family: var(--font-ui); }
.quiz .q { font-weight: 600; margin-bottom: 10px; }
.quiz button.opt {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 15px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; margin: 6px 0; cursor: pointer;
}
.quiz button.opt:hover { border-color: var(--accent); }
.quiz button.opt.right { border-color: var(--cash-in); background: color-mix(in srgb, var(--cash-in) 14%, var(--surface)); }
.quiz button.opt.wrong { border-color: var(--cash-out); background: color-mix(in srgb, var(--cash-out) 12%, var(--surface)); }
.quiz .why { font-size: 14.5px; color: var(--muted); margin-top: 8px; display: none; }
.quiz.done .why { display: block; }

/* Forms / calculators */
.calc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 1.4em 0; font-family: var(--font-ui); box-shadow: var(--shadow); }
.calc .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.calc label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.calc .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.calc input[type=number] {
  width: 100%; font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.calc input[type=range] { width: 100%; accent-color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.presets button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.presets button.on, .presets button:hover { border-color: var(--accent); color: var(--accent); }
.result { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.big { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }

/* Prev / next */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 3.5em; font-family: var(--font-ui); }
.pager a {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
  text-decoration: none; color: var(--text); background: var(--surface);
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); font-size: 12px; }
.pager .next { text-align: right; }

footer.site-footer { font-family: var(--font-ui); font-size: 13px; color: var(--muted); margin-top: 4em; padding-top: 1.2em; border-top: 1px solid var(--border); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  #menu-btn { display: inline-block; }
  .sidebar {
    position: fixed; left: 0; top: 56px; z-index: 40; background: var(--bg);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  main { padding: 28px 16px 64px; }
  body { font-size: 17px; }
  h1 { font-size: 1.7rem; }
  .pager { flex-direction: column; }
}
