/* ============================================================
   SKHY Premium Monitor — token-level theming, mobile-first.
   Venue palette validated with the dataviz palette validator
   (both modes pass): HL teal, Binance gold, reserved semantic
   up/down for long/short + funding direction only.
   ============================================================ */

:root {
  /* light is the base; dark redefined below */
  --ground:#f2f4f7; --surface:#ffffff; --surface2:#eaeef3;
  --hairline:#dce3ea; --ink:#17222e; --ink2:#52657a; --ink3:#7c8da0;
  --hl:#0b8f70; --bn:#9a6e14;
  --up:#177a50; --down:#c03434;
  --up-soft:rgba(23,122,80,.12); --down-soft:rgba(192,52,52,.12);
  --chip-hl:rgba(11,143,112,.12); --chip-bn:rgba(154,110,20,.12);
  --accent-ring:rgba(11,143,112,.35);
  --best:rgba(23,122,80,.10);
  --flash:rgba(23,122,80,.22);
  --shadow:0 1px 2px rgba(20,30,45,.05), 0 6px 20px rgba(20,30,45,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground:#0b1016; --surface:#121924; --surface2:#0e1520;
    --hairline:#1f2b3a; --ink:#e7edf4; --ink2:#8ca0b3; --ink3:#5c6e80;
    --hl:#1b9e7e; --bn:#b9872f;
    --up:#3fae7c; --down:#d95757;
    --up-soft:rgba(63,174,124,.14); --down-soft:rgba(217,87,87,.14);
    --chip-hl:rgba(27,158,126,.16); --chip-bn:rgba(185,135,47,.16);
    --accent-ring:rgba(27,158,126,.4);
    --best:rgba(63,174,124,.12);
    --flash:rgba(63,174,124,.20);
    --shadow:0 1px 2px rgba(0,0,0,.3), 0 8px 26px rgba(0,0,0,.35);
  }
}
/* viewer toggle overrides the media query in both directions */
:root[data-theme="light"] {
  --ground:#f2f4f7; --surface:#ffffff; --surface2:#eaeef3;
  --hairline:#dce3ea; --ink:#17222e; --ink2:#52657a; --ink3:#7c8da0;
  --hl:#0b8f70; --bn:#9a6e14; --up:#177a50; --down:#c03434;
  --up-soft:rgba(23,122,80,.12); --down-soft:rgba(192,52,52,.12);
  --chip-hl:rgba(11,143,112,.12); --chip-bn:rgba(154,110,20,.12);
  --accent-ring:rgba(11,143,112,.35); --best:rgba(23,122,80,.10);
  --flash:rgba(23,122,80,.22);
  --shadow:0 1px 2px rgba(20,30,45,.05), 0 6px 20px rgba(20,30,45,.05);
}
:root[data-theme="dark"] {
  --ground:#0b1016; --surface:#121924; --surface2:#0e1520;
  --hairline:#1f2b3a; --ink:#e7edf4; --ink2:#8ca0b3; --ink3:#5c6e80;
  --hl:#1b9e7e; --bn:#b9872f; --up:#3fae7c; --down:#d95757;
  --up-soft:rgba(63,174,124,.14); --down-soft:rgba(217,87,87,.14);
  --chip-hl:rgba(27,158,126,.16); --chip-bn:rgba(185,135,47,.16);
  --accent-ring:rgba(27,158,126,.4); --best:rgba(63,174,124,.12);
  --flash:rgba(63,174,124,.20);
  --shadow:0 1px 2px rgba(0,0,0,.3), 0 8px 26px rgba(0,0,0,.35);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.num {
  font-family: ui-monospace, "Cascadia Code", "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.wrap {
  max-width: 1060px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(48px + env(safe-area-inset-bottom));
}

/* ---------- shared atoms ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.microlabel {
  font-size: 10.5px; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink3);
}
.section-label { margin: 20px 2px 9px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip.hl { background: var(--chip-hl); color: var(--hl); } .chip.hl .dot { background: var(--hl); }
.chip.bn { background: var(--chip-bn); color: var(--bn); } .chip.bn .dot { background: var(--bn); }
.pos { color: var(--up); } .neg { color: var(--down); }
.grid { display: grid; gap: 10px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr; }
@media (min-width: 900px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr; } }
@media (max-width: 430px) { #crowding.grid-2 { grid-template-columns: 1fr; } }
.scrollx { overflow-x: auto; -webkit-overflow-scrolling: touch; }
[data-stale-flag="1"] { opacity: .45; }

/* ---------- header ---------- */
.sitehead {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 8px 2px 14px; justify-content: space-between;
}
.sitehead .title { font-size: 16px; font-weight: 750; letter-spacing: -.01em; }
.sitehead .title small {
  display: block; font-weight: 500; font-size: 11.5px;
  color: var(--ink3); letter-spacing: 0; margin-top: 2px;
}
.conn { display: flex; gap: 12px; align-items: center; font-size: 11.5px; color: var(--ink2); }
.conn span { display: inline-flex; align-items: center; gap: 5px; }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink3); transition: background .3s; }
.conn [data-conn][data-live="1"] i { background: var(--up); box-shadow: 0 0 0 3px var(--up-soft); }
.conn [data-conn][data-live="0"] i { background: var(--down); }
.countdown {
  display: inline-flex; gap: 8px; align-items: baseline;
  padding: 6px 12px; border-radius: 9px;
  background: var(--surface2); border: 1px solid var(--hairline);
}
.countdown b { font-size: 15px; font-weight: 700; }

