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

body, html {
  width: 100%; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #222;
  overflow: hidden;
}

#map {
  position: absolute; inset: 0;
  z-index: 0;
}

/* ------------------------------------------------------------------ */
/*  Loading overlay                                                    */
/* ------------------------------------------------------------------ */
#loading-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 999;
  background: rgba(0,0,0,.35);
  transition: opacity .3s;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }
#loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  background: rgba(255,255,255,.96);
  padding: 22px 32px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
  min-width: 280px;
  text-align: center;
}
#loading-bar-track {
  height: 6px;
  border-radius: 3px;
  background: #e0e0e0;
  margin: 10px 0 8px;
  overflow: hidden;
}
#loading-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #4caf50, #2e7d32);
  transition: width .4s ease;
}
#loading-bar-fill.indeterminate {
  width: 40% !important;
  animation: indeterminate 1.2s ease-in-out infinite;
}
@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
#loading-detail {
  font-size: 11.5px;
  color: #777;
  min-height: 16px;
}

/* ------------------------------------------------------------------ */
/*  Shared panel chrome                                                */
/* ------------------------------------------------------------------ */
.panel {
  position: absolute;
  z-index: 800;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
  padding: 14px 18px;
  max-width: 340px;
  pointer-events: auto;
}

/* ------------------------------------------------------------------ */
/*  Info panel – top left                                              */
/* ------------------------------------------------------------------ */
#info-panel {
  top: 12px; left: 12px;
  max-width: 310px;
}
#info-panel h1 {
  font-size: 16px; font-weight: 700;
  margin-bottom: 6px;
}
#info-panel p {
  font-size: 12.5px; line-height: 1.45;
  color: #444;
  margin-bottom: 0.65em;
}
#info-panel p:last-child { margin-bottom: 0; }
#info-panel .info-panel-disclaimer {
  font-size: 12px;
  line-height: 1.4;
  color: #555;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 6px;
  border-left: 3px solid #999;
}
#info-panel .info-panel-attribution {
  font-size: 11.5px;
  color: #666;
  margin-top: 8px;
}
#info-panel .info-panel-attribution a {
  color: #1565c0;
}

/* ------------------------------------------------------------------ */
/*  Neighborhood dropdown – top right                                  */
/* ------------------------------------------------------------------ */
#neighborhood-panel {
  top: 12px; right: 12px;
}
#neighborhood-panel label {
  display: block;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #666;
  margin-bottom: 5px;
}
#neighborhood-select {
  width: 100%; min-width: 220px;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 13px;
  background: #fff;
}

/* ------------------------------------------------------------------ */
/*  Slider – bottom center                                             */
/* ------------------------------------------------------------------ */
#slider-panel {
  bottom: 24px;
  left: 50%; transform: translateX(-50%);
  width: 420px; max-width: calc(100vw - 24px);
  text-align: center;
}
#slider-label {
  font-weight: 600; font-size: 14px;
  margin-bottom: 6px;
}
#slider-value {
  color: #d32f2f;
  font-variant-numeric: tabular-nums;
}
#buffer-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%; height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #4caf50 0%, #d32f2f 100%);
  outline: none;
  cursor: pointer;
}
#buffer-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #555;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  cursor: grab;
}
#buffer-slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #555;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  cursor: grab;
}
#slider-range-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: #888;
  margin-top: 3px;
}

/* ------------------------------------------------------------------ */
/*  Stats / draw panel – right side                                    */
/* ------------------------------------------------------------------ */
#stats-panel {
  top: 90px; right: 12px;
  width: 260px;
}
#stats-panel h2 {
  font-size: 14px; font-weight: 700;
  margin-bottom: 6px;
}
.hint {
  font-size: 12px; color: #777;
  line-height: 1.4;
  margin-bottom: 10px;
}

#draw-buttons {
  display: flex; gap: 6px;
  margin-bottom: 10px;
}
#draw-buttons button {
  flex: 1;
  padding: 6px 4px;
  font-size: 12px;
  border: 1px solid #bbb;
  border-radius: 5px;
  background: #f5f5f5;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
#draw-buttons button:hover:not(:disabled) {
  background: #e0e0e0;
  border-color: #888;
}
#draw-buttons button:disabled {
  opacity: .45;
  cursor: default;
}
#draw-buttons button.active {
  background: #1976d2;
  color: #fff;
  border-color: #1565c0;
}

/* Collapsible instructions (caret on summary) */
.stats-instructions {
  margin-bottom: 10px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fafafa;
  overflow: hidden;
}
.stats-instructions-summary {
  list-style: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.stats-instructions-summary::-webkit-details-marker {
  display: none;
}
.stats-instructions-summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent #555;
  flex-shrink: 0;
  transition: transform 0.15s ease;
  transform-origin: 35% 50%;
}
.stats-instructions[open] > .stats-instructions-summary::before {
  transform: rotate(90deg);
}
.stats-instructions-body {
  padding: 0 10px 10px 28px;
  border-top: 1px solid #eee;
}
.stats-instructions-body p {
  font-size: 11.5px;
  line-height: 1.45;
  color: #555;
  margin: 8px 0 0;
}

.hidden { display: none !important; }

.stat-row {
  display: flex; justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.stat-label { font-size: 13px; color: #555; }
.stat-value {
  font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #d32f2f;
}

#stat-bar-wrap {
  display: flex;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  background: #eee;
  margin-bottom: 6px;
}
#stat-bar-remaining {
  background: #4caf50;
  transition: width .2s;
}
#stat-bar-lost {
  background: #d32f2f;
  transition: width .2s;
}

.stat-caption {
  font-size: 11px; color: #777;
  display: flex; align-items: center; gap: 4px;
}
.swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
}
.swatch.available  { background: #4caf50; }
.swatch.eliminated { background: #d32f2f; margin-left: 8px; }

/* ------------------------------------------------------------------ */
/*  Legend – bottom left                                                */
/* ------------------------------------------------------------------ */
#legend-panel {
  bottom: 24px; left: 12px;
  font-size: 12px;
}
.legend-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.legend-toggle {
  display: flex; align-items: center; gap: 5px;
  cursor: pointer;
  font-size: 12px;
  user-select: none;
}
.legend-toggle input[type="checkbox"] {
  width: 14px; height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: #e65100;
}

/* ------------------------------------------------------------------ */
/*  Responsive                                                         */
/* ------------------------------------------------------------------ */
@media (max-width: 640px) {
  #info-panel {
    max-width: min(310px, calc(100vw - 24px));
    max-height: min(42vh, 320px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #stats-panel { top: auto; bottom: 100px; right: 8px; width: 220px; }
  #slider-panel { width: calc(100vw - 16px); }
  #neighborhood-panel { top: 8px; right: 8px; }
  #neighborhood-select { min-width: 160px; }
}
