:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --line: #dedcd6;
  --ink: #0b0b0b; --ink-2: #52514e; --ink-3: #7a7873;
  --bid: #2a78d6; --ask: #eb6834; --maker: #1baf7a; --mine: #e87ba4; --accent: #0f8b94;
  --good: #0ca30c; --critical: #d03b3b;
  --bid-bar: #cde2fb; --ask-bar: #fbdccd;
  --radius: 12px; --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #33322f;
    --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #8f8e86;
    --bid: #3987e5; --ask: #d95926; --maker: #199e70; --mine: #d55181; --accent: #39c5cf;
    --bid-bar: #17365e; --ask-bar: #4a2618;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #33322f;
  --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #8f8e86;
  --bid: #3987e5; --ask: #d95926; --maker: #199e70; --mine: #d55181; --accent: #39c5cf;
  --bid-bar: #17365e; --ask-bar: #4a2618;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { padding: 0 16px calc(24px + env(safe-area-inset-bottom)); max-width: 1080px; margin: 0 auto; }
main { display: grid; gap: 14px; min-width: 0; }
.card, .two > div, .tile { min-width: 0; }
h2 { font-size: 15px; margin: 0; font-weight: 650; }
.muted { color: var(--ink-3); font-weight: 400; }
code { font-family: var(--mono); font-size: 12px; }
a { color: var(--accent); }
button { font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; }
button[disabled] { opacity: .5; cursor: default; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0 10px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.sub { color: var(--ink-2); font-size: 13px; }
.pill { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); }
.pill.up .dot { background: var(--good); }
.pill.down .dot { background: var(--critical); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head .muted { font-size: 12px; }

.about summary { cursor: pointer; font-weight: 650; }
.about summary .open-page { float: right; font-weight: 400; font-size: 12.5px; color: var(--accent); text-decoration: none; }
.about-body { margin-top: 10px; color: var(--ink-2); font-size: 14px; }
.about-body ul { padding-left: 18px; }
.about-body li { margin: 6px 0; }
.about-body b, .about-body i, .about-body em { color: var(--ink); }
.topo { display: grid; gap: 6px 4px; margin: 12px 0; align-items: stretch; font-size: 12px;
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr) max-content minmax(0, 1.15fr) max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  grid-template-areas:
    "l1 feed a1  md     a2  trader .   .   .   ."
    "l5 cfs  a9  cmd    a10 trader .   .   .   ."
    "l2 .    .   .      .   trader a3  gw  a4  me"
    "l6 .    .   .      .   trader a11 cgw a12 cme"
    "l4 page a7  bridge a8  trader .   .   .   ."; }
.topo .lane { grid-row: auto; align-self: center; writing-mode: vertical-rl; transform: rotate(180deg); color: var(--ink-3); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; padding: 0 2px; border-right: 1px solid var(--line); }
.topo .node { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; line-height: 1.3; color: var(--ink-2); min-width: 0; }
.topo .node b { display: block; color: var(--ink); font-family: var(--mono); font-size: 12.5px; margin-bottom: 3px; }
.topo .node.hi { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.topo .arr { align-self: center; justify-self: center; color: var(--ink-3); font-family: var(--mono); font-size: 11px; white-space: normal; max-width: 8.5em; line-height: 1.25; text-align: center; }
.topo .arr::before { content: attr(data-h); }
.topo.post { margin-top: 4px;
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1.1fr) max-content minmax(0, 1fr) max-content minmax(0, 1.2fr) max-content minmax(0, 1.2fr);
  grid-template-areas:
    "l1 me  a1 dc  a2 kafka a3 pos  a4 gui"
    "l1 cme a5 cdc a6 kafka a3 risk a4 gui"; }
