/* Tokens.
   Light is the base definition; dark is a selected set of steps from the same
   ramps, declared under both the OS media query and the explicit theme stamp so
   a manual toggle wins in either direction. */
:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface-1:    #fcfcfb;
  --surface-2:    #f3f3f0;
  --border:       #e2e1dc;
  --border-strong:#cbcac3;
  --text-primary: #0b0b0b;
  --text-secondary:#52514e;
  --text-muted:   #85847e;

  /* diverging: buy <-> sell. blue/red with a gray midpoint, which stays
     readable under deuteranopia in a way green/red does not. */
  --buy:          #2a78d6;
  --sell:         #e34948;
  --mid:          #f0efec;

  /* categorical, fixed slot order: blue, orange, aqua */
  --series-1:     #2a78d6;
  --series-2:     #eb6834;
  --series-3:     #1baf7a;

  --good:         #0ca30c;
  --warning:      #fab219;
  --critical:     #d03b3b;

  --grid:         #ececE7;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, Inter, system-ui, sans-serif;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface-1:    #1a1a19;
    --surface-2:    #222221;
    --border:       #2e2e2c;
    --border-strong:#42423f;
    --text-primary: #ffffff;
    --text-secondary:#c3c2b7;
    --text-muted:   #8f8e85;
    --buy:          #3987e5;
    --sell:         #e66767;
    --mid:          #383835;
    --series-1:     #3987e5;
    --series-2:     #d95926;
    --series-3:     #199e70;
    --grid:         #2a2a28;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:#0d0d0d; --surface-1:#1a1a19; --surface-2:#222221;
  --border:#2e2e2c; --border-strong:#42423f;
  --text-primary:#fff; --text-secondary:#c3c2b7; --text-muted:#8f8e85;
  --buy:#3987e5; --sell:#e66767; --mid:#383835;
  --series-1:#3987e5; --series-2:#d95926; --series-3:#199e70; --grid:#2a2a28;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  /* stop iOS Safari from inflating text in landscape */
  -webkit-text-size-adjust: 100%;
}
body {
  background: var(--plane); color: var(--text-primary);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  /* kill the 300ms tap delay without disabling pinch-zoom */
  touch-action: manipulation;
  overflow-x: hidden;
}
a { color: var(--series-1); }
.wrap {
  max-width: 1280px; margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) calc(72px + env(safe-area-inset-bottom));
}

/* Header + tabs stick together as one unit */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-1);
  padding-top: env(safe-area-inset-top);
}
header { border-bottom: 1px solid var(--border); background: var(--surface-1); }
.hdr-in { max-width: 1280px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-left)); display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; }
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 15px; display: flex; align-items: center; gap: 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.dot.stale { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 22%, transparent); }
/* Visible, not hover-only: a title attribute cannot be read on a phone. */
.livelbl { margin-left: 7px; font-size: 10px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: 4px; padding: 1px 5px; white-space: nowrap; }
.hdr-stats { display: flex; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.hs { display: flex; flex-direction: column; gap: 1px; }
.hs b { font: 600 15px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.hs span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.up { color: var(--buy); } .down { color: var(--sell); }

/* Tabs — scroll horizontally on narrow screens rather than wrapping or squeezing */
nav.tabs {
  display: flex; border-bottom: 1px solid var(--border); background: var(--surface-1);
  padding: 0 max(16px, env(safe-area-inset-left));
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs .inner { max-width: 1280px; margin: 0 auto; width: 100%; display: flex; gap: 4px; }
.tab {
  appearance: none; background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 13px 14px; font: 500 14px var(--sans); color: var(--text-secondary); cursor: pointer;
  white-space: nowrap; min-height: 44px; /* iOS minimum touch target */
}
.tab:hover { color: var(--text-primary); }
.tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }
.panel[hidden] { display: none !important; }

/* Cards and layout */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; }
.card > h3 { margin: 0 0 2px; font-size: 13.5px; font-weight: 620; letter-spacing: -.005em; }
.card > p.sub { margin: 0 0 14px; font-size: 12px; color: var(--text-muted); }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 980px) { .g4, .g3, .g2 { grid-template-columns: repeat(2, 1fr); } }
/* On a phone, keep stat tiles two-up: one-up would turn the header into a
   scroll marathon before any chart is visible. Charts go full width. */
@media (max-width: 620px) {
  .g4, .g3 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .g2 { grid-template-columns: 1fr; }
}
.section-title { margin: 26px 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 620; }

