:root {
  --bg: #0a0514;
  --panel: rgba(12, 6, 22, 0.92);
  --border: rgba(255, 45, 196, 0.35);
  --text: #f4ecff;
  --muted: #9a8ab8;
  --accent: #ff2dbe;
  --accent2: #00f5ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
}

html,
body {
  margin: 0;
  height: 100%;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

body {
  background: var(--bg);
}

.map-stack {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.map-pane {
  flex: 1;
  min-height: 0;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.map-float {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  z-index: 550;
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.map-float .fab {
  pointer-events: auto;
}

.fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(18, 8, 32, 0.88);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  touch-action: manipulation;
}

.fab:active {
  filter: brightness(1.08);
}

.fab-accent {
  background: linear-gradient(145deg, rgba(255, 45, 196, 0.55), rgba(120, 0, 255, 0.45));
  border-color: rgba(255, 45, 196, 0.55);
  font-weight: 800;
}

.leaflet-bottom.leaflet-right {
  bottom: 8px;
}

.leaflet-top.leaflet-left {
  top: calc(48px + var(--safe-top));
}

.split-splitter {
  flex: 0 0 12px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  background: linear-gradient(180deg, rgba(255, 45, 196, 0.2), rgba(8, 4, 18, 0.95));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 610;
}

.split-splitter:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: -2px;
}

.split-splitter::after {
  content: "";
  width: 52px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.sheet {
  flex: 0 0 auto;
  height: 280px;
  min-height: 140px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  overflow: hidden;
  z-index: 600;
}

.sheet-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
}

.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(10, 5, 20, 0.92), transparent);
  pointer-events: none;
}

.app-header > * {
  pointer-events: auto;
}

.app-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(255, 45, 196, 0.6);
}

.offline-badge {
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(57, 255, 20, 0.15);
  color: #7dff9a;
  border: 1px solid rgba(57, 255, 20, 0.35);
}

.offline-badge[data-state="pending"] {
  background: rgba(255, 200, 0, 0.12);
  color: #ffd566;
  border-color: rgba(255, 200, 0, 0.35);
}

.sheet-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 8px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sheet-tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: linear-gradient(180deg, rgba(255, 45, 196, 0.08), transparent);
}

.sheet-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

.sheet-tab[aria-selected="true"] .sheet-tab-count {
  background: rgba(255, 45, 196, 0.25);
  color: var(--text);
}

.sheet-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sheet-panel[hidden] {
  display: none;
}

.venue-toolbar {
  display: flex;
  padding: 8px 12px 4px;
  flex-shrink: 0;
}

.cat-chips {
  display: flex;
  gap: 6px;
  padding: 0 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex-shrink: 0;
}

.cat-chips::-webkit-scrollbar {
  display: none;
}

