:root {
  /* Light defaults */
  --bg: #ffffff;
  --card: #f9f9f9;
  --muted: #555;
  --text: #111;
  --brand: #0077cc;
  --accent: #0099ff;
  --border: #ddd;

  --surface-98: rgba(255,255,255,0.98);
  --surface-95: rgba(255,255,255,0.95);
  --surface-92: rgba(255,255,255,0.92);
  --surface-90: rgba(255,255,255,0.90);
  --surface-88: rgba(255,255,255,0.88);

  --attributionBg: rgba(255,255,255,0.9);
  --debugBg: #f6f8fb;

  --topH: 58px;   /* desktop topbar height */
  --ctrlH: 56px;  /* mobile sticky controls bar height */
  --tabH: 56px;   /* mobile bottom tabs height */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d11;
    --card: #111418;
    --muted: #8a93a5;
    --text: #e9eef6;
    --brand: #00c2ff;
    --accent: #7df9ff;
    --border: #1c2230;

    --surface-98: rgba(16,20,26,0.98);
    --surface-95: rgba(16,20,26,0.95);
    --surface-92: rgba(16,20,26,0.92);
    --surface-90: rgba(16,20,26,0.90);
    --surface-88: rgba(16,20,26,0.88);

    --attributionBg: rgba(17,20,24,0.9);
    --debugBg: #0f141d;
  }
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- DESKTOP header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--surface-95), var(--surface-90));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.brand { font-weight: 700; letter-spacing: 0.2px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- MOBILE header (two lines) ---------- */
.brandbar, .controlbar { display: none; } /* hidden on desktop */
@media (max-width: 899px) {
  .topbar { display: none; } /* hide desktop bar on mobile */
  .brandbar {
    display: block;
    background: linear-gradient(180deg, var(--surface-98), var(--surface-92));
    border-bottom: 1px solid var(--border);
    padding: 12px 14px 8px;
  }
  .brandbar .brand { font-weight: 800; letter-spacing: .2px; font-size: 20px; }
  .controlbar {
    display: block; position: sticky; top: 0; z-index: 30;
    background: linear-gradient(180deg, var(--surface-95), var(--surface-88));
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .controlbar .row {
    display: flex; gap: 10px; align-items: center; justify-content: flex-start;
    padding: 10px 12px; max-width: 1200px; margin: 0 auto;
  }
}

.btn, select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
.btn.active { outline: 2px solid var(--brand); }
.btn:hover, select:hover { border-color: #2a354a; }

/* ----------- Layout ----------- */
.wrap { height: calc(100% - var(--topH)); display: grid; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .wrap { grid-template-columns: 55% 45%; }
  .mobile-tabs { display: none !important; }
}
@media (max-width: 899px) {
  .wrap { height: calc(100vh - var(--ctrlH)); grid-template-columns: 1fr; }
}

.panel { position: relative; overflow: auto; border-left: 1px solid var(--border); }
.panel.map { border-left: none; }
#map { width: 100%; height: 100%; }

.content { max-width: 800px; margin: 0 auto; padding: 18px 16px 100px; }
.preheader { color: var(--muted); margin: 6px 0 16px; font-size: 14px; }
.disclaimer {
  margin-top: 24px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}
h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: 0.2px; }
h3 { margin: 22px 0 8px; font-size: 16px; color: #555; border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
ul { margin: 8px 0 0 0; padding: 0 0 0 18px; }
li { margin: 8px 0; }

/* -------- Mobile bottom tabs -------- */
.mobile-tabs {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface-98);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr;
  z-index: 9999; height: var(--tabH);
}

.tabbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  padding: 6px 0;
}

.tabbtn.active { color: var(--text); border-top: 2px solid var(--brand); }

.tabbtn .btn-icon { width: 24px; height: 24px; fill: currentColor; display: block; }
.tabbtn .label { line-height: 1; }

@media (max-width: 899px) {
  .panel { display: none; }
  .panel.active { display: block; height: calc(100vh - var(--ctrlH) - var(--tabH)); }
  #map { height: 100%; }
  .content { padding-bottom: calc(var(--tabH) + 24px); }
}

/* Leaflet attribution */
.leaflet-control-attribution {
  background: var(--attributionBg) !important;
  color: var(--muted) !important;
}
.leaflet-container a { color: var(--accent) !important; }

/* Debug */
.debug { background: var(--debugBg); border-top: 1px solid var(--border); padding: 12px; font-size: 13px; color: var(--muted); }
.debug h4 { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 10px; }
.key { color: var(--muted); }
