/* Theme shared with mabiweather / mabitimers / mabicreatures, plus the
   data-viz tokens this page adds. */
:root {
  --darkest: #1a1a2e;
  --darker: #16213e;
  --dark: #0f3460;
  --highlight: #fbbf24;
  --light: #213555;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(148, 163, 184, 0.2);

  /* --- chart surface + chrome ---
     `--card` is what the SVG paints its surface rings with, so it must stay
     equal to the card background or the end-dot halo will show a seam. */
  --card: var(--darker);
  --grid: rgba(148, 163, 184, 0.12);
  --axis: rgba(148, 163, 184, 0.3);

  /* --- series colours ---
     One series (population) wears the theme accent, so no legend box is
     needed: the card title names it.
     The four race slots are the reference categorical palette stepped for a
     dark surface, validated against #16213e: worst adjacent CVD dE 8.4
     (protan), worst adjacent normal-vision dE 19.8, all >= 3:1 contrast.
     The ORDER is the CVD-safety mechanism -- re-run the validator before
     reordering or restepping any slot. */
  --series-pop: var(--highlight);
  --series-1: #3987e5; /* Human  */
  --series-2: #d95926; /* Elf    */
  --series-3: #199e70; /* Giant  */
  --series-4: #c98500; /* Pet    */

  /* Reserved status colour; only ever used for "no sample", never as a
     series. Always shipped with the caption that explains it. */
  --status-critical: #d03b3b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--darkest);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

#app {
  min-height: 100vh;
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */

header h1 {
  margin: 0 0 1.5rem;
  text-align: center;
  font-size: 2.25rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f9fafb;
}

.error {
  background: rgba(208, 59, 59, 0.12);
  border: 1px solid var(--status-critical);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

/* ===== Hero: the one number the page leads with ===== */

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  background: var(--darker);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.hero-main {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

/* Proportional figures on purpose -- tabular-nums makes a big standalone
   number look loose. Tabular is reserved for the columns below. */
.hero-value {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--highlight);
}

.hero-label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-ago {
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 0.75rem;
  opacity: 0.75;
}

.hero-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin: 0;
}

/* ===== Stat tiles ===== */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0 0;
}

.tiles .tile {
  background: var(--darker);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
}

.tile dt {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.tile dd {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}

.tile dd small {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
}

/* ===== Filter rail: one row, above everything it scopes ===== */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.chip-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  padding: 0.4rem 0.9rem;
  background: var(--darker);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  background: var(--light);
  border-color: var(--highlight);
}

.chip:focus-visible {
  outline: none;
  border-color: var(--highlight);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.4);
}

.chip.is-active {
  background: var(--highlight);
  color: var(--darkest);
  border-color: var(--highlight);
}

.chip--ghost {
  background: transparent;
}

.chip--sm {
  font-size: 0.75rem;
  padding: 0.28rem 0.7rem;
}

/* ===== Chart cards ===== */

.charts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: opacity 0.2s ease;
}

/* Refetch keeps the frame: the previous render holds at reduced opacity
   instead of collapsing to a skeleton and jumping the layout. */
.charts.is-loading {
  opacity: 0.5;
}

/* Marks where the range filter stops applying. */
.divider {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0.75rem 0 -0.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.divider small {
  margin-left: auto;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--muted);
}

.card {
  background: var(--darker);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.1rem 1.25rem 1.25rem;
}

.card-head h2 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.card-sub {
  margin: 0.25rem 0 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.card-sub strong {
  color: var(--text);
  font-weight: 600;
}

.card-warn {
  margin: 0 0 0.9rem;
  padding: 0.45rem 0.7rem;
  background: rgba(251, 191, 36, 0.08);
  border-left: 2px solid var(--highlight);
  border-radius: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.chart {
  position: relative;
}

.chart:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.4);
  border-radius: 0.5rem;
}

.chart svg {
  display: block;
  overflow: visible;
}

/* SVG chrome. Text inside a chart wears an ink token, never a series colour. */
.c-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.c-label--strong {
  fill: var(--text);
  font-weight: 600;
}

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

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

/* ===== Crosshair + tooltip ===== */

.rail {
  position: absolute;
  width: 1px;
  background: var(--axis);
  pointer-events: none;
}

.tip {
  position: absolute;
  transform: translate(-50%, 8px);
  min-width: 8rem;
  padding: 0.5rem 0.7rem;
  background: var(--darkest);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-variant-numeric: tabular-nums;
}

.tip-title {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.15rem;
  white-space: nowrap;
}

.tip-row {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  white-space: nowrap;
}

/* Line keys, not boxes: at tooltip density a filled block is data-weight ink
   doing a label's job. */
.tip-key {
  width: 10px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
  transform: translateY(-3px);
}

/* Values lead, labels follow -- the reader already has the series. */
.tip-val {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.tip-lab {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ===== Legend ===== */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Legends mirror the mark: a rect for bars and areas. */
.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  flex-shrink: 0;
}

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

/* ===== Heatmap ramp legend ===== */

.tz-toggle {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.ramp {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.75rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.ramp-step {
  width: 22px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.ramp-step--none {
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0 2px,
    var(--border) 2px 4px
  );
  background-color: var(--darker);
}

.ramp-end {
  white-space: nowrap;
}

.ramp-note {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
}

/* ===== Captions ===== */

.caption {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}

.swatch {
  width: 14px;
  height: 3px;
  border-radius: 1px;
  flex-shrink: 0;
  transform: translateY(-2px);
}

.swatch--gap {
  background: var(--status-critical);
}

/* ===== Table view ===== */

.table-card {
  margin-top: 1rem;
}

.table-scroll {
  max-height: 24rem;
  overflow: auto;
}

.table-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.table-card th,
.table-card td {
  text-align: right;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-card th:first-child,
.table-card td:first-child {
  text-align: left;
}

.table-card thead th {
  position: sticky;
  top: 0;
  background: var(--darker);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

/* ===== Footer ===== */

.foot {
  margin-top: 1.75rem;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--muted);
  text-align: center;
}

.foot p {
  margin: 0.2rem 0;
}

.foot a {
  color: var(--highlight);
}

/* ===== Small screens ===== */

@media (max-width: 640px) {
  header h1 {
    font-size: 1.6rem;
  }

  #app {
    padding: 1.25rem 0.75rem 2.5rem;
  }

  .hero {
    justify-content: center;
    text-align: center;
  }

  .hero-tiles {
    gap: 0.9rem;
    justify-content: center;
  }

  .card {
    padding: 1rem 0.75rem 1.1rem;
  }
}