.cat-chip {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.cat-chip[data-active="true"] {
  color: var(--text);
}

.poi-search {
  flex: 1 1 60%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.poi-cat {
  flex: 1 1 40%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 0.9rem;
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.poi-list {
  min-height: 0;
}

.map-attribution {
  margin: 0;
  padding: 6px 14px calc(8px + var(--safe-bottom));
  font-size: 0.65rem;
  line-height: 1.35;
  color: var(--muted);
  opacity: 0.85;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  text-align: center;
}

.map-attribution a {
  color: inherit;
}

.empty-hint {
  margin: 4px 14px 8px;
  padding: 10px 12px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.empty-hint[hidden] {
  display: none;
}

.leaflet-tooltip.poi-tip {
  background: rgba(18, 8, 32, 0.95);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
}

.sheet-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
  flex-shrink: 0;
}

.sheet-toolbar::-webkit-scrollbar {
  display: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 45, 196, 0.12);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.82rem;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(255, 45, 196, 0.45), rgba(120, 0, 255, 0.35));
  border-color: rgba(255, 45, 196, 0.55);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
}

.coord-strip {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 8px 14px 0;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  flex-shrink: 0;
}

.pin-list {
  list-style: none;
  margin: 0;
  padding: 6px 10px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

.pin-item {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  min-height: 56px;
}

.pin-item[data-active="true"] {
  border-color: rgba(0, 245, 255, 0.45);
  background: rgba(0, 245, 255, 0.08);
}

.pin-swatch {
  width: 8px;
  align-self: stretch;
  border-radius: 4px;
  flex-shrink: 0;
}

.pin-meta {
  min-width: 0;
}

.pin-name {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-ll {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
}

.pin-actions button {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  min-height: 32px;
  -webkit-tap-highlight-color: transparent;
}

.pin-actions button[data-a="del"] {
  border-color: rgba(255, 80, 100, 0.4);
  color: #ffb1bf;
}

@media (max-width: 380px) {
  .pin-actions {
    flex-direction: column;
    gap: 4px;
  }
  .pin-actions button {
    min-height: 28px;
    padding: 6px 8px;
  }
}

.nav-overlay {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: none;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #050208 70%);
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

.nav-overlay[data-open="true"] {
  display: flex;
}

.nav-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-target {
  text-align: center;
  margin-top: 8px;
}

.nav-target h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.nav-target p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.compass-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px 0;
}

.nav-compass-panel {
  flex-shrink: 0;
}

.nav-compass-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: min(40vw, 148px);
  padding: 14px 16px;
  margin: 2px 0;
  border-radius: 16px;
  border: 1px dashed rgba(255, 45, 196, 0.35);
  background: rgba(10, 5, 20, 0.45);
}

.nav-compass-fallback-text {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
  max-width: 320px;
}

.compass-ring {
  width: min(40vw, 148px);
  height: min(40vw, 148px);
  border-radius: 50%;
  border: 2px solid rgba(255, 45, 196, 0.25);
  box-shadow: 0 0 40px rgba(255, 45, 196, 0.15), inset 0 0 60px rgba(0, 0, 0, 0.4);
  position: relative;
  background: rgba(10, 5, 20, 0.5);
  transform-origin: 50% 50%;
  transition: transform 0.12s ease-out;
}

.compass-n {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.arrow-wrap {
  position: absolute;
  inset: 18%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 50% 50%;
  transition: transform 0.12s ease-out;
}

.arrow {
  width: 0;
  height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-bottom: 48px solid var(--accent);
  filter: drop-shadow(0 0 8px rgba(255, 45, 196, 0.8));
}

.nav-stats {
  text-align: center;
  padding: 12px 0 4px;
}

.nav-distance {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.nav-bearing {
  font-size: 0.95rem;
  color: var(--muted);
}

.nav-hint {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 1200;
  background: rgba(30, 15, 45, 0.96);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
}

.toast[data-visible="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

dialog.modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  background: #14081f;
  color: var(--text);
  max-width: min(420px, 92vw);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.55);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-body {
  padding: 16px 18px 18px;
}

.modal-body h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.modal-body p,
.modal-body label {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.45;
}

.pin-hint {
  font-size: 0.78rem;
  color: var(--accent2);
  margin: 0 0 10px;
  line-height: 1.35;
}

.modal-body input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.user-marker {
  background: transparent;
  border: none;
}

.user-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #00f5ff;
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(0, 245, 255, 0.45), 0 2px 12px rgba(0, 0, 0, 0.5);
}

.pin-marker-inner {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.leaflet-container {
  background: #0d0220;
}

/* Stage / zone labels — non-interactive, below pins */
.edc-stage-label-wrap {
  pointer-events: none !important;
  background: transparent !important;
  border: none !important;
}

.edc-stage-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: rgba(244, 236, 255, 0.38);
  text-shadow:
    0 0 10px rgba(0, 0, 0, 0.95),
    0 1px 3px rgba(0, 0, 0, 0.9);
  text-align: center;
  white-space: nowrap;
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Map pin / POI selection — Navigate opens compass overlay */
.leaflet-popup-nav-shell .leaflet-popup-content-wrapper {
  background: rgba(12, 6, 22, 0.96);
  color: var(--text);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  padding: 0;
}

.leaflet-popup-nav-shell .leaflet-popup-content {
  margin: 10px 12px 12px;
  /* Reserve space so the close button never overlays title text (mobile). */
  padding-right: 26px;
  line-height: 1.35;
}

.leaflet-popup-nav-shell a.leaflet-popup-close-button {
  color: var(--text);
  top: 6px;
  right: 6px;
  padding: 0;
  width: 32px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  font-size: 1.25rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.leaflet-popup-nav-shell .leaflet-popup-tip {
  background: rgba(12, 6, 22, 0.96);
  border: 1px solid rgba(255, 45, 196, 0.25);
  border-top: none;
  border-left: none;
}

.map-nav-popup-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.map-nav-popup-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.map-nav-popup-btn {
  width: 100%;
  margin-top: 2px;
}

.nav-mini-map {
  flex: 1 1 auto;
  min-height: 150px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 6px 0;
}

.nav-mini-map .leaflet-container {
  border-radius: 12px;
}

.nav-compass-ctrl {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0 0;
}

.compass-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
}

.toggle-track {
  display: block;
  width: 46px;
  height: 26px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transition: transform 0.22s ease, background 0.2s;
}

.toggle-input:checked ~ .toggle-switch .toggle-track {
  background: rgba(255, 45, 196, 0.4);
  border-color: rgba(255, 45, 196, 0.65);
}

.toggle-input:checked ~ .toggle-switch .toggle-thumb {
  transform: translateX(20px);
  background: var(--accent);
}

.toggle-input:focus-visible ~ .toggle-switch .toggle-track {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
