:root {
  --bg: #08090c;
  --card: #111318;
  --border: rgb(255 255 255 / 0.065);
  --grid: rgb(255 255 255 / 0.07);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --dim: #52525b;
  --accent: #34d399;
  --sun: #fbbf24;
  --rain: #38bdf8;
  --snow: #e2e8f0;
  --moon: #c7d2fe;
  --cloud: #d4d4d8;

  --glow-sun: rgb(251 191 36 / 0.32);
  --glow-night: rgb(99 102 241 / 0.32);
  --glow-cloud: rgb(148 163 184 / 0.26);
  --glow-night-cloud: rgb(71 85 105 / 0.38);
  --glow-rain: rgb(56 189 248 / 0.32);
  --glow-snow: rgb(226 232 240 / 0.26);
  --glow-fog: rgb(161 161 170 / 0.22);
  --glow-storm: rgb(167 139 250 / 0.38);
  --glow: var(--glow-cloud);

  --gap: 10px;
  --row: 32px;
  /* Clear of the status bar and of the blur iOS draws below it. */
  --top: calc(env(safe-area-inset-top) + 20px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--text);
  font:
    15px / 1.3 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(110% 55% at 18% -8%, var(--glow), transparent 72%),
    radial-gradient(90% 40% at 100% 105%, var(--glow), transparent 70%);
  opacity: 0.9;
  pointer-events: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* Layout: one screen, no scrolling. The chart takes whatever height is left. */

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  max-width: 34rem;
  height: min(100%, 980px);
  margin: auto;
}

.view-weather {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  min-height: 0;
  padding: var(--top) 14px 4px;
}

.view-radar {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* Header with the current conditions */

.hero {
  --icon-bg: var(--bg);
}

.topline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.place {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
}

.place span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.place .glyph {
  flex: none;
  font-size: 13px;
  color: var(--faint);
}

.place.is-gps .glyph {
  color: var(--accent);
  fill: var(--accent);
}

.status {
  margin-left: auto;
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
}

.status.is-stale {
  color: var(--sun);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-right: -8px;
  border-radius: 50%;
  font-size: 18px;
  color: var(--muted);
}

.icon-btn.is-loading .glyph {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hero-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hero-temp {
  font-size: clamp(4.4rem, 24vw, 6.2rem);
  font-weight: 200;
  line-height: 0.95;
  letter-spacing: -0.055em;
  font-variant-numeric: normal;
  margin-left: -0.04em;
}

.hero-side {
  display: grid;
  flex: 1;
  min-width: 0;
}

.hero-cond {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.15;
}

.hero-cond .wx {
  flex: none;
  font-size: 44px;
}

/* Cards */

.card {
  /* Sections sit on the page itself: halos and masks take the page colour. */
  --card: var(--bg);
  --icon-bg: var(--bg);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  column-gap: 10px;
  row-gap: 2px;
}

/* The title keeps its line; the detail wraps below it when both do not fit. */
.card-head h2 {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.muted {
  flex: none;
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
}

/* Next 24 hours */

.hours {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 6px;
}

#chart-head {
  flex-wrap: nowrap;
}

#chart-head.is-wet h2 {
  color: var(--rain);
}

#chart-head .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}

#chart-head h2 {
  flex-shrink: 0;
}

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

.pill {
  flex: none;
  margin: -4px -4px -4px auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
}

.chart {
  flex: 1;
  min-height: 120px;
  margin: 4px -14px 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  outline: none;
}

.chart svg {
  display: block;
  font:
    11px system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}

.c-sky-night {
  stop-color: rgb(14 20 46 / 0.6);
}

.c-sky-none {
  stop-color: rgb(0 0 8 / 0);
}

.c-sky-top {
  stop-color: rgb(84 166 246 / 0.72);
}

.c-sky-horizon {
  stop-color: rgb(168 218 252 / 0.62);
}

.c-mask-on {
  stop-color: #fff;
}

.c-page {
  stop-color: var(--bg);
}

.c-puff-day {
  stop-color: rgb(241 245 249);
}

.c-puff-day-night {
  stop-color: rgb(100 116 139);
}

