:root {
  --ink: #1c1915;
  --muted: #6d645b;
  --line: #e4ddd2;
  --paper: rgba(255, 252, 247, 0.94);
  --red: #c23b33;
  --red-deep: #8d241e;
  --map: #e6dfd4;
  --dept-line: #c4baaf;
  --ref-blue: #3a7ab8;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  overflow: hidden;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: var(--ink);
  background: var(--map);
}

#load-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: start center;
  padding-top: min(16vh, 108px);
  background: rgba(230, 223, 212, 0.78);
  backdrop-filter: blur(5px);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

#load-overlay.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#load-overlay[hidden] {
  display: none;
}

.load-card {
  width: min(320px, calc(100vw - 40px));
  padding: 16px 18px 14px;
  border: 1px solid rgba(28, 25, 21, 0.1);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 12px 36px rgba(28, 25, 21, 0.12);
}

.load-text {
  margin: 0 0 12px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.load-bar {
  height: 7px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.load-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red-deep), var(--red));
  transition: width 0.28s ease-out;
}

#map-shell {
  position: relative;
  flex: 1 1 auto;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#seed-handle {
  position: absolute;
  z-index: 3;
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  border: 2px solid #c23b33;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 5px rgba(28, 25, 21, 0.18);
  cursor: grab;
  touch-action: none;
  transform: translate(-50%, -50%);
}

#seed-handle[hidden] {
  display: none;
}

.map-hint {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px 32px;
  pointer-events: none;
  user-select: none;
}

.map-hint-card {
  max-width: min(300px, calc(100% - 48px));
  padding: 14px 18px;
  border: 1px solid rgba(28, 25, 21, 0.08);
  border-radius: 12px;
  background: rgba(255, 252, 247, 0.72);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(28, 25, 21, 0.1);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
  color: var(--ink);
}

.map-hint[hidden] {
  display: none;
}

#seed-handle.is-dragging {
  cursor: grabbing;
}

.map-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(28, 25, 21, 0.1);
  border-radius: 10px;
  background: rgba(255, 252, 247, 0.94);
  box-shadow: 0 4px 18px rgba(28, 25, 21, 0.08);
  pointer-events: auto;
}

.map-hud .legend {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.maplibregl-ctrl-attrib {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
}

#panel {
  order: -1;
  z-index: 2;
  flex: 0 0 clamp(240px, 32vw, 380px);
  width: clamp(240px, 32vw, 380px);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 14px 16px 12px;
  background: #fffcf7;
  border-right: 1px solid rgba(28, 25, 21, 0.1);
}

.kicker {
  margin: 0 0 4px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--red);
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.lead {
  margin: 6px 0 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
}

.presets-block { margin-top: 8px; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: white;
}

.mode-switch button {
  border: 0;
  background: white;
  color: var(--muted);
  padding: 7px 10px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.mode-switch button + button {
  border-left: 1px solid var(--line);
}

.mode-switch button:hover {
  color: var(--ink);
  background: #fbf6f1;
}

.mode-switch button[aria-pressed="true"] {
  background: #2a6494;
  color: white;
}

.mode-switch button[aria-pressed="true"]:hover {
  background: #245a85;
  color: white;
}

.presets-block.is-half-mode #presets {
  opacity: 0.55;
}

.field-label {
  margin: 0 0 8px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

#presets button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11.5px;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
}

#presets button:hover { border-color: #c8b8a8; }

#presets button[aria-pressed="true"] {
  background: #2a6494;
  border-color: #2a6494;
  color: white;
}

#presets button:disabled {
  cursor: not-allowed;
}

#presets button:disabled:hover {
  border-color: var(--line);
}

.dep-picker-wrap {
  position: relative;
  margin-top: 4px;
}

#dep-picker-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11.5px;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
}

#dep-picker-btn:hover:not(:disabled) {
  border-color: #c8b8a8;
}

#dep-picker-btn[aria-pressed="true"] {
  background: #2a6494;
  border-color: #2a6494;
  color: white;
}

#dep-picker-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#dep-picker-btn:disabled:hover {
  border-color: var(--line);
}

.presets-block.is-half-mode .dep-picker-wrap {
  opacity: 0.55;
}

#dep-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 7;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: min(240px, 42vh);
  overflow-y: auto;
  background: white;
  box-shadow: 0 10px 28px rgba(28, 25, 21, 0.12);
}

#dep-list button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  padding: 8px 12px;
  font: inherit;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 14px;
  cursor: pointer;
}

#dep-list li:last-child button {
  border-bottom: 0;
}

#dep-list button:hover,
#dep-list button:focus {
  background: #fbf6f1;
  color: var(--red-deep);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  color: var(--muted);
}

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

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

