:root {
  color-scheme: dark;
  --bg: #101614;
  --glow: rgba(228, 161, 90, 0.18);
  --panel: #18211c;
  --ink: #f3efe4;
  --muted: #b7c4b6;
  --brass: #e4a15a;
  --on-brass: #24180d;
  --line: #2d3b34;
  --map: #0c1915;
  --dot: #e7f0df;
  --county: #8ec8d8;
  --halo: #0c1915;
  --wash: rgba(228, 161, 90, 0.14);
  --ring: rgba(228, 161, 90, 0.16);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4efe4;
    --glow: rgba(154, 84, 24, 0.14);
    --panel: #fffaf2;
    --ink: #1c241c;
    --muted: #4d5c50;
    --brass: #9a5418;
    --on-brass: #fffaf3;
    --line: #e0d5c4;
    --map: #e5f0e3;
    --dot: #1d4a32;
    --county: #14586e;
    --halo: #e5f0e3;
    --wash: rgba(154, 84, 24, 0.1);
    --ring: rgba(154, 84, 24, 0.12);
    --shadow: 0 12px 32px rgba(60, 40, 10, 0.08);
  }
}

* { box-sizing: border-box; }

html {
  background:
    radial-gradient(880px 420px at 100% -10%, var(--glow), transparent 55%),
    var(--bg);
  color: var(--ink);
  height: 100%;
}

body {
  margin: 0 auto;
  max-width: 1160px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 18px clamp(14px, 3vw, 28px) 14px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--brass);
  color: var(--on-brass);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 30;
}
.skip:focus { top: 12px; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--brass);
}

.mark { width: 40px; height: 40px; flex: none; }

.kicker {
  margin: 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.6rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
  color: var(--ink);
}

.lede {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.45;
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px 16px;
  align-items: end;
}

.field { position: relative; min-width: 0; }

label, .label-row {
  display: flex;
  justify-content: space-between;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="search"] {
  width: 100%;
  height: 46px;
  font: 1.05rem/1.2 ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brass);
  height: 46px;
}

output {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: 0;
  text-transform: none;
}

.suggest {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow: auto;
}

.suggest button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 8px 10px;
  min-height: 44px;
}

.suggest button[aria-selected="true"],
.suggest button:hover { background: var(--wash); }

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filters { display: flex; gap: 6px; }

button {
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 12px;
  cursor: pointer;
}

button[aria-pressed="true"] {
  background: var(--brass);
  color: var(--on-brass);
  border-color: transparent;
}

button:hover { border-color: var(--brass); }

#summary {
  margin: 14px 0 8px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

#note {
  margin: 0 0 12px;
  min-height: 1.2em;
  color: var(--brass);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.92rem;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
  gap: 14px;
}

.panel, .map-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-height: 0;
}

.panel { overflow: auto; }

.panel h2, .map-wrap h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 12px 14px 8px;
  background: var(--panel);
  font-size: 0.95rem;
  font-weight: 600;
}

#results {
  list-style: none;
  margin: 0;
  padding: 0 6px 8px;
}

#empty, #more {
  margin: 0;
  padding: 8px 14px 14px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.result {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: inherit;
  padding: 10px 8px;
  font: inherit;
}

.result:hover,
.result.hot,
.result[aria-current="true"] { background: var(--wash); }

.row-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.name { font-weight: 600; }

.idx {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", ui-monospace, monospace;
  font-size: 0.78rem;
  font-weight: 500;
  margin-right: 6px;
}

.dist {
  flex: none;
  font-family: ui-monospace, "SFMono-Regular", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
}

.bar {
  display: block;
  height: 3px;
  margin-top: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: var(--w);
  background: var(--brass);
  border-radius: inherit;
}

.map-wrap {
  position: relative;
  overflow: hidden;
  background: var(--map);
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--map);
}

.legend {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }

.legend i {
  width: 8px;
  height: 8px;
  display: inline-block;
  background: var(--dot);
  border-radius: 99px;
}

.legend i.county { border-radius: 2px; background: var(--county); }
.legend i.origin { background: var(--brass); transform: rotate(45deg); border-radius: 1px; }

footer {
  flex: none;
  margin-top: 10px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  line-height: 1.4;
}

footer a { color: var(--brass); }

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

.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;
}

@media (max-width: 800px) {
  html, body { height: auto; }
  body { display: block; overflow: visible; }
  .top { flex-direction: column; align-items: start; gap: 8px; }
  form { grid-template-columns: 1fr; }
  .stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .map-wrap { height: 280px; order: -1; flex: none; }
  .panel { max-height: none; overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .result[aria-current="true"] { outline: 2px solid CanvasText; }
}
