:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6b6a66;
  --grid: #ecebe7;
  --accent: #1c5cab;
  --series-1: #2a78d6;   /* spot price */
  --series-2: #eb6834;   /* 50-day MA */
  --series-3: #1baf7a;   /* 200-day MA */
  --score-line: #52514e; /* Bull Run Score line (left axis) */
  --proxy: #8fb4e3;
  --up: #006300;
  --down: #b42318;
  --band-0: #d03b3b;
  --band-1: #ec835a;
  --band-2: #d99a00;
  --band-3: #0ca30c;
  --band-4: #067006;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --border: #33332f;
    --text: #ffffff; --text-2: #c3c2b7; --text-3: #a3a29a; --grid: #2a2a28; --accent: #86b6ef;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --score-line: #c3c2b7; --proxy: #4f7fb8;
    --up: #4cc94c; --down: #ff7b72;
    --band-0: #e66767; --band-1: #ec835a; --band-2: #fab219; --band-3: #0ca30c; --band-4: #3cd13c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #a3a29a; --grid: #2a2a28; --accent: #86b6ef;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --score-line: #c3c2b7; --proxy: #4f7fb8;
  --up: #4cc94c; --down: #ff7b72;
  --band-0: #e66767; --band-1: #ec835a; --band-2: #fab219; --band-3: #0ca30c; --band-4: #3cd13c;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  padding: 0 16px env(safe-area-inset-bottom);
}
main, .top, .foot { max-width: 1080px; margin: 0 auto; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 16px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0 12px; }
.top h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.sym { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.live { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.live.ok .dot { background: var(--band-3); box-shadow: 0 0 0 0 color-mix(in srgb, var(--band-3) 60%, transparent); animation: pulse 2.4s infinite; }
.live.err .dot { background: var(--down); }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .live.ok .dot { animation: none; } }
.theme-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 359px) { .tiles { grid-template-columns: 1fr 1fr; } .tiles .tile:last-child { grid-column: 1 / -1; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.tile-value { font-size: clamp(16px, 4.6vw, 26px); font-weight: 650; letter-spacing: -.01em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: 12px; line-height: 1.3; color: var(--text-3); margin-top: 2px; }
.up { color: var(--up); } .down { color: var(--down); }
.chg-pct { display: block; font-size: 13px; font-weight: 600; }
@media (min-width: 560px) { .chg-pct { display: inline; margin-left: 6px; font-size: 15px; } }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 12px; margin-top: 12px; box-shadow: var(--shadow); }
@media (min-width: 560px) { .card { padding: 16px 18px; } }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.card h2 { font-size: 16px; font-weight: 650; }
.card h3 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }

