:root {
  --bg: #0b1f3a;
  --green: #1f8a4c;
  --red: #c0392b;
  --yellow: #d8a521;
  --gray: #5b6675;
  --panel: rgba(11, 31, 58, 0.92);
  --text: #f5f7fa;
  --border: rgba(255,255,255,0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}

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

/* ---- Status banner (top) ---- */
#status-banner {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 14px 16px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  border-bottom: 1px solid var(--border);
}
#status-banner.status-legal    { background: var(--green); }
#status-banner.status-illegal  { background: var(--red); }
#status-banner.status-tbd      { background: var(--yellow); color: #2a1a00; }
#status-banner.status-unknown  { background: var(--gray); }
#status-headline {
  font-size: 1.25rem;
  text-transform: uppercase;
  margin-bottom: 2px;
}
#status-sub {
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.92;
}

/* ---- Rules panel (left) ---- */
#rules-panel {
  position: fixed;
  left: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0) + 8px);
  z-index: 999;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 78vw;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#rules-toggle, #layer-toggle, #recenter-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 10px 14px;
  cursor: pointer;
}
#rules-body {
  padding: 4px 14px 14px;
  font-size: 0.85rem;
  line-height: 1.4;
  max-height: 45vh;
  overflow-y: auto;
}
#rules-panel.collapsed #rules-body { display: none; }

.rule {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.rule:first-child { border-top: none; }
.rule .rule-zone { font-weight: 700; }
.rule .rule-auth { font-size: 0.72rem; opacity: 0.7; }
.rule .rule-verdict-allowed   { color: #6ee7a0; }
.rule .rule-verdict-prohibited { color: #ff8b80; }
.rule .rule-verdict-restricted { color: #ffd966; }

/* ---- Layer panel (right) ---- */
#layer-panel {
  position: fixed;
  right: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0) + 8px);
  z-index: 999;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#layer-body {
  padding: 4px 14px 14px;
  font-size: 0.85rem;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#layer-panel.collapsed #layer-body { display: none; }
#layer-body label {
  display: block;
  padding: 4px 0;
  cursor: pointer;
}
.panel-section { padding: 6px 0; }
.panel-section + .panel-section { border-top: 1px solid var(--border); margin-top: 6px; }
.panel-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.65;
  margin-bottom: 4px;
}

/* ---- Recenter button ---- */
#recenter-btn {
  position: fixed;
  right: 12px;
  top: calc(env(safe-area-inset-top, 0) + 80px);
  z-index: 999;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#recenter-btn.no-fix {
  background: var(--yellow);
  color: #2a1a00;
  border-color: #b48413;
  animation: pulse-btn 1.8s infinite;
}
@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 0 rgba(216,165,33,0.6); }
  50%      { box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 10px rgba(216,165,33,0); }
}

/* ---- Offline banner ---- */
#offline-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: var(--yellow);
  color: #2a1a00;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ---- Leaflet tweaks ---- */
.leaflet-container { background: #0a1726; }
.leaflet-control-attribution {
  background: rgba(11,31,58,0.7) !important;
  color: var(--text) !important;
}
.leaflet-control-attribution a { color: #9ecbff !important; }

/* --- Click-to-check popup --- */
.leaflet-popup.click-legality-popup .leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
  /* Override Leaflet's internal sizing: fill width on mobile, cap on desktop */
  width: 94vw;
  max-width: 520px;
}
.leaflet-popup.click-legality-popup .leaflet-popup-content {
  margin: 0;
  width: auto !important;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* Big tap-friendly close X with solid contrasted bubble */
.leaflet-popup.click-legality-popup .leaflet-popup-close-button {
  width: 34px;
  height: 34px;
  font-size: 22px;
  font-weight: 700;
  line-height: 32px;
  padding: 0;
  top: 8px;
  right: 8px;
  color: #1b1b1b;
  background: white;
  border: 1.5px solid rgba(0,0,0,0.6);
  border-radius: 50%;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
  z-index: 10;
}
.leaflet-popup.click-legality-popup .leaflet-popup-close-button:hover,
.leaflet-popup.click-legality-popup .leaflet-popup-close-button:active {
  background: #1b1b1b;
  color: white;
  border-color: white;
}
.click-popup {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: #1b1b1b;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.98);
}
.cp-headers {
  display: flex;
  width: 100%;
}
.cp-header { color: white; flex: 1; min-width: 0; }
.cp-header.verdict-yes   { background: var(--green); }
.cp-header.verdict-no    { background: var(--red); }
.cp-header.verdict-maybe { background: var(--yellow); color: #2a1a00; }
.cp-header + .cp-header  { border-left: 1px solid rgba(255,255,255,0.25); }
.cp-headline {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 14px 10px;
  text-align: center;
  line-height: 1.1;
  white-space: nowrap;
}
@media (max-width: 380px) {
  .cp-headline { font-size: 0.9rem; padding: 12px 6px; letter-spacing: 0; }
}
.cp-sub {
  font-size: 0.78rem;
  text-align: center;
  padding: 6px 12px 10px;
  font-weight: 600;
  color: #444;
  background: #f4f6f9;
}
.cp-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 8px 14px 2px;
  background: #ecf0f4;
  color: #555;
}
.cp-poi {
  padding: 10px 14px;
  background: #f4f6f9;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.88rem;
  line-height: 1.4;
}
.cp-poi b { font-size: 1rem; }
.cp-list {
  list-style: none;
  margin: 0;
  padding: 10px 14px 14px;
  background: rgba(255,255,255,0.98);
  color: #1b1b1b;
  font-size: 0.85rem;
}
.cp-list li {
  padding: 7px 0;
  border-top: 1px solid #e0e0e0;
  line-height: 1.35;
}
.cp-list li:first-child { border-top: none; }
.cp-list li small { color: #555; font-size: 0.72rem; }
.cp-list li.b-prohibited { border-left: 3px solid var(--red);    padding-left: 8px; }
.cp-list li.b-restricted { border-left: 3px solid var(--yellow); padding-left: 8px; }
.cp-list li.b-allowed    { border-left: 3px solid var(--green);  padding-left: 8px; color: #145a32; }
.cp-list li.b-info       { border-left: 3px solid var(--gray);   padding-left: 8px; color: #444; }

/* User location pulse */
.user-pos {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #4aa3ff;
  border: 3px solid white;
  box-shadow: 0 0 0 0 rgba(74,163,255,0.6);
  animation: pulse 2s infinite;
}
.user-pos.manual {
  background: #f1c40f;
  border-color: #2a1a00;
  animation: none;
  width: 22px; height: 22px;
  font-size: 0;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,163,255,0.6); }
  70%  { box-shadow: 0 0 0 18px rgba(74,163,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,163,255,0); }
}

#status-banner.manual-mode {
  background: linear-gradient(90deg, var(--yellow) 0%, var(--gray) 100%);
  color: #2a1a00;
}