.c-puff-rain {
  stop-color: rgb(100 116 139);
}

.c-puff-rain-night {
  stop-color: rgb(71 85 105);
}

/* Clouds sway, wider and faster in more wind; every other puff the other way. */
.c-sway {
  animation: c-sway-0 7s ease-in-out infinite alternate;
}

.c-sway-1 {
  animation-name: c-sway-1;
  animation-duration: 4s;
}

.c-sway-2 {
  animation-name: c-sway-2;
  animation-duration: 2s;
}

.c-sway-alt {
  animation-direction: alternate-reverse;
}

@keyframes c-sway-0 {
  from {
    transform: translateX(-1.5px);
  }
  to {
    transform: translateX(1.5px);
  }
}

@keyframes c-sway-1 {
  from {
    transform: translateX(-3px);
  }
  to {
    transform: translateX(3px);
  }
}

@keyframes c-sway-2 {
  from {
    transform: translateX(-5px);
  }
  to {
    transform: translateX(5px);
  }
}

/* Drops and flakes move down along their lines: the dash offset runs one
   dash period. */
.c-drop,
.c-flake {
  fill: none;
  stroke: var(--rain);
  stroke-linecap: round;
  stroke-width: 1.5;
  stroke-dasharray: 5 10;
  animation: c-rain 0.25s linear infinite;
}

.c-flake {
  stroke: #e2e8f0;
  stroke-width: 2.4;
  stroke-dasharray: 0 9;
  animation: c-snow 1s linear infinite;
}