/* timeframe segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; min-width: 44px; height: 36px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.overlays { border: 0; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; color: var(--text-2); }
.overlays label { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; }
.overlays input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.key { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; }
.key-price { border-color: var(--series-1); }
.key-proxy { border-top-style: dashed; border-color: var(--proxy); }
.key-ma50 { border-color: var(--series-2); border-top-style: dashed; }
.key-ma200 { border-color: var(--series-3); border-top-style: dotted; border-top-width: 3px; }
.key-scoreline { position: relative; border-color: var(--score-line); }
.key-scoreline::after { content: ""; position: absolute; left: 4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--band-2); }

.readout { font-size: 13px; color: var(--text-2); margin-top: 6px; min-height: 1.45em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout b { color: var(--text); font-weight: 650; }
.chart-wrap { position: relative; margin-top: 4px; }
.chart { height: 300px; transition: opacity .2s; }
.chart.loading { opacity: .5; }
@media (min-width: 560px) { .chart { height: 400px; } }
.legend { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.note { font-size: 12px; color: var(--text-3); margin-top: 6px; }

.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 240px; }
.tip .tip-v { font-size: 18px; font-weight: 700; }
.tip .tip-l { color: var(--text-2); }

/* score panel */
.score-when { font-size: 13px; color: var(--text-2); }
.score-hero { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.score-num { font-size: 52px; font-weight: 750; line-height: 1; letter-spacing: -.03em; }
.score-num .of { font-size: 18px; font-weight: 500; color: var(--text-3); margin-left: 2px; letter-spacing: 0; }
.band-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-weight: 650; font-size: 15px; }
.band-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--band-color, var(--text-3)); }
.gauge { position: relative; margin-top: 14px; }
.gauge-track { display: flex; height: 10px; gap: 2px; }
.gauge-track span { width: var(--w); border-radius: 3px; opacity: .85; }
.gauge-track [data-b="0"] { background: var(--band-0); } .gauge-track [data-b="1"] { background: var(--band-1); }
.gauge-track [data-b="2"] { background: var(--band-2); } .gauge-track [data-b="3"] { background: var(--band-3); }
.gauge-track [data-b="4"] { background: var(--band-4); }
.gauge-needle { position: absolute; top: -4px; width: 4px; height: 18px; margin-left: -2px; background: var(--text); border-radius: 2px; box-shadow: 0 0 0 2px var(--surface); left: 0; transition: left .4s; }
.gauge-scale { position: relative; height: 16px; font-size: 11px; color: var(--text-3); margin-top: 4px; }
.gauge-scale span { position: absolute; transform: translateX(-50%); }
.gauge-scale span:nth-child(1) { left: 0; transform: none; } .gauge-scale span:nth-child(2) { left: 30%; }
.gauge-scale span:nth-child(3) { left: 50%; } .gauge-scale span:nth-child(4) { left: 70%; }
.gauge-scale span:nth-child(5) { left: 85%; } .gauge-scale span:nth-child(6) { right: 0; left: auto; transform: none; }

.factors { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.factors details { border-radius: 8px; }
.factors summary { list-style: none; cursor: pointer; padding: 6px 4px; border-radius: 8px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.factors summary::-webkit-details-marker { display: none; }
.factors summary:hover { background: var(--surface-2); }
.f-name { font-size: 14px; font-weight: 550; }
.f-name::after { content: "▸"; color: var(--text-3); margin-left: 6px; font-size: 11px; display: inline-block; transition: transform .15s; }
.factors details[open] .f-name::after { transform: rotate(90deg); }
.f-pts { font-size: 14px; font-weight: 650; }
.f-pts small { color: var(--text-3); font-weight: 500; }
.f-bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.f-bar i { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.f-reason { font-size: 14px; color: var(--text-2); padding: 2px 4px 8px; }
.next { font-size: 15px; }
.snap { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin: 0; }
.snap div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.snap dt { font-size: 12px; color: var(--text-2); }
.snap dd { margin: 0; font-weight: 650; }
.sources { margin-top: 16px; font-size: 14px; }
.sources summary { cursor: pointer; color: var(--text-2); min-height: 32px; display: flex; align-items: center; }
.sources ul { padding-left: 18px; margin: 6px 0 0; }
.sources li { margin: 4px 0; overflow-wrap: anywhere; }
.empty { color: var(--text-2); padding: 16px 0; }

.hist-wrap { position: relative; }
.hist { width: 100%; height: 150px; display: block; overflow: visible; }
.hist text { fill: var(--text-3); font-size: 11px; }
.hist .grid { stroke: var(--grid); }
.hist .bandfill { opacity: .08; }
.hist .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; }
.hist .pt { stroke: var(--surface); stroke-width: 2; }
.hist .hit { fill: transparent; cursor: pointer; }
.hist .hit:focus-visible { outline: none; stroke: var(--accent); stroke-width: 2; }
.hist-table { margin-top: 10px; font-size: 14px; }
.hist-table summary { cursor: pointer; color: var(--text-2); min-height: 32px; display: flex; align-items: center; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; margin-top: 6px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--text-2); font-size: 13px; }

.foot { text-align: center; padding: 20px 0 28px; color: var(--text-2); font-size: 14px; }
.foot .small { font-size: 12px; color: var(--text-3); margin-top: 6px; }
