:root {
  --bg: #15171a;
  --panel: #1d2024;
  --border: #2e3238;
  --text: #e4e6e8;
  --muted: #8a9099;
  --accent: #d4a63a;
  --bunker: #8fa35a;
  --lost: #c0583f;
  --ruin: #9a7fc2;
  --mine: #3fa7c0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body { display: flex; }

#sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#map { flex: 1; height: 100%; }

h1 { margin: 0; font-size: 22px; letter-spacing: .5px; color: var(--accent); }
h2 { margin: 4px 0 0; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
.tagline { margin: 2px 0 0; color: var(--muted); }

input[type="search"], input:not([type]), input[type="date"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.filters, .sources { display: flex; flex-direction: column; gap: 4px; }
.sources-box summary { cursor: pointer; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.sources-box[open] summary { margin-bottom: 6px; }
.filters select { margin-top: 4px; }
.filters label, .sources label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.sources small { color: var(--muted); }
.status { font-size: 12px; color: var(--muted); min-height: 16px; }
.status.error { color: var(--lost); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.bunker { background: var(--bunker); }
.dot.lost { background: var(--lost); }
.dot.ruin { background: var(--ruin); }
.dot.mine { background: var(--mine); }
.dot.nature { background: #a3a9b3; }

.actions { display: flex; gap: 8px; }
button, .button {
  flex: 1;
  padding: 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  text-align: center;
}
button:hover, .button:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: #111; border-color: var(--accent); }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); }
button.danger { color: var(--lost); }

#list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
#list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#list li:hover { background: var(--bg); }
#list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list li .src { font-size: 11px; color: var(--muted); }
#count { color: var(--text); }

footer { font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; }

/* Markers */
.pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #111;
  box-shadow: 0 0 0 2px rgba(255,255,255,.6);
}
.pin.bunker { background: var(--bunker); }
.pin.lost { background: var(--lost); }
.pin.ruin { background: var(--ruin); }
.pin.approx { border-style: dashed; opacity: .75; }
.pin.mine { border-color: var(--mine); box-shadow: 0 0 0 2px var(--mine); }

/* Popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; min-width: 200px; }
.popup .photo { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 6px; margin-bottom: 8px; background: var(--bg); }
.popup h4 { margin: 0 0 4px; font-size: 15px; }
.popup .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.popup p { margin: 4px 0; white-space: pre-wrap; }
.popup .links { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.popup a { color: var(--accent); }
.popup .links button { flex: none; padding: 2px 8px; font-size: 12px; }

#map.adding { cursor: crosshair; }

/* Dialog */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin-bottom: 10px; color: var(--muted); }
dialog label > * { margin-top: 4px; }
dialog menu { display: flex; gap: 8px; padding: 0; margin: 12px 0 0; }
.coords { font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }

#sheet-toggle { display: none; }

/* Phones: full-screen map, sidebar as a bottom sheet. */
@media (max-width: 720px) {
  #map { position: fixed; inset: 0; height: auto; }
  #sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 72%;
    z-index: 1100;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
    transform: translateY(100%);
    transition: transform .25s ease;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  body.sheet-open #sidebar { transform: none; }
  #sidebar { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #list { flex: none; overflow: visible; }
  #sheet-toggle {
    display: block;
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 1200;
    flex: none;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--accent);
    color: #111;
    border: none;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  }
  body.sheet-open #sheet-toggle { bottom: calc(72% + 10px); }
  .leaflet-control-attribution { max-height: 2.6em; overflow: hidden; }
}

.lidar-opacity { background: var(--panel); color: var(--text); padding: 6px 8px; font-size: 12px; }
.lidar-opacity input { width: 110px; vertical-align: middle; }

/* Clusters */
.cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font: 600 12px/1 system-ui, sans-serif;
  color: #111;
  box-shadow: 0 0 0 5px rgba(0, 0, 0, .25);
}
.cluster-s { background: rgba(143, 196, 90, .9); }
.cluster-m { background: rgba(230, 196, 60, .9); }
.cluster-l { background: rgba(230, 140, 60, .92); }

footer a { color: var(--accent); }
#notice-dialog p, #notice-dialog li { color: var(--text); line-height: 1.5; }
#notice-dialog a { color: var(--accent); }
#notice-dialog ul { padding-left: 18px; }

/* Current-location button */
.locate-control a.locate-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; color: #555; background: #fff; cursor: pointer;
}
.locate-control a.locate-btn:hover { color: #222; }
.locate-control a.locate-btn.searching { color: #2f7df6; animation: locate-pulse 1s ease-in-out infinite; }
.locate-control a.locate-btn.active { color: #2f7df6; }
@keyframes locate-pulse { 50% { opacity: .35; } }
@media (max-width: 720px) {
  .locate-control a.locate-btn { width: 44px; height: 44px; }
}

.popup .photo-credit { font-size: 11px; color: var(--muted); margin: -4px 0 8px; line-height: 1.35; }
.popup .photo-credit a { color: var(--muted); text-decoration: underline; }
