:root {
  --bg: #f7f5ef;
  --panel: #fcfaf4;
  --panel-2: #ffffff;
  --ink: #0c1018;
  --ink-soft: #4a5060;
  --ink-faint: #8a8f9d;
  --line: #e2dccc;
  --line-soft: #ece6d5;

  --bl: oklch(0.54 0.14 32);     /* freeze red */
  --bl-soft: oklch(0.93 0.05 32);
  --ub: oklch(0.52 0.12 158);    /* unfreeze green */
  --ub-soft: oklch(0.93 0.04 158);
  --na: oklch(0.62 0.08 75);     /* unattributed amber */
  --na-soft: oklch(0.94 0.04 75);
  --court: oklch(0.50 0.12 260);
  --hack: oklch(0.55 0.14 320);

  --shadow-sm: 0 1px 0 rgba(20,20,30,0.04);
  --shadow: 0 1px 0 rgba(20,20,30,0.04), 0 6px 18px -10px rgba(20,20,30,0.10);

  --sans: 'Inter Tight', ui-sans-serif, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --serif: 'Source Serif 4', Georgia, serif;
}
body.dark {
  --bg: #0e0f12;
  --panel: #15171c;
  --panel-2: #1b1d23;
  --ink: #ecedf0;
  --ink-soft: #b3b8c4;
  --ink-faint: #6f7380;
  --line: #292d36;
  --line-soft: #1c1f25;
  --bl: oklch(0.66 0.16 32);
  --ub: oklch(0.66 0.13 158);
  --na: oklch(0.7 0.10 75);
  --court: oklch(0.65 0.14 260);
  --hack: oklch(0.66 0.15 320);
  --bl-soft: oklch(0.30 0.10 32);
  --ub-soft: oklch(0.28 0.08 158);
  --na-soft: oklch(0.30 0.08 75);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  transition: background 200ms ease, color 200ms ease;
}

/* ===== Header ===== */
.header {
  padding: 36px 48px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: relative;
}
.header-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 32px; margin-bottom: 18px;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  display: flex; align-items: center; gap: 10px;
}
.eyebrow .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--bl);
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--bl) 18%, transparent);
}
.eyebrow .sep { color: var(--ink-faint); opacity: 0.5; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  background: var(--panel);
}
.theme-toggle button {
  border: 0; background: transparent;
  width: 28px; height: 24px; border-radius: 999px;
  cursor: pointer; color: var(--ink-faint);
  font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 120ms;
}
.theme-toggle button.active {
  background: var(--ink);
  color: var(--bg);
}
.header h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 52px;
  line-height: 1.02;
  letter-spacing: -0.025em;
  margin: 0 0 14px;
  max-width: 22ch;
  text-wrap: balance;
}
.header h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--bl);
}
.header .subhead {
  font-size: 16.5px;
  color: var(--ink-soft);
  max-width: 64ch;
  margin: 0;
  text-wrap: pretty;
}
.header .nav {
  display: flex; gap: 22px;
  margin-top: 22px;
  font-size: 13px;
}
.header .nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding-bottom: 4px;
  border-bottom: 1px solid transparent;
}
.header .nav a.current {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 600;
}
.header .nav a:hover { color: var(--ink); }

/* ===== KPI strip ===== */
.kpis {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.kpi {
  background: var(--panel);
  padding: 20px 22px 18px;
  min-width: 0;
  cursor: pointer;
  transition: background 120ms;
  position: relative;
}
.kpi:hover { background: color-mix(in oklch, var(--panel) 90%, var(--ink) 5%); }
.kpi .k-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 7px;
}
.kpi .k-swatch {
  width: 8px; height: 8px; border-radius: 1px;
  flex-shrink: 0;
}
.kpi .k-value {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 36px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: block;
}
.kpi .k-unit {
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 400;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
  display: block;
}
.kpi .k-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
  line-height: 1.4;
}
.kpi .k-bar {
  height: 3px; margin-top: 10px;
  background: var(--line-soft);
  border-radius: 2px;
  overflow: hidden;
}
.kpi .k-bar > span {
  display: block; height: 100%;
  background: var(--bl);
  transition: width 400ms ease;
}
.kpi .k-spark {
  margin-top: 10px;
  height: 24px;
  width: 100%;
  display: block;
}

