:root {
  --bg: #0a0d14;
  --ink: #e8eef8;
  --dim: #8d99ad;
  --faint: #566174;
  --line: #222b3b;
  --gain: #4ea8ff;
  --loss: #ff7433;
  --chip: #131a26;
  --chipOn: #e8eef8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; overflow: hidden; background: var(--bg); }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

.top {
  position: absolute; left: 20px; right: 20px; top: 16px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
  pointer-events: none;
}
.head { max-width: 560px; }
.kicker { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
h1 { margin: 6px 0 0; font-size: 26px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; font-size: 13px; line-height: 1.4; color: var(--dim); }

.counter { text-align: right; flex: none; }
.date { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stats { display: flex; gap: 18px; justify-content: flex-end; margin-top: 6px; }
.stats > div { display: flex; flex-direction: column; align-items: flex-end; }
.lab { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.val { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.val.neg { color: var(--loss); }

.bottom {
  position: absolute; left: 16px; right: 16px; bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.info { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; min-height: 18px; }
.finding { font-size: 13px; line-height: 1.4; color: var(--ink); max-width: 760px; }
.finding b { font-weight: 650; }
.finding .k { color: var(--dim); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; margin-right: 6px; }
.legend { font-size: 11px; color: var(--dim); white-space: nowrap; display: flex; gap: 12px; flex: none; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }

#pulse { width: 100%; height: 56px; display: block; cursor: ew-resize; touch-action: none; }

.controls { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.group { display: flex; gap: 4px; }
.chip {
  border: 1px solid var(--line); background: var(--chip); color: var(--ink);
  border-radius: 999px; padding: 5px 11px; font-size: 12px; line-height: 1.2; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { border-color: #3a4558; }
.chip.on { background: var(--chipOn); color: #0a0d14; border-color: var(--chipOn); }
.chip.play { min-width: 64px; font-weight: 600; }
.chip.lossOn { background: var(--loss); border-color: var(--loss); color: #140803; }
.chip.hubsOn { background: #ffc23d; border-color: #ffc23d; color: #1a1300; font-weight: 600; }
.chip:focus-visible { outline: 2px solid var(--gain); outline-offset: 2px; }

.callout {
  position: absolute; transform: translateX(-50%);
  background: rgba(10, 13, 20, 0.9); border: 1px solid #2c3648; border-radius: 10px;
  padding: 9px 14px; font-size: 14px; line-height: 1.35; text-align: center; max-width: min(520px, calc(100% - 32px));
  pointer-events: none;
}
.callout b { font-weight: 700; }
.callout .k { display: block; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); margin-bottom: 2px; }

.hubBanner {
  position: absolute; z-index: 4; transform: translateX(-50%);
  width: min(680px, calc(100% - 24px));
  background: #ffc23d; color: #1a1300; border-radius: 8px;
  padding: 8px 12px; font-size: 13px; line-height: 1.35; font-weight: 600; text-align: center;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
@media (max-width: 720px) { .hubBanner { font-size: 12px; padding: 7px 10px; } }

.tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: rgba(14, 18, 27, 0.96); border: 1px solid #2c3648; border-radius: 8px;
  padding: 8px 11px; font-size: 12px; line-height: 1.45; min-width: 160px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.tip .t { font-weight: 650; font-size: 13px; }
.tip .m { color: var(--dim); }
.tip .row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .neg { color: var(--loss); }
.tip .warn { color: #ffc23d; font-weight: 600; margin: 3px 0 4px; max-width: 280px; }
.tip .hint { color: var(--faint); font-size: 11px; margin-top: 3px; }

.endcard {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(10, 13, 20, 0.86); text-align: center; padding: 24px; pointer-events: none;
}
.endBig { font-size: 34px; font-weight: 700; letter-spacing: -0.01em; }
.endSub { margin-top: 10px; font-size: 14px; color: var(--dim); }

.foot { position: absolute; right: 18px; bottom: 2px; font-size: 9px; color: #3b4556; pointer-events: none; }

.error {
  position: absolute; left: 20px; right: 20px; top: 45%; text-align: center;
  color: var(--loss); font-size: 14px;
}

@media (max-width: 720px) {
  .top { flex-direction: column; gap: 10px; left: 16px; right: 16px; top: 14px; }
  h1 { font-size: 22px; }
  .sub { font-size: 12px; }
  .counter { text-align: left; width: 100%; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .date { font-size: 16px; }
  .stats { gap: 14px; margin-top: 0; }
  .val { font-size: 14px; }
  .info { flex-direction: column; align-items: flex-start; gap: 4px; }
  .finding { font-size: 12px; }
  #pulse { height: 48px; }
  .chip { padding: 5px 9px; font-size: 11.5px; }
  .controls { gap: 6px 6px; }
  .endBig { font-size: 26px; }
}
@media (max-width: 420px) {
  .counter { flex-direction: column; align-items: flex-start; gap: 4px; }
  .stats > div { align-items: flex-start; }
}