@keyframes c-rain {
  from {
    stroke-dashoffset: 15;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes c-snow {
  from {
    stroke-dashoffset: 9;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* A gust is drawn on along its path and wiped off again, then rests. The dash
   is longer than the longest gust (GUSTS in chart.js). */
.c-gust {
  fill: none;
  stroke: rgb(148 163 184 / 0.9);
  stroke-linecap: round;
  stroke-width: 1.4;
  stroke-dasharray: 56 56;
  animation: c-gust 2.6s linear infinite;
}

.c-gust-2 {
  stroke-width: 1.8;
  animation-duration: 1.4s;
}

.c-gust-alt {
  animation-delay: -1.3s;
}

.c-gust-2.c-gust-alt {
  animation-delay: -0.7s;
}

@keyframes c-gust {
  from {
    stroke-dashoffset: 56;
  }
  70%,
  to {
    stroke-dashoffset: -56;
  }
}

@media (prefers-reduced-motion: reduce) {
  .c-sway,
  .c-drop,
  .c-flake,
  .c-gust {
    animation: none;
  }
}

.c-wind {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.c-wind-unit {
  font-weight: 400;
  fill: var(--faint);
}

.c-wind.is-fresh {
  fill: var(--text);
}

.c-wind.is-strong {
  fill: var(--sun);
}

.c-mask-off {
  stop-color: #000;
}

.c-star {
  fill: #e0e7ff;
}

.c-day {
  stroke: rgb(255 255 255 / 0.16);
  stroke-dasharray: 2 3;
}

.c-label {
  fill: var(--faint);
}

.c-weekday {
  fill: var(--muted);
  font-weight: 600;
}

.c-uv-sun {
  fill: var(--sun);
  stroke: var(--sun);
  stroke-linecap: round;
  stroke-width: 1;
}

.c-uv-sun-0 {
  fill: #ef4444;
  stroke: #ef4444;
  stroke-width: 1.5;
}

.c-uv-sun-1 {
  fill: #fb923c;
  stroke: #fb923c;
  stroke-width: 1.2;
}

.c-amount {
  fill: var(--rain);
  font-size: 10px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
}

.c-past {
  fill: var(--card);
  opacity: 0.5;
}

.c-now {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.c-now-label {
  fill: var(--accent);
  font-weight: 600;
}

.c-ev {
  opacity: 0.75;
  fill: none;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.c-ev-sun {
  fill: var(--sun);
}

.c-ev-moon {
  fill: var(--moon);
}

.c-ev-arrow {
  stroke: var(--muted);
}

.c-temp {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.c-extreme {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
}

.c-marker line {
  stroke: rgb(255 255 255 / 0.4);
}

.c-marker circle {
  fill: var(--text);
  stroke: var(--card);
  stroke-width: 2;
}

/* 7 days */

.days {
  padding: 0;
}

#days {
  margin: 0;
  padding: 0;
  list-style: none;
}

#days button {
  display: grid;
  grid-template-columns: 3.5em 1.6em 3.4em 2.1em minmax(2em, 1fr) 2.1em;
  align-items: center;
  column-gap: 6px;
  width: calc(100% + 16px);
  height: var(--row);
  margin: 0 -8px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
}

#days button.is-active {
  background: rgb(52 211 153 / 0.12);
}

.d-name {
  font-weight: 500;
  white-space: nowrap;
}

.d-name small {
  margin-left: 4px;
  font-size: 11px;
  color: var(--faint);
}

.d-icon {
  display: flex;
  font-size: 22px;
}

.d-rain {
  display: grid;
  font-size: 11px;
  line-height: 1.1;
  color: var(--rain);
  text-align: right;
  white-space: nowrap;
}

.d-rain small {
  font-size: 10px;
  color: var(--faint);
}

.d-lo {
  color: var(--faint);
  text-align: right;
}

.d-bar {
  position: relative;
  height: 5px;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.07);
}

.d-bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
}

.d-bar b {
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--card);
}

/* Tab bar at the bottom, in thumb reach */

.tabs {
  display: flex;
  justify-content: center;
  padding: 2px 0 calc(env(safe-area-inset-bottom) + 2px);
}

.tabs button {
  display: flex;
  flex: 1;
  max-width: 10rem;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--faint);
}

.tabs .glyph {
  font-size: 20px;
}

.tabs [aria-selected='true'] {
  color: var(--text);
}

.tabs .glyph {
  box-sizing: content-box;
  padding: 3px 18px;
  border-radius: 999px;
}

.tabs [aria-selected='true'] .glyph {
  color: var(--accent);
  background: rgb(52 211 153 / 0.14);
}

/* Icons */

.wx {
  width: 1em;
  height: 1em;
  overflow: visible;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-sun {
  stroke: var(--sun);
}

circle.i-sun {
  fill: rgb(251 191 36 / 0.22);
}

.i-moon {
  stroke: var(--moon);
  fill: rgb(199 210 254 / 0.14);
}

.i-cloud {
  stroke: var(--cloud);
}

.i-cloud {
  fill: rgb(212 212 216 / 0.1);
}

/* Opaque, so a cloud covers the sun or moon behind it. */
.i-fill {
  fill: color-mix(in srgb, var(--icon-bg), #d4d4d8 10%);
}

.i-rain {
  stroke: var(--rain);
}

.i-snow {
  stroke: var(--snow);
}

.i-dot {
  stroke-width: 2.6;
}

.i-bolt {
  stroke: var(--sun);
}

.glyph {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-moon-disc {
  fill: rgb(255 255 255 / 0.07);
  stroke: rgb(199 210 254 / 0.35);
  stroke-width: 1;
}

.i-moon-lit {
  fill: var(--moon);
  stroke: none;
}

/* Before the first forecast arrives */

.is-empty .card,
.is-empty .hero-main {
  opacity: 0.45;
}

/* Place picker */

.picker {
  width: min(100% - 20px, 480px);
  max-height: calc(100% - var(--top) - 20px);
  margin: var(--top) auto auto;
  padding: 10px 14px 4px;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  overflow: auto;
}

.picker::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.picker-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.picker-form input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  /* 16 px or more, or iOS zooms in on focus. */
  font: inherit;
  font-size: 17px;
  user-select: text;
  -webkit-user-select: text;
}

.picker-list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.picker-list button {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 8px 2px;
  font-size: 16px;
  text-align: left;
}

.picker-list small {
  overflow: hidden;
  font-size: 13px;
  color: var(--faint);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.picker-list .picker-gps {
  align-items: center;
  color: var(--accent);
}

.picker-note {
  padding: 10px 2px;
  font-size: 14px;
  color: var(--faint);
}

/* Rain radar */

.map {
  position: absolute;
  inset: var(--top) 0 0;
  overflow: hidden;
  background: #0d0e12;
  touch-action: none;
  cursor: grab;
}

.map:active {
  cursor: grabbing;
}

.map-pan,
.map-layer,
.map-frame {
  position: absolute;
  inset: 0;
}

/* Gesture previews scale around the top left corner (see radar.js). */
.map-pan {
  transform-origin: 0 0;
}

.map-layer img {
  position: absolute;
  max-width: none;
  pointer-events: none;
}

.map-radar {
  opacity: 0.8;
}

.map-frame {
  opacity: 0;
}

.map-frame.is-active {
  opacity: 1;
}

.map-me {
  position: absolute;
  top: 0;
  left: 0;
}

.map-me::before,
.map-me::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px;
  border-radius: 50%;
  background: var(--accent);
}

.map-me::before {
  box-shadow: 0 0 0 2px var(--bg);
}

.map-me::after {
  animation: pulse 2.4s ease-out infinite;
}

@keyframes pulse {
  from {
    opacity: 0.6;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(3.2);
  }
}

.card-glass {
  background: rgb(17 19 24 / 0.86);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.radar-head {
  position: absolute;
  top: calc(var(--top) + 10px);
  left: 50%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 15px;
  white-space: nowrap;
  transform: translateX(-50%);
}

#radar-age {
  font-size: 12px;
  color: var(--muted);
}

.radar-zoom {
  position: absolute;
  top: calc(var(--top) + 60px);
  right: 12px;
  display: grid;
  gap: 8px;
}

.map-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 18px;
  background: rgb(17 19 24 / 0.86);
}

.radar-bar {
  position: absolute;
  right: 12px;
  bottom: 26px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 6px;
  border-radius: 16px;
}

.radar-bar .map-btn {
  flex: none;
  border: 0;
  background: none;
}

#radar-age.is-forecast {
  color: var(--sun);
}

/* Radar timeline: one tick per frame, forecast frames in yellow. */

.rt {
  position: relative;
  flex: 1;
  padding: 6px 0 16px;
  touch-action: none;
  cursor: pointer;
  outline: none;
}

.rt-ticks {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
}

.rt-ticks i {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  background: rgb(255 255 255 / 0.25);
}

.rt-ticks i.is-forecast {
  background: rgb(251 191 36 / 0.45);
}

.rt-ticks i.is-now {
  height: 14px;
  background: var(--text);
}

.rt-ticks i.is-active {
  height: 18px;
  background: var(--accent);
}

.rt-labels {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 14px;
  font-size: 10px;
  color: var(--faint);
}

.rt-labels span {
  position: absolute;
  top: 0;
}

.rt-labels span:first-child {
  left: 0;
}

.rt-labels .rt-now {
  transform: translateX(-50%);
  color: var(--muted);
}

#radar-end {
  right: 0;
  color: var(--sun);
}

