:root {
  --bg: #f4f4f5; --surface: #ffffff; --surface-2: #f4f4f5; --text: #0a0a0a; --muted: #6b7280;
  --border: rgb(0 0 0 / 0.08); --shadow: 0 8px 30px rgb(0 0 0 / 0.12), 0 1px 3px rgb(0 0 0 / 0.08);
  --accent: #e82127; --good: #16a34a; --ok: #d97706; --bad: #dc2626; --none: #9ca3af;
  --radius: 16px; --blur: saturate(180%) blur(16px); --glass: rgb(255 255 255 / 0.82);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a; --surface: #161618; --surface-2: #222225; --text: #f5f5f5; --muted: #9ca3af;
    --border: rgb(255 255 255 / 0.08); --shadow: 0 8px 30px rgb(0 0 0 / 0.5); --glass: rgb(22 22 24 / 0.82);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 "Inter", system-ui, -apple-system, sans-serif; letter-spacing: -0.01em;
  background: var(--bg); color: var(--text); overflow: hidden;
}
a { color: inherit; }
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer; border: 0; border-radius: 999px;
  padding: 10px 16px; background: var(--surface-2); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active, .btn:active { transform: scale(0.97); }
.btn.primary, button.primary { background: var(--text); color: var(--bg); }
.btn.accent { background: var(--accent); color: #fff; }
button.danger { background: transparent; color: var(--bad); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; }

/* ---------- Map + floating chrome ---------- */
#map { position: fixed; inset: 0; background: var(--bg); }
.chrome {
  position: fixed; left: 0; right: 0; top: 0; z-index: 1000; pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) 16px 0; display: grid; gap: 10px;
}
.chrome > * { pointer-events: auto; }
.searchbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px;
  background: var(--glass); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-radius: 999px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.searchbar .logo { font-weight: 700; letter-spacing: -0.03em; white-space: nowrap; }
.searchbar .logo b { color: var(--accent); }
.searchbar input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font: inherit; padding: 8px 4px; outline: none;
}
.icon-btn { width: 40px; height: 40px; padding: 0; background: var(--surface-2); }
.icon-btn.on { background: var(--accent); color: #fff; }
.row-chips { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.segmented {
  display: inline-flex; padding: 4px; border-radius: 999px; box-shadow: var(--shadow);
  background: var(--glass); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
}
.segmented button { padding: 7px 16px; background: transparent; font-size: 14px; }
.segmented button.active { background: var(--text); color: var(--bg); }
.chip {
  padding: 7px 14px; font-size: 14px; box-shadow: var(--shadow); border: 1px solid var(--border);
  background: var(--glass); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.chip.on { background: var(--good); color: #fff; }
.count {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1000; font-size: 13px; padding: 6px 12px; border-radius: 999px;
  background: var(--glass); backdrop-filter: var(--blur); box-shadow: var(--shadow); color: var(--muted);
}

/* ---------- Markers ---------- */
.pin {
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
}
.score-pin {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg); color: #fff; font-weight: 700; font-size: 13px;
  border: 2px solid #fff; box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}
.score-pin span { transform: rotate(45deg); }
.marker-cluster div { background: var(--text) !important; color: var(--bg) !important; font-weight: 600; }
.marker-cluster { background: rgb(0 0 0 / 0.15) !important; }
.me { width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgb(37 99 235 / 0.25); }
.leaflet-control-attribution { font-size: 10px; background: var(--glass) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-control-zoom { display: none; }

/* ---------- List ---------- */
#list {
  position: fixed; inset: 0; z-index: 500; overflow-y: auto; background: var(--bg);
  padding: 140px 16px 72px;
}
.list-inner { max-width: 720px; margin: 0 auto; display: grid; gap: 10px; }
.hint { text-align: center; padding: 24px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  border: 1px solid var(--border);
}
.item:hover { border-color: var(--muted); }
.item h3 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.item .sub { font-size: 13px; color: var(--muted); }
.item .right { grid-row: span 2; text-align: right; display: grid; justify-items: end; gap: 4px; }
.dist { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.score {
  display: inline-grid; place-items: center; min-width: 38px; height: 26px; padding: 0 8px;
  border-radius: 8px; color: #fff; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
}
.score.lg { min-width: 56px; height: 40px; font-size: 20px; border-radius: 12px; }
.mini { display: flex; gap: 3px; margin-top: 6px; }
.mini i { width: 18px; height: 4px; border-radius: 2px; background: var(--surface-2); }
.more { justify-self: center; margin-top: 8px; }

/* ---------- Sheet (detail) ---------- */
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border: 0; border-radius: 24px 24px 0 0; padding: 8px 20px max(20px, env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  animation: up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 24px; } }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.35); backdrop-filter: blur(2px); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--surface-2); margin: 4px auto 14px; }
.sheet-head { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; line-height: 1.25; letter-spacing: -0.02em; }
.sheet-head .addr { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bars { display: grid; gap: 10px; margin: 6px 0 16px; }
.bar { display: grid; grid-template-columns: 130px 1fr 22px; align-items: center; gap: 10px; font-size: 14px; }
.bar .track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar .fill { height: 100%; border-radius: 4px; }
.bar .n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.quote {
  background: var(--surface-2); border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; margin-bottom: 8px;
}
.meta { font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 18px; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions > * { flex: 1; }

/* ---------- Admin ---------- */
.page { position: fixed; inset: 0; overflow-y: auto; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--glass); backdrop-filter: var(--blur); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 16px; margin: 0; flex: 1; }
.form { max-width: 560px; margin: 0 auto; padding: 20px 16px 120px; }
.form h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 4px 16px; margin-top: 16px; }
.field { padding: 14px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field .label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 10px; }
.field .label small { font-weight: 400; color: var(--muted); }
.seg5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg5 input { position: absolute; opacity: 0; pointer-events: none; }
.seg5 label {
  display: grid; place-items: center; height: 44px; border-radius: 12px; background: var(--surface-2);
  font-weight: 600; cursor: pointer; user-select: none;
}
.seg5 input:checked + label { color: #fff; }
.seg5 input:focus-visible + label { outline: 2px solid var(--text); }
input[type="date"], input[type="search"].plain, textarea {
  font: inherit; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
textarea { min-height: 140px; resize: vertical; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  background: var(--glass); backdrop-filter: var(--blur); border-top: 1px solid var(--border);
}
.savebar .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.savebar .msg { flex: 1; font-size: 13px; color: var(--muted); }
.results { display: grid; gap: 8px; margin-top: 12px; }
.seg5 input[value="1"]:checked + label, .seg5 input[value="2"]:checked + label { background: var(--bad); }
.seg5 input[value="3"]:checked + label { background: var(--ok); }
.seg5 input[value="4"]:checked + label, .seg5 input[value="5"]:checked + label { background: var(--good); }
.clear { padding: 2px 8px; font-size: 12px; background: transparent; color: var(--muted); font-weight: 400; }
/* Mute the standard OSM tiles so markers stand out; invert them in dark mode. */
.tiles { filter: grayscale(0.85) contrast(0.9) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  .tiles { filter: grayscale(1) invert(1) brightness(0.85) contrast(0.9); }
}
