:root {
  --bg: #161b16;
  --bg2: #1f261f;
  --line: #32402f;
  --text: #eef2ea;
  --muted: #9fae9a;
  --accent: #6abf4b;
  --danger: #e05a4e;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
#map { position: fixed; inset: 0; }
.hidden { display: none !important; }

h1 { font-size: 19px; margin: 0; letter-spacing: .3px; }
h1 span { color: var(--accent); font-weight: 500; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 18px 0 8px; }

/* ---- floating buttons ---- */
.fab-stack {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 10px;
  display: flex; flex-direction: column; gap: 10px; z-index: 30;
}
.fab {
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(.94); }

.fab.recording { border-color: #e53935; animation: recpulse 1.4s ease-in-out infinite; }
@keyframes recpulse { 50% { box-shadow: 0 0 0 6px rgba(229, 57, 53, .25); } }

/* ---- search ---- */
#searchbox {
  position: fixed; z-index: 28;
  top: calc(10px + env(safe-area-inset-top));
  left: 70px; right: 60px; max-width: 430px; margin: 0 auto;
}
@media (min-width: 761px) { #searchbox { left: 74px; right: auto; width: 400px; } }
#search-form { position: relative; }
#searchbox .search-icon {
  position: absolute; left: 12px; top: 12px; width: 20px; height: 20px; color: var(--muted);
  pointer-events: none;
}
#search-input {
  width: 100%; padding: 12px 14px 12px 40px; border-radius: 23px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  font: inherit; font-size: 14.5px; box-shadow: var(--shadow); outline: none;
}
#search-input:focus { border-color: var(--accent); }
#search-input.searching { opacity: .6; }
#search-results {
  margin-top: 6px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.search-row {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; text-align: left; padding: 10px 14px;
  background: none; border: none; border-bottom: 1px solid rgba(255,255,255,.05);
  color: var(--text); font: inherit; cursor: pointer;
}
.search-row:hover { background: var(--bg2); }
.search-row small { color: var(--muted); font-size: 12px; }

