:root {
  --sky-day-top: #0b1a3a;
  --sky-day-mid: #3a6fb0;
  --sky-day-low: #9ec9e8;
  --sky-night-top: #020414;
  --sky-night-mid: #0a1430;
  --sky-night-low: #15243f;
  --fg: #f8fafc;
  --fg-dim: rgba(248, 250, 252, 0.72);
  --panel: rgba(0, 0, 0, 0.38);
  --panel-border: rgba(255, 255, 255, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: #000;
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

/* ---------- background layers ---------- */
.bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bg.sky {
  background: linear-gradient(to bottom,
    #0e1f48 0%,
    #2a4f8a 30%,
    #5a8ec4 65%,
    #b3d3ea 100%);
  z-index: 0;
  transition: background 600ms ease;
}
body.night .bg.sky {
  background: linear-gradient(to bottom,
    #02030c 0%,
    #060a1c 35%,
    #0c1530 65%,
    #1a2745 100%);
}
body.cloudy .bg.sky,
body.fog .bg.sky {
  background: linear-gradient(to bottom,
    #4a5266 0%,
    #6c7585 40%,
    #8d96a4 75%,
    #b2b9c2 100%);
}
body.cloudy.night .bg.sky,
body.fog.night .bg.sky {
  background: linear-gradient(to bottom,
    #1a1d28 0%,
    #2a2e3d 40%,
    #3a3f51 75%,
    #4d5364 100%);
}
body.rain .bg.sky,
body.thunderstorm .bg.sky {
  background: linear-gradient(to bottom,
    #1c2236 0%,
    #2c3550 35%,
    #4a5572 70%,
    #6d7793 100%);
}

body.snow .bg.sky {
  background: linear-gradient(to bottom,
    #5b6878 0%,
    #818c9d 40%,
    #adb5c1 75%,
    #d4d8de 100%);
}
body.snow.night .bg.sky {
  background: linear-gradient(to bottom,
    #1d2230 0%,
    #2e3543 40%,
    #444b5c 75%,
    #606779 100%);
}

/* ---------- stars ---------- */
.bg.stars {
  z-index: 1;
  opacity: 0;
  transition: opacity 600ms ease;
  background-image:
    radial-gradient(1px 1px at 4%  6%,  #fff, transparent 60%),
    radial-gradient(1px 1px at 11% 14%, #fff, transparent 60%),
    radial-gradient(1.4px 1.4px at 19% 4%, #fff, transparent 60%),
    radial-gradient(1px 1px at 27% 11%, #fff, transparent 60%),
    radial-gradient(1.2px 1.2px at 34% 7%, #fff, transparent 60%),
    radial-gradient(1px 1px at 41% 15%, #fff, transparent 60%),
    radial-gradient(1.4px 1.4px at 49% 5%, #fff, transparent 60%),
    radial-gradient(1px 1px at 57% 12%, #fff, transparent 60%),
    radial-gradient(1.6px 1.6px at 64% 8%, #fff, transparent 60%),
    radial-gradient(1px 1px at 72% 16%, #fff, transparent 60%),
    radial-gradient(1.4px 1.4px at 79% 6%, #fff, transparent 60%),
    radial-gradient(1px 1px at 86% 13%, #fff, transparent 60%),
    radial-gradient(1.2px 1.2px at 93% 9%, #fff, transparent 60%),
    radial-gradient(1px 1px at 8%  22%, #fff, transparent 60%),
    radial-gradient(1px 1px at 30% 26%, #fff, transparent 60%),
    radial-gradient(1.4px 1.4px at 55% 23%, #fff, transparent 60%),
    radial-gradient(1px 1px at 80% 27%, #fff, transparent 60%);
  background-repeat: no-repeat;
  animation: starsTwinkle 4s ease-in-out infinite alternate;
}
body.night.clear-night .bg.stars,
body.night.partly-cloudy-night .bg.stars { opacity: 1; }
body.night.cloudy .bg.stars,
body.night.rain .bg.stars,
body.night.snow .bg.stars,
body.night.thunderstorm .bg.stars,
body.night.fog .bg.stars { opacity: 0.25; }
@keyframes starsTwinkle {
  from { opacity: var(--stars-opacity, 0); }
  to   { opacity: calc(var(--stars-opacity, 0) * 0.7); }
}

/* ---------- celestial: sun + moon ---------- */
.bg.celestial { z-index: 2; }

.sun, .moon {
  position: absolute;
  top: 9%;
  right: 14%;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 600ms ease, transform 800ms ease;
}

.sun {
  background:
    radial-gradient(circle at 38% 38%, #fff5d4 0%, #ffd861 35%, #ffaf2e 70%, #ff8a14 100%);
  box-shadow:
    0 0 30px rgba(255, 220, 110, 0.7),
    0 0 70px rgba(255, 180, 60, 0.45),
    0 0 140px rgba(255, 160, 40, 0.25);
  animation: sunPulse 7s ease-in-out infinite;
}
.sun::before {
  content: "";
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 110, 0.35) 0%, transparent 60%);
  z-index: -1;
}
@keyframes sunPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
body.day.clear-day .sun { opacity: 1; }
body.day.partly-cloudy-day .sun { opacity: 0.85; }

.moon {
  background:
    radial-gradient(circle at 32% 32%, #fbf8e8 0%, #d6d2bc 70%, #9c9882 100%);
  box-shadow:
    0 0 25px rgba(248, 245, 232, 0.45),
    inset -14px -10px 26px rgba(0, 0, 0, 0.35);
  width: 78px;
  height: 78px;
}
body.night.clear-night .moon { opacity: 1; }
body.night.partly-cloudy-night .moon { opacity: 0.85; }

/* ---------- clouds ---------- */
.bg.clouds { z-index: 3; pointer-events: none; }

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 100px;
  filter: blur(2px);
  opacity: 0;
  transition: opacity 600ms ease;
}
.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}
.cloud::before { width: 60%; height: 160%; top: -55%; left: 18%; }
.cloud::after  { width: 45%; height: 140%; top: -45%; right: 18%; }

.cloud.c1 { width: 180px; height: 50px; top: 10%; left: -10%; animation: drift 90s linear infinite; }
.cloud.c2 { width: 140px; height: 38px; top: 17%; left: 30%; animation: drift 130s linear infinite; animation-delay: -40s; }
.cloud.c3 { width: 220px; height: 60px; top: 24%; left: 60%; animation: drift 110s linear infinite; animation-delay: -70s; }
.cloud.c4 { width: 110px; height: 32px; top: 33%; left: 5%;  animation: drift 150s linear infinite; animation-delay: -20s; opacity: 0; filter: blur(3px); }
.cloud.c5 { width: 260px; height: 70px; top: 42%; left: 45%; animation: drift 100s linear infinite; animation-delay: -55s; opacity: 0; }

@keyframes drift {
  from { transform: translateX(0); }
  to   { transform: translateX(120vw); }
}

/* Conditional cloud visibility + recoloring */
body.partly-cloudy-day .cloud.c1,
body.partly-cloudy-day .cloud.c2,
body.partly-cloudy-day .cloud.c3 { opacity: 0.92; }
body.partly-cloudy-night .cloud.c1,
body.partly-cloudy-night .cloud.c2,
body.partly-cloudy-night .cloud.c3 { opacity: 0.55; background: rgba(180, 190, 210, 0.85); }

body.cloudy .cloud { opacity: 0.95; }
body.cloudy.night .cloud { opacity: 0.7; background: rgba(140, 150, 170, 0.95); }

body.rain .cloud,
body.thunderstorm .cloud {
  opacity: 0.95;
  background: rgba(60, 70, 90, 0.92);
}
body.rain.night .cloud,
body.thunderstorm.night .cloud {
  background: rgba(35, 42, 58, 0.95);
}

body.snow .cloud { opacity: 0.92; background: rgba(220, 225, 235, 0.95); }
body.snow.night .cloud { opacity: 0.75; background: rgba(180, 190, 205, 0.9); }

/* ---------- precipitation ---------- */
.bg.precip { z-index: 4; pointer-events: none; opacity: 0; }
body.rain .bg.precip,
body.thunderstorm .bg.precip,
body.snow .bg.precip { opacity: 1; }

body.rain .bg.precip,
body.thunderstorm .bg.precip {
  /* Two offset layers so the pattern reads as scattered raindrops rather
     than uniform stripes. */
  background-image:
    linear-gradient(112deg,
      transparent 49.4%,
      rgba(210, 225, 245, 0.35) 50%,
      transparent 50.6%),
    linear-gradient(108deg,
      transparent 49.4%,
      rgba(210, 225, 245, 0.22) 50%,
      transparent 50.6%);
  background-size: 13px 26px, 19px 32px;
  animation: rainFall 1s linear infinite;
  /* Hide rain entirely behind the data column so streaks live in the sky,
     not over the wind labels. */
  -webkit-mask-image: linear-gradient(to bottom,
    rgba(0,0,0,1)    0%,
    rgba(0,0,0,0.65) 22%,
    rgba(0,0,0,0.15) 38%,
    rgba(0,0,0,0)    50%);
          mask-image: linear-gradient(to bottom,
    rgba(0,0,0,1)    0%,
    rgba(0,0,0,0.65) 22%,
    rgba(0,0,0,0.15) 38%,
    rgba(0,0,0,0)    50%);
  opacity: 0.9;
}
@keyframes rainFall {
  from { background-position: 0 0, 0 0; }
  to   { background-position: -13px 26px, -19px 32px; }
}
body.thunderstorm .bg.precip {
  animation-duration: 0.7s;
  background-size: 11px 30px, 17px 36px;
}

body.snow .bg.precip {
  background-image:
    radial-gradient(2.4px 2.4px at  6%  4%, #fff, transparent 70%),
    radial-gradient(1.8px 1.8px at 17% 14%, #fff, transparent 70%),
    radial-gradient(2.6px 2.6px at 28%  7%, #fff, transparent 70%),
    radial-gradient(1.6px 1.6px at 39% 18%, #fff, transparent 70%),
    radial-gradient(2.2px 2.2px at 50%  3%, #fff, transparent 70%),
    radial-gradient(1.8px 1.8px at 61% 16%, #fff, transparent 70%),
    radial-gradient(2.4px 2.4px at 72%  9%, #fff, transparent 70%),
    radial-gradient(1.6px 1.6px at 83% 13%, #fff, transparent 70%),
    radial-gradient(2.2px 2.2px at 94%  6%, #fff, transparent 70%);
  animation: snowFall 8s linear infinite;
}
@keyframes snowFall {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(8px, 60vh, 0); }
}

/* ---------- fog ---------- */
.bg.fog { z-index: 5; pointer-events: none; opacity: 0; }
body.fog .bg.fog { opacity: 1; }
body.fog .bg.fog {
  background:
    linear-gradient(to bottom,
      transparent 0%,
      rgba(220, 222, 228, 0.55) 35%,
      rgba(230, 232, 236, 0.7) 65%,
      rgba(240, 242, 245, 0.78) 100%);
}
body.fog .bg.fog::after {
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0%,
      rgba(255, 255, 255, 0.05) 8%,
      transparent 16%);
  animation: fogDrift 18s linear infinite;
}
@keyframes fogDrift {
  from { transform: translateX(0); }
  to   { transform: translateX(40px); }
}

/* ---------- thunderstorm bolt + flash ---------- */
.bg.bolt { z-index: 5; pointer-events: none; opacity: 0; }
.bg.bolt svg {
  position: absolute;
  top: 12%;
  right: 22%;
  width: 38px;
  height: 95px;
  filter:
    drop-shadow(0 0 8px rgba(255, 240, 140, 0.95))
    drop-shadow(0 0 24px rgba(255, 230, 100, 0.6));
}
body.thunderstorm .bg.bolt {
  opacity: 0.85;
  animation: boltStrike 7s infinite;
}
@keyframes boltStrike {
  0%, 88%, 100% { opacity: 0.55; transform: translateX(0); }
  90%           { opacity: 1; transform: translateX(-3px); }
  92%           { opacity: 0.7; transform: translateX(3px); }
  94%           { opacity: 1; transform: translateX(-2px); }
  96%           { opacity: 0.5; }
}

.bg.flash { z-index: 6; pointer-events: none; opacity: 0; }
body.thunderstorm .bg.flash {
  background: rgba(255, 255, 255, 0.95);
  animation: lightning 7s infinite;
}
@keyframes lightning {
  0%, 92%, 100% { opacity: 0; }
  93%           { opacity: 0.9; }
  93.5%         { opacity: 0; }
  94%           { opacity: 0.6; }
  94.5%         { opacity: 0; }
  98%           { opacity: 0.85; }
  98.4%         { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sun, .cloud,
  body.rain .bg.precip,
  body.snow .bg.precip,
  body.thunderstorm .bg.precip,
  body.fog .bg.fog::after,
  body.thunderstorm .bg.flash,
  body.thunderstorm .bg.bolt {
    animation: none !important;
  }
  body.thunderstorm .bg.flash { opacity: 0; }
  body.thunderstorm .bg.bolt { opacity: 0.85; }
}

/* ---------- ground ---------- */
.bg.ground {
  top: auto;
  height: 6%;
  bottom: 0;
  background:
    linear-gradient(to bottom, #1a0e07 0%, #0a0604 100%);
  border-top: 1px solid rgba(255,255,255,0.18);
  z-index: 4;
}

/* ---------- topbar ---------- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: max(env(safe-area-inset-top, 8px), 8px) 16px 8px 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  pointer-events: none;
}
.topbar .title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  pointer-events: auto;
}
.topbar .title { font-weight: 600; font-size: 18px; }
.set-loc-btn {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.set-loc-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}
.topbar .meta {
  font-size: 12px;
  color: var(--fg-dim);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- ruler ---------- */
.ruler {
  position: absolute;
  left: 0; right: 0;
  top: 64px;
  bottom: 6%;
  z-index: 5;
}

.spine {
  position: absolute;
  left: 50%;
  top: 0; bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom,
    rgba(255,255,255,0.10),
    rgba(255,255,255,0.40));
}

.tick {
  position: absolute;
  left: 0; right: 0;
  height: 0;
}
.tick .tick-mark {
  position: absolute;
  left: 50%;
  top: -1px;
  width: 14px;
  height: 2px;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.55);
}
/* Default (mobile portrait): wind-info on LEFT of spine,
   alt-label on RIGHT. Keeps wind-info clear of the bottom-right map. */
.tick .alt-label {
  position: absolute;
  left: calc(50% + 12px);
  top: -8px;
  font-size: 11px;
  color: var(--fg-dim);
  white-space: nowrap;
}
.tick .wind-info {
  position: absolute;
  right: calc(50% + 12px);
  top: -10px;
  display: flex;
  align-items: center;
  flex-direction: row-reverse;  /* arrow ends up nearest the spine */
  gap: 8px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.tick .arrow { display: inline-flex; }
.tick .arrow svg { overflow: visible; }
.tick .text-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.tick .primary {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tick .compass { font-weight: 600; font-size: 13px; }
.tick .speed   { font-size: 12px; color: var(--fg-dim); }
.tick .gust    {
  font-size: 10px;
  color: #ff9c33;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* Tablet+: alternate sides for visual rhythm (.alt ticks flip to the right) */
@media (min-width: 720px) {
  .tick.alt .alt-label {
    left: auto;
    right: calc(50% + 12px);
  }
  .tick.alt .wind-info {
    right: auto;
    left: calc(50% + 12px);
    flex-direction: row;
  }
}

/* ---------- unit toggle ---------- */
.unit-toggle {
  position: absolute;
  bottom: calc(6% + 12px);
  left: 16px;
  z-index: 11;
  display: inline-flex;
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
}
.unit-btn {
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.unit-btn.active {
  background: rgba(255,255,255,0.20);
  color: var(--fg);
}
.unit-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* ---------- map widget ---------- */
.map-wrap {
  position: absolute;
  bottom: calc(6% + 12px);
  right: 16px;
  width: 180px;
  height: 180px;
  resize: both;
  overflow: hidden;
  min-width: 120px;
  min-height: 120px;
  max-width: min(480px, 50vw);
  max-height: min(480px, 50vh);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  z-index: 11;
  background: rgba(0,0,0,0.3);
  cursor: pointer;
}
#map { width: 100%; height: 100%; }
.map-grip {
  position: absolute;
  right: 4px; bottom: 2px;
  width: 14px; height: 14px;
  pointer-events: none;
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  text-align: center;
  line-height: 14px;
  z-index: 401;
}

@media (max-width: 640px) {
  .map-wrap {
    width: 132px;
    height: 132px;
  }
}

@media (max-width: 360px) {
  .map-wrap {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    resize: none;
  }
  .map-grip { display: none; }
}

.map-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.map-modal-inner {
  position: relative;
  width: 92vw;
  height: 80vh;
  max-width: 1000px;
  background: #1a1a1a;
  border-radius: 12px;
  overflow: hidden;
}
#mapBig { width: 100%; height: 100%; }
#mapClose {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 1000;
}

/* ---------- manual input ---------- */
.manual-input {
  position: absolute;
  top: 70px;
  left: 16px;
  right: 16px;
  z-index: 12;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  padding: 8px 28px 8px 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  max-width: 340px;
}
.manual-close {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,0.15);
  color: var(--fg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.manual-close:hover { background: rgba(255,255,255,0.25); }
.manual-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.manual-input label { display: flex; align-items: center; gap: 4px; }
.manual-input input {
  width: 90px;
  background: rgba(255,255,255,0.10);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  padding: 4px 8px;
  border-radius: 6px;
  font: inherit;
}
.manual-input button {
  background: rgba(255,255,255,0.20);
  color: var(--fg);
  border: 0;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

/* ---------- toast ---------- */
.toast {
  position: absolute;
  bottom: calc(6% + 64px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(60, 0, 0, 0.85);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
}

.hidden { display: none !important; }
