:root {
  --coral: #ff6b81;
  --teal: #4ecdc4;
  --lavender: #b4a7ff;
  --lemon: #ffe66d;
  --sky-blue: #6cc4ff;
  --plum: #b890ff;
  --text: #ffffff;
  --muted: rgba(255,255,255,0.70);
  --hint: rgba(255,255,255,0.50);
  --glass: rgba(255,255,255,0.15);
  --glass-border: rgba(255,255,255,0.30);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 70% 60% at 78% 85%, rgba(255,180,120,0.55), transparent 60%),
    linear-gradient(180deg, #4e348a 0%, #d95c8a 60%, #ff9f64 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

.muted { color: var(--muted); }

.app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "topbar"
    "alert"
    "content"
    "tabs";
  padding: 8px;
  gap: 8px;
}
.topbar       { grid-area: topbar; }
.alert-banner { grid-area: alert; }
.tab-content  { grid-area: content; }
.bottom-bar   { grid-area: tabs; }

/* ---- topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 13px;
  letter-spacing: 0.05em;
  gap: 8px;
}
.topbar .loc strong { letter-spacing: 0.16em; font-size: 14px; }
.status { display: flex; align-items: center; gap: 7px; font-size: 11px; letter-spacing: 0.14em; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #888;
  transition: background 0.3s, box-shadow 0.3s;
}
.dot.live    { background: #4cd964; box-shadow: 0 0 10px #4cd964; }
.dot.rest    { background: #ffd23f; box-shadow: 0 0 10px #ffd23f; }
.dot.offline { background: #ff3b30; box-shadow: 0 0 10px #ff3b30; }
.clock { display: flex; gap: 8px; align-items: baseline; font-variant-numeric: tabular-nums; }

/* ---- alert banner ---- */
.alert-banner {
  background: rgba(255,59,48,0.20);
  border: 1px solid rgba(255,59,48,0.55);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
}
.alert-banner[hidden] { display: none; }

/* ---- tab content ---- */
.tab-content { position: relative; min-height: 0; }
.tab {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  gap: 8px;
}
.tab.active { display: flex; }