/* ---- recording chip ---- */
.rec-chip {
  position: fixed; z-index: 28; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid #e53935; border-radius: 24px;
  padding: 8px 10px 8px 16px; box-shadow: var(--shadow); font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e53935; animation: recpulse 1.4s infinite; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---- beeline HUD ---- */
.beeline {
  position: fixed; z-index: 28; left: 50%; transform: translateX(-50%);
  top: calc(64px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px 10px 14px; box-shadow: var(--shadow);
}
.bee-arrow { width: 34px; height: 34px; transition: transform .3s ease; }
.bee-meta { display: flex; flex-direction: column; }
.bee-meta strong { font-size: 14px; }
.bee-dist { color: var(--accent); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- account ---- */
.account-box { margin-top: 12px; }
#account-signedin { display: flex; align-items: center; gap: 10px; }
#account-signedin.hidden { display: none; }
#account-pic { width: 34px; height: 34px; border-radius: 50%; background: var(--bg2); }
.account-box code { background: var(--bg2); padding: 1px 5px; border-radius: 5px; font-size: 11.5px; }

/* ---- nav options ---- */
.nav-options { display: flex; flex-direction: column; gap: 8px; }
.nav-options .btn { width: 100%; text-align: center; }

/* ---- crosshair placement ---- */
#crosshair {
  position: fixed; inset: 0; z-index: 25; pointer-events: none;
  display: grid; place-items: center;
}
#crosshair svg { width: 56px; height: 56px; }
.crosshair-actions {
  position: absolute; bottom: calc(30px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; pointer-events: auto;
}

/* ---- panel ---- */
.panel {
  position: fixed; z-index: 40; background: var(--bg);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .28s ease;
  overflow: hidden;
}
@media (min-width: 761px) {
  .panel {
    top: 12px; left: 12px; bottom: 12px; width: 340px;
    border-radius: var(--radius);
    transform: translateX(calc(-100% - 24px));
  }
  .panel.open { transform: none; }
  .panel-grab { display: none; }
  .fab-stack { left: 12px; top: 12px; }
  /* Shift floating controls clear of the open sidebar */
  body:has(.panel.open) .fab-stack { left: 366px; }
  body:has(.panel.open) #searchbox { left: 428px; }
}
@media (max-width: 760px) {
  .panel {
    left: 0; right: 0; bottom: 0; max-height: 72dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: none; }
}
.panel-grab { padding: 8px 0 0; display: grid; place-items: center; }
.panel-grab span { width: 42px; height: 4px; border-radius: 2px; background: var(--line); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 8px;
}
.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 9px 4px; background: none; border: none; color: var(--muted);
  font: inherit; font-size: 14px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-page { display: none; overflow-y: auto; padding: 4px 16px 20px; -webkit-overflow-scrolling: touch; }
.tab-page.active { display: block; }

/* ---- basemap + layer rows ---- */
.basemap-row { display: flex; gap: 8px; }
.basemap-btn {
  flex: 1; padding: 9px 0; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--muted); font: inherit; font-size: 13.5px; cursor: pointer;
}
.basemap-btn.sel { border-color: var(--accent); color: var(--text); background: #24331f; }

.layer-list { display: flex; flex-direction: column; }
.layer-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,.04); cursor: pointer;
}
.layer-item input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.swatch {
  width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0;
  background: var(--c); opacity: .85; border: 1px solid rgba(255,255,255,.35);
}
.layer-meta { display: flex; flex-direction: column; min-width: 0; }
.layer-meta strong { font-weight: 600; font-size: 14.5px; }
.layer-meta small, .wpt-meta small { color: var(--muted); font-size: 12px; }
.zoomhint { color: #d9a441 !important; }
.fineprint { color: var(--muted); font-size: 12px; margin-top: 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 2px; }

/* ---- waypoint / track lists ---- */
.row-actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.wpt-list { display: flex; flex-direction: column; }
.wpt-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,.04); cursor: pointer;
}
.wpt-item .dot { width: 13px; height: 13px; border-radius: 50%; background: var(--c); border: 2px solid #111; flex-shrink: 0; }
.wpt-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.wpt-meta strong { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- buttons ---- */
.btn {
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d130a; font-weight: 600; }
.btn-danger { background: none; border-color: var(--danger); color: var(--danger); }
.file-btn { display: inline-flex; align-items: center; }
.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 16px;
  cursor: pointer; padding: 6px 8px;
}

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  color: var(--text); width: min(92vw, 380px); padding: 20px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 14px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog input, dialog textarea {
  width: 100%; margin-top: 4px; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit;
}
.color-row { display: flex; gap: 10px; margin: 4px 0 12px; }
.color-dot {
  width: 26px; height: 26px; border-radius: 50%; background: var(--c);
  border: 2px solid transparent; cursor: pointer;
}
.color-dot.sel { border-color: #fff; }
.coords { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; font-variant-numeric: tabular-nums; }

/* ---- popup ---- */
.maplibregl-popup-content {
  background: var(--bg) !important; color: var(--text);
  border-radius: 12px; border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 12px 14px; font: 13.5px/1.45 inherit;
}
.maplibregl-popup-tip { border-top-color: var(--bg) !important; border-bottom-color: var(--bg) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 2px 8px; }
.pop-section + .pop-section { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.pop-chip {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  color: var(--c); border: 1px solid var(--c); border-radius: 20px; padding: 1px 9px; margin-bottom: 5px;
}
.popup h3 { margin: 0 0 6px; font-size: 14.5px; }
.pop-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.pop-row span { color: var(--muted); }
.pop-note { margin-top: 7px; color: #d9c37f; font-size: 12px; }

/* ---- toast + loading ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 18px; box-shadow: var(--shadow); max-width: 86vw; font-size: 14px;
}
.loading {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 50; display: flex; gap: 9px; align-items: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px;
  padding: 7px 15px; font-size: 13px; color: var(--muted); box-shadow: var(--shadow);
}
.spin, .mini-spin {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* maplibre control theming */
.maplibregl-ctrl-group { background: var(--bg2) !important; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(.9); }
.maplibregl-ctrl-attrib { font-size: 10px !important; }