/* Stat tiles */
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 15px; }
.tile .lbl { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 7px; }
.tile .val { font: 650 25px/1.1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .note { font-size: 11.5px; color: var(--text-secondary); margin-top: 6px; }

/* Charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.axis text { font: 10.5px var(--mono); fill: var(--text-muted); }
.gridline { stroke: var(--grid); stroke-width: 1; }
.zeroline { stroke: var(--border-strong); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; opacity: 0; transition: opacity .08s;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 7px 9px; font: 11.5px/1.55 var(--mono); color: var(--text-primary);
  box-shadow: 0 6px 20px rgba(0,0,0,.18); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tip.on { opacity: 1; }
.tip .k { color: var(--text-muted); }
.crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }

/* Legend */
.legend { display: flex; gap: 15px; flex-wrap: wrap; margin-bottom: 10px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend span { font-size: 12px; color: var(--text-secondary); }

/* Controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, .btn {
  appearance: none; background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px;
  /* 16px: anything smaller makes iOS Safari zoom the page on focus */
  font: 16px var(--sans); cursor: pointer; min-height: 44px; max-width: 100%;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { appearance: none; background: var(--surface-2); border: 0; border-right: 1px solid var(--border); padding: 10px 13px; font: 13px var(--mono); color: var(--text-secondary); cursor: pointer; min-height: 44px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--series-1); color: #fff; }

/* Tables */
table { width: 100%; border-collapse: collapse; font: 12.5px var(--mono); font-variant-numeric: tabular-nums; }
th { text-align: right; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 7px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
/* momentum scrolling for the wide tables, with an edge hint that there is more */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll::-webkit-scrollbar { height: 5px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.bar-cell { position: relative; min-width: 130px; }
.bar-cell .fill { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); height: 13px; border-radius: 0 3px 3px 0; background: color-mix(in srgb, var(--series-1) 34%, transparent); }
.bar-cell span { position: relative; }

/* Misc */
.badge { display: inline-flex; align-items: center; gap: 5px; font: 600 11px var(--sans); padding: 3px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .04em; }
.badge.ok { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.bad { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical); }
.mono { font-family: var(--mono); }
code { font: 12px var(--mono); background: var(--surface-2); padding: 1.5px 5px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--text-muted); }
footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
footer h4 { color: var(--text-secondary); font-size: 12px; margin: 16px 0 7px; text-transform: uppercase; letter-spacing: .05em; }
.kv { display: grid; grid-template-columns: 210px 1fr; gap: 4px 14px; font: 11.5px var(--mono); }
.kv div:nth-child(odd) { color: var(--text-muted); }
.loading { padding: 40px; text-align: center; color: var(--text-muted); }
.err { border-left: 3px solid var(--critical); padding: 10px 14px; background: color-mix(in srgb, var(--critical) 7%, transparent); border-radius: 4px; margin: 12px 0; font-size: 13px; }
.hint { font-size: 11.5px; color: var(--text-muted); margin-top: 8px; }
.gauge-scale { display: flex; justify-content: space-between; font: 10.5px var(--mono); color: var(--text-muted); margin-top: 5px; }

/* ── Investor view ─────────────────────────────────────────────────────────
   The takeaway line is the point of this tab: a chart that needs interpreting
   is a chart the reader has to be an analyst to use. Every panel states its
   own conclusion in a sentence, in plain language, computed from the data. */
/* Rating badge. It states what it is rating, because a large coloured word gets
   read as a price call whether or not that is what it means. */
.rating {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
  padding: 18px 20px; margin-bottom: 14px;
}
.rating-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.rating .word { font: 750 40px/1 var(--sans); letter-spacing: -.03em; }
.rating .word.bull { color: var(--good); }
.rating .word.bear { color: var(--sell); }
.rating .word.neutral { color: var(--text-secondary); }
.rating .scope { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; flex: 1 1 260px; }
.rating .scale { position: relative; height: 8px; border-radius: 4px; margin: 16px 0 6px;
  background: linear-gradient(90deg, var(--sell), var(--mid) 50%, var(--good)); }
.rating .needle { position: absolute; top: -4px; width: 3px; height: 16px; border-radius: 2px;
  background: var(--text-primary); box-shadow: 0 0 0 2px var(--surface-1); }
.rating .scale-ends { display: flex; justify-content: space-between; font: 10.5px var(--mono); color: var(--text-muted); }
.components { margin-top: 14px; }
.components .row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.components .row .w { font: 10.5px var(--mono); color: var(--text-muted); white-space: nowrap; }
.components .row .v { font: 600 12.5px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 620px) {
  .rating { padding: 14px; }
  .rating .word { font-size: 30px; }
  .rating .scope { font-size: 11.5px; }
  .components .row { font-size: 11.5px; gap: 8px; }
}

.verdict {
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 4px solid var(--series-1); border-radius: var(--r);
  padding: 16px 18px; margin-bottom: 16px;
}
.verdict .lead { font: 600 18px/1.35 var(--sans); letter-spacing: -.015em; margin-bottom: 7px; }
.verdict .detail { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.verdict.pos { border-left-color: var(--buy); }
.verdict.neg { border-left-color: var(--sell); }

.takeaway {
  margin-top: 12px; padding: 9px 11px; border-radius: 6px;
  background: var(--surface-2); font-size: 12.5px; line-height: 1.55;
  border-left: 3px solid var(--border-strong);
}
.takeaway b { font-weight: 650; }
.takeaway.pos { border-left-color: var(--buy); }
.takeaway.neg { border-left-color: var(--sell); }
.takeaway.warn { border-left-color: var(--warning); }

.kpi { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 2px; }
.kpi .big { font: 650 27px/1.05 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .delta { font: 600 13px var(--mono); }
.kpi .unit { font-size: 12px; color: var(--text-muted); }

/* regime scorecard */
.regime td .band { display: inline-block; padding: 2px 7px; border-radius: 4px; font: 600 10.5px var(--sans); text-transform: uppercase; letter-spacing: .04em; }
.band.bear { background: color-mix(in srgb, var(--sell) 18%, transparent); color: var(--sell); }
.band.base { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--series-1); }
.band.bull { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.band.xbull { background: color-mix(in srgb, var(--series-2) 20%, transparent); color: var(--series-2); }
.band.na { background: var(--surface-2); color: var(--text-muted); }

@media (max-width: 620px) {
  .verdict { padding: 13px 14px; }
  .verdict .lead { font-size: 15.5px; }
  .verdict .detail { font-size: 12px; }
  .kpi .big { font-size: 22px; }
  .takeaway { font-size: 11.5px; padding: 8px 10px; }
}

/* ── Phone ────────────────────────────────────────────────────────────────
   Primary viewing surface is an iPhone, so this block is load-bearing, not a
   courtesy fallback: denser tiles, smaller hero numbers, and a tooltip that is
   pinned rather than floating (a finger-following tooltip sits under the finger). */
@media (max-width: 620px) {
  body { font-size: 13.5px; }
  .brand { font-size: 14px; }
  .hdr-in { padding: 10px 16px; gap: 10px 16px; }
  .hdr-stats { gap: 0; margin-left: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
  .hs b { font-size: 14px; }
  .hs span { font-size: 10px; }
  .card { padding: 13px; border-radius: 10px; }
  .card > h3 { font-size: 13px; }
  .card > p.sub { font-size: 11.5px; margin-bottom: 11px; }
  .tile { padding: 11px 12px; }
  .tile .lbl { font-size: 10px; margin-bottom: 5px; }
  .tile .val { font-size: 19px; }
  .tile .note { font-size: 10.5px; line-height: 1.4; }
  .section-title { margin: 20px 0 10px; font-size: 11px; }
  .controls { gap: 7px; }
  .controls select { flex: 1 1 100%; }
  .legend { gap: 12px; margin-bottom: 8px; }
  .legend span { font-size: 11.5px; }
  /* pin the tooltip to the top of the chart so it is never under the finger */
  .tip { font-size: 11px; padding: 6px 8px; left: 0 !important; top: 0 !important; max-width: 100%; white-space: normal; }
  table { font-size: 11.5px; }
  th { font-size: 10px; padding: 6px 7px; }
  td { padding: 6px 7px; }
  .kv { grid-template-columns: 1fr; gap: 1px 0; }
  .kv div:nth-child(odd) { margin-top: 7px; }
  footer { font-size: 11.5px; }
}

/* How much of the rating is actually carrying weight. */
.coverage { margin-top: 8px; font-size: 11px; line-height: 1.5; color: var(--text-muted); }

/* An unmeasured window in the data is a fact the reader must not have to hunt for. */
.warnline { display:block; margin-top:5px; color: var(--warning); font-weight:500; }

/* How old the indexed layer is, stated where it cannot be missed.
   It used to be a footnote at the bottom of the page. The indexing schedule is
   throttled to roughly one run every four hours, so "how old is this" is not a
   footnote question -- it decides whether any level on the page can be acted on. */
#staleBanner { margin: 0 0 14px; padding: 10px 13px; border-radius: 8px; font-size: 12.5px; line-height: 1.55;
  border: 1px solid color-mix(in srgb, var(--warning) 42%, transparent);
  background: color-mix(in srgb, var(--warning) 9%, transparent); color: var(--text-primary); }
#staleBanner.bad { border-color: color-mix(in srgb, var(--serious, var(--warning)) 55%, transparent);
  background: color-mix(in srgb, var(--serious, var(--warning)) 12%, transparent); }
#staleBanner b { color: var(--warning); }

/* A live reading beside a settled one; the contrast is the information. */
.livenote { margin-top:7px; font-size:11.5px; line-height:1.5; color: var(--text-secondary); }
.livenote b { color: var(--text-primary); }

/* "What moved since I last looked" -- the first question anyone opening this on a
   phone actually has, and previously it took reading eight cards to answer. */
#sinceLast { margin: 0 0 14px; padding: 11px 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2, transparent); font-size: 12.5px; line-height: 1.6; }
#sinceLast .hd { font-weight: 600; color: var(--text-primary); margin-bottom: 5px; }
#sinceLast ul { margin: 0; padding-left: 17px; color: var(--text-secondary); }
#sinceLast li { margin: 1px 0; }
#sinceLast b { color: var(--text-primary); }
#sinceLast .up { color: var(--buy); }
#sinceLast .down { color: var(--sell); }
#sinceLast .dismiss { float: right; font-size: 11px; color: var(--text-muted);
  background: none; border: 0; cursor: pointer; padding: 0 0 0 10px; }
