/* Regions by county — shares the palette with /config, /map, /explainer. */

:root {
  --green:       #2d6a4f;
  --green-dark:  #1b4332;
  --green-mid:   #40916c;
  --green-light: #74c69d;
  --green-pale:  #d8f3dc;
  --blue:        #1a3a4a;
  --gold:        #f4c842;
  --gold-warm:   #f4a261;
  --cross:       #7e22ce;
  --bg:          #f4f7f5;
  --surface:     #ffffff;
  --text:        #1a2e25;
  --text-muted:  #607a6e;
  --border:      #cce0d5;
  --border-soft: #e3eee8;
  --radius:      14px;
  --radius-sm:   9px;
  --shadow-card: 0 1px 4px rgba(27,67,50,0.08);
  --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono:   ui-monospace, "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  --panel-w:     372px;
}

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

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}

code { font-family: var(--font-mono); }
a { color: var(--green); }

.skip-link {
  position: absolute; top: -100%; left: 1rem; z-index: 1200;
  background: var(--green-dark); color: #fff;
  padding: 0.5rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.875rem; text-decoration: none;
}
.skip-link:focus { top: 0.75rem; }

:where(button, input, a):focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ── Header ──────────────────────────────────────────────────────────────── */

.page-header {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--blue) 100%);
  color: #fff; padding: 1.1rem 1.4rem 1.2rem;
  position: relative; overflow: hidden; flex: 0 0 auto;
}
.page-header::before {
  content: "";
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='60'%3E%3Cpolygon points='0,60 60,0 120,60' fill='rgba(255,255,255,0.03)'/%3E%3C/svg%3E") repeat-x bottom;
  background-size: 120px 60px;
}
.header-inner {
  position: relative; max-width: 1720px; margin: 0 auto;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1.5rem; flex-wrap: wrap;
}
.header-text { min-width: 0; }
.page-header .badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 99px; padding: 0.2rem 0.7rem;
  font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase;
  font-weight: 600; margin-bottom: 0.45rem;
}
.page-header h1 {
  font-size: clamp(1.25rem, 2.6vw, 1.6rem);
  font-weight: 800; letter-spacing: -0.02em; line-height: 1.15;
}
.page-header .lede {
  margin-top: 0.35rem; font-size: 0.88rem; max-width: 64ch;
  color: rgba(255,255,255,0.82); line-height: 1.5;
}
.page-header em { font-style: normal; color: var(--gold); font-weight: 600; }