.map-forecast {
  pointer-events: none;
  opacity: 0.85;
}

.map-credits {
  position: absolute;
  right: 10px;
  bottom: 6px;
  left: 10px;
  margin: 0;
  font-size: 10px;
  color: var(--faint);
  text-align: right;
}

/* Smaller phones: tighten, then drop the last days rather than scroll. */

@media (max-height: 760px) {
  :root {
    --gap: 8px;
    --row: 27px;
  }
  .hero-temp {
    font-size: clamp(4rem, 21vw, 5.2rem);
  }
}

@media (max-height: 700px) {
  :root {
    --row: 26px;
  }
  .hero-temp {
    font-size: 3.8rem;
  }
  .hero-cond {
    font-size: 19px;
  }
  .hero-cond .wx {
    font-size: 42px;
  }
  #days li:nth-child(n + 6) {
    display: none;
  }
}

@media (max-height: 660px) {
  #days li:nth-child(n + 5) {
    display: none;
  }
}

/* Phones held sideways (installed app is portrait): let it scroll rather than clip. */

@media (orientation: landscape) and (max-height: 520px) {
  html,
  body {
    overflow: auto;
  }
  .app {
    position: static;
    height: auto;
  }
  .view-weather {
    grid-template-rows: auto;
  }
  .chart {
    height: 160px;
    flex: none;
  }
}
