:root {
  --bg: #090c13;
  --panel: #0d121d;
  --ink: #eef1f6;
  --mute: #8b93a5;
  --rule: rgba(255, 255, 255, 0.1);
  --loss: #ff7a33;
  --gain: #4ea8ff;
  --accent: #ffd166;
}

html, body { height: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#app {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(130% 100% at 55% 35%, #121a2b 0%, var(--bg) 72%);
}

/* ---------------------------------------------------------------- header */

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 16px 24px 0;
  flex: none;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
}

h1 {
  margin: 6px 0 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

h2 {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 1.2;
}

.sub {
  margin: 6px 0 0;
  max-width: 760px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--mute);
}
.sub b { color: var(--ink); font-weight: 600; }
.sub .l { color: var(--loss); font-weight: 600; }
.sub .g { color: var(--gain); font-weight: 600; }
.sub .a { color: var(--accent); font-weight: 600; }

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
  font-size: 12px;
  color: var(--mute);
  white-space: nowrap;
}
.legend .ramp {
  display: inline-block;
  width: 96px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #ff5a1f, #ff9558, #c3ccdc, #72b1ff, #3a86ff);
}
.legend em { font-style: normal; margin-left: 10px; opacity: 0.8; }

/* ---------------------------------------------------------------- river */

#river {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.chips {
  position: absolute;
  left: 20px;
  bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.group {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px;
}
.group .lab {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mute);
  padding: 0 8px 0 10px;
}
.group button, .solo {
  font: inherit;
  font-size: 12.5px;
  color: var(--mute);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.group button:hover, .solo:hover { color: var(--ink); }
.group button.on { background: rgba(255, 255, 255, 0.14); color: var(--ink); }
.solo { border: 1px solid var(--rule); background: rgba(255, 255, 255, 0.05); }
.solo.on { border-color: rgba(255, 209, 102, 0.6); color: var(--accent); background: rgba(255, 209, 102, 0.1); }

.pill {
  position: absolute;
  right: 24px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 55%;
  font-size: 12.5px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
}
.pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill button {
  flex: none;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  line-height: 18px;
  cursor: pointer;
}

.foot {
  position: absolute;
  right: 24px;
  bottom: 18px;
  font-size: 10.5px;
  color: rgba(139, 147, 165, 0.6);
  pointer-events: none;
}
.pill:not([hidden]) ~ .foot { display: none; }

/* ---------------------------------------------------------------- season */

#season {
  flex: none;
  display: flex;
  flex-direction: column;
  margin: 0 16px 14px;
  padding: 12px 16px 12px;
  background: rgba(13, 18, 29, 0.82);
  border: 1px solid var(--rule);
  border-radius: 14px;
}

.shead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex: none;
}
.shead .sub { font-size: 12.5px; margin-top: 4px; max-width: 820px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.sbody {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) 210px;
  gap: 18px;
  margin-top: 10px;
}
.mchart, .heatwrap { position: relative; min-width: 0; min-height: 0; }
#months, #heat { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
#months { cursor: crosshair; touch-action: none; }

svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.cell { cursor: pointer; }
.ylab { cursor: pointer; }
.ylab:hover { fill: var(--ink); }

.kpis {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
  border-left: 1px solid var(--rule);
  padding-left: 16px;
}
.kpis .scope { font-size: 12px; color: var(--accent); font-weight: 600; line-height: 1.3; }
.kpis .k { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kpis .k span { font-size: 11.5px; color: var(--mute); }
.kpis .k b { font-size: 14.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpis .k b.l { color: var(--loss); }
.kpis .k b.g { color: var(--gain); }
.kpis .note { font-size: 11.5px; color: var(--mute); line-height: 1.4; margin-top: 2px; }
.kpis .note b { color: var(--ink); }

/* ---------------------------------------------------------------- tooltip */

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 170px;
  max-width: 270px;
  background: rgba(14, 19, 31, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.tip .t { font-weight: 650; font-size: 13.5px; margin-bottom: 3px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; color: var(--mute); }
.tip .r b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .r b.l { color: var(--loss); }
.tip .r b.g { color: var(--gain); }
.tip .hint { margin-top: 5px; font-size: 11px; color: var(--mute); }

.error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--loss);
  font-size: 14px;
}

/* ---------------------------------------------------------------- sizes */

#app.narrow .sbody { grid-template-columns: minmax(0, 1fr) 190px; }
#app.narrow .heatwrap { display: none; }
#app.narrow .shead { flex-direction: column; }
#app.narrow .controls { justify-content: flex-start; }
#app.narrow .shead .sub { display: none; }

#app.compact .sub, #app.compact .legend em, #app.compact .foot { display: none; }
#app.compact h1 { font-size: 17px; }
#app.compact .head { padding: 10px 14px 0; }
#app.compact .chips { left: 10px; bottom: 6px; gap: 6px; }
#app.compact .group .lab { display: none; }
#app.compact .group button, #app.compact .solo { padding: 3px 8px; font-size: 11.5px; }
#app.compact .pill { right: 14px; bottom: 6px; }

#app.strip .head, #app.strip .chips, #app.strip .foot, #app.strip .pill { display: none; }

@media (prefers-reduced-motion: reduce) {
  .group button, .solo { transition: none; }
}

/* Wide: the season story sits in a left column beside its charts. */
#app.wide #season { flex-direction: row; gap: 26px; padding: 14px 18px; }
#app.wide .shead { flex: 0 0 360px; flex-direction: column; justify-content: space-between; gap: 10px; min-height: 0; overflow: hidden; }
#app.wide .shead .sub { max-width: none; font-size: 13px; line-height: 1.5; }
#app.wide .controls { justify-content: flex-start; }
#app.wide .sbody { flex: 1 1 auto; min-width: 0; margin-top: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 200px; gap: 20px; }
#app.wide .kpis .k b { font-size: 15.5px; }
#app.wide .kpis .k span { font-size: 12px; }

#app.tiny .sbody { grid-template-columns: minmax(0, 1fr); }
#app.tiny .kpis { display: none; }
#app.tiny .controls .group button { padding: 4px 8px; font-size: 11.5px; }
#app.tiny #season { margin: 0 8px 8px; padding: 10px 10px; }