/* ---- glass panels ---- */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* ---- hero ---- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  gap: 16px;
  flex-shrink: 0;
}
.hero-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.temp {
  font-size: 84px;
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.conditions { font-size: 17px; color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; font-variant-numeric: tabular-nums; }
.meta .sep { opacity: 0.45; }
.hero-right { font-size: 60px; line-height: 1; }

/* ---- stats grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-template-areas:
    "wind wind pres pres"
    "wind wind ltg  ltg"
    "hum  dew  uv   uv";
  gap: 8px;
  flex: 1;
  min-height: 0;
}
.tile[data-stat="wind"]      { grid-area: wind; }
.tile[data-stat="pressure"]  { grid-area: pres; }
.tile[data-stat="lightning"] { grid-area: ltg; }
.tile[data-stat="humidity"]  { grid-area: hum; }
.tile[data-stat="dew"]       { grid-area: dew; }
.tile[data-stat="uv"]        { grid-area: uv; }

.tile {
  position: relative;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 12px 14px 10px 20px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  min-width: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: background 0.4s, transform 0.15s;
}
.tile:active { transform: scale(0.98); }
.tile:hover { background: rgba(255,255,255,0.13); }
.tile::before {
  content: "";
  position: absolute;
  left: 0; top: 10px; bottom: 10px;
  width: 4px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.tile .label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.10em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tile .val {
  align-self: center;
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}
.tile .val .number {
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
}
.tile .val .unit { font-size: 12px; color: var(--muted); }
.tile .sparkline {
  width: 100%;
  height: 24px;
  align-self: end;
  opacity: 0.55;
}
.tile .sparkline path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* lightning flash on new strike */
.tile.flash {
  animation: flash 0.55s ease-out;
}
@keyframes flash {
  0%   { background: rgba(255,255,255,0.55); }
  100% { background: rgba(255,255,255,0.10); }
}

/* wind tile (large, with compass + readout side by side) */
.wind-tile { grid-template-rows: auto 1fr; }
.wind-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
}
.wind-tile .compass svg {
  width: clamp(70px, 22vmin, 130px);
  height: clamp(70px, 22vmin, 130px);
  display: block;
}
.wind-readout { display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.wind-speed { display: flex; align-items: baseline; gap: 5px; }
.wind-speed .number { font-size: clamp(28px, 6vmin, 40px); font-weight: 300; line-height: 1; }
.wind-speed .unit { font-size: 12px; color: var(--muted); }
.wind-dir { font-size: 12px; letter-spacing: 0.12em; }
.wind-gust { font-size: 11px; }

/* pressure trend arrow */
.pressure-tile .trend {
  font-size: 16px;
  line-height: 1;
  padding-left: 4px;
  color: var(--muted);
  display: inline-block;
  transition: transform 0.3s;
}
.trend.rising_fast::before  { content: "⇈"; color: var(--coral); }
.trend.rising::before       { content: "↑"; color: var(--coral); opacity: 0.85; }
.trend.steady::before       { content: "→"; opacity: 0.5; }
.trend.falling::before      { content: "↓"; color: var(--sky-blue); opacity: 0.85; }
.trend.falling_fast::before { content: "⇊"; color: var(--sky-blue); }

/* lightning tile */
.lightning-tile { grid-template-rows: auto 1fr auto; }
.ltg-dist { font-size: 11px; }

/* ---- hourly strip ---- */
.hourly {
  display: flex;
  gap: 6px;
  padding: 8px;
  flex-shrink: 0;
  height: 110px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  backdrop-filter: blur(20px);
}
.hour {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
.hour .h-time   { color: var(--muted); font-size: 10px; letter-spacing: 0.06em; }
.hour .h-icon   { font-size: 18px; line-height: 1; }
.hour .h-temp   { font-size: 14px; font-weight: 500; }
.hour .h-precip { font-size: 9px; color: var(--sky-blue); }

/* ---- radar tab ---- */
.tab-radar { padding: 0; }
.tab-radar #radar-map {
  width: 100%;
  height: 100%;
  border-radius: 18px;
  border: 1px solid var(--glass-border);
}
.leaflet-container { background: #1a2a3a; border-radius: 18px; }
.leaflet-tile {
  image-rendering: -webkit-optimize-contrast;
}
.leaflet-tile-container,
.leaflet-tile {
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
}
.radar-label {
  position: absolute;
  top: 10px; left: 14px;
  z-index: 500;
  font-size: 10px; letter-spacing: 0.14em; color: #fff;
  text-transform: uppercase;
  background: rgba(0,0,0,0.45);
  padding: 5px 9px;
  border-radius: 6px;
  pointer-events: none;
}
.radar-play {
  position: absolute;
  bottom: 12px; right: 12px;
  z-index: 500;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  padding-left: 2px;
  cursor: pointer;
}
.radar-play.playing { background: rgba(255,105,180,0.7); border-color: #ff69b4; padding-left: 0; }
.radar-play.loading { animation: spin-pulse 1s ease-in-out infinite; padding-left: 0; }
@keyframes spin-pulse { 0% { opacity: 0.55; } 50% { opacity: 1; } 100% { opacity: 0.55; } }

.home-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #ff69b4;
  box-shadow: 0 0 0 0 rgba(255,105,180,0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(255,105,180,0.65); }
  70%  { box-shadow: 0 0 0 18px rgba(255,105,180,0); }
  100% { box-shadow: 0 0 0 0   rgba(255,105,180,0); }
}

/* ---- placeholder tabs ---- */
.placeholder {
  margin: auto;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  display: flex; flex-direction: column; gap: 10px;
  padding: 28px;
}
.placeholder-glyph { font-size: 64px; opacity: 0.5; line-height: 1; }

/* ---- bottom tab bar ---- */
.bottom-bar {
  display: flex;
  background: rgba(0,0,0,0.40);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 18px;
  height: 58px;
  overflow: hidden;
  flex-shrink: 0;
  backdrop-filter: blur(20px);
}
.bnav {
  flex: 1;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.58);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.bnav .glyph { font-size: 22px; line-height: 1; }
.bnav.active { color: #fff; background: rgba(255,255,255,0.12); }
.bnav:active { transform: scale(0.96); }

/* ---- history modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-in 0.18s ease-out;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  width: min(720px, 92vw);
  max-height: 86vh;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 1;
  border-radius: 22px;
}
@keyframes modal-in {
  0%   { opacity: 0; transform: scale(0.96); }
  100% { opacity: 1; transform: scale(1.00); }
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; }
.modal-label { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
.modal-current { font-size: 56px; font-weight: 200; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.modal-current .unit { font-size: 16px; color: var(--muted); margin-left: 4px; }
.modal-close {
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.25);
  color: #fff; width: 38px; height: 38px; border-radius: 50%; font-size: 22px;
  line-height: 1; cursor: pointer;
}
.modal-stats { display: flex; gap: 22px; font-variant-numeric: tabular-nums; font-size: 13px; }
.modal-stats > div { display: flex; gap: 6px; align-items: baseline; }
.modal-stats .muted { letter-spacing: 0.08em; text-transform: uppercase; font-size: 10px; }
.modal-chart { width: 100%; height: 220px; }
.modal-chart .chart-line {
  fill: none; stroke: var(--chart-accent, #fff); stroke-width: 2;
  vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round;
}
.modal-chart .chart-fill { fill: var(--chart-accent, #fff); opacity: 0.15; }
.modal-chart .chart-min, .modal-chart .chart-max { fill: var(--chart-accent, #fff); }
.modal-chart .chart-min-line, .modal-chart .chart-max-line {
  stroke: rgba(255,255,255,0.25); stroke-dasharray: 3 3; stroke-width: 1;
}
.modal-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ===========================================
   Responsive
   =========================================== */

/* Narrow phone */
@media (max-width: 480px) {
  .temp { font-size: 70px; }
  .hero-right { font-size: 48px; }
  .tile .val .number { font-size: 24px; }
  .hourly { height: 96px; }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, 1fr);
    grid-template-areas:
      "wind wind"
      "pres ltg"
      "hum  dew"
      "uv   uv";
  }
  .wind-body { gap: 8px; }
  .wind-tile .compass svg { width: 72px; height: 72px; }
}

/* Wide screens — landscape iPad, desktop. Side-by-side Today layout. */
@media (min-width: 900px) and (orientation: landscape) {
  .tab-today.active {
    display: grid;
    grid-template-columns: 0.85fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "hero    stats"
      "hourly  stats"
      "hourly  stats";
    gap: 8px;
  }
  .tab-today .hero    { grid-area: hero; }
  .tab-today .stats-grid { grid-area: stats; }
  .tab-today .hourly  { grid-area: hourly; }
  .temp { font-size: 90px; }
}
