:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-raised: #1f2630;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --gold: #e3b341;
  --up: #3fb950;
  --down: #f85149;
  --warn: #d29922;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--gold); }
h1, h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
h2 .small, h1 .small { text-transform: none; letter-spacing: 0; font-weight: 400; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.error { color: var(--down); margin-top: 8px; }

.feed-notice {
  background: var(--warn);
  color: #1a1300;
  font-weight: 700;
  text-align: center;
  padding: 6px 16px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--gold); }
/* The logo is dark red on white and must not be recoloured, so on this dark theme it keeps its white background. */
.brand-logo { display: block; width: auto; height: 40px; background: #fff; border-radius: 4px; }
@media (min-width: 768px) {
  .brand-logo { height: 52px; }
}
.topbar-status { display: flex; align-items: center; gap: 10px; }
.topbar-user { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-left: auto; }

.pill { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; white-space: nowrap; }
.pill-live { background: rgba(63, 185, 80, 0.16); color: var(--up); }
.pill-stale, .pill-reconnecting { background: rgba(248, 81, 73, 0.16); color: var(--down); }
.pill-delayed { background: rgba(210, 153, 34, 0.18); color: var(--warn); }
.pill-closed { background: rgba(154, 164, 178, 0.16); color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
  padding: 12px 16px 24px;
  max-width: 1800px;
  margin: 0 auto;
}
.layout > * { min-width: 0; }
.layout > .hero, .layout > .units { grid-column: span 4; }
.layout > .chart-panel { grid-column: span 8; grid-row: span 2; display: flex; flex-direction: column; }
.layout > .board { grid-column: span 6; }
.layout > .lbma { grid-column: span 6; }
.layout > .purity { grid-column: span 4; }
.layout > .performance { grid-column: span 8; }
.layout > .closes { grid-column: span 12; }

.attribution { padding: 0 16px 16px; color: var(--muted); font-size: 12px; text-align: center; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 8px; }
.panel > h2 { margin-bottom: 8px; }

.selectors { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.selectors label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }

select, input, .button, .segment button {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  min-height: 32px;
  padding: 3px 8px;
}
.button { display: inline-flex; align-items: center; text-decoration: none; }
.segment { display: inline-flex; flex-wrap: wrap; }
.segment button { border-radius: 0; margin-left: -1px; cursor: pointer; }
.segment button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.segment button:last-child { border-radius: 0 6px 6px 0; }
.segment button[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #1a1300; font-weight: 600; }
.link-button { background: none; border: 0; padding: 0; color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.quote { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.quote-side { display: flex; flex-direction: column; min-width: 0; }
.label { color: var(--muted); font-size: 12px; }
.big { font-size: clamp(24px, 4vw, 40px); font-weight: 700; line-height: 1.15; border-radius: 4px; }
.change { font-size: 18px; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 12px 0 0; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-weight: 600; }

/* Height comes from the layout only. If the chart's own canvas could add to it, the two
   would feed each other and the page would grow forever. */
.chart { flex: 1 1 0; height: 0; min-height: 460px; width: 100%; overflow: hidden; }

.lbma > p { margin-bottom: 8px; }
.lbma-sim { color: var(--warn); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 5px 6px; text-align: left; font-weight: 400; border-bottom: 1px solid rgba(48, 54, 61, 0.6); white-space: nowrap; }
thead th { color: var(--muted); font-size: 12px; background: var(--panel); }
.closes-scroll thead th { position: sticky; top: 0; }
tbody th { font-weight: 600; }
.num { text-align: right; }
tr.selected { background: var(--panel-raised); }
.table-wrap { overflow-x: auto; }
.closes-scroll { max-height: 360px; overflow-y: auto; }

/* A source with one price has no ask or spread to show. */
.no-bid-ask .ask-only { display: none; }
.no-bid-ask .quote, .no-bid-ask .tv-quote { grid-template-columns: 1fr; }

/* An old price must never look live. */
.prices-frozen .price, .row-stale .price,
.prices-frozen .change, .prices-frozen .tv-change { color: var(--muted); opacity: 0.6; }

.flash-up { animation: flash-up 0.6s ease-out; }
.flash-down { animation: flash-down 0.6s ease-out; }
@keyframes flash-up { from { background: rgba(63, 185, 80, 0.4); } to { background: transparent; } }
@keyframes flash-down { from { background: rgba(248, 81, 73, 0.4); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) {
  .flash-up, .flash-down { animation: none; }
}

@media (max-width: 1279px) {
  .layout > .hero { grid-column: span 12; order: 1; }
  .layout > .chart-panel { grid-column: span 12; grid-row: auto; order: 2; }
  .layout > .board { grid-column: span 12; order: 3; }
  .layout > .lbma { grid-column: span 12; order: 4; }
  .layout > .units { grid-column: span 7; order: 5; }
  .layout > .purity { grid-column: span 5; order: 6; }
  .layout > .performance { grid-column: span 12; order: 7; }
  .layout > .closes { order: 8; }
  .chart { min-height: 400px; }
}

@media (max-width: 680px) {
  .layout { gap: 10px; padding: 10px 10px 20px; }
  .layout > .units, .layout > .purity { grid-column: span 12; }
  .chart { min-height: 300px; }
  .hide-narrow { display: none; }
  .topbar-user { margin-left: 0; }
  th, td { padding: 6px 4px; }
  /* Comfortable touch targets on phones. */
  select, input, .button, .segment button { min-height: 40px; }
}

/* Forms shared by the pairing page. */
.narrow-page { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
.pair-note { margin: 8px 0 12px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-row input { width: 100%; }
.primary { background: var(--gold); color: #1a1300; border: 0; border-radius: 6px; font: inherit; font-weight: 600; min-height: 40px; padding: 6px 14px; cursor: pointer; }
.success { color: var(--up); }
.login-page { max-width: 400px; margin: 0 auto; padding: 32px 16px; }
.login-page h1 { margin: 0 0 16px; }
/* 16px stops phones zooming in when a field is tapped. */
.login-page input { font-size: 16px; min-height: 40px; }
.login-page .primary { width: 100%; }
.login-error { color: var(--down); margin: 12px 0 0; }