/* ---------- hero premium ---------- */
.prem-tile { padding: 15px 16px; }
.prem-tile .row1 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.prem-tile .val { font-size: clamp(30px, 8.5vw, 46px); font-weight: 700; letter-spacing: -.02em; line-height: 1.02; }
.prem-tile .sub { font-size: 12px; color: var(--ink2); margin-top: 5px; }
.venue-gap { color: var(--ink2); font-size: 12.5px; margin: 8px 2px 0; }
.venue-gap b { color: var(--ink); }

/* ---------- router table ---------- */
table.matrix { border-collapse: collapse; width: 100%; font-size: 13.5px; white-space: nowrap; }
table.matrix th {
  text-align: right; font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink3); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--hairline);
}
table.matrix th:first-child, table.matrix td:first-child { text-align: left; }
table.matrix td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--hairline); }
table.matrix tbody tr:last-child td { border-bottom: 0; }
table.matrix tr.best td { background: var(--best); }
table.matrix tr.best td:first-child { box-shadow: inset 3px 0 0 var(--up); }
table.matrix .chip { margin-right: 3px; }
/* On phones the 5-column table won't fit; stack each combo into a labeled card
   so the Edge column (the panel's whole point) is always visible without scroll. */
@media (max-width: 560px) {
  #router thead { display: none; }
  #router, #router tbody, #router tr, #router td { display: block; width: 100%; }
  #router tr { padding: 4px 6px 6px; border-bottom: 1px solid var(--hairline); }
  #router tbody tr:last-child { border-bottom: 0; }
  #router tr.best { background: var(--best); border-radius: 8px; box-shadow: inset 3px 0 0 var(--up); }
  #router td {
    display: flex; justify-content: space-between; align-items: center;
    border: 0; padding: 5px 4px; text-align: right; white-space: nowrap;
  }
  #router td::before {
    content: attr(data-label); text-align: left;
    color: var(--ink3); font-size: 10px; font-weight: 650;
    letter-spacing: .05em; text-transform: uppercase;
  }
  #router td[data-label="Edge → Jul 29"] { font-size: 15px; margin-top: 2px; }
}
.note { color: var(--ink3); font-size: 11.5px; line-height: 1.55; margin: 8px 2px 0; max-width: 82ch; }
.note em { color: var(--ink2); font-style: normal; font-weight: 650; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
  background: var(--up-soft); color: var(--up);
}
.pill.pill-off { background: var(--surface2); color: var(--ink3); }
.pill.pill-armed { background: var(--up-soft); color: var(--up); }
.pill.pill-fire { background: var(--down-soft); color: var(--down); }

