/* ============================================================
   Learning Notes — shared design system
   ============================================================ */

:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1d1b;
  --muted: #64635e;
  --border: #e2dfd6;
  --accent: #2f5d8a;
  --accent-bg: #e8eff7;
  --good: #2a7349;
  --good-bg: #e6f3eb;
  --bad: #a8372b;
  --bad-bg: #f8e7e4;
  --warn: #8a5f00;
  --warn-bg: #fbf1d9;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* chart palette (validated categorical slots 1–3) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e7e5df;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161615;
    --surface: #1f1f1d;
    --surface-2: #2a2a27;
    --text: #ecebe6;
    --muted: #a8a69f;
    --border: #353531;
    --accent: #7fb0e0;
    --accent-bg: #1c2a38;
    --good: #6fcf97;
    --good-bg: #1d3326;
    --bad: #f08a7e;
    --bad-bg: #3a201d;
    --warn: #e6b94d;
    --warn-bg: #3a2f17;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #33332f;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161615;
  --surface: #1f1f1d;
  --surface-2: #2a2a27;
  --text: #ecebe6;
  --muted: #a8a69f;
  --border: #353531;
  --accent: #7fb0e0;
  --accent-bg: #1c2a38;
  --good: #6fcf97;
  --good-bg: #1d3326;
  --bad: #f08a7e;
  --bad-bg: #3a201d;
  --warn: #e6b94d;
  --warn-bg: #3a2f17;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #33332f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (min-width: 1100px) { html { scroll-padding-top: 20px; } }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 32px 16px 80px; }

/* ---------- Spacing utilities */
.mt { margin-top: 14px; }
.mt-sm { margin-top: 8px; }
.note { margin-bottom: 0; }

/* ---------- Layout with sidebar */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.sidebar {
  min-width: 0; position: sticky; top: 0; z-index: 5;
  margin: 0 -16px; padding: 8px 16px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.sidebar nav { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.sidebar nav::-webkit-scrollbar { display: none; }
.sidebar a {
  flex: none; font-size: 14px; text-decoration: none; color: var(--muted);
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
}
.sidebar a:hover { color: var(--accent); border-color: var(--accent); }
.sidebar a.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }

@media (min-width: 1100px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); gap: 32px; }
  .sidebar { position: static; margin: 0; padding: 0; background: none; border: none; }
  .sidebar nav {
    position: sticky; top: 24px; flex-direction: column; gap: 2px; overflow: visible;
    border-left: 2px solid var(--border); padding: 0;
  }
  .sidebar a { border: none; background: none; border-radius: 0; padding: 4px 14px; margin-left: -2px; border-left: 2px solid transparent; }
  .sidebar a:hover { border-left-color: var(--accent); }
  .sidebar a.active { color: var(--accent); background: none; border-left-color: var(--accent); font-weight: 600; }
}

main { min-width: 0; }

/* ---------- Typography */
header.page { margin-bottom: 28px; }
header.page .crumb { font-size: 13px; color: var(--muted); }
header.page h1 { font-size: clamp(26px, 5vw, 32px); line-height: 1.3; margin: 6px 0 10px; letter-spacing: -0.01em; }
header.page p { color: var(--muted); max-width: 72ch; margin: 0; }
header.page .meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }

section { margin-top: 56px; }
h2 { font-size: 23px; line-height: 1.35; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
h2 .num {
  flex: none; display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: 8px;
  background: var(--accent-bg); color: var(--accent); font-size: 15px;
}
h3 { font-size: 17px; margin: 28px 0 8px; }
.prose p, .prose ul, .prose ol { max-width: 72ch; }
.prose li { margin: 4px 0; }
.lead { color: var(--muted); max-width: 72ch; }

/* ---------- Boxes */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card h3 { margin-top: 0; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }

.callout { border-left: 4px solid var(--warn); background: var(--warn-bg); padding: 12px 16px; border-radius: 8px; margin: 16px 0; max-width: 88ch; }
.callout.good { border-color: var(--good); background: var(--good-bg); }
.callout.bad { border-color: var(--bad); background: var(--bad-bg); }
.callout.info { border-color: var(--accent); background: var(--accent-bg); }

.keypoints { background: var(--accent-bg); border-radius: var(--radius); padding: 14px 20px; margin: 0 0 20px; max-width: 88ch; }
.keypoints > strong:first-child { display: block; font-size: 13px; color: var(--accent); letter-spacing: 0.04em; }
.keypoints ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Stat tiles */
.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); margin: 12px 0 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.4; }
.stat .label { font-size: 13px; color: var(--muted); }

