:root {
  color-scheme: light;

  --paper: #f7f4ef;
  --surface: #fffefb;
  --ink: #191817;
  --muted: #6b655d;
  --rule: #ded7cb;
  /* Endpoints of the server palette, so UI text and map ends match. */
  --cone: #1b4e93;
  --gone: #c1460e;

  /* map shapes, kept in tokens so the palette can follow the theme */
  --map-stroke: #4a443c;
  --map-empty: #e9e3d7;
  --map-hatch: #cbc2b1;
  --map-halo: rgba(255, 255, 255, 0.7);

  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Set on <html> by the head script: stored choice, else the OS preference. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --paper: #171613;
  --surface: #1f1e19;
  --ink: #f4f0e8;
  --muted: #a49c8d;
  --rule: #34302a;
  --cone: #82a9e6;
  --gone: #f2915f;

  /* Lighter than the page, so an unvoted county still reads as land. */
  --map-stroke: #565044;
  --map-empty: #34312a;
  --map-hatch: #494233;
  --map-halo: rgba(0, 0, 0, 0.72);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--cone); color: var(--paper); }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.masthead, main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.colophon {
  max-width: 40rem;
  margin: 2.5rem auto 0;
  padding: 0 1.5rem 2.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* The rule sits on the text block, not the padded box, so it lines up with the
   table rules above instead of overhanging them by the gutter. */
.colophon p {
  margin: 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

.colophon a {
  color: var(--ink);
  text-decoration-color: var(--rule);
  text-underline-offset: 0.2em;
}

.colophon a:hover { text-decoration-color: currentColor; }

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
  padding-top: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--rule);
}

h1 {
  margin: 0 0 0.5rem;
  font: 400 clamp(2.25rem, 8vw, 3.25rem)/0.95 var(--serif);
  letter-spacing: -0.025em;
  text-wrap: balance;
}
h1 span { color: var(--muted); }

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 1.0625rem;
  text-wrap: pretty;
}

/* --- theme toggle --- */

.theme-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink); }
.theme-toggle svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}
.theme-toggle__moon { display: none; fill: currentColor; stroke: none; }
:root[data-theme="dark"] .theme-toggle__sun { display: none; }
:root[data-theme="dark"] .theme-toggle__moon { display: block; }
.tagline em { color: var(--ink); font-style: italic; }

section { margin: 0 0 2.5rem; }

h2 {
  margin: 0 0 1rem;
  font: 600 0.75rem/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- the two choices --- */

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.choice {
  display: grid;
  gap: 0.125rem;
  padding: 1rem 1.125rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.choice:hover { border-color: var(--ink); }
/* Pressed cards take a wash of their own colour, which reads at a glance. */
.choice[aria-pressed="true"] {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 8%, var(--surface));
}
.choice[aria-pressed="true"] .choice__word { text-decoration: underline; text-underline-offset: 0.18em; }

.choice__word { font: 400 1.75rem/1 var(--serif); letter-spacing: -0.01em; }
.choice--cone { color: var(--cone); }
.choice--gone { color: var(--gone); }
.choice__rhyme { color: var(--muted); font-size: 0.875rem; }
.choice__rhyme strong { font-weight: 600; }

/* --- details --- */

.details {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.details label {
  display: grid;
  gap: 0.375rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.details select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background-color: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
  font: 1rem/1.4 var(--sans);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.1rem) 1.15rem, calc(100% - 0.75rem) 1.15rem;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}
.details select:hover { border-color: var(--ink); }

.status {
  min-height: 1.5rem;
  margin: 1rem 0 0;
  font-size: 0.9375rem;
  color: var(--muted);
}
.status[data-tone="error"] { color: var(--gone); }
.status[data-tone="ok"] { color: var(--ink); }

/* --- map --- */

.map {
  display: grid;
  gap: 1.5rem;
}

#map {
  display: block;
  width: 100%;
  max-width: 30rem;
  height: auto;
  margin: 0 auto;
}

#map path {
  stroke: var(--map-stroke);
  stroke-width: 1.2;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 200ms ease, filter 120ms ease;
}
/* No votes is not a value on the scale, so it is hatched, not shaded: a mid
   county must never be mistaken for an unvoted one. */
#map path[data-empty="true"] { fill: var(--map-empty); fill: url(#no-votes); }
#map .no-votes__fill { fill: var(--map-empty); }
#map .no-votes__line { stroke: var(--map-hatch); }

#map path:hover { stroke: var(--ink); stroke-width: 2.2; filter: brightness(1.06) saturate(1.1); }
:root[data-theme="dark"] #map path:hover { filter: brightness(1.2) saturate(1.1); }

.map__label {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 600;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--map-halo);
  stroke-width: 3px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  font-size: 0.6875rem;
  color: var(--muted);
  white-space: nowrap;
}
.legend__scale {
  flex: 1 1 auto;
  height: 0.7rem;
  background: var(--scale, var(--rule));
  border: 1px solid var(--rule);
}

/* --- island split --- */

.bar {
  display: flex;
  height: 3.5rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  overflow: hidden;
}
.bar__cone { background: var(--cone); }
.bar__gone { background: var(--gone); }
.bar__cone, .bar__gone { transition: flex-basis 400ms ease; }

.bar__labels {
  display: flex;
  justify-content: space-between;
  margin: 0.5rem 0 0;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.bar__label--cone { color: var(--cone); }
.bar__label--gone { color: var(--gone); }

.totals {
  display: flex;
  gap: 2rem;
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.totals dt {
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.totals dd {
  margin: 0.125rem 0 0;
  font: 400 1.5rem/1.2 var(--serif);
  font-variant-numeric: tabular-nums;
}

.updated {
  margin: 0.75rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --- ranking --- */

.hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.875rem;
  color: var(--muted);
  text-wrap: pretty;
}

#map-panel .hint { margin-top: 0.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
thead th {
  padding: 0 0 0.5rem;
  border-bottom: 1px solid var(--ink);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: left;
  color: var(--muted);
}
tbody th, tbody td {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  font-weight: 400;
  text-align: left;
}
tbody tr:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.num { text-align: right; }
tbody th { font-size: 1rem; }
tbody td { color: var(--muted); }
tbody tr[data-empty="true"] th { color: var(--muted); }

.chip {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  margin-right: 0.6rem;
  vertical-align: baseline;
}
.chip--empty { border: 1px solid var(--rule); }

@media (max-width: 21rem) {
  .choices { grid-template-columns: 1fr; }
  .totals { gap: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Wide screens: the map sits beside the form instead of a scroll below it, so
   the whole point of the page is visible without scrolling. */
@media (min-width: 60rem) {
  .masthead, main, .colophon { max-width: 60rem; }

  main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 3rem;
    align-items: start;
  }
  #vote { grid-column: 1; grid-row: 1; }
  #map-panel { grid-column: 2; grid-row: 1 / span 2; }
  #split { grid-column: 1; grid-row: 2; }
  #ranking { grid-column: 1 / -1; grid-row: 3; }

  #map, .legend { max-width: 100%; }
  .totals { gap: 3rem; }
}
