/* Paths — chrome and chart tokens.
   Palette values come from the validated reference palette; node-type hues are
   categorical slots 1–3 (blue / orange / aqua), which clear the all-pairs CVD and
   normal-vision floors in both modes. Light-mode aqua sits at 2.74:1 against the
   surface, so the relief rule applies: node labels and the table view are always
   available, and no meaning is ever carried by hue alone (each type also has its
   own mark shape). */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);

  --type-physical: #2a78d6;
  --type-ideological: #eb6834;
  --type-event: #1baf7a;

  --path-line: #52514e;

  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);

    --type-physical: #3987e5;
    --type-ideological: #d95926;
    --type-event: #199e70;

    --path-line: #c3c2b7;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.06);

  --type-physical: #3987e5;
  --type-ideological: #d95926;
  --type-event: #199e70;

  --path-line: #c3c2b7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.masthead__wordmark {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.masthead h1 {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}

.masthead p {
  margin: 0;
  max-width: 62ch;
  color: var(--text-secondary);
}

.icon-btn {
  flex: none;
  font: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 11px;
  cursor: pointer;
}

.icon-btn:hover { background: var(--wash); }

/* ---------- filter row (one row, above everything it scopes) ---------- */

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.controls__label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.chips { display: flex; gap: 7px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  cursor: pointer;
}

.chip:hover { background: var(--wash); }
.chip[aria-pressed="false"] { color: var(--text-muted); }
.chip[aria-pressed="false"] .chip__mark { opacity: 0.28; }
.chip[aria-pressed="true"] { border-color: currentColor; }

.chip__mark { flex: none; }

.controls__spacer { flex: 1 1 auto; }

.range-readout {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.select {
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
}

/* ---------- chart card ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 18px;
}

.plot-card { padding: 8px 8px 0; position: relative; }

.plot-hint {
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

svg.plot { display: block; width: 100%; height: auto; overflow: visible; }

/* paths — identity is position (upper / lower) plus a direct label at each end,
   never hue; the categorical hues belong to the node types. */
.path-line {
  fill: none;
  stroke: var(--path-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.path-cap { fill: var(--path-line); }

.path-name {
  font-size: 12.5px;
  font-weight: 550;
  fill: var(--text-primary);
}

.path-note { font-size: 11px; fill: var(--text-muted); }

.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }

.tick-label {
  font-size: 11px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
}

.spine { stroke: var(--grid); stroke-width: 1; }

/* nodes */
.node { cursor: pointer; }
.node__hit { fill: transparent; }

/* invisible until the node is selected or focused — an SVG circle with no fill
   declared paints solid black, which is not what a halo is for */
.node__halo { fill: none; stroke: none; }

.node__mark {
  stroke: var(--surface-1);
  stroke-width: 4; /* 2px of surface ring outside the mark */
  paint-order: stroke;
}

.node--physical .node__mark { fill: var(--type-physical); }
.node--ideological .node__mark { fill: var(--type-ideological); }
.node--event .node__mark { fill: var(--type-event); }

.node__leader { stroke: var(--axis); stroke-width: 1; fill: none; }

.node__label {
  font-size: 11.5px;
  fill: var(--text-secondary);
  text-anchor: middle;
  pointer-events: none;
}

.node__year {
  font-size: 10.5px;
  fill: var(--text-muted);
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.node.is-hover .node__label,
.node.is-selected .node__label { fill: var(--text-primary); font-weight: 600; }


.node.is-selected .node__halo {
  fill: none;
  stroke: var(--text-primary);
  stroke-width: 1.5;
  opacity: 0.55;
}

.node.is-dimmed { opacity: 0.24; }

.node:focus { outline: none; }
.node:focus-visible .node__halo {
  fill: none;
  stroke: var(--text-primary);
  stroke-width: 2;
}

/* impact arcs — dashed and hued so they stay a separate layer from the neutral
   path lines they cross */
.arc {
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  opacity: 0.9;
}

.arc--physical { stroke: var(--type-physical); }
.arc--ideological { stroke: var(--type-ideological); }
.arc--event { stroke: var(--type-event); }

.arc-head { stroke: none; opacity: 0.9; }
.arc-head--physical { fill: var(--type-physical); }
.arc-head--ideological { fill: var(--type-ideological); }
.arc-head--event { fill: var(--type-event); }

/* brush + overview strip */
.brush-band { fill: var(--wash); stroke: var(--axis); stroke-width: 1; }
.brush-surface { fill: transparent; cursor: ew-resize; }

.strip-tick--physical { fill: var(--type-physical); }
.strip-tick--ideological { fill: var(--type-ideological); }
.strip-tick--event { fill: var(--type-event); }

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

.tooltip {
  position: absolute;
  z-index: 20;
  min-width: 190px;
  max-width: 300px;
  padding: 9px 11px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms ease;
}

.tooltip.is-visible { opacity: 1; }

.tooltip__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.tooltip__meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}

.key-line { flex: none; border-radius: 1px; width: 14px; height: 3px; }
.key-line--physical { background: var(--type-physical); }
.key-line--ideological { background: var(--type-ideological); }
.key-line--event { background: var(--type-event); }

/* ---------- lower grid ---------- */

.lower {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

@media (max-width: 900px) {
  .lower { grid-template-columns: minmax(0, 1fr); }
}

h2.panel-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 14px;
  font-weight: 600;
}

/* stat tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.tile__label { font-size: 12px; color: var(--text-secondary); margin-bottom: 2px; }
.tile__value { font-size: 26px; font-weight: 600; letter-spacing: -0.015em; }
.tile__sub { font-size: 12px; color: var(--text-muted); }

/* composition bar */
.composition { margin-bottom: 6px; }

.comp-bar {
  display: flex;
  gap: 2px; /* the surface gap does the separating */
  height: 10px;
  margin-bottom: 12px;
}

.comp-bar__seg { min-width: 3px; }
.comp-bar__seg:first-child { border-radius: 4px 0 0 4px; }
.comp-bar__seg:last-child { border-radius: 0 4px 4px 0; }
.comp-bar__seg--physical { background: var(--type-physical); }
.comp-bar__seg--ideological { background: var(--type-ideological); }
.comp-bar__seg--event { background: var(--type-event); }

.comp-bar--empty {
  background: var(--grid);
  border-radius: 4px;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; }

.legend__item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend__value {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* detail panel */
.detail__empty { color: var(--text-muted); font-size: 13px; }

.detail__date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.detail h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 3px 0 8px;
}

.detail__type {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.detail__summary { margin: 0 0 14px; color: var(--text-secondary); }

.detail__split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

@media (max-width: 620px) {
  .detail__split { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: minmax(0, 1fr); }
}

.detail__who {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail__who-text { font-size: 13px; color: var(--text-secondary); }

.detail__section {
  padding-top: 12px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.link-btn {
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text-primary);
  background: none;
  border: none;
  border-bottom: 1px solid var(--axis);
  padding: 0;
  cursor: pointer;
}

.link-btn:hover { border-bottom-color: var(--text-primary); }

.downstream { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

.sources { margin: 0; padding-left: 18px; font-size: 12px; color: var(--text-muted); }

/* table view — the relief channel; nothing is gated behind hover */
.table-card { margin-top: 14px; }

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.table-scroll { overflow-x: auto; margin-top: 14px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }

th, td {
  text-align: left;
  vertical-align: top;
  padding: 8px 14px 8px 0;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

td { color: var(--text-secondary); }
td.date-cell { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-primary); }
td.node-cell { color: var(--text-primary); }

.type-cell { display: flex; align-items: center; gap: 7px; white-space: nowrap; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
