:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #74726d;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --accent-ink: #1c5cab;
  --up: #006300;
  --down: #c2302f;
  --pos: #2a78d6;
  --neg: #e34948;
  --mid: #f0efec;
  --select: rgba(42, 120, 214, 0.18);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --accent-ink: #5598e7;
    --up: #2fbf4a;
    --down: #ff6b6a;
    --pos: #3987e5;
    --neg: #e66767;
    --mid: #383835;
    --select: rgba(57, 135, 229, 0.32);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --accent-ink: #5598e7;
  --up: #2fbf4a;
  --down: #ff6b6a;
  --pos: #3987e5;
  --neg: #e66767;
  --mid: #383835;
  --select: rgba(57, 135, 229, 0.32);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--select); color: inherit; }

a { color: inherit; text-decoration-color: var(--axis); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: currentColor; }

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

h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
h2 { font-size: 1.0625rem; line-height: 1.35; }
p { margin: 0; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--s5); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--ring);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); height: 56px; }
.brand { font-weight: 650; font-size: 1.0625rem; text-decoration: none; }
.updated { color: var(--muted); font-size: 0.8125rem; text-align: right; display: flex; gap: var(--s3); flex-wrap: wrap; justify-content: flex-end; }

/* Today */
.today { padding: var(--s7) 0 var(--s6); }
.headline { font-size: 1.625rem; line-height: 1.3; max-width: 34em; letter-spacing: -0.01em; }
.headline-meta { margin-top: var(--s2); color: var(--muted); font-size: 0.875rem; }

.stats {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
  margin-top: var(--s6);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
}
.stat { padding: var(--s5); min-width: 0; }
.stat + .stat { border-left: 1px solid var(--ring); }
.stat-label { color: var(--ink-2); font-size: 0.875rem; display: flex; gap: var(--s2); align-items: baseline; justify-content: space-between; }
.stat-label .when { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.stat-value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; margin-top: var(--s2); white-space: nowrap; }
.stat-value .unit { font-size: 1rem; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.stat.hero .stat-value { font-size: 3rem; letter-spacing: -0.02em; line-height: 1.1; }
.stat-delta { margin-top: var(--s2); font-size: 0.875rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); }

.delta { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s1); }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--ink-2); }
.delta svg { width: 10px; height: 10px; flex: none; }

/* Blocks */
.block { padding: var(--s6) 0; border-top: 1px solid var(--ring); }
.block > h2, .block-head { margin-bottom: var(--s4); }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.block-head h2 { margin: 0; }
.meta { color: var(--muted); font-size: 0.8125rem; margin-top: var(--s3); }

.columns { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); column-gap: var(--s8); }
.col-main, .col-side { min-width: 0; }

/* Segmented control */
.segmented { display: inline-flex; padding: var(--s1); background: var(--surface-2); border-radius: 10px; border: 1px solid var(--ring); }
.segmented button {
  font: 500 0.8125rem/1 var(--font);
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: var(--s2) var(--s4);
  cursor: pointer;
  position: relative;
  transition: background-color 150ms ease-out, color 150ms ease-out, transform 100ms ease-out;
}
.segmented button::after { content: ""; position: absolute; inset: -6px 0; }
.segmented button:active { transform: scale(0.97); }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--ring); }