.swatch-ref { background: var(--ref-blue); }
.swatch-zone { background: #c23b33; }

body.is-half-mode .swatch-ref {
  background: #ffffff;
  border: 1px solid var(--dept-line);
  box-sizing: border-box;
}

body.is-half-mode .legend .swatch-ref {
  border-radius: 3px;
}

body.is-half-mode .stats-title .swatch-ref {
  border-radius: 50%;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-ui {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #d3c9ba;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.15s ease;
}

.toggle input:checked + .toggle-ui { background: #2a6494; }

.toggle input:checked + .toggle-ui::after { transform: translateX(14px); }

.toggle input:focus-visible + .toggle-ui {
  outline: 2px solid rgba(194, 59, 51, 0.45);
  outline-offset: 2px;
}

.city-label {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  white-space: nowrap;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: #1c1915;
  text-shadow:
    0 0 3px #f7f3ec,
    0 0 3px #f7f3ec,
    0 0 4px #f7f3ec;
}

.city-label.major { font-weight: 650; }

.city-label[hidden] { display: none; }

#status:empty { display: none; }

.city-label i {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #1c1915;
  box-shadow: 0 0 0 2px rgba(247, 243, 236, 0.92);
}

.search-wrap {
  position: relative;
  z-index: 6;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.search {
  display: block;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.search span {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: white;
}

.search input:focus {
  outline: 2px solid rgba(194, 59, 51, 0.35);
  border-color: var(--red);
}

#results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: min(220px, 38vh);
  overflow-y: auto;
  background: white;
  box-shadow: 0 10px 28px rgba(28, 25, 21, 0.12);
}

#results button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  padding: 8px 12px;
  font: inherit;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 14px;
  cursor: pointer;
}

#results li:last-child button { border-bottom: 0; }

#results button:hover,
#results button:focus {
  background: #fbf6f1;
  color: var(--red-deep);
}

.stats-section {
  margin-top: 14px;
}

.stats-section:first-of-type {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.stats-section + .stats-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.stats-kicker {
  margin: 0 0 4px;
  padding-left: 18px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--muted);
}

.stats-kicker[hidden] {
  display: none;
}

.stats-title {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.stats-title .swatch {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 0.35em;
  border-radius: 50%;
}

.stats-place {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.stats-dep {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0;
  color: var(--muted);
}

.stats-dep:empty {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin: 0;
}

.stats-grid dt {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats-grid dd {
  margin: 2px 0 0;
  font-size: 17px;
  letter-spacing: -0.03em;
}

#status {
  margin: 8px 0 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

#tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}

#tip[hidden] {
  display: none;
}

.tip-card {
  position: relative;
  min-width: 120px;
  max-width: min(240px, calc(100vw - 24px));
  padding: 8px 12px 10px;
  border: 1px solid rgba(28, 25, 21, 0.1);
  border-radius: 10px;
  background: rgba(255, 252, 247, 0.97);
  box-shadow: 0 8px 24px rgba(28, 25, 21, 0.14);
  text-align: center;
}

.tip-card::before,
.tip-card::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}

.tip-card::before {
  bottom: -8px;
  border-top: 8px solid rgba(28, 25, 21, 0.12);
}

.tip-card::after {
  bottom: -7px;
  border-top: 7px solid rgba(255, 252, 247, 0.97);
}

.tip-name {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink);
}

.tip-dep {
  margin: 2px 0 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--muted);
}

.tip-pop {
  margin: 5px 0 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: var(--ink);
}

@media (max-height: 820px) {
  h1 { font-size: 27px; }

  .lead {
    margin-top: 5px;
    font-size: 12.5px;
    line-height: 1.32;
  }

  .stats-grid dd { font-size: 15px; }

}

@media (max-width: 580px) {
  html,
  body {
    height: 100%;
    height: 100dvh;
  }

  body {
    flex-direction: column;
  }

  #panel {
    order: -1;
    flex: 0 1 auto;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 8px 10px 8px;
    padding-top: max(8px, env(safe-area-inset-top));
    border-right: none;
    border-bottom: 1px solid rgba(28, 25, 21, 0.1);
  }

  #panel .stats-section {
    display: none;
  }

  #map-shell {
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
    min-height: min(300px, 54dvh);
    height: auto;
  }

  .kicker {
    margin-bottom: 2px;
    font-size: 10px;
  }

  h1 {
    font-size: 22px;
    line-height: 1.02;
  }

  .lead {
    margin-top: 4px;
    font-size: 11.5px;
    line-height: 1.28;
  }

  .presets-block {
    margin-top: 6px;
  }

  .mode-switch {
    margin-bottom: 4px;
    border-radius: 8px;
  }

  .mode-switch button {
    padding: 4px 6px;
    font-size: 11px;
    line-height: 1.15;
  }

  #presets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
  }

  #presets button {
    padding: 4px 3px;
    border-radius: 6px;
    font-size: 9.5px;
    line-height: 1.1;
  }

  .dep-picker-wrap {
    margin-top: 3px;
  }

  #dep-picker-btn {
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 10px;
    line-height: 1.15;
  }

  .search-wrap {
    margin-top: 10px;
    padding-top: 10px;
  }

  .search input {
    font-size: 16px;
    padding: 8px 10px;
  }

  #dep-list {
    max-height: min(200px, 36dvh);
  }

  #results {
    max-height: min(200px, 36dvh);
  }

  .map-hud {
    top: 8px;
    right: 8px;
    left: auto;
    max-width: calc(100% - 16px);
    padding: 8px 10px;
    gap: 0;
  }

  .map-hud .toggle {
    display: none;
  }

  .map-hud .legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 10px;
  }

  .legend {
    font-size: 11px;
  }

  .map-hint {
    padding: 16px;
  }

  .map-hint-card {
    font-size: 14px;
    padding: 12px 14px;
  }

  #seed-handle {
    width: 20px;
    height: 20px;
    border-width: 2.5px;
  }

  #load-overlay {
    padding-top: max(12vh, env(safe-area-inset-top, 12px));
  }
}
