:root {
  --bg: rgba(20, 24, 31, 0.86);
  --bg-solid: #14181f;
  --fg: #eef2f6;
  --muted: #9aa6b2;
  --accent: #4fb3ff;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg-solid); color: var(--fg); overflow: hidden; }
#map { position: absolute; inset: 0; }
#particles { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: var(--bg); font-size: 18px; line-height: 40px; text-align: center; }

#topbar {
  position: absolute; z-index: 5; top: calc(10px + var(--safe-top)); left: 10px; right: 10px;
  display: flex; gap: 8px; align-items: flex-start;
}
.search { position: relative; flex: 1; max-width: 360px; }
#search {
  width: 100%; height: 40px; border-radius: 10px; border: 0; padding: 0 12px;
  background: var(--bg); color: var(--fg); font-size: 15px; outline: none;
}
#results, #favlist {
  list-style: none; margin: 6px 0 0; padding: 4px; background: var(--bg-solid); border-radius: 10px;
  max-height: 50vh; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
#results { position: absolute; left: 0; right: 0; }
#favlist { position: absolute; right: 0; top: 40px; min-width: 220px; }
#results li, #favlist li { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#results li:hover, #favlist li:hover { background: rgba(255,255,255,.08); }
#results small, #favlist small { color: var(--muted); }
#favlist .del { color: var(--muted); padding: 0 4px; }

#layers {
  position: absolute; z-index: 4; top: calc(60px + var(--safe-top)); right: 10px;
  display: flex; flex-direction: column; gap: 4px; background: var(--bg); padding: 4px; border-radius: var(--radius);
}
#layers button { padding: 8px 12px; border-radius: 8px; text-align: left; font-size: 14px; }
#layers button.active { background: var(--accent); color: #04121f; font-weight: 600; }

#legend {
  position: absolute; z-index: 3; left: 10px; bottom: calc(118px + var(--safe-bottom));
  width: 220px; background: var(--bg); padding: 6px 8px; border-radius: 10px; font-size: 11px;
}
#legend .bar { height: 10px; border-radius: 4px; }
#legend .ticks { display: flex; justify-content: space-between; color: var(--muted); margin-top: 3px; }

#timeline {
  position: absolute; z-index: 4; left: 0; right: 0; bottom: 0;
  padding: 8px 12px calc(10px + var(--safe-bottom)); background: var(--bg);
}
#timeline .row { display: flex; align-items: center; gap: 10px; }
#timelabel { font-weight: 600; font-size: 15px; }
#runlabel { margin-left: auto; color: var(--muted); font-size: 11px; }
#slider { width: 100%; margin: 8px 0 4px; accent-color: var(--accent); }
#days { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
#days::-webkit-scrollbar { display: none; }
#days button {
  flex: 0 0 auto; padding: 4px 9px; border-radius: 7px; font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,.06);
}
#days button.active { color: #04121f; background: var(--accent); }
#days button.daily { border: 1px dashed rgba(255,255,255,.18); }

#panel {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: 0; max-height: 72vh; overflow: auto;
  background: var(--bg-solid); border-radius: 16px 16px 0 0; padding: 12px 12px calc(16px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.5);
}
@media (min-width: 900px) {
  #panel { left: auto; right: 10px; bottom: 120px; top: 70px; width: 420px; max-height: none; border-radius: 16px; }
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.panel-actions { display: flex; gap: 6px; }
#place { font-size: 18px; font-weight: 600; }
#placesub { color: var(--muted); font-size: 12px; margin-top: 2px; }
#chart { width: 100%; height: 150px; margin-top: 8px; }

.hscroll { display: flex; overflow-x: auto; gap: 2px; padding: 6px 0; }
.hcell { flex: 0 0 auto; width: 56px; text-align: center; font-size: 12px; padding: 6px 2px; border-radius: 8px; background: rgba(255,255,255,.04); }
.hcell .t { color: var(--muted); }
.hcell .temp { font-size: 15px; font-weight: 600; margin: 3px 0; }
.hcell .rain { color: #7cc4ff; min-height: 15px; }
.hcell .wind { color: var(--fg); }
.hcell.newday { border-left: 2px solid var(--accent); }
.arrow { display: inline-block; }

#daily { margin-top: 8px; }
.drow { display: grid; grid-template-columns: 82px 1fr 64px 76px; gap: 6px; align-items: center; padding: 7px 4px; border-top: 1px solid rgba(255,255,255,.06); font-size: 13px; }
.drow .d { color: var(--muted); }
.drow .range { display: flex; align-items: center; gap: 6px; }
.drow .range .bar { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #67c5e9, #fee08b, #f46d43); opacity: .85; }
.drow .rain { color: #7cc4ff; text-align: right; }
.drow .wind { text-align: right; }
#panelnote { color: var(--muted); font-size: 11px; margin-top: 10px; }

#toast {
  position: absolute; z-index: 10; left: 50%; top: calc(64px + var(--safe-top)); transform: translateX(-50%);
  background: var(--bg-solid); padding: 8px 14px; border-radius: 10px; font-size: 13px; max-width: 90vw;
}

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right { bottom: calc(110px + var(--safe-bottom)); }
.maplibregl-popup-content { background: var(--bg-solid); color: var(--fg); padding: 6px 10px; border-radius: 8px; font-size: 13px; }
.maplibregl-popup-tip { border-top-color: var(--bg-solid) !important; border-bottom-color: var(--bg-solid) !important; }
#legend .lbl { color: var(--fg); margin-bottom: 4px; font-weight: 600; }

@media (max-width: 700px) {
  #layers {
    flex-direction: row; top: auto; left: 8px; right: 8px; bottom: calc(112px + var(--safe-bottom));
    overflow-x: auto; scrollbar-width: none; padding: 3px;
  }
  #layers::-webkit-scrollbar { display: none; }
  #layers button { padding: 6px 10px; font-size: 13px; flex: 0 0 auto; text-align: center; }
  #legend { top: calc(58px + var(--safe-top)); bottom: auto; width: 190px; }
  #timelabel { font-size: 14px; }
  #runlabel { display: none; }
  .maplibregl-ctrl-bottom-right { bottom: calc(160px + var(--safe-bottom)); }
}