.header-nav { display: flex; flex-wrap: wrap; gap: 0.35rem; padding-top: 0.2rem; }
.header-nav a {
  font-size: 0.78rem; font-weight: 600; text-decoration: none;
  color: rgba(255,255,255,0.88);
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.07);
  border-radius: 99px; padding: 0.22rem 0.75rem;
  transition: background 0.15s, border-color 0.15s;
}
.header-nav a:hover { background: rgba(255,255,255,0.16); border-color: rgba(255,255,255,0.4); color: #fff; }

/* ── Controls ────────────────────────────────────────────────────────────── */

.controls {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.5rem;
  padding: 0.7rem 1.4rem 0.8rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.control-block { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.control-overlay { flex: 1 1 220px; }
.control-search { flex: 0 1 280px; margin-left: auto; }

.control-label {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--text-muted);
}

.btn-group { display: flex; gap: 0.35rem; }
.seg-btn {
  padding: 0.35rem 0.8rem; border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer;
  line-height: 1.2; text-align: left;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg-btn small { display: block; font-weight: 500; font-size: 0.66rem; color: var(--text-muted); margin-top: 0.05rem; }
.seg-btn:hover { border-color: var(--green-light); background: #f5fbf7; }
.seg-btn.selected {
  border-color: var(--green); background: #edf7f1; color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.10);
}
.seg-btn.selected small { color: var(--green-mid); }

.overlay-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.overlay-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.6rem; border: 1.5px solid var(--border); border-radius: 99px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 0.78rem; cursor: pointer; line-height: 1.3;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.overlay-chip code { font-size: 0.76rem; font-weight: 700; }
.overlay-chip:hover { border-color: var(--cross); }
.overlay-chip.is-on {
  border-color: var(--cross); background: color-mix(in srgb, var(--cross) 9%, #fff);
  color: var(--cross); font-weight: 600;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cross) 14%, transparent);
}
.overlay-chip.is-none { font-size: 0.74rem; color: var(--text-muted); }
.overlay-chip.is-none.is-on { color: var(--text); background: var(--bg); border-color: var(--border); box-shadow: none; }
.chip-count {
  font-size: 0.66rem; font-weight: 700; color: var(--text-muted);
  background: var(--bg); border-radius: 99px; padding: 0.02rem 0.35rem;
}

.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap input {
  flex: 1; min-width: 0; font-family: inherit; font-size: 0.88rem;
  padding: 0.42rem 5rem 0.42rem 0.7rem;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-wrap input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,106,79,0.12); }
.search-wrap input::placeholder { color: #aac0b4; }
.search-count {
  position: absolute; right: 0.65rem; font-size: 0.68rem;
  color: var(--text-muted); pointer-events: none;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */

.app-shell {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w);
}

.map-wrap { position: relative; min-width: 0; }
#mapPane { position: absolute; inset: 0; background: #eef2f0; }

.map-loading {
  position: absolute; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text-muted); font-size: 0.9rem;
}

/* ── Map furniture ───────────────────────────────────────────────────────── */

.leaflet-container { font-family: var(--font); background: #eef2f0; }
.leaflet-container a { color: var(--green); }

.region-label-wrap { background: none; border: none; }
.region-label {
  display: inline-block; transform: translate(-50%, -50%);
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
  color: var(--ink); background: rgba(255,255,255,0.86);
  border: 1px solid color-mix(in srgb, var(--ink) 40%, #fff);
  border-radius: 5px; padding: 0.5px 5px; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.10);
}
.region-label.is-dim { opacity: 0.3; }

.overlay-label {
  display: inline-block; transform: translate(-50%, -140%);
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  color: #fff; background: #1f2937;
  border-radius: 5px; padding: 1px 6px; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.leaflet-tooltip.county-tip {
  background: rgba(26,46,37,0.95); color: #fff;
  border: none; border-radius: 7px; box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  font-size: 0.78rem; line-height: 1.45; padding: 0.4rem 0.6rem;
}
.leaflet-tooltip.county-tip::before { display: none; }
.county-tip .tip-sub { color: rgba(255,255,255,0.65); }
.county-tip .tip-region {
  font-family: var(--font-mono); font-weight: 700;
  background: var(--ink); color: #fff;
  padding: 0 0.3rem; border-radius: 3px; font-size: 0.74rem;
}
.county-tip .tip-split { color: var(--gold); }

/* ── Legend ──────────────────────────────────────────────────────────────── */

.legend {
  position: absolute; left: 0.75rem; bottom: 0.75rem; z-index: 800;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.9rem;
  max-width: min(560px, calc(100% - 1.5rem));
  padding: 0.45rem 0.7rem;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15,23,42,0.10);
  font-size: 0.72rem; color: var(--text-muted);
}
.legend-group { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0.3rem 0.6rem; }
.legend-title {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--text-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.32rem; }
.lg { width: 15px; height: 11px; border-radius: 2px; flex: 0 0 auto; }
.lg-split {
  border: 1px solid var(--border);
  background: repeating-linear-gradient(45deg, #cfe0f4 0 3px, #f7d6c4 3px 6px);
}
.lg-seed {
  width: 9px; height: 9px; border-radius: 50%;
  background: #2a78d6; border: 1.5px solid #fff; box-shadow: 0 0 0 1px var(--border);
}
.lg-cross { background: none; border-top: 3px dashed #1f2937; height: 0; }
.lg-far {
  background: repeating-linear-gradient(90deg, #cfe0f4 0 6px, #ffffff 6px 8px);
  opacity: 0.55; border: 1px solid var(--border);
}
.legend-note { font-style: italic; }

/* ── Panel ───────────────────────────────────────────────────────────────── */

.panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto; min-height: 0;
  padding: 1rem 1.1rem 2.5rem;
}

.overlay-card {
  border: 1px solid var(--border); background: #fbfdfc;
  border-left: 3px solid #1f2937;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.7rem 0.85rem; margin-bottom: 1rem;
}
.overlay-card-head { margin-bottom: 0.35rem; }
.overlay-card-head span {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--text-muted);
}
.overlay-card p { font-size: 0.81rem; line-height: 1.5; color: var(--text); }
.overlay-card code { font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700; }
.overlay-card-foot { font-size: 0.76rem; color: var(--text-muted); margin-top: 0.45rem; }

.overlay-list { list-style: none; margin: 0.5rem 0 0; display: flex; flex-direction: column; gap: 0.3rem; }
.overlay-list li { display: flex; align-items: center; gap: 0.4rem; font-size: 0.79rem; }
.overlay-key {
  width: 24px; height: 0; flex: 0 0 auto;
  border-top: 2.5px dashed #1f2937;
}
.overlay-li-name { color: var(--text-muted); min-width: 0; }
.overlay-li-meta { margin-left: auto; font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }

.panel-note.is-far { border-left-color: var(--border); }
.panel-note code { font-family: var(--font-mono); font-size: 0.74rem; }

.panel-intro h2 { font-size: 1.02rem; font-weight: 700; color: var(--green-dark); line-height: 1.3; }
.panel-intro p { font-size: 0.84rem; margin-top: 0.45rem; line-height: 1.55; }
.panel-note {
  font-size: 0.8rem; color: var(--text-muted); line-height: 1.5;
  background: var(--bg); border-left: 3px solid var(--gold);
  border-radius: 0 7px 7px 0; padding: 0.5rem 0.7rem; margin-top: 0.6rem;
}
.panel-note strong { color: var(--text); }

.dir-state { margin-top: 1.25rem; }
.dir-state h3 {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted);
  padding-bottom: 0.3rem; border-bottom: 1px solid var(--border-soft); margin-bottom: 0.5rem;
}
.dir-state.is-note h3 { border-bottom-color: var(--border); }

.dir-region { margin-bottom: 0.7rem; }
.dir-head {
  display: flex; align-items: center; gap: 0.4rem;
  text-decoration: none; color: var(--text); padding: 0.1rem 0;
}
.dir-head:hover code { text-decoration: underline; }
.dir-swatch {
  width: 13px; height: 13px; border-radius: 3px; border: 2px solid; flex: 0 0 auto;
  display: inline-block; vertical-align: -2px;
}
.dir-head code { font-size: 0.78rem; font-weight: 700; color: var(--ink); }
.dir-name { font-size: 0.8rem; color: var(--text); min-width: 0; }
.dir-count {
  margin-left: auto; font-size: 0.66rem; font-weight: 700; color: var(--text-muted);
  background: var(--bg); border-radius: 99px; padding: 0.02rem 0.4rem;
}

.dir-counties { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-top: 0.2rem; padding-left: 1.15rem; }
.county-link {
  font-size: 0.76rem; text-decoration: none; color: var(--text-muted);
  border: 1px solid var(--border-soft); border-radius: 5px;
  padding: 0.02rem 0.35rem; background: var(--surface);
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.county-link:hover { border-color: var(--green); color: var(--green-dark); background: #f4faf6; }
.county-link.is-split {
  border-style: dashed; border-color: var(--gold-warm); color: #96591f;
}
.county-link.is-current { background: var(--green-dark); color: #fff; border-color: var(--green-dark); }
.county-link.is-static { cursor: default; }
.county-link.is-static:hover { border-color: var(--border-soft); color: var(--text-muted); background: var(--surface); }

.panel-back {
  font-family: inherit; font-size: 0.76rem; font-weight: 600;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 0 0 0.5rem;
}
.panel-back:hover { color: var(--green-dark); }

.panel-kind {
  display: inline-block; font-size: 0.6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted);
}
.panel-head h2 { font-size: 1.15rem; font-weight: 700; color: var(--green-dark); line-height: 1.25; }
.panel-meta {
  display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--text-muted); margin-top: 0.25rem;
}
.panel-meta code { font-size: 0.78rem; font-weight: 700; color: var(--text); }

.panel-section { border-top: 1px solid var(--border-soft); margin-top: 0.9rem; padding-top: 0.7rem; }
.panel-section h3 {
  font-size: 0.64rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--text-muted); margin-bottom: 0.45rem;
}
.panel-section.is-split h3 { color: #96591f; }
.panel-foot { font-size: 0.76rem; color: var(--text-muted); line-height: 1.5; margin-top: 0.45rem; }

.split-bars { display: flex; flex-direction: column; gap: 0.3rem; }
.split-row { display: flex; align-items: center; gap: 0.45rem; }
.split-tag code { font-size: 0.74rem; font-weight: 700; color: var(--ink); }
.split-tag { min-width: 4.2rem; }
.split-bar { flex: 1; height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.split-bar span { display: block; height: 100%; border-radius: 99px; }
.split-pct { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 2.4rem; text-align: right; }

.tag-row { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.tag-row-label {
  font-size: 0.66rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; margin: 0.45rem 0 0.25rem;
}
.tag-chip {
  display: inline-flex; border: 1.5px solid var(--border); border-radius: 6px;
  padding: 0.05rem 0.35rem; background: var(--surface);
}
.tag-chip code { font-size: 0.73rem; font-weight: 700; color: var(--text); }
.tag-chip.is-ancestry { border-color: var(--green-pale); background: #f4faf6; }
.tag-chip.is-ancestry code { color: var(--green-dark); }
.tag-chip.is-extra { border-color: var(--cross); background: color-mix(in srgb, var(--cross) 8%, #fff); }
.tag-chip.is-extra code { color: var(--cross); }
.tag-chip.is-gated { border-color: var(--cross); border-style: dashed; }
.tag-chip.is-gated code { color: var(--cross); }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1000px) {
  body { display: block; height: auto; }
  .app-shell { display: block; }
  .map-wrap { position: relative; height: 62vh; }
  .panel { border-left: none; border-top: 1px solid var(--border); overflow: visible; }
  .control-search { margin-left: 0; }
}

@media (max-width: 620px) {
  .controls { gap: 0.9rem; padding: 0.7rem 0.9rem 0.8rem; }
  .page-header { padding: 0.9rem 1rem 1rem; }
  .legend { font-size: 0.68rem; gap: 0.25rem 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