.topo.post .node[style*="gui"] { align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.topo .node.nd { border-style: dashed; background: transparent; color: var(--ink-3); position: relative; }
.topo .node.nd b { color: var(--ink-2); }
.topo .node.nd i { display: inline-block; margin-top: 4px; font-style: normal; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); border: 1px dashed var(--line); border-radius: 999px; padding: 1px 6px; }
.legend-note { font-size: 12px; color: var(--ink-3); margin: 6px 0 0; }
.legend-note .sw.nd { display: inline-block; width: 12px; height: 10px; border: 1px dashed var(--ink-3); border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
@media (max-width: 719px) {
  .topo { display: flex; flex-direction: column; gap: 6px; }
  .topo.post .lane { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
  .topo .lane { writing-mode: horizontal-tb; transform: none; border-right: 0; border-top: 1px solid var(--line); padding: 8px 0 2px; margin-top: 4px; }
  .topo .lane[style*="l1"] { border-top: 0; margin-top: 0; padding-top: 0; order: 1; }
  .topo.post .lane[style*="l1"] { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
  .topo .arr::before { content: attr(data-v); }
  .topo .arr { padding: 2px 0; max-width: none; }
}

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile .s { font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; }

.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.bid { background: var(--bid); } .sw.ask { background: var(--ask); } .sw.maker { background: var(--maker); } .sw.mine { background: var(--mine); }

.ladder { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 2px 8px; font-family: var(--mono); font-size: 13.5px; }
.ladder .lvl { display: grid; grid-template-columns: 1fr; position: relative; min-height: 30px; align-items: center; }
.ladder .bar { position: absolute; top: 3px; bottom: 3px; border-radius: 4px; }
.ladder .b .bar { right: 0; background: var(--bid-bar); }
.ladder .a .bar { left: 0; background: var(--ask-bar); }
.ladder .txt { position: relative; display: flex; justify-content: space-between; padding: 0 8px; gap: 8px; }
.ladder .b .txt { flex-direction: row-reverse; }
.ladder .px { grid-column: 2; align-self: center; text-align: center; padding: 0 6px; color: var(--ink-2); min-width: 92px; }
.ladder .px.best { color: var(--ink); font-weight: 700; }
.ladder .tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; color: #fff; }
.tag.maker { background: var(--maker); } .tag.mine { background: var(--mine); }
.ladder .spr { grid-column: 1 / -1; text-align: center; color: var(--ink-3); font-size: 12px; padding: 4px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); }
.signal { margin-top: 10px; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px 14px; flex-wrap: wrap; font-family: var(--mono); overflow-wrap: anywhere; }
.spark-wrap { position: relative; margin-top: 10px; }
#spark { width: 100%; height: 64px; display: block; }
#spark .line { fill: none; stroke: var(--bid); stroke-width: 2; vector-effect: non-scaling-stroke; }
#spark .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
#spark .cross { stroke: var(--ink-3); stroke-width: 1; vector-effect: non-scaling-stroke; }
#spark .pt { fill: var(--bid); stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-tip { position: absolute; top: 0; right: 0; font: 12px var(--mono); color: var(--ink-2); background: var(--surface-2); padding: 2px 8px; border-radius: 6px; pointer-events: none; }

.pad .row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on[data-side="SELL"] { background: var(--ask); }
.qty { display: inline-flex; align-items: center; gap: 8px; }
.qty button { min-width: 44px; padding: 8px 0; }
.qty span { font-family: var(--mono); font-size: 18px; min-width: 20px; text-align: center; }
.chip.on { background: var(--surface-2); border-color: var(--ink); }
.pad label { display: flex; align-items: center; gap: 8px; }
.pad input { font: inherit; font-family: var(--mono); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); width: 130px; }
.msg { min-height: 20px; font-size: 13.5px; color: var(--ink-2); }
.msg.err { color: var(--critical); }
.open { display: grid; gap: 4px; margin-top: 6px; font-family: var(--mono); font-size: 13px; }
.open .o { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 6px 8px; background: var(--surface-2); border-radius: 8px; }
.open .muted { overflow-wrap: anywhere; }
.open .o.mine { outline: 1px solid var(--mine); }

.two { display: grid; gap: 14px; }
@media (min-width: 720px) { .two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.tape { font-family: var(--mono); font-size: 12.5px; max-height: 340px; overflow: auto; display: grid; gap: 2px; }
.tape .r { display: grid; grid-template-columns: 66px 58px 40px minmax(0, 1fr); gap: 6px; padding: 4px 6px; border-radius: 6px; align-items: center; }
.tape .r > span { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .tape .bbo { display: none; } }
.tape .r.visitor { background: var(--surface-2); }
.tape .r .who { color: var(--ink-3); }
.tape .r .who.maker { color: var(--maker); } .tape .r .who.visitor { color: var(--mine); }
.tape .act { font-weight: 600; }
.tape .side.BUY { color: var(--bid); } .tape .side.SELL { color: var(--ask); }
.tape .t { color: var(--ink-3); }

.procs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.proc { font-family: var(--mono); font-size: 12.5px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.proc .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }
.proc.up .dot { background: var(--good); }
.foot { color: var(--ink-2); font-size: 13px; padding: 4px 2px 12px; }

/* news windows: the maker pulls quotes around High-impact releases / its auction */
.newsbar { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--ink-2); background: var(--surface); }
.newsbar.paused { border-color: var(--s2); background: color-mix(in srgb, var(--s2) 10%, var(--surface)); color: var(--ink); }
.newsbar b { color: var(--ink); }

/* CME hedge leg */
.cme .two { display: grid; gap: 14px; }
@media (min-width: 900px) { .cme .two { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); } }
.cme-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
.cme .note { font-size: 12.5px; color: var(--ink-2); margin: 10px 0 6px; }
.cme .note code { font-size: 11.5px; }
.tape .r .who.hedge { color: var(--maker); }
.tape .r.hedge { box-shadow: inset 3px 0 0 var(--maker); }

/* post-trade: drop copy -> Kafka -> position server -> risk server */
.post .post-grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .post .post-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); } }
.post h3 { font-size: 12.5px; font-weight: 650; margin: 10px 0 4px; }
.post h3:first-child { margin-top: 0; }
.post h3 .muted { font-weight: 500; font-size: 11.5px; }
table.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.mini th, table.mini td { padding: 3px 6px; text-align: left; border-bottom: 1px solid var(--line); }
table.mini th { color: var(--ink-3); font-weight: 600; font-size: 11.5px; }
table.mini .num { text-align: right; font-variant-numeric: tabular-nums; }
table.mini .mono { font-family: var(--mono); font-size: 12px; }
.post .note { font-size: 12.5px; color: var(--ink-2); margin: 10px 0 0; }
.post .note code { font-size: 11.5px; }
.post .tape { max-height: 300px; }