/* ---------- chart ---------- */
.chart-card { padding: 12px 14px 10px; margin-top: 10px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink2); }
.legend i { display: inline-block; width: 14px; height: 2.5px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.chart-host { position: relative; }
#chart { width: 100%; height: 232px; display: block; touch-action: pan-y; }
.chart-readout {
  position: absolute; top: 4px; left: 4px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 8px;
  padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); line-height: 1.5;
}
.chart-readout .t { color: var(--ink3); font-size: 11px; }
.chart-readout .r { display: flex; gap: 8px; align-items: center; }
.chart-readout .r i { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- instrument cards ---------- */
.inst { padding: 13px 14px; display: flex; flex-direction: column; gap: 9px; }
.inst .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inst .sym { font-weight: 750; font-size: 13.5px; }
.inst .sym small { color: var(--ink3); font-weight: 600; font-size: 10.5px; margin-left: 5px; letter-spacing: .04em; }
.inst .px { font-size: 23px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.inst .px small { font-size: 11.5px; color: var(--ink3); font-weight: 500; margin-left: 7px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; margin: 0; }
.kv dt { color: var(--ink3); } .kv dd { margin: 0; text-align: right; }

/* ---------- crowding ---------- */
.lsr { padding: 13px 14px; display: flex; flex-direction: column; gap: 8px; }
.lsr .lab { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: var(--ink2); }
.lsr .lab b { color: var(--ink); font-size: 13.5px; }
.lsr .bar { display: flex; height: 15px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface2); }
.lsr .bar .l { background: var(--up); border-radius: 5px 2px 2px 5px; min-width: 2px; transition: width .4s; }
.lsr .bar .s { background: var(--down); border-radius: 2px 5px 5px 2px; min-width: 2px; transition: width .4s; }
.lsr .pct { display: flex; justify-content: space-between; font-size: 11.5px; }
.lsr .spark { width: 100%; height: 30px; display: block; }
.lsr .extra { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink3); }

/* ---------- alert bar ---------- */
.alertbar {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  padding: 13px 14px; margin-top: 10px;
}
.alertbar label { font-size: 12.5px; color: var(--ink2); display: inline-flex; align-items: center; gap: 6px; }
.alertbar input[type="number"] {
  width: 62px; padding: 6px 8px; border-radius: 7px; border: 1px solid var(--hairline);
  background: var(--surface2); color: var(--ink); font: inherit; font-size: 13px;
}
.alertbar input[type="number"]:focus-visible { outline: 2px solid var(--hl); outline-offset: 1px; }
.alertbar .chk { gap: 5px; }
.alertbar .pill { margin-left: auto; }
button.ghost {
  padding: 6px 12px; border-radius: 7px; border: 1px solid var(--hairline);
  background: var(--surface2); color: var(--ink2); font: inherit; font-size: 12.5px;
  font-weight: 600; cursor: pointer;
}
button.ghost:hover { color: var(--ink); border-color: var(--accent-ring); }
button.ghost:focus-visible { outline: 2px solid var(--hl); outline-offset: 1px; }

/* ---------- footer ---------- */
.footer { margin-top: 22px; color: var(--ink2); font-size: 12px; line-height: 1.6; max-width: 82ch; }
.footer p { margin: 0 0 8px; }
.footer b { color: var(--ink); font-weight: 650; }
.footer .disclaimer { color: var(--ink3); font-size: 11px; }

/* ---------- alert flash ---------- */
@keyframes flashpulse { 0%,100% { background: var(--ground); } 50% { background: var(--flash); } }
body.flash { animation: flashpulse .7s ease-in-out 4; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .conn [data-conn][data-live="1"] i { box-shadow: none; }
}
