/* ===========================================================================
   Market Intelligence — trading console
   ---------------------------------------------------------------------------
   Design intent: an internal sportsbook trading surface. Dark-first because
   that is where trading desks live. Structure comes from hairline rules and
   density, not from floating cards — no drop shadows, near-square corners.
   Chrome is monochrome; colour is reserved entirely for data, so a coloured
   pixel always means something. Numerics are monospaced and tabular.

   Brand tokens are isolated in one block below so a real Fanatics palette can
   be dropped in without touching anything else.
   =========================================================================== */

/* --- brand (swap these) --- */
:root {
  --brand-rule: #c8102e;          /* hairline under the masthead */
  --brand-ink: #ffffff;
  --brand-tracking: 0.14em;
}

/* --- surfaces & type --- */
:root {
  --bg: #0a0d12;
  --panel: #0f141b;
  --panel-2: #131a23;
  --rule: #1c242f;
  --rule-soft: #161d26;
  --ink: #e9edf3;
  --ink-2: #9aa7b8;
  --muted: #64707f;

  /* venues — fixed hues, never reused for anything else */
  --kalshi: #e9a13b;
  --poly: #8b7cf6;

  /* data semantics */
  --agree: #2fbf71;
  --partial: #4c9ae8;
  --diverge: #e5484d;
  --idle: #3a4552;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --panel-2: #f2f4f7;
    --rule: #dde3ea;
    --rule-soft: #e7ecf1;
    --ink: #0c1116;
    --ink-2: #4a5766;
    --muted: #77838f;
    --kalshi: #a86a12;
    --poly: #5a4bc4;
    --agree: #17864c;
    --partial: #2b6fb0;
    --diverge: #c0362f;
    --idle: #c2cad3;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0d12; --panel: #0f141b; --panel-2: #131a23;
  --rule: #1c242f; --rule-soft: #161d26;
  --ink: #e9edf3; --ink-2: #9aa7b8; --muted: #64707f;
  --kalshi: #e9a13b; --poly: #8b7cf6;
  --agree: #2fbf71; --partial: #4c9ae8; --diverge: #e5484d; --idle: #3a4552;
}
:root[data-theme="light"] {
  --bg: #f7f8fa; --panel: #ffffff; --panel-2: #f2f4f7;
  --rule: #dde3ea; --rule-soft: #e7ecf1;
  --ink: #0c1116; --ink-2: #4a5766; --muted: #77838f;
  --kalshi: #a86a12; --poly: #5a4bc4;
  --agree: #17864c; --partial: #2b6fb0; --diverge: #c0362f; --idle: #c2cad3;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: 9.5px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}

/* ===== masthead ===================================================== */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  box-shadow: inset 0 -2px 0 0 var(--brand-rule);
}
.masthead .inner {
  max-width: 1240px; margin: 0 auto; padding: 13px 24px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.wordmark { display: flex; align-items: baseline; gap: 9px; margin-right: auto; }
.wordmark b {
  font-size: 15px; font-weight: 800; letter-spacing: var(--brand-tracking);
  text-transform: uppercase; color: var(--brand-ink);
}
@media (prefers-color-scheme: light) { .wordmark b { color: var(--ink); } }
:root[data-theme="light"] .wordmark b { color: var(--ink); }
:root[data-theme="dark"] .wordmark b { color: var(--brand-ink); }
.wordmark span { font-size: 13px; color: var(--ink-2); letter-spacing: 0.01em; }
.wordmark i {
  width: 4px; height: 4px; border-radius: 50%; background: var(--brand-rule);
  align-self: center; flex: none;
}

.hstatus {
  display: inline-flex; align-items: center; gap: 8px;
  font: 11.5px/1 var(--mono); color: var(--ink-2);
  padding: 6px 10px; border: 1px solid var(--rule); border-radius: 3px;
  background: var(--panel);
}
.led { width: 6px; height: 6px; border-radius: 50%; background: var(--agree); flex: none; }
.led.stale { background: var(--partial); }
.led.err { background: var(--diverge); }
@media (prefers-reduced-motion: no-preference) {
  .led { animation: blink 2.8s ease-in-out infinite; }
  @keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
}

button {
  font: 600 11.5px/1 var(--sans); letter-spacing: 0.02em;
  color: var(--ink-2); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: 7px 11px; cursor: pointer;
}
button:hover { color: var(--ink); border-color: var(--muted); }
button:focus-visible { outline: 2px solid var(--poly); outline-offset: 1px; }
button[disabled] { opacity: 0.5; cursor: default; }
button.on { color: var(--ink); background: var(--panel-2); border-color: var(--muted); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px 96px; }

/* ===== KPI strip — ruled columns, not tiles ========================= */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border-bottom: 1px solid var(--rule); margin: 26px 0 0;
}
.kpi { padding: 4px 20px 20px 0; border-left: 1px solid var(--rule-soft); padding-left: 18px; }
.kpi:first-child { border-left: none; padding-left: 0; }
.kpi .v {
  font: 600 30px/1.05 var(--mono); letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; display: block;
}
.kpi .v small { font-size: 15px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.kpi .eyebrow { display: block; margin-top: 7px; }
.kpi.lead .v { color: var(--agree); }

/* ===== toolbar ====================================================== */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 16px 0 14px; border-bottom: 1px solid var(--rule);
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.venues { margin-left: auto; display: flex; gap: 15px; font-size: 11px; color: var(--muted); }
.venues span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.key.k { background: var(--kalshi); }
.key.p { background: var(--poly); }
.key.a { background: var(--agree); }

/* ===== fixtures — bounded panels ===================================== */
/* Flat hairline rows read as one continuous list; separation has to be obvious
   at a glance. Each fixture is its own panel with real air between them, and
   the whole fixture collapses so 45 games scan as 45 lines, not 200 tables. */
.fixtures { display: flex; flex-direction: column; gap: 9px; }

.fx {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--idle);
  border-radius: 4px;
  overflow: hidden;
}
.fx.agree { border-left-color: var(--agree); }
.fx.partial { border-left-color: var(--partial); }
.fx.diverge { border-left-color: var(--diverge); }
.fx[open] { border-color: var(--muted); }