/* ---------- Tables */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.6; }
th, td { text-align: left; vertical-align: top; padding: 10px 14px; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.best { background: var(--good-bg); }
tr.highlight { background: var(--accent-bg); }
th.col-wide { min-width: 150px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.sorted-asc::after { content: " ↑"; color: var(--accent); }
th.sorted-desc::after { content: " ↓"; color: var(--accent); }

details.data-details { margin-top: 10px; }
details.data-details summary { cursor: pointer; }

.ticker { font-family: var(--mono); font-weight: 700; }
.sub { color: var(--muted); font-size: 13px; line-height: 1.55; }

.pill { display: inline-block; font-size: 12.5px; line-height: 1.6; padding: 1px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.pill.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.info { background: var(--accent-bg); color: var(--accent); border-color: transparent; }

ul.pc { margin: 0; padding-left: 18px; font-size: 14.5px; line-height: 1.65; }
ul.pc li { margin: 3px 0; }
ul.pros li::marker { content: "+ "; color: var(--good); font-weight: 700; }
ul.cons li::marker { content: "− "; color: var(--bad); font-weight: 700; }

/* ---------- Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; align-items: center; }
.toolbar button {
  font: inherit; font-size: 13.5px; line-height: 1.4; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.toolbar button.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.toolbar input[type="search"] {
  font: inherit; font-size: 14px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); width: min(320px, 100%);
}
.toolbar .spacer { flex: 1; }

/* ---------- Item cards (ETFs, banks) */
.etf-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); }
.etf-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.etf-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.etf-card .top .ticker { font-size: 20px; }
.etf-card .name { font-weight: 600; line-height: 1.45; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-size: 13.5px; }
.metrics div { display: flex; flex-direction: column; }
.metrics dt { color: var(--muted); font-size: 12px; }
.metrics dd { margin: 0; font-weight: 600; }
.etf-card .pc-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.etf-card .best { margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 14px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13.5px; color: var(--muted); margin: 8px 0 4px; }

/* ---------- Calculator */
.calc { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.calc label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
.calc label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.calc input, table input { font: inherit; padding: 4px 8px; width: 90px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.calc input { width: 140px; padding: 6px 10px; }
.calc input[type="checkbox"] { width: auto; }
.result { font-size: 15px; margin-top: 14px; line-height: 1.9; }

/* ---------- Charts */
.chart-card { position: relative; }
.chart-card svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-card text { font-family: var(--font); fill: var(--muted); font-size: 12px; }
.chart-card .direct-label { font-size: 12.5px; font-weight: 600; fill: var(--text); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13.5px; margin-bottom: 8px; }
.chart-legend .swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; line-height: 1.6; box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
  opacity: 0; transition: opacity .1s; white-space: nowrap; z-index: 2;
}
.tooltip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(84px, 150px) minmax(0, 1fr); gap: 8px; align-items: center; padding: 3px 0; font-size: 13.5px; }
.bar-label { text-align: right; line-height: 1.3; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar { height: 16px; border-radius: 0 4px 4px 0; background: var(--series-1); flex: none; }
.bar-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-row:hover .bar { filter: brightness(1.1); }
@media (max-width: 480px) { .bar-value .sub { display: none; } }

/* ---------- Floating actions (injected by common.js) */
.fab-group { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.fab {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
  display: grid; place-items: center;
}
.fab:hover { border-color: var(--accent); color: var(--accent); }
.fab[hidden] { display: none; }

/* ---------- Footer */
footer { margin-top: 64px; color: var(--muted); font-size: 13px; }
.related { margin-top: 48px; }
.related h2 { font-size: 18px; }

/* ---------- Home page */
.home-search { margin: 0 0 20px; }
.home-group { margin-top: 32px; }
.home-group h2 { font-size: 19px; }
.page-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; transition: border-color .15s; }
.page-card:hover { border-color: var(--accent); }
.page-card h3 { margin: 0; }
.page-card .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }

/* ---------- Print */
@media print {
  :root { --bg: #fff; --surface: #fff; }
  body { font-size: 12pt; }
  .sidebar, .toolbar, .fab-group, #val-presets { display: none !important; }
  .layout { display: block; }
  .card, .etf-card, .stat, .callout, .keypoints, tr { break-inside: avoid; }
  section { margin-top: 28px; }
  a { color: inherit; text-decoration: none; }
  .table-scroll { overflow: visible; }
}
