:root {
  --paper: #f3f5f8;
  --surface: #ffffff;
  --ink: #1b2340;
  --muted: #586179;
  --rule: #dde1e9;
  --accent: #3d52c4;
  --accent-ink: #ffffff;
  --up: #0b7a55;
  --down: #b42318;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --bad-bg: #fde8e6;
  --s-close: #3d52c4;
  --s-sma50: #008c7a;
  --s-sma200: #c27000;
  --hatch: #c27000;
  --forecast: #6a3fb5;
  --radius-s: 4px;
  --radius-m: 10px;
  --shadow: 0 1px 0 var(--rule);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1220; --surface: #121829; --ink: #e6e9f2; --muted: #9aa3b8; --rule: #263049;
    --accent: #8a9bf0; --accent-ink: #0d1220; --up: #4cc794; --down: #ff8a7a; --warn: #f0b85a;
    --warn-bg: #2c2410; --bad-bg: #331a1a; --s-close: #6e80e6; --s-sma50: #13a08b; --s-sma200: #c9821a;
    --hatch: #c9821a; --forecast: #b79cf0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1220; --surface: #121829; --ink: #e6e9f2; --muted: #9aa3b8; --rule: #263049;
  --accent: #8a9bf0; --accent-ink: #0d1220; --up: #4cc794; --down: #ff8a7a; --warn: #f0b85a;
  --warn-bg: #2c2410; --bad-bg: #331a1a; --s-close: #6e80e6; --s-sma50: #13a08b; --s-sma200: #c9821a;
  --hatch: #c9821a; --forecast: #b79cf0; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.5; font-variant-numeric: tabular-nums;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { padding: 18px 0 6px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 1.05rem; margin: 0; font-weight: 700; letter-spacing: 0; }
.top .fresh { color: var(--muted); font-size: .85rem; text-align: right; }
.offline { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: var(--radius-s); font-size: .9rem; margin: 8px 0; }

/* nav */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface);
  border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs ul { list-style: none; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); max-width: 920px; }
nav.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; color: var(--muted);
  text-decoration: none; font-size: .78rem; min-height: 56px; justify-content: center; }
nav.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
nav.tabs svg { width: 22px; height: 22px; }

/* type scale (1.25) */
h2 { font-size: 1.25rem; line-height: 1.3; margin: 28px 0 10px; }
h3 { font-size: 1rem; margin: 18px 0 6px; }
p { margin: 0 0 10px; max-width: 70ch; }
.lede { font-size: 1.5rem; line-height: 1.3; font-weight: 600; margin: 14px 0 6px; max-width: 30ch; }
.lede .n { font-weight: 800; }
.sub { color: var(--muted); font-size: .92rem; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }

/* provenance marks — the system's signature: every value shows where it came from */
.pv { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: 0; flex: none; }
.pv-official { background: var(--ink); }
.pv-vendor { border: 2px solid var(--ink); }
.pv-forecast { border: 2px dashed var(--forecast); border-radius: 50%; }
.pv-hypo { background: repeating-linear-gradient(45deg, var(--hatch) 0 2px, transparent 2px 4px); border: 1px solid var(--hatch); }
.pv-missing { border: 1px dotted var(--muted); }
.key { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--muted); margin: 6px 0 2px; }
.key span { display: inline-flex; align-items: center; }

/* blocks */
.block { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 14px 16px; margin: 10px 0; }
.block.forecast { border: 1px dashed var(--forecast); }
.block.hypo { position: relative; padding-left: 24px; }
.block.hypo::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; border-radius: var(--radius-m) 0 0 var(--radius-m);
  background: repeating-linear-gradient(45deg, var(--hatch) 0 2px, transparent 2px 5px); }
.block.warn { background: var(--warn-bg); border-color: transparent; color: var(--ink); }
.block.bad { background: var(--bad-bg); border-color: transparent; }
.block > :first-child { margin-top: 0; }

/* market strip */
.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1px; background: var(--rule);
  border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.strip > div { background: var(--surface); padding: 10px 12px; }
.strip .nm { font-size: .82rem; color: var(--muted); }
.strip .v { font-weight: 700; }

.up { color: var(--up); }
.down { color: var(--down); }

/* rows */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); }
.rows li + li { border-top: 1px solid var(--rule); }
.rows a.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px; color: inherit; text-decoration: none; min-height: 56px; }
.rows a.row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.row .sym { font-weight: 700; }
.row .nm { color: var(--muted); font-size: .85rem; }
.row .px { text-align: right; font-weight: 700; }
.row .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .85rem; color: var(--muted); }

.state { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700; padding: 2px 8px 2px 6px;
  border-radius: var(--radius-s); background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); white-space: nowrap; }
.state::before { content: ""; width: 4px; height: 14px; border-radius: 2px; background: var(--muted); }
.state.BUY_CANDIDATE::before { background: var(--up); }
.state.HOLD::before { background: var(--accent); }
.state.WATCH::before { background: var(--s-sma200); }
.state.REDUCE_REVIEW::before, .state.AVOID::before { background: var(--down); }
.state.INSUFFICIENT_DATA::before { background: transparent; border: 1px dotted var(--muted); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.tbl td.r, .tbl th.r { text-align: right; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* bars */
.bar { height: 8px; background: color-mix(in srgb, var(--ink) 10%, transparent); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--s-close); border-radius: 0 4px 4px 0; }
.catrow { display: grid; grid-template-columns: 9.5rem 1fr 3.2rem; gap: 10px; align-items: center; padding: 6px 0; }
.catrow .r { text-align: right; font-weight: 700; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; max-width: 100%; height: auto; touch-action: pan-y; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-s); padding: 6px 8px; font-size: .8rem; box-shadow: 0 2px 8px rgba(0,0,0,.12); white-space: nowrap; display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; padding: 6px 12px; border: 0; background: var(--surface); color: var(--ink); min-height: 36px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.ctrl { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }

/* lists */
ul.plain { margin: 6px 0; padding-left: 1.1rem; }
ul.plain li { margin: 3px 0; max-width: 70ch; }
.news { list-style: none; margin: 0; padding: 0; }
.news li { padding: 9px 0; border-bottom: 1px solid var(--rule); }
.news .src { font-size: .82rem; color: var(--muted); }
.tag { font-size: .75rem; font-weight: 700; border: 1px solid currentColor; border-radius: 3px; padding: 0 5px; margin-left: 6px; }

details { margin: 6px 0; }
details > summary { cursor: pointer; color: var(--accent); min-height: 32px; display: flex; align-items: center; }
.grid2 { display: grid; gap: 10px; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; } .lede { font-size: 1.75rem; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.empty { color: var(--muted); padding: 18px 0; }
select, input[type=number] { font: inherit; padding: 6px 8px; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); min-height: 40px; }
.btn { display: inline-block; font: inherit; font-weight: 700; padding: 10px 14px; border-radius: var(--radius-s); background: var(--accent); color: var(--accent-ink); text-decoration: none; border: 0; min-height: 44px; }
@media (prefers-reduced-motion: no-preference) { .lede { animation: rise .5s ease-out both; } @keyframes rise { from { opacity: 0; transform: translateY(6px); } } }