.fx > summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 14px; align-items: center; padding: 14px 18px;
}
.fx > summary::-webkit-details-marker { display: none; }
.fx > summary:hover { background: var(--panel-2); }
.fx > summary:focus-visible { outline: 2px solid var(--poly); outline-offset: -2px; }
.chev { color: var(--muted); font-size: 10px; justify-self: center; transition: transform 0.15s ease; }
.fx[open] .chev { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

.matchup { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.tm { font: 700 17px/1 var(--mono); letter-spacing: 0.02em; }
.vs { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.longname { color: var(--ink-2); font-size: 12.5px; }
.fxmeta {
  margin-top: 8px; display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted);
}
.fxmeta .mono { font-size: 11px; }

.phase {
  font: 700 9.5px/1 var(--sans); letter-spacing: 0.11em; text-transform: uppercase;
  padding: 4px 7px; border-radius: 2px; border: 1px solid var(--rule); color: var(--muted);
}
.phase.live {
  color: var(--diverge); border-color: color-mix(in srgb, var(--diverge) 45%, transparent);
  background: color-mix(in srgb, var(--diverge) 12%, transparent);
}
.phase.postponed { color: var(--kalshi); border-color: color-mix(in srgb, var(--kalshi) 45%, transparent); }
.phase.pre { color: var(--partial); border-color: color-mix(in srgb, var(--partial) 40%, transparent); }
.score { font: 700 13px/1 var(--mono); color: var(--ink); }

.readout { text-align: right; display: flex; align-items: center; gap: 16px; }
.readout .num { font: 600 22px/1 var(--mono); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.readout .num small { font-size: 10.5px; color: var(--muted); font-weight: 500; }
.tag {
  display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 2px;
  font: 700 10.5px/1 var(--sans); letter-spacing: 0.03em; border: 1px solid transparent; white-space: nowrap;
}
.tag.agree { color: var(--agree); border-color: color-mix(in srgb, var(--agree) 40%, transparent); background: color-mix(in srgb, var(--agree) 11%, transparent); }
.tag.partial { color: var(--partial); border-color: color-mix(in srgb, var(--partial) 40%, transparent); background: color-mix(in srgb, var(--partial) 11%, transparent); }
.tag.diverge { color: var(--diverge); border-color: color-mix(in srgb, var(--diverge) 40%, transparent); background: color-mix(in srgb, var(--diverge) 11%, transparent); }
.tag.none { color: var(--muted); border-color: var(--rule); }

.rail { position: relative; height: 16px; margin-top: 10px; max-width: 400px; }
.rail .base { position: absolute; inset: 7px 0 auto 0; height: 2px; background: var(--rule); }
.rail .gap { position: absolute; top: 7px; height: 2px; background: var(--diverge); }
.rail .gap.ok { background: var(--agree); }
.rail .mk { position: absolute; top: 2px; width: 2px; height: 12px; }
.rail .mk.k { background: var(--kalshi); }
.rail .mk.p { background: var(--poly); }
.raillabel { margin-top: 4px; font: 10px/1.4 var(--mono); color: var(--muted); }

.divider {
  display: flex; align-items: center; gap: 12px; margin: 26px 0 2px;
  font: 600 9.5px/1 var(--sans); letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted);
}
.divider::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

/* ===== market groups ================================================ */
.groups { border-top: 1px solid var(--rule); background: var(--panel-2); }
.groups details { border-bottom: 1px solid var(--rule-soft); }
.groups details:last-child { border-bottom: none; }
.groups summary {
  list-style: none; cursor: pointer; padding: 9px 18px;
  display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center;
  font-size: 12.5px;
}
.groups summary::-webkit-details-marker { display: none; }
.groups summary:hover { background: var(--panel); }
.groups summary:focus-visible { outline: 2px solid var(--poly); outline-offset: -2px; }
.gname { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.01em; }
.tw { color: var(--muted); font-size: 9px; display: inline-block; transition: transform 0.14s ease; }
.groups details[open] .tw { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .tw { transition: none; } }
.count { font: 11px/1 var(--mono); color: var(--muted); }
.bars { display: flex; gap: 2px; }
.bar { width: 4px; height: 10px; background: var(--idle); }
.bar.ok { background: var(--agree); }
.bar.k { background: var(--kalshi); }
.bar.p { background: var(--poly); }

.tblwrap { padding: 2px 18px 14px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  text-align: right; font: 600 9.5px/1 var(--sans); letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--muted);
  padding: 8px 10px 7px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
th:first-child { text-align: left; }
td {
  padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); text-align: right;
  font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap;
}
td:first-child { text-align: left; color: var(--ink-2); }
tr:last-child td { border-bottom: none; }
.pk { color: var(--kalshi); font-weight: 600; }
.pp { color: var(--poly); font-weight: 600; }
.nil { color: var(--idle); }
.ok { color: var(--agree); font-weight: 600; }
.no { color: var(--diverge); font-weight: 600; }
.pend { color: var(--muted); }

/* ===== briefing ===================================================== */
.brief { margin-top: 56px; border-top: 1px solid var(--rule); padding-top: 34px; }
.brief h2 {
  margin: 0 0 6px; font-size: 17px; font-weight: 650; letter-spacing: -0.015em;
}
.brief .lede { margin: 0 0 26px; color: var(--ink-2); font-size: 14px; max-width: 74ch; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 30px; }
.brief h3 {
  margin: 0 0 12px; font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.brief p { margin: 0 0 12px; color: var(--ink-2); font-size: 13.5px; max-width: 68ch; }
.brief strong { color: var(--ink); font-weight: 620; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li {
  counter-increment: s; position: relative; padding: 0 0 14px 30px;
  color: var(--ink-2); font-size: 13.5px; max-width: 66ch;
}
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 1px;
  font: 600 10px/17px var(--mono); width: 17px; height: 17px; text-align: center;
  color: var(--muted); border: 1px solid var(--rule); border-radius: 2px;
}
.gaps { margin: 0; padding: 0; list-style: none; }
.gaps li {
  padding: 12px 0 12px 14px; border-top: 1px solid var(--rule-soft);
  border-left: 2px solid var(--diverge); padding-left: 14px;
  color: var(--ink-2); font-size: 13.5px; max-width: 68ch;
}
.gaps li:first-child { border-top: none; }
.gaps li.soft { border-left-color: var(--partial); }
.gaps li b { display: block; color: var(--ink); font-weight: 620; margin-bottom: 3px; font-size: 13.5px; }
.ask {
  margin-top: 26px; padding: 16px 18px; border: 1px solid var(--rule);
  border-left: 2px solid var(--brand-rule); background: var(--panel);
}
.ask h3 { margin-bottom: 8px; }
.ask p:last-child { margin-bottom: 0; }

/* ===== states & footer ============================================== */
.msg { padding: 22px 18px; border: 1px solid var(--rule); background: var(--panel); color: var(--ink-2); font-size: 13.5px; }
.msg.bad { border-left: 2px solid var(--diverge); }
.msg code { font: 12px/1.4 var(--mono); background: var(--panel-2); padding: 2px 5px; border: 1px solid var(--rule-soft); }
.ghost > div { height: 74px; border-bottom: 1px solid var(--rule-soft); }
@media (prefers-reduced-motion: no-preference) {
  .ghost > div { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
}
footer {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule);
  color: var(--muted); font-size: 11px; display: flex; gap: 8px 22px;
  flex-wrap: wrap; justify-content: space-between;
}

@media (max-width: 800px) {
  .fxhead { grid-template-columns: 1fr; }
  .readout { justify-content: flex-start; text-align: left; }
  summary { grid-template-columns: 1fr auto; }
  .bars { display: none; }
  .venues { margin-left: 0; width: 100%; }
}

/* ===== raw JSON panel =============================================== */
.rawtools {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 0 18px 13px 48px;
}
.rawbtn {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.02em; padding: 5px 9px;
}
.rawbtn.on { color: var(--poly); border-color: color-mix(in srgb, var(--poly) 50%, transparent); }
.rawhint { font-size: 11px; color: var(--muted); }
.rawbox { border-top: 1px solid var(--rule); background: var(--bg); }
.rawhead {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--rule-soft); color: var(--muted);
}
.rawhead .mono { font-size: 11px; }
.copybtn { font-size: 10.5px; padding: 5px 9px; }
.rawpre {
  margin: 0; padding: 14px 18px; max-height: 460px; overflow: auto;
  font: 11.5px/1.65 var(--mono); color: var(--ink-2); white-space: pre;
  tab-size: 2;
}
.rawpend { padding: 14px 18px; font-size: 12px; color: var(--muted); }

/* Game date — a series repeats the same club pair, so the fixture line has to
   carry the date or three cards read as one duplicated three times. */
.when { color: var(--ink-2); font-size: 11px; font-weight: 500; }
.thin { font-weight: 500; color: var(--idle); letter-spacing: 0.06em; }
