:root {
  --bg: #05070d;
  --bg-card: #10162a;
  --bg-card-2: #151d38;
  --border: #232c4a;
  --text: #e8ecff;
  --text-dim: #8891b5;
  --accent: #6ea8fe;
  --accent-dim: #3a4a7a;
  --good: #4ade80;
  --ok: #facc15;
  --bad: #f87171;
  --red-mode-bg: #0a0000;
  --red-mode-card: #170303;
  --red-mode-border: #3a0808;
  --red-mode-text: #ff5c5c;
  --red-mode-dim: #a03030;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

body.red-mode {
  background: var(--red-mode-bg);
  color: var(--red-mode-text);
}

body.red-mode .card {
  background: var(--red-mode-card);
  border-color: var(--red-mode-border);
}

body.red-mode .text-dim { color: var(--red-mode-dim) !important; }
body.red-mode .accent { color: var(--red-mode-text) !important; }
body.red-mode .app-header { border-color: var(--red-mode-border); }
body.red-mode .stat-icon, body.red-mode svg { filter: grayscale(1) sepia(1) saturate(6) hue-rotate(-40deg); }
body.red-mode .verdict-banner { filter: grayscale(1) sepia(1) saturate(6) hue-rotate(-40deg); }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(24px + var(--safe-bottom));
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.app-header .loc {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.app-header .loc-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.app-header .loc-updated {
  font-size: 11px;
  color: var(--text-dim);
}

.header-btns {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.verdict-banner {
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--bg-card), var(--bg-card-2));
}

.verdict-emoji { font-size: 34px; line-height: 1; }
.verdict-text { display: flex; flex-direction: column; gap: 2px; }
.verdict-title { font-size: 17px; font-weight: 700; }
.verdict-sub { font-size: 12.5px; color: var(--text-dim); }

.weather-card {
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 18px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.weather-main { display: flex; align-items: center; gap: 14px; }
.weather-icon { font-size: 44px; }
.weather-temp { font-size: 30px; font-weight: 700; }
.weather-desc { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-icon { font-size: 18px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-unit { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-left: 1px; }
.stat-sub { font-size: 12px; color: var(--text-dim); }
.stat-link { font-size: 12px; color: var(--accent); margin-top: 2px; cursor: pointer; font-weight: 600; }
.stat-link:active { opacity: 0.7; }

.bar-track {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-top: 2px;
}
.bar-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }

.sun-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 14px 18px;
  display: flex;
  justify-content: space-around;
  margin-bottom: 14px;
}
.sun-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sun-icon { font-size: 22px; }
.sun-time { font-size: 17px; font-weight: 700; }
.sun-label { font-size: 11px; color: var(--text-dim); }

.chart-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 14px 16px 10px;
  margin-bottom: 14px;
}
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.chart-sub { font-size: 11px; color: var(--text-dim); margin-bottom: 10px; }

.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-tooltip {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  background: var(--accent);
  color: #05070d;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 5;
}
.chart-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--accent);
}
.chart-tap-hint {
  font-size: 10.5px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 6px;
  opacity: 0.8;
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  justify-content: flex-start;
}
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend-gradient-swatch {
  width: 34px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, hsl(120,72%,46%), hsl(60,72%,46%), hsl(0,72%,46%));
  display: inline-block;
}

.live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.live-banner.hidden { display: none; }
.live-banner:active { opacity: 0.8; }

.cloud-blocks {
  display: flex;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.cloud-block {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6px 0;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-right: 1px solid rgba(5,7,13,0.25);
  position: relative;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.cloud-block:last-child { border-right: none; }
.cloud-block-now-icon { font-size: 9px; line-height: 1; }
.cloud-block-hour { line-height: 1; }
.cloud-block.now { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.8); }
.cloud-block.selected { box-shadow: inset 0 0 0 2px var(--accent); z-index: 1; }

.cloud-gradient-bar {
  width: 100%;
  height: 10px;
  border-radius: 6px;
  margin-top: 6px;
}

.status-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px 20px;
}

.text-dim { color: var(--text-dim); }
.accent { color: var(--accent); }

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.settings-panel.hidden { display: none; }
.settings-sheet {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(28px + var(--safe-bottom));
}
.settings-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row label { font-size: 14px; }
.settings-row .hint { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

select, input[type=range] {
  background: var(--bg-card-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
}

.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  background: var(--border);
  border-radius: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: left .2s ease;
}
.toggle.on::after { left: 23px; }

.close-btn {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  background: var(--accent-dim);
  color: var(--text);
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.attribution {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.5;
}

.map-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.map-panel.hidden { display: none; }
.map-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.map-panel-title { font-size: 15px; font-weight: 700; }
#lpMap {
  flex: 1;
  width: 100%;
  background: #0a0e1a;
}
.map-panel-footer {
  padding: 8px 14px calc(10px + var(--safe-bottom));
  flex-shrink: 0;
  margin-top: 0;
}
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(5,7,13,0.75) !important;
  color: #8891b5 !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

.forecast-content {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.forecast-day-card {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 12px 14px;
}

.fd-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.fd-date { font-size: 14px; font-weight: 700; text-transform: capitalize; }
.fd-weather { display: flex; align-items: center; gap: 8px; }
.fd-icon { font-size: 20px; }
.fd-temp { font-size: 13px; color: var(--text-dim); font-weight: 600; }

.fd-verdict {
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 3px solid var(--border);
  padding: 6px 0 6px 10px;
  margin-bottom: 6px;
}
.fd-verdict-nodata { border-left-color: var(--border); opacity: 0.7; }
.fd-verdict-emoji { font-size: 22px; }
.fd-verdict-title { font-size: 13.5px; font-weight: 700; }
.fd-verdict-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }

.fd-moon { font-size: 11.5px; color: var(--text-dim); }

.info-platform-card {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 14px;
}
.info-platform-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.info-platform-icon { font-size: 20px; }
.info-step-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.info-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.info-step-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-step-text { font-size: 13.5px; line-height: 1.5; padding-top: 1px; }
.info-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.5;
}
