:root {
  --bg: #0f1117;
  --panel: #171a23;
  --ink: #e8eaf0;
  --muted: #8b90a0;
  --grid: #262a36;
  --accent: #ffcc33;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
header {
  padding: 20px 28px 12px;
  border-bottom: 1px solid var(--grid);
}
h1 { margin: 0 0 10px; font-size: 18px; font-weight: 650; }
.controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
label { color: var(--muted); font-size: 13px; }
select {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  margin-left: 6px;
}
.summary { color: var(--muted); font-size: 13px; }
.summary b { color: var(--accent); }
main { padding: 18px 28px 40px; max-width: 1100px; }
/* the chart owns drag gestures: no page scroll/zoom while interacting */
#chart-wrap { position: relative; touch-action: none; }
#chart { width: 100%; height: 345px; display: block; touch-action: none; }
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  margin: 14px 0 4px;
}
.legend .item {
  display: flex; align-items: center; gap: 7px;
  cursor: pointer; user-select: none;
  font-size: 13px; color: var(--ink);
  padding: 2px 4px; border-radius: 4px;
}
.legend .item.off { opacity: .35; }
.legend .sw { width: 22px; height: 3px; border-radius: 2px; }
.legend .win::after { content: " ★"; color: var(--accent); }
.note { color: var(--muted); font-size: 12px; max-width: 760px; margin-top: 16px; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(20,23,32,.97);
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12px;
  min-width: 170px;
  box-shadow: 0 6px 22px rgba(0,0,0,.45);
}
.tooltip h4 { margin: 0 0 6px; font-size: 12px; color: var(--accent); }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .row span:first-child { color: var(--muted); }
.tooltip .ph { color: var(--muted); margin-top: 5px; font-size: 11px; }

/* svg primitives */
.axis { stroke: var(--grid); stroke-width: 1; }
.gridline { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 2 4; }
.tick { fill: var(--muted); font-size: 11px; }
.divider { stroke: #5a6172; stroke-width: 1.5; stroke-dasharray: 6 5; }
.divider-label { fill: var(--muted); font-size: 11px; }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; }
.series.faint { stroke: #3a3f4d; stroke-width: 1; }
.series.win { stroke-width: 3.5; }
.guide { stroke: #4a5066; stroke-width: 1; stroke-dasharray: 3 3; }
.locked { stroke: var(--accent); stroke-width: 1.5; opacity: .55; }
.mk-elim line { stroke-width: 2.5; stroke-linecap: round; }
.tooltip .ev { margin-top: 4px; font-size: 11px; color: #c9cede; }
.legendkey { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.legendkey b { color: var(--ink); font-weight: 600; }

/* detail tile */
.panel {
  margin: 16px 0 4px;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 10px;
  padding: 14px 16px;
}
.panel .phead { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.panel .phead b { color: var(--ink); }
.panel .preview { color: var(--muted); font-style: italic; margin-left: 6px; }
.panel .lk { color: var(--accent); margin-left: 6px; }
.panel .cols { display: flex; gap: 34px; flex-wrap: wrap; }
.panel .col { flex: 1; min-width: 280px; }
.panel h3 {
  margin: 0 0 9px; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.brow {
  display: grid; grid-template-columns: 130px 1fr 46px;
  align-items: center; gap: 9px; height: 21px; font-size: 12px;
}
.brow .bl { color: var(--ink); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.brow .bt { background: #20242f; border-radius: 3px; height: 9px; }
.brow .bf { display: block; height: 100%; border-radius: 3px;
  background: #4f7cc4; }
.brow .bv { text-align: right; color: var(--muted);
  font-variant-numeric: tabular-nums; }
.brow.win .bl { color: var(--accent); font-weight: 600; }
.brow.win .bf { background: var(--accent); }
.brow.win .bv { color: var(--accent); }

/* ---- mobile / narrow screens ---- */
@media (max-width: 640px) {
  header { padding: 14px 14px 10px; }
  h1 { font-size: 15px; margin-bottom: 8px; }
  .controls { gap: 10px; }
  select { padding: 7px 8px; }      /* easier tap target */
  main { padding: 12px 14px 28px; }

  #chart { height: 46vh; min-height: 225px; max-height: 330px; }

  .legend { gap: 5px 12px; }
  .legend .item { padding: 4px 4px; font-size: 12px; }
  .note, .legendkey { max-width: none; }

  /* tile: single column, full width */
  .panel { padding: 12px; }
  .panel .cols { gap: 16px; }
  .panel .col { min-width: 0; flex: 1 1 100%; }
  .brow {
    grid-template-columns: minmax(0, 1fr) 1.2fr 42px;
    gap: 7px; height: 22px;
  }
}
