/* CaratWatch: one stylesheet. Colors are tokens; dark mode has its own steps (not an automatic flip). */
:root {
  color-scheme: light;
  --bg: #f9f9f7; --surface: #fcfcfb; --text: #0b0b0b; --text2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,0.10); --link: #1c5cab;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --other: #c3c2b7;
  --up: #0a8f0a; --down: #d03b3b; --vol: #d6d5cf;
  --q1: #cde2fb; --q2: #9ec5f4; --q3: #5598e7; --q4: #256abf; --q5: #104281;
  --chip: #eef3fb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --text: #f0efec; --text2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10); --link: #86b6ef;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --other: #4a4a46;
    --up: #0ca30c; --down: #e66767; --vol: #3a3a37;
    --q1: #184f95; --q2: #1c5cab; --q3: #2a78d6; --q4: #5598e7; --q5: #9ec5f4;
    --chip: #17233a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --text: #f0efec; --text2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10); --link: #86b6ef;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --other: #4a4a46;
  --up: #0ca30c; --down: #e66767; --vol: #3a3a37;
  --q1: #184f95; --q2: #1c5cab; --q3: #2a78d6; --q4: #5598e7; --q5: #9ec5f4;
  --chip: #17233a;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55; }
a { color: var(--link); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
header.site { background: var(--surface); border-bottom: 1px solid var(--ring); position: sticky; top: 0; z-index: 5; }
header.site .wrap { display: flex; align-items: center; gap: 8px 22px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { font-weight: 750; font-size: 1.1rem; letter-spacing: -.01em; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand svg { flex: none; }
nav { display: flex; flex-wrap: wrap; gap: 2px 4px; }
nav a { color: var(--text2); text-decoration: none; font-size: .9rem; padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
nav a[aria-current="page"] { background: var(--chip); color: var(--text); font-weight: 600; }
main { padding: 22px 0 48px; }
h1 { font-size: 1.65rem; line-height: 1.2; letter-spacing: -.015em; margin: 4px 0 6px; }
h2 { font-size: 1.12rem; margin: 0 0 2px; letter-spacing: -.005em; }
.lede { color: var(--text2); margin: 0 0 18px; max-width: 760px; }
.asof { color: var(--muted); font-size: .85rem; margin: 0 0 14px; }
.asof b { color: var(--text2); font-weight: 600; }

/* number tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 18px; }
.kpi { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.kpi small { display: block; color: var(--text2); font-size: .8rem; line-height: 1.3; }
.kpi b { display: block; font-size: 1.7rem; line-height: 1.15; margin: 6px 0 2px; font-weight: 700; letter-spacing: -.02em; }
.kpi span { display: block; font-size: .8rem; color: var(--muted); }
.pos { color: var(--up); } .neg { color: var(--down); }
.kpi .pos, .kpi .neg { font-weight: 600; }

/* chart cards */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.grid3 h3 { font-size: .95rem; margin: 4px 0 6px; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 16px 16px 12px; margin: 0 0 16px; min-width: 0; }
.card .sub { color: var(--text2); font-size: .86rem; margin: 0 0 10px; }
.card .src { color: var(--muted); font-size: .78rem; margin: 8px 0 0; }
.chart { position: relative; width: 100%; min-height: 60px; }
.chart svg { display: block; overflow: visible; }
.chart text.ax { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.axhi { font-size: 11px; fill: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart text.tl { font-size: 11px; fill: var(--text); font-weight: 600; pointer-events: none; }
.chart text.tl.inv { fill: #fff; }
.tip { position: absolute; display: none; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--ring);
       box-shadow: 0 4px 16px rgba(0,0,0,.14); border-radius: 8px; padding: 8px 10px; font-size: .8rem; line-height: 1.45; white-space: nowrap; z-index: 3; font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tf { display: flex; gap: 4px; margin: 0 0 8px; flex-wrap: wrap; }
.tf button { font: inherit; font-size: .8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--ring); background: transparent; color: var(--text2); cursor: pointer; }
.tf button.log { margin-left: auto; }
.tf button[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.keyline { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .78rem; color: var(--text2); margin: 6px 0 0; }
.keyline i { display: inline-block; vertical-align: -1px; margin-right: 5px; }
.k-up { width: 9px; height: 11px; border: 1.5px solid var(--up); border-radius: 1px; }
.k-down { width: 9px; height: 11px; background: var(--down); border-radius: 1px; }
.k-ma { width: 14px; height: 2px; background: var(--s1); vertical-align: 3px !important; }
.k-vol { width: 9px; height: 9px; background: var(--vol); border-radius: 1px; }

/* rank bars and share rows */
.hb, .st { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; align-items: center; gap: 10px; padding: 5px 0; font-size: .86rem; }
.hb-n, .st-n { color: var(--text); overflow-wrap: anywhere; }
.hb-t, .st-t { display: flex; height: 14px; border-radius: 4px; overflow: hidden; }
.hb-t i { display: block; height: 14px; background: var(--s1); border-radius: 0 4px 4px 0; }
.st-t i { display: block; height: 14px; border-right: 2px solid var(--surface); }
.st-t i:last-child { border-right: 0; }
.hb-v, .st-v { font-variant-numeric: tabular-nums; color: var(--text2); text-align: right; min-width: 64px; }
.hb-v small { display: block; color: var(--muted); font-size: .74rem; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--text2); margin: 0 0 8px; }

/* flow: three ranked lists side by side */
.flow { display: grid; grid-template-columns: 1fr 28px 1fr 28px 1fr; align-items: start; gap: 8px; }
.flow .arrow { align-self: center; text-align: center; color: var(--muted); font-size: 1.4rem; }
.flow h3 { font-size: .92rem; margin: 0 0 2px; }
.flow .sub { margin-bottom: 6px; }

/* tables (inside "Show the numbers") */
details.nums { margin: 10px 0 0; }
details.nums summary { cursor: pointer; color: var(--link); font-size: .85rem; }
.tablewrap { overflow-x: auto; max-height: 420px; overflow-y: auto; margin-top: 8px; border: 1px solid var(--ring); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface); color: var(--text2); font-weight: 600; }
td.l, th.l { text-align: left; white-space: normal; }

/* text blocks */
.notes { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 18px; margin: 0 0 16px; }
.notes ul { margin: 6px 0 0; padding-left: 20px; }
.notes li { margin: 4px 0; }
.quote { border-left: 3px solid var(--axis); margin: 10px 0; padding: 2px 0 2px 14px; color: var(--text2); }
.callout { background: var(--chip); border-radius: 10px; padding: 10px 14px; font-size: .9rem; margin: 0 0 16px; }
.pill { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--chip); color: var(--text2); margin-left: 6px; vertical-align: 2px; }
footer.site { border-top: 1px solid var(--ring); padding: 20px 0 32px; color: var(--muted); font-size: .82rem; }
footer.site p { margin: 4px 0; max-width: 860px; }
footer.site a { color: var(--text2); margin-right: 12px; }

@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .flow { grid-template-columns: minmax(0, 1fr); }
  .flow .arrow { transform: rotate(90deg); }
}
@media (max-width: 520px) {
  header.site { position: static; }
  nav { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  h1 { font-size: 1.35rem; }
  .kpi b { font-size: 1.35rem; }
  .card { padding: 14px 12px 10px; }
  .hb, .st { grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 8px; }
  nav a { padding: 3px 6px; font-size: .85rem; }
}

/* heatmap */
.hm { display: grid; gap: 3px; font-size: .72rem; font-variant-numeric: tabular-nums; }
.hm-h { color: var(--muted); text-align: center; }
.hm-y { color: var(--text2); align-self: center; }
.hm-c { border-radius: 4px; padding: 6px 2px; text-align: center; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: clip; }
.hm-c.inv { color: #fff; }
.hm-na { background: transparent; border: 1px dashed var(--grid); }
.chart text.axv { font-size: 12px; fill: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
/* calculator */
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; margin: 4px 0 14px; }
.calc label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--text2); }
.calc input, .calc select { font: inherit; font-size: .95rem; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--axis); background: var(--bg); color: var(--text); min-width: 0; }
.calc-out .hb { grid-template-columns: 1fr auto auto; }
.calc-out .hb.tot { border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 8px; font-weight: 700; }
@media (max-width: 620px) { .hm { gap: 2px; } .hm-c { font-size: 0; padding: 9px 0; } .hm-h { font-size: .6rem; } }

.hm + .legend { margin-top: 10px; align-items: center; }
