:root {
  --bg: #0b0e13;
  --panel: #10141b;
  --fg: #e8edf4;
  --muted: #8b95a5;
  --grid: #1e242d;
  --zero: #6d7787;
  --origin: #9aa6b8;

  /* Instrument lines: two distinct light hues, readable on near-black. */
  --a: #7fd7ff;   /* TSLA */
  --b: #ffc46b;   /* SPCX */

  /* Spread shading. Green = TSLA leading (see GREEN_WHEN_TSLA_LEADS). */
  --fill-lead: rgba(74, 222, 128, 0.22);
  --fill-lag: rgba(248, 113, 113, 0.22);
  --up: #5ee08a;
  --down: #ff7b7b;

  --sma1: #b9a8ff;
  --sma2: #79e6d3;

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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) 14px;
  gap: 6px;
}

#head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 26px;
  flex: 0 0 auto;
}

.cell { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cell.right { margin-left: auto; }

.cell .k {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.cell .v {
  font-family: var(--mono);
  font-size: 22px;
  line-height: 1.15;
  white-space: nowrap;
}

.cell .v em { font-style: normal; font-size: 17px; }
.cell .v b { font-weight: 600; }

#cell-a .k { color: var(--a); }
#cell-b .k { color: var(--b); }

#cell-meta .v { font-size: 15px; color: var(--muted); }
#cell-origin .v { font-size: 15px; }

.flags { margin-left: 8px; font-size: 11px; letter-spacing: .06em; }
.flags span {
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 5px;
  text-transform: uppercase;
}
.flag-stale { color: var(--down); }
.flag-delayed { color: var(--muted); }

.up { color: var(--up); }
.down { color: var(--down); }

#cell-sma .v { font-size: 13px; display: flex; gap: 12px; align-items: center; }
#cell-sma label { display: flex; gap: 5px; align-items: center; cursor: pointer; }
#cell-sma input[type=number] {
  width: 3.6em;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--grid);
  border-radius: 4px;
  font: inherit;
  padding: 1px 3px;
}
#cell-sma input[type=checkbox] { accent-color: var(--fg); margin: 0; }
.swatch { display: inline-block; width: 14px; border-top: 2px dashed currentColor; }
.smaval { color: var(--muted); font-family: var(--mono); margin-left: 2px; }

#notes {
  margin: 0;
  min-height: 14px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

#chartwrap { flex: 1 1 auto; min-height: 160px; position: relative; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; }

#sliderrow { flex: 0 0 auto; }

#origin {
  width: 100%;
  margin: 0;
  accent-color: var(--origin);
  background: transparent;
}

#signout {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  border-bottom: 1px solid var(--grid);
}
#signout:hover { color: var(--fg); }

#gate {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
#gate[hidden] { display: none; }
#gate button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
}

@media (max-width: 620px) {
  #head { gap: 4px 16px; }
  .cell .v { font-size: 18px; }
  .cell.right { margin-left: 0; }
}
