:root {
  color-scheme: dark;
  --bg: #121214;
  --sheet: #141416;
  --card: #1c1c1f;
  --line: #2e2e33;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --orange: #ff6d00;
  --ink: #1a1008;
  --green: #4ade80;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

button, .btn, input, select { font-family: inherit; }
button, .btn { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

#safeProbe {
  position: absolute;
  width: 0;
  height: var(--safe-b);
  pointer-events: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

#map { height: 100%; background: #1c1e1a; }
.leaflet-container { background: #1c1e1a; font-family: inherit; }

#sheet {
  position: relative;
  flex: none;
  height: 70dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--sheet);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
  z-index: 2;
  padding-bottom: var(--safe-b);
  overflow: hidden;
  transition: height 0.22s ease;
}

#sheet.is-drag { transition: none; }

#handle {
  flex: none;
  height: 28px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 0 6px;
  touch-action: none;
  cursor: grab;
}

.grab {
  display: block;
  width: 36px;
  height: 4px;
  margin: 0 auto;
  border-radius: 4px;
  background: #3f3f46;
}

#chrome { flex: none; }
#brand { touch-action: none; min-width: 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px 0 14px;
}

.brand strong { display: block; font-size: 16px; letter-spacing: -0.01em; }
#progressText { display: block; margin-top: 1px; color: var(--muted); font-size: 12px; }

#menuBtn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}

#menuBtn svg { fill: currentColor; display: block; margin: 0 auto; }

.bar { height: 3px; background: #27272a; }
.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  transition: width 0.25s ease;
}

#filters, #detailHead { padding: 6px 12px 6px; }