/* ===== Filters ===== */
.controls {
  padding: 16px 48px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 28px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  background: var(--panel);
}
.filter-group {
  display: flex; align-items: center; gap: 10px;
}
.filter-group .fg-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.10em;
}
.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 5px 11px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 100ms;
}
.chip:hover { color: var(--ink); border-color: var(--ink-faint); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.chip[aria-pressed="true"] .chip-count { color: var(--bg); opacity: 0.7; }
.chip .chip-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.chip .chip-count {
  font-family: var(--mono);
  font-size: 10.5px;
  opacity: 0.7;
}
.chip .chip-x {
  margin-left: 2px; opacity: 0.6; font-size: 11px;
}
.controls .reset {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: inline-flex; align-items: center; gap: 5px;
}
.controls .reset:hover { color: var(--ink); }

/* ===== Main layout ===== */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  background: var(--panel);
}
.main-left { min-width: 0; border-right: 1px solid var(--line); }
.main-right {
  background: var(--panel);
  padding: 20px 24px 26px;
  display: flex; flex-direction: column; gap: 22px;
  min-width: 0;
}

/* ===== Chart ===== */
.chart-wrap {
  padding: 22px 36px 8px 48px;
  background: var(--panel);
}
.chart-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap; gap: 12px;
}
.chart-head h2 {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chart-head h2 .h2-faint {
  color: var(--ink-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 8px;
}
.chart-head .legend {
  display: flex; gap: 16px;
  font-size: 11px;
  color: var(--ink-soft);
}
.chart-head .legend > span {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chart-head .legend i {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
}
.chart-head .legend i.ring {
  background: transparent;
  border: 2px solid var(--na);
}
.timeline-svg {
  width: 100%;
  display: block;
  height: auto;
  user-select: none;
}
.brush-wrap {
  padding: 4px 36px 18px 48px;
  background: var(--panel);
  position: relative;
}
.brush-svg {
  width: 100%;
  height: 64px;
  display: block;
}
.brush-hint {
  position: absolute;
  top: 8px; right: 36px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  pointer-events: none;
}

/* ===== Detail card ===== */
.detail-card {
  margin: 18px 36px 28px 48px;
  padding: 20px 24px 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--bl);
  border-radius: 3px;
  min-height: 130px;
  transition: border-left-color 200ms;
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 24px;
  row-gap: 10px;
}
.detail-card.empty { border-left-color: var(--line); }
.detail-card.unbl { border-left-color: var(--ub); }
.detail-card.empty .dc-body { color: var(--ink-faint); font-style: italic; }
.dc-head {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  grid-column: 1;
}
.dc-count-cell {
  grid-column: 2; grid-row: 1 / span 2;
  text-align: right;
  align-self: start;
  padding-left: 16px;
  border-left: 1px solid var(--line-soft);
  min-width: 130px;
}
.dc-count-num {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.dc-count-lbl {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 6px;
}
.dc-count-attr {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
}
.dc-date {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.dc-tag {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 2px;
  font-weight: 600;
  background: var(--bl-soft);
  color: var(--bl);
}
.dc-tag.unbl { background: var(--ub-soft); color: var(--ub); }
.dc-tag.muted { background: var(--line-soft); color: var(--ink-soft); }
.dc-tag.pinned { background: var(--ink); color: var(--bg); margin-left: auto; cursor: help; }
.dc-body {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.55;
  grid-column: 1;
}
.dc-body .trigger-desc {
  color: var(--ink);
  margin: 0;
}
.dc-meta {
  grid-column: 1 / -1;
  display: flex; gap: 20px; flex-wrap: wrap;
  font-size: 11px;
  color: var(--ink-faint);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  margin-top: 4px;
}
.dc-meta b {
  color: var(--ink-soft);
  font-weight: 500;
}

/* ===== Right rail panels ===== */
.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.panel-head {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h3 {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.panel-head p {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--ink-faint);
}
.panel-body { padding: 14px 16px 16px; }

/* Reasons donut */
.donut-wrap {
  display: flex; gap: 14px; align-items: center;
}
.donut-svg { width: 96px; height: 96px; flex-shrink: 0; }
.donut-list {
  flex: 1;
  display: flex; flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.donut-row {
  display: grid;
  grid-template-columns: 9px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  cursor: pointer;
  padding: 1px 0;
}
.donut-row:hover .dr-label { color: var(--ink); }
.donut-row .dr-swatch {
  width: 9px; height: 9px; border-radius: 2px;
}
.donut-row .dr-swatch.ring {
  background: transparent !important;
  border: 1.5px solid var(--na);
}
.donut-row .dr-label {
  color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 100ms;
}
.donut-row .dr-val {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  font-weight: 500;
}

/* Top events list */
.top-list {
  display: flex; flex-direction: column;
  gap: 1px;
  background: var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
}
.top-row {
  background: var(--panel-2);
  padding: 9px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: background 100ms;
}
.top-row:hover { background: color-mix(in oklch, var(--panel-2) 90%, var(--ink) 5%); }
.top-row .tr-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--bl);
  align-self: stretch;
}
.top-row .tr-bar.unbl { background: var(--ub); }
.top-row .tr-bar.na { background: var(--na); }
.top-row .tr-text { min-width: 0; }
.top-row .tr-date {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.top-row .tr-desc {
  font-size: 11.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.top-row .tr-count {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}
.top-row .tr-count small {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-faint);
  font-weight: 400;
  margin-left: 1px;
}

/* Year mini bars */
.year-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: 1fr auto;
  gap: 5px 5px;
  height: 110px;
  padding-top: 16px;
}
.year-bar {
  display: grid;
  grid-template-rows: 1fr auto;
  grid-row: 1 / span 2;
  cursor: pointer;
  position: relative;
  min-height: 0;
}
.year-bar .yb-stack {
  display: flex; flex-direction: column;
  justify-content: end;
  gap: 1px;
  min-height: 0;
  height: 100%;
}
.year-bar .yb-seg { background: var(--bl); }
.year-bar .yb-seg.na { background: var(--na); }
.year-bar .yb-seg.court { background: var(--court); }
.year-bar .yb-seg.hack { background: var(--hack); }
.year-bar .yb-label {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  text-align: center;
}
.year-bar:hover .yb-label { color: var(--ink); }
.year-bar .yb-tot {
  position: absolute;
  top: -14px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ===== Footer ===== */
.footer {
  padding: 24px 48px 40px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 11.5px;
  background: var(--bg);
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 28px;
}
.footer h4 {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ink-soft);
  margin: 0 0 8px;
}
.footer p, .footer ul {
  margin: 0;
  line-height: 1.5;
  color: var(--ink-faint);
  font-size: 12px;
}
.footer ul { list-style: none; padding: 0; }
.footer ul li { margin-bottom: 4px; }
.footer a { color: var(--ink-soft); text-decoration: none; border-bottom: 1px solid var(--line); }
.footer a:hover { color: var(--ink); }

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 9px;
  border-radius: 3px;
  z-index: 100;
  opacity: 0;
  transition: opacity 80ms;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
.tooltip.show { opacity: 1; }
.tooltip .tt-line { display: block; }
.tooltip .tt-faint { color: var(--ink-faint); }

/* ===== Bubble interactions ===== */
.tl-bubble {
  cursor: pointer;
  transition: opacity 140ms, stroke-width 100ms;
}
.tl-bubble.dim { opacity: 0.10; }
.tl-bubble.hidden { opacity: 0; pointer-events: none; }
.tl-bubble.active {
  stroke: var(--ink) !important;
  stroke-width: 1.8 !important;
}
.tl-bubble.pinned {
  filter: drop-shadow(0 0 8px var(--ink));
}

/* ===== Brush ===== */
.brush-handle {
  fill: var(--ink);
  fill-opacity: 0.85;
  stroke: var(--bg);
  stroke-width: 1;
  cursor: ew-resize;
}
.brush-window {
  fill: var(--ink);
  fill-opacity: 0.04;
  stroke: var(--ink);
  stroke-opacity: 0.55;
  stroke-width: 1;
  cursor: grab;
}
.brush-window.dragging { cursor: grabbing; }

/* ===== Annotations on the timeline ===== */
.tl-annotation {
  cursor: pointer;
  transition: opacity 200ms;
}
.tl-anno-label {
  font-family: var(--mono);
  font-size: 9.5px;
  fill: var(--ink-soft);
  letter-spacing: 0.04em;
}
.tl-anno-label tspan.bold { font-weight: 600; fill: var(--ink); }
.tl-anno-line {
  stroke: var(--ink-faint);
  stroke-width: 0.7;
  stroke-dasharray: 2,2;
}
body.hide-annotations .tl-annotation { opacity: 0; pointer-events: none; }

/* ===== Responsive ===== */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .main { grid-template-columns: 1fr; }
  .main-left { border-right: none; border-bottom: 1px solid var(--line); }
  .main-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 20px 48px 28px;
  }
  .main-right .panel.year { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .header { padding: 26px 22px 18px; }
  .header h1 { font-size: 36px; }
  .controls, .chart-wrap, .brush-wrap, .footer { padding-left: 22px; padding-right: 22px; }
  .detail-card { margin-left: 22px; margin-right: 22px; padding: 16px; grid-template-columns: 1fr; }
  .detail-card .dc-count-cell { grid-column: 1; grid-row: auto; padding-left: 0; border-left: none; border-top: 1px solid var(--line-soft); padding-top: 12px; text-align: left; }
  .footer-grid { grid-template-columns: 1fr; gap: 20px; }
  .main-right { grid-template-columns: 1fr; padding: 18px 22px 24px; }
  .header-top { flex-direction: column; gap: 14px; }
}