.link-button {
  font: 500 0.875rem/1 var(--font);
  color: var(--accent-ink);
  background: none;
  border: 0;
  padding: var(--s3) 0;
  margin: calc(-1 * var(--s3)) 0;
  cursor: pointer;
}
.link-button:active { opacity: 0.7; }
.link-button:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Chart */
.chart { position: relative; height: 300px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart:focus-visible { outline-offset: 6px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick text, .chart .x text { fill: var(--muted); font: 400 11.5px var(--font); font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-wash); stroke: none; }
.chart .record line { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; opacity: 0.55; }
.chart .record text { fill: var(--ink-2); font: 500 11.5px var(--font); }
.chart .end circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .end text { fill: var(--ink); font: 600 12px var(--font); }
.chart .cross { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hover-dot { fill: var(--accent); stroke: var(--page); stroke-width: 2; }
.chart .zero { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--ring);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  padding: var(--s2) var(--s3);
  font-size: 0.8125rem;
  line-height: 1.4;
  min-width: 132px;
}
.tooltip .tt-value { font-weight: 650; font-size: 1rem; font-variant-numeric: tabular-nums; }
.tooltip .tt-row { display: flex; align-items: center; gap: var(--s2); }
.tooltip .tt-key { width: 12px; height: 2px; background: var(--accent); border-radius: 1px; flex: none; }
.tooltip .tt-date { color: var(--muted); }

/* Tables */
.table-view { margin-top: var(--s4); }
.table-view summary { cursor: pointer; color: var(--ink-2); font-size: 0.875rem; width: max-content; list-style: none; display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s3) 0; margin: calc(-1 * var(--s3)) 0; }
.table-view summary::-webkit-details-marker { display: none; }
.table-view summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform 150ms ease-out; margin-right: 2px; }
.table-view[open] summary::before { transform: rotate(45deg); }
.table-view summary:hover { color: var(--ink); }
.table-view[open] summary { margin-bottom: var(--s3); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--axis) transparent; }
.th-short { display: none; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8125rem; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--ring); white-space: nowrap; }
td { padding: var(--s3); border-bottom: 1px solid var(--ring); vertical-align: baseline; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
#chart-table { max-width: 420px; }

.companies td.sym { font-weight: 600; white-space: nowrap; }
.companies td.name { color: var(--ink-2); min-width: 180px; }
.companies .tag { display: inline-block; font-size: 0.75rem; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--ring); border-radius: 4px; padding: 0 var(--s1); margin-left: var(--s2); font-weight: 500; }
.companies tbody tr { transition: background-color 150ms ease-out; }
.companies tbody tr:hover { background: var(--surface-2); }
.weight-bar { display: inline-block; height: 6px; border-radius: 0 3px 3px 0; background: var(--accent); opacity: 0.8; vertical-align: middle; margin-right: var(--s2); }

.funds th:first-child { width: 42%; }

/* Prose */
.prose p + p { margin-top: var(--s3); }
.prose p { max-width: 68ch; }

/* Sentiment */
.senti-top { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.senti-score { font-size: 2.25rem; font-weight: 600; line-height: 1; letter-spacing: -0.01em; }
.senti-label { font-size: 1.0625rem; font-weight: 600; }
.senti-change { color: var(--ink-2); font-size: 0.875rem; }
.scale { position: relative; margin-top: var(--s4); height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--neg) 0%, var(--mid) 50%, var(--pos) 100%); opacity: 0.9; }
.scale-marker { position: absolute; top: -5px; width: 4px; height: 18px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); transform: translateX(-50%); }
.scale-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; margin-top: var(--s2); }

.components { list-style: none; margin: var(--s5) 0 0; padding: 0; display: grid; gap: var(--s4); }
.comp-row { display: grid; grid-template-columns: 11rem minmax(0, 1fr) 3.25rem; gap: var(--s3); align-items: center; }
.comp-name { font-size: 1rem; font-weight: 500; }
.comp-name small { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.comp-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; }
.bar::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.bar-fill { position: absolute; top: 0; height: 100%; }
.bar-fill.neg { background: var(--ink-2); border-radius: 4px 0 0 4px; }
.bar-fill.pos { background: var(--ink-2); border-radius: 0 4px 4px 0; }
.comp-note { grid-column: 1 / -1; color: var(--ink-2); font-size: 0.875rem; margin-top: calc(-1 * var(--s1)); max-width: 68ch; }
.comp-note .conf { color: var(--muted); }
.bar.stale { background: var(--grid); }
.bar.stale::before { display: none; }

.history { margin-top: var(--s5); }
.history h3 { font-size: 0.875rem; font-weight: 500; color: var(--ink-2); margin-bottom: var(--s2); }
.history .chart { height: 140px; }
.chart.is-empty { height: auto; }
.name-inline { display: none; }
.history-empty { color: var(--muted); font-size: 0.875rem; }