.search { position: relative; }
.search input {
  width: 100%;
  height: 40px;
  font-size: 16px;
  padding: 0 36px 0 12px;
  border-radius: 10px;
  border: 1px solid #333338;
  background: #0e0e10;
  color: white;
}
.search input:focus { border-color: var(--orange); outline: none; }
#searchClear {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.chips button {
  flex: none;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid #333338;
  background: #1c1c1f;
  color: #e4e4e7;
  font-size: 13px;
  font-weight: 650;
}
.chips button[aria-pressed="true"] {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--ink);
}
.chips button.tier-a[aria-pressed="true"] { background: #2563eb; border-color: #2563eb; color: white; }
.chips button.tier-b[aria-pressed="true"] { background: #15803d; border-color: #15803d; color: white; }

.ascent {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.ascent-label {
  flex: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  padding-left: 2px;
}
.ascent input {
  flex: 1;
  min-width: 0;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #333338;
  background: #0e0e10;
  color: white;
  font-size: 14px;
  padding: 0 8px;
  text-align: center;
}
.ascent input:focus {
  border-color: var(--orange);
  outline: none;
}
.ascent input::-webkit-outer-spin-button,
.ascent input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.ascent input[type=number] {
  -moz-appearance: textfield;
}

.selects {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 6px;
  margin-top: 6px;
}
select {
  width: 100%;
  min-width: 0;
  height: 40px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid #333338;
  background: #0e0e10;
  color: white;
  padding: 0 28px 0 10px;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
#linesBtn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid #3f3f46;
  background: #27272a;
  color: white;
  font-size: 13px;
  font-weight: 650;
}
#linesBtn[aria-pressed="true"] { background: var(--orange); border-color: var(--orange); color: var(--ink); }

#scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 10px 12px;
}

.card {
  display: flex;
  align-items: stretch;
  gap: 2px;
  margin: 0 0 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-left-color: transparent;
  border-radius: 12px;
}
.card.is-done { background: #18181b; }
.card.is-done .card-title { color: #d4d4d8; }
.card-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 11px 4px 11px 12px;
}
.card-kicker { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}
.badge.tier-S { color: #ffb067; background: rgba(255, 109, 0, 0.16); }
.badge.tier-A { color: #93c5fd; background: rgba(37, 99, 235, 0.18); }
.badge.tier-B { color: #86efac; background: rgba(22, 163, 74, 0.18); }
.prov { color: var(--muted); font-size: 12px; }
.swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.card-title { font-size: 15px; font-weight: 700; line-height: 1.3; color: #fafafa; }
.card-meta, .card-why { color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 4px; }
.card-why {
  color: #d4d4d8;
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-done {
  width: 48px;
  flex: none;
  border: 0;
  background: transparent;
  color: #71717a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-done .mark { opacity: 0; }
.card-done[aria-pressed="true"] { color: var(--green); }
.card-done[aria-pressed="true"] .mark { opacity: 1; }

.empty { padding: 18px 8px; color: var(--muted); font-size: 14px; }
.empty button {
  display: block;
  margin-top: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #3f3f46;
  background: #27272a;
  color: white;
}

.detail-top { display: flex; gap: 6px; align-items: flex-start; }
.detail-titles { min-width: 0; flex: 1; }
.back {
  width: 36px;
  height: 36px;
  min-height: 36px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: #27272a;
  color: #f4f4f5;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}
#dTitle {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#dKicker { margin: 2px 0 8px; color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
@media (max-width: 859px) {
  .actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.btn {
  min-height: 40px;
  padding: 0 6px;
  border-radius: 10px;
  border: 1px solid #3f3f46;
  background: #27272a;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.primary { background: var(--orange); border-color: var(--orange); color: var(--ink); flex: 1; }
.btn.done[aria-pressed="true"] { background: #14532d; border-color: #166534; color: #bbf7d0; }
.btn.ghost { width: 100%; margin-top: 12px; background: transparent; }
.note {
  min-height: 0;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note:empty { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.stat {
  background: #1c1c1f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 6px;
}
.stat b { display: block; font-size: 13px; }
.stat span { color: var(--muted); font-size: 10px; }
.away { margin: 10px 0 0; color: #7dd3fc; font-size: 13px; }
.why-block { margin: 12px 0; color: #e4e4e7; font-size: 14px; line-height: 1.45; }
.note { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.park { margin: 0; color: var(--muted); font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.tags span {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #27272a;
  color: #d4d4d8;
}
.tags span.bad { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

.dossier {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #3f3f46;
}
#dossierBtn[aria-pressed="true"] {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--ink);
}
.dossier h2, .dossier h3 { font-size: 15px; margin: 16px 0 6px; }
.dossier p, .dossier li { font-size: 14px; line-height: 1.45; color: #d4d4d8; }
.dossier ul { margin: 6px 0; padding-left: 18px; }
.dossier blockquote {
  margin: 0 0 8px;
  padding-left: 8px;
  border-left: 2px solid var(--orange);
  color: var(--muted);
}
.dossier hr { border: 0; border-top: 1px solid #2a2a2e; margin: 12px 0; }
.dossier code { font-size: 12px; color: #e4e4e7; }

#menu {
  position: absolute;
  top: 64px;
  right: 10px;
  z-index: 6;
  width: min(300px, calc(100% - 20px));
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  background: #1c1c1f;
  border: 1px solid #333338;
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
#menu button {
  min-height: 44px;
  text-align: left;
  background: transparent;
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 0 10px;
  font-size: 15px;
}
#menu button:hover, #menu button:focus-visible { background: #27272a; }
#menu p { margin: 6px 8px; color: var(--muted); font-size: 12px; line-height: 1.4; }
#resetBtn.armed { color: #fca5a5; }

.map-prompt {
  position: absolute;
  z-index: 800;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  background: #18181b;
  color: var(--text);
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 6px 6px 6px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.map-prompt[hidden] {
  display: none !important;
}
.map-prompt button {
  min-height: 32px;
  border: 0;
  background: var(--orange);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  border-radius: 999px;
  padding: 0 12px;
  cursor: pointer;
}

#toast {
  position: absolute;
  z-index: 800;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  background: #18181b;
  color: var(--text);
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 8px 8px 8px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 14px;
}
#toast button {
  min-height: 36px;
  border: 0;
  background: var(--orange);
  color: var(--ink);
  font-weight: 700;
  border-radius: 999px;
  padding: 0 12px;
}

.boot-error { padding: 24px; font-size: 16px; }

.map-tools { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
#baseBtn, #locateBtn {
  height: 44px;
  border-radius: 12px;
  border: 1px solid #333338;
  background: #161618;
  color: white;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
#baseBtn { padding: 0 12px; font-weight: 700; font-size: 14px; }
#locateBtn { width: 44px; display: grid; place-items: center; }
#locateBtn svg { display: block; }
.base-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #161618;
  border: 1px solid #333338;
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.base-menu button {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: white;
  text-align: left;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 14px;
}
.base-menu button[aria-pressed="true"] { background: var(--orange); color: var(--ink); }

.leaflet-top.leaflet-right {
  top: calc(var(--safe-t) + 8px);
  right: 8px;
}
.leaflet-bar {
  border: 1px solid #333338 !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28) !important;
}
.leaflet-bar a {
  background: #161618 !important;
  color: white !important;
  width: 44px !important;
  height: 44px !important;
  line-height: 44px !important;
  border-bottom-color: #333338 !important;
}
.leaflet-bar a:hover { background: #27272a !important; }
.leaflet-control-attribution {
  background: rgba(18, 18, 20, 0.78) !important;
  color: #a1a1aa !important;
  font-size: 10px !important;
  max-width: 46vw;
}
.leaflet-control-attribution a { color: #d4d4d8 !important; }

.pin-wrap, .cluster-icon {
  background: transparent !important;
  border: none !important;
}
.pin {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  --c: #ff6d00;
}
.pin.tier-A { --c: #3b82f6; }
.pin.tier-B { --c: #22c55e; }
.pin span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.pin.is-on span {
  width: 18px;
  height: 18px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 50%, transparent);
}
.pin.is-done span { background: #3f3f46; border-color: var(--green); }
.cluster {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 22, 0.92);
  color: white;
  border: 2px solid var(--orange);
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.cluster.is-done { border-color: var(--green); color: #bbf7d0; }

@media (min-width: 860px) {
  #app { flex-direction: row; }
  #sheet {
    order: -1;
    width: 400px;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    border-right: 1px solid #2a2a2e;
    padding-bottom: 0;
    transition: none;
  }
  #handle { display: none; }
  #stage { order: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet, .bar > span { transition: none; }
}

/* Language switcher in menu */
.lang-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.lang-switch button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.lang-switch button.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}
.lang-switch .sep {
  color: var(--muted);
  font-size: 12px;
  opacity: 0.5;
}

