:root {
  --bg: #0b0f14;
  --panel: rgba(14, 19, 26, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e6edf3;
  --dim: #8b98a5;
  --accent: #3ee0a1;
  --accent-2: #4cc3ff;
  --warn: #ffb547;
  --bad: #ff5d5d;
  --r: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden;
  overscroll-behavior: none; }
#map { position: fixed; inset: 0; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: rgba(255,255,255,.06);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.8; fill: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.glass { background: var(--panel); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.45); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; color: var(--dim); flex: none; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }

/* top search */
#topbar { position: fixed; top: calc(10px + var(--sat)); left: 10px; right: 10px; z-index: 20; max-width: 520px; }
.search { display: flex; align-items: center; gap: 8px; border-radius: var(--r); padding: 4px 6px 4px 12px; }
.search input { border: 0; background: none; padding: 8px 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); flex: none; box-shadow: 0 0 8px currentColor; }
.dot.on { background: var(--accent); }
#results { margin-top: 6px; border-radius: var(--r); max-height: 50vh; overflow: auto; }
#results button { display: block; width: 100%; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#results button:last-child { border-bottom: 0; }
#results small { color: var(--dim); display: block; }

/* crosshair */
#crosshair { position: fixed; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; pointer-events: none; z-index: 5; opacity: .55; }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
#crosshair::before { left: 12px; top: 0; width: 2px; height: 26px; }
#crosshair::after { top: 12px; left: 0; height: 2px; width: 26px; }
body.tool-active #crosshair { opacity: 1; }
body.tool-active #crosshair::before, body.tool-active #crosshair::after { background: var(--accent); }

/* fabs */
#fabs { position: fixed; right: 10px; top: calc(66px + var(--sat)); display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.fab { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.fab.on { color: var(--accent); }
.fill-red { fill: var(--bad); stroke: none; } .fill-dim { fill: var(--dim); stroke: none; }
#northIcon { transition: transform .1s linear; }

/* hud */
#hud { position: fixed; left: 10px; bottom: calc(78px + var(--sab)); z-index: 10; border-radius: 10px; padding: 4px 10px;
  font: 12px var(--mono); display: flex; gap: 10px; align-items: center; max-width: calc(100% - 20px); }
#coordText { font: inherit; color: var(--text); padding: 2px 0; white-space: nowrap; }
#hudMeta { color: var(--dim); white-space: nowrap; }

/* toolbar */
#toolbar { position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--sab)); z-index: 15; border-radius: 18px;
  display: flex; justify-content: space-around; padding: 6px; max-width: 520px; margin: 0 auto; }
#toolbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; border-radius: 12px; color: var(--dim); font-size: 11px; min-width: 56px; }
#toolbar button.on, #toolbar button:hover { color: var(--accent); background: rgba(62,224,161,.08); }

/* tool card */
#toolcard { position: fixed; left: 10px; right: 10px; bottom: calc(112px + var(--sab)); z-index: 12; border-radius: var(--r); padding: 12px; max-width: 520px; margin: 0 auto; }
#toolcard .read { font: 600 18px var(--mono); }
#toolcard .sub { color: var(--dim); font-size: 12px; font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.btn { border-radius: 10px; padding: 9px 12px; background: rgba(255,255,255,.07); border: 1px solid var(--line); flex: 1; white-space: nowrap; text-align: center; }
.btn:hover { background: rgba(255,255,255,.12); }
.btn.primary { background: var(--accent); color: #04140d; border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 12px; flex: none; }
.mt { margin-top: 10px; }

/* sheet */
#sheet { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; max-height: 78vh; border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column; padding-bottom: var(--sab); max-width: 560px; margin: 0 auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; padding: 14px 14px 8px 18px; position: relative; }
.grabber { position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 3px; background: rgba(255,255,255,.2); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
#sheetBody { overflow: auto; padding: 0 16px 18px; -webkit-overflow-scrolling: touch; }
.sec { margin-top: 14px; }
.sec h3 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); margin: 0 0 6px; }
.card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: rgba(255,255,255,.025); }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small, .muted { color: var(--dim); font-size: 12px; }
.item .extra { width: 100%; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: rgba(76,195,255,.15); color: var(--accent-2); text-transform: uppercase; letter-spacing: .05em; }
.badge.off { background: rgba(255,93,93,.15); color: var(--bad); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 12px; background: rgba(255,255,255,.14); transition: .15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.tile { text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.03); }
.tile:hover { border-color: var(--accent); }
.tile b { display: block; margin-bottom: 2px; }
.tile small { color: var(--dim); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; }
.chip.sel { border-color: #fff; }
label.f { display: block; font-size: 12px; color: var(--dim); margin: 10px 0 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; font-family: var(--mono); }
.kv span:nth-child(odd) { color: var(--dim); }
.photo { width: 100%; border-radius: 12px; display: block; margin-top: 8px; }
.progress { height: 4px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.help { font-size: 12px; color: var(--dim); line-height: 1.5; }
.help code { font-family: var(--mono); background: rgba(255,255,255,.07); padding: 1px 4px; border-radius: 4px; color: var(--text); word-break: break-all; }

#toast { position: fixed; left: 50%; top: calc(70px + var(--sat)); transform: translateX(-50%); z-index: 50; background: var(--panel);
  border: 1px solid var(--line); padding: 9px 14px; border-radius: 12px; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.5); backdrop-filter: blur(12px); }

/* maplibre popups */
.maplibregl-popup-content { background: var(--panel); color: var(--text); border-radius: 12px; border: 1px solid var(--line); padding: 10px 12px; backdrop-filter: blur(12px); max-width: 320px; }
.maplibregl-popup-tip { display: none; }
.maplibregl-popup-close-button { color: var(--dim); font-size: 18px; right: 4px; top: 2px; }
.pop h4 { margin: 0 18px 4px 0; font-size: 14px; }
.pop img { width: 100%; min-height: 120px; border-radius: 8px; display: block; background: #000; margin: 6px 0; }
.pop .row { margin-top: 6px; }
.maplibregl-ctrl-attrib { background: rgba(0,0,0,.4) !important; }
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }
.maplibregl-ctrl-bottom-right { bottom: calc(80px + var(--sab)); }
.maplibregl-ctrl-scale { background: rgba(0,0,0,.4); color: var(--text); border-color: var(--text); }
.maplibregl-ctrl-top-left { top: calc(62px + var(--sat)); }

@media (min-width: 900px) {
  #sheet { left: 10px; right: auto; top: calc(70px + var(--sat)); bottom: calc(80px + var(--sab)); width: 400px; max-height: none; border-radius: 18px; margin: 0; }
}
@media (min-width: 900px) { #hud { left: auto; right: 10px; } }