/* Scenarios */
.scenarios { list-style: none; margin: 0; padding: 0; }
.scenario { padding: var(--s4) 0; border-bottom: 1px solid var(--ring); }
.scenario:first-child { padding-top: 0; }
.scenario:last-child { border-bottom: 0; }
.scenario-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.scenario h3 { font-size: 1rem; }
.likelihood { font-size: 0.8125rem; color: var(--ink-2); white-space: nowrap; }
.likelihood b { font-weight: 600; color: var(--ink); }
.scenario p { margin-top: var(--s2); color: var(--ink-2); font-size: 1rem; }

/* Events */
.events { list-style: none; margin: 0; padding: 0; }
.event { display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--ring); }
.event:first-child { padding-top: 0; }
.event:last-child { border-bottom: 0; }
.event-date { text-align: center; line-height: 1.1; padding-top: 2px; }
.event-date .d { display: block; font-size: 1.375rem; font-weight: 600; }
.event-date .m { display: block; font-size: 0.75rem; color: var(--muted); }
.event h3 { font-size: 1rem; font-weight: 600; }
.event p { color: var(--ink-2); font-size: 0.875rem; margin-top: 2px; }
.event-when { font-size: 0.8125rem; color: var(--muted); margin-top: 4px; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: var(--s1); font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--ring); color: var(--ink-2); background: var(--surface); }
.pill.today { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-wash); }
.pill.done { color: var(--ink); background: var(--surface-2); }
.event.past { opacity: 0.72; }

/* Views */
.views { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s4); }
.views li p { font-size: 1rem; }
.views .who { font-size: 0.8125rem; color: var(--muted); margin-top: 4px; }
.views .who b { color: var(--ink-2); font-weight: 600; }

/* News */
.news { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: var(--s8); }
.news li { break-inside: avoid; padding: var(--s3) 0; border-bottom: 1px solid var(--ring); }
.news a { font-weight: 500; }
.news .why { color: var(--ink-2); font-size: 0.875rem; margin-top: 2px; }
.news .src { color: var(--muted); font-size: 0.8125rem; margin-top: 4px; }

.footer { padding-bottom: var(--s7); color: var(--muted); font-size: 0.8125rem; }
.footer p { max-width: 80ch; padding-top: var(--s6); border-top: 1px solid var(--ring); }


.skeleton-text { color: var(--muted); font-weight: 500; }
.error { color: var(--down); font-size: 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 1020px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--ring); }
  .columns { grid-template-columns: minmax(0, 1fr); }
  .news { columns: 1; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 var(--s4); }
  .today { padding: var(--s5) 0 var(--s5); }
  .headline { font-size: 1.375rem; }
  .stats { margin-top: var(--s5); }
  .stat { padding: var(--s4); }
  .stats { grid-template-columns: 1fr; }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--ring); }
  .stat:nth-child(3) { border-left: 0; }
  .stat.hero .stat-value { font-size: 2.5rem; }
  .stat:not(.hero) { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s3); align-items: baseline; padding: var(--s3) var(--s4); }
  .stat:not(.hero) .stat-value { grid-column: 2; grid-row: 1; margin-top: 0; font-size: 1.25rem; }
  .stat:not(.hero) .stat-delta { grid-column: 1 / -1; margin-top: 2px; }
  .chart { height: 240px; }
  .comp-row { grid-template-columns: minmax(0, 1fr) 3rem; }
  .companies .name, .companies .price, .companies .month, .weight-bar, .th-long { display: none; }
  .th-short { display: inline-block; }
  .companies th, .companies td { padding-left: 8px; padding-right: 8px; }
  .companies th:first-child, .companies td:first-child { padding-left: 0; }
  .companies th:last-child, .companies td:last-child { padding-right: 0; }
  .companies .name-inline { display: block; font-weight: 400; font-size: 0.8125rem; color: var(--ink-2); white-space: normal; }
  .companies td.sym { white-space: normal; }
  .comp-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .comp-note { margin-top: 0; }
  .block { padding: var(--s5) 0; }
  .updated { font-size: 0.75rem; }
  .updated-brief { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
