:root {
  --bg: #0d1620;
  --panel: rgba(255,255,255,.92);
  --panel-ink: #14202b;
  --accent: #0d7a8a;
  --accent-ink: #08505b;
  --hair: #d7e0e7;
  --shadow: 0 2px 8px rgba(14,33,48,.18), 0 12px 32px rgba(14,33,48,.14);
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-family: var(--sans);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
/* z-index:0 makes #map establish its own stacking context so Leaflet's internal panes
   (tiles z-index 200, controls z-index 800) stay CONTAINED below our overlay UI — without
   it those panes leak into the root context and paint over the toolbar/timeline/canvas. */
#map { position: absolute; inset: 0; z-index: 0; background: #a9c7d6; }
/* Current animation canvas — overlays the map, clicks pass through. */
#veccanvas { position: absolute; inset: 0; z-index: 2; pointer-events: none; }

/* Currents style segmented control (in layers panel) */
.seg { display: flex; gap: 6px; padding: 4px 14px 12px; }
.seg-btn { flex: 1; padding: 7px; border: 1px solid var(--hair); background: transparent;
  border-radius: 8px; font-size: .82rem; cursor: pointer; color: var(--panel-ink); }
.seg-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Top bar */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: env(safe-area-inset-top, 8px) 14px 8px;
  pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 8px; pointer-events: auto;
  background: var(--panel); color: var(--panel-ink);
  padding: 7px 12px; border-radius: 999px; box-shadow: var(--shadow);
  font-weight: 700; letter-spacing: -.01em;
}
.brand svg { color: var(--accent); }
.top-actions { pointer-events: auto; }
.pill {
  border: none; background: var(--panel); color: var(--panel-ink);
  padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
  font-weight: 700; font-size: .85rem; cursor: pointer;
}

/* Right controls */
.controls {
  position: absolute; right: 14px; bottom: 96px; z-index: 5;
  display: flex; flex-direction: column; gap: 10px;
}
.ctl {
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: var(--panel); color: var(--accent-ink);
  box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.ctl:active { transform: scale(.94); }

/* Timeline */
.timeline {
  position: absolute; left: 10px; right: 10px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 8px; color: var(--panel-ink);
}
.play {
  flex: none; width: 40px; height: 40px; border-radius: 10px; border: none;
  background: transparent; color: var(--accent); font-size: 1.1rem; cursor: pointer;
}
.steps { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.steps::-webkit-scrollbar { display: none; }
.step {
  flex: none; min-width: 62px; text-align: center; padding: 6px 8px;
  border-radius: 9px; font-size: .78rem; line-height: 1.15; cursor: pointer;
  color: var(--panel-ink); border: 1.5px solid transparent; background: transparent;
}
.step.now { font-weight: 700; }
.step.sel { border-color: var(--accent); color: var(--accent-ink); background: rgba(13,122,138,.08); }
.step small { display: block; opacity: .6; font-size: .68rem; }

/* Legend */
.legend {
  position: absolute; left: 12px; bottom: calc(78px + env(safe-area-inset-bottom, 0px)); z-index: 4;
  background: var(--panel); color: var(--panel-ink); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px 10px; min-width: 150px; max-width: 60vw;
}
.legend-title { font-size: .74rem; font-weight: 700; margin-bottom: 4px; }
.legend-bar { height: 8px; border-radius: 4px; }
.legend-scale { display: flex; justify-content: space-between; font-size: .68rem; opacity: .7; margin-top: 2px; }

/* Sheets */
.sheet {
  position: absolute; z-index: 20; right: 14px; bottom: 96px;
  width: min(380px, calc(100vw - 28px)); max-height: 70vh;
  background: var(--panel); color: var(--panel-ink);
  border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
  backdrop-filter: blur(8px);
}
/* An author display:flex overrides the UA [hidden] rule — restore it explicitly. */
.sheet[hidden] { display: none; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--hair);
}
.sheet-head h2 { margin: 0; font-size: 1rem; }
.x { border: none; background: transparent; font-size: 1.4rem; line-height: 1; cursor: pointer; color: #667; }
.sheet-body { overflow-y: auto; padding: 6px 0; }

/* Layer rows */
.lgroup { padding: 8px 14px 2px; font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: #7a8a96; font-weight: 700; }
.lrow { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.lrow span { font-size: .92rem; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #c7d0d8; border-radius: 999px; transition: .18s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Favorites */
.fav-item { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; cursor: pointer; }
.fav-item:hover { background: rgba(13,122,138,.06); }
.fav-item .meta { font-size: .72rem; color: #6b7b87; }
.fav-item .del { border: none; background: transparent; color: #c23b2f; cursor: pointer; font-size: 1rem; padding: 4px 8px; }
.empty { padding: 28px 16px; text-align: center; color: #7a8a96; font-size: .9rem; }

/* Advisor chat */
.sheet-advisor { width: min(400px, calc(100vw - 28px)); height: 70vh; }
.chat { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 14px; font-size: .9rem; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #eef3f6; color: var(--panel-ink); border-bottom-left-radius: 4px; }
.msg.typing { opacity: .6; font-style: italic; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--hair); }
.chat-input input { flex: 1; border: 1px solid var(--hair); border-radius: 999px; padding: 10px 14px; font-size: .9rem; outline: none; }
.chat-input button { border: none; background: var(--accent); color: #fff; width: 40px; border-radius: 50%; cursor: pointer; font-size: 1rem; }

/* Meteogram panel — wide bottom sheet with stacked sparkline charts */
.sheet-meteo {
  left: 10px; right: 10px; bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  width: auto; max-width: none; max-height: 56vh;
}
.meteo-row { padding: 7px 14px 9px; border-bottom: 1px solid var(--hair); }
.meteo-row:last-of-type { border-bottom: none; }
.meteo-lab { display: flex; align-items: baseline; justify-content: space-between; font-size: .78rem; font-weight: 700; margin-bottom: 3px; }
.meteo-lab .cur { font-variant-numeric: tabular-nums; font-size: .82rem; }
.mg-wrap { position: relative; }
.mg-arrows { position: relative; height: 13px; }
.mg-arrow { position: absolute; top: 0; font-size: 10px; line-height: 1; color: #46586a; }
.mg-svg { display: block; width: 100%; height: 42px; }
@media (prefers-color-scheme: dark) { .mg-arrow { color: #9fb2c2; } }
.meteo-axis { position: relative; height: 15px; margin: 2px 14px 0; }
.mg-day { position: absolute; top: 0; font-size: .6rem; color: #7a8a96; white-space: nowrap; transform: translateX(2px); }
.meteo-add { margin: 10px 14px; }

/* Point forecast popup */
.maplibregl-popup-content { border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; font-family: var(--sans); }
.pf h3 { margin: 0 0 6px; font-size: .95rem; }
.pf table { border-collapse: collapse; font-size: .82rem; }
.pf td { padding: 2px 0; }
.pf td:first-child { color: #6b7b87; padding-right: 14px; }
.pf .add-fav { margin-top: 8px; width: 100%; border: 1px solid var(--accent); color: var(--accent-ink); background: #fff; border-radius: 8px; padding: 7px; cursor: pointer; font-weight: 600; font-size: .82rem; }

@media (prefers-color-scheme: dark) {
  :root { --panel: rgba(20,32,43,.94); --panel-ink: #e7eff5; --hair: #2a3b47; --accent: #2bb7c8; --accent-ink: #7fd7e1; }
  .msg.assistant { background: #1b2b36; }
  .pf .add-fav { background: transparent; }
  .maplibregl-popup-content { background: #14202b; color: #e7eff5; }
  .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #14202b; }
}
