:root {
  color-scheme: light dark;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --accent: #2a78d6;
  --notice: #fdf3d6;
  --na: #e1e0d9;
  /* Sequential blue ramp, low to high. One hue, so it reads as "more". */
  --q0: #86b6ef;
  --q1: #5598e7;
  --q2: #2a78d6;
  --q3: #1c5cab;
  --q4: #0d366b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --line: #2c2c2a;
    --accent: #3987e5;
    --notice: #3a3115;
    --na: #383835;
    /* On a dark surface "more" is lighter, so the ramp runs the other way. */
    --q0: #184f95;
    --q1: #256abf;
    --q2: #3987e5;
    --q3: #86b6ef;
    --q4: #cde2fb;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  max-width: 1200px;
  padding: 24px 16px 48px;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 1.05rem;
}

p {
  margin: 0 0 8px;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--ink-2);
  font-size: 0.85rem;
}

.notice {
  display: inline-block;
  margin-top: 4px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--notice);
}

select {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  max-width: 100%;
}

.slicers {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: 16px 0 8px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend label {
  font: inherit;
}

legend {
  padding: 0;
  margin-bottom: 4px;
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 600;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.segmented input:checked + span {
  background: var(--accent);
  color: #ffffff;
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

.segmented input:disabled + span {
  color: var(--muted);
  text-decoration: line-through;
  cursor: not-allowed;
}

.status {
  min-height: 1.5em;
  color: var(--ink-2);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.tile,
.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 14px 16px;
}

.tile {
  display: flex;
  flex-direction: column;
}

.tile-label {
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 600;
}

.tile-value {
  font-size: 1.6rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.tile-note {
  color: var(--ink-2);
  font-size: 0.8rem;
  min-height: 1.2em;
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 12px;
  align-items: start;
}

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

.map-frame {
  position: relative;
  margin-top: 8px;
}

#map {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
}

.area {
  stroke: var(--surface);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.area.active {
  stroke: var(--ink);
  stroke-width: 2;
}

.q0 {
  fill: var(--q0);
  background: var(--q0);
}
.q1 {
  fill: var(--q1);
  background: var(--q1);
}
.q2 {
  fill: var(--q2);
  background: var(--q2);
}
.q3 {
  fill: var(--q3);
  background: var(--q3);
}
.q4 {
  fill: var(--q4);
  background: var(--q4);
}
.na {
  fill: var(--na);
}

.tooltip {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgb(0 0 0 / 18%);
  font-size: 0.85rem;
  pointer-events: none;
}

.tooltip[hidden] {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  color: var(--ink-2);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.ranked {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.ranked li {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.7fr) auto;
  gap: 8px;
  align-items: center;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}

.ranked-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranked-track {
  display: block;
  height: 10px;
}

.ranked-bar {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}

.ranked-value {
  font-variant-numeric: tabular-nums;
}

.table-card {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.table-scroll {
  max-height: 420px;
  margin-top: 10px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
}

td:last-child,
th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.page-footer {
  margin-top: 24px;
  color: var(--ink-2);
  font-size: 0.8rem;
}
