/* Temp° — a quiet room with one large number in it.
   Paper, ink, hairlines; the only colour is the air around the reading. */

:root {
  color-scheme: light;
  --paper: #f6f6f3;
  --paper-deep: #eeefec;
  --ink: #22282a;
  --soft: #5b6264;
  --muted: #6d7375;
  --hairline: #d6d9d6;
  --stale: #8a5443;
  --heat: #a8321f;
  --cold: #1f4f7d;

  /* One measure governs every edge, so the hairlines and the type share a margin. */
  --gutter: clamp(1.25rem, 5.4vw, 3rem);
  /* Tracked small capitals: the museum-label voice. */
  --label-size: clamp(.68rem, 1.9vw, .78rem);
  --label-track: .19em;
  /* The header row is the tightest line on a phone, so it tracks a little closer. */
  --header-track: clamp(.12em, calc(.6vw - .09em), .19em);

  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

p, h1, button, a, strong, time {
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

html, body { margin: 0; min-height: 100%; background: var(--paper); }

body {
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  background-image: linear-gradient(to bottom, var(--paper) 0%, var(--paper) 55%, var(--paper-deep) 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, a, input { font: inherit; }

.shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    max(clamp(1.1rem, 3.4vw, 2rem), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(clamp(1.1rem, 3.4vw, 2rem), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

/* ── Header ─────────────────────────────────────────────── */

header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "heading status"
    "weather precip";
  column-gap: .9rem;
  row-gap: .7rem;
  align-items: center;
  min-width: 0;
  padding-bottom: clamp(1rem, 2.6vw, 1.4rem);
  border-bottom: 1px solid var(--hairline);
}

.header-copy { display: contents; }

.brand {
  grid-area: heading;
  display: flex;
  /* If the status needs the room, "Local weather" drops to a second line and is
     clipped away whole, rather than colliding or being cut mid-word. */
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  height: 1.75rem;
  overflow: hidden;
  min-width: 0;
  margin: 0;
}

/* The mark is a ring of twelve dots: a dial with nothing on it yet. */
.mark {
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  margin-right: .55rem;
  overflow: visible;
}
.mark circle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.9;
  stroke-linecap: round;
  /* circumference 2π·9.5 ≈ 59.69 → twelve dots */
  stroke-dasharray: 0 4.974;
  transform-origin: center;
}
header:has(.status.loading) .mark circle { animation: turn 6s linear infinite; }

.wordmark {
  font-size: clamp(1.15rem, 4.4vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -.035em;
  line-height: 1.75rem;
}

.eyebrow {
  margin-left: clamp(.5rem, 2.2vw, 1rem);
  padding-left: clamp(.5rem, 2.2vw, 1rem);
  border-left: 1px solid var(--hairline);
  color: var(--soft);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--header-track);
  line-height: 1.75rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.status {
  grid-area: status;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: .6em;
  color: var(--soft);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--header-track);
  line-height: 1.2;
  white-space: nowrap;
  text-transform: uppercase;
}

.status::before {
  content: "";
  width: .5em;
  height: .5em;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}
.status.loading::before { animation: breathe 1.6s ease-in-out infinite; }
.status.stale { color: var(--stale); }
.status.error { color: var(--heat); }

.last-updated {
  grid-area: weather;
  margin: 0;
  color: var(--muted);
  font-size: clamp(.82rem, 2.6vw, .92rem);
  font-weight: 400;
  letter-spacing: .005em;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* One small mark for what is falling. It lives in the header, well away from
   the number. Each kind has its own pigment: rain blue, snow white with a thin
   dark rim, lightning yellow. Full colour: station and model agree. A wash of
   the same colour: only one of them, or not yet. */
.precipitation {
  --rain: #0f62d6;
  --bolt: #ffc300;
  --bolt-rim: #7a5600;
  --snow: #ffffff;
  grid-area: precip;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: .45em;
  color: var(--muted);
  font-size: clamp(.82rem, 2.6vw, .92rem);
  line-height: 1.4;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.precipitation[hidden] { display: none; }
.precipitation svg {
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  overflow: visible;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.precipitation.rain .body { stroke: var(--rain); fill: var(--rain); fill-opacity: .42; }
.precipitation.rain.now .body { fill-opacity: 1; }

.precipitation.storm .body { stroke: var(--bolt-rim); stroke-width: 1.4; fill: var(--bolt); fill-opacity: .6; }
.precipitation.storm.now .body { fill-opacity: 1; }

/* The flake is drawn twice: a dark stroke, then a narrower white one on top,
   which leaves a hairline rim around white arms. */
.precipitation.snow .rim { stroke: var(--soft); stroke-width: 3; }
.precipitation.snow .arms { stroke: var(--snow); stroke-width: 1.3; }
.precipitation.snow.now .rim { stroke: var(--ink); stroke-width: 3.3; }

@media (forced-colors: active) {
  .precipitation .body, .precipitation .rim { stroke: CanvasText; }
  .precipitation .arms { stroke: Canvas; }
}

/* ── The reading ────────────────────────────────────────── */

main {
  display: flex;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 2.5vw, 1.5rem);
  padding: clamp(1.5rem, 5vw, 3rem) 0;
}

.reading {
  --thermal-halo: #e3e9ec;
  --humidity: .5;
  width: min(100%, 60rem);
  min-width: 0;
  text-align: center;
}

/* Banded fallbacks; where oklch() is available the script paints a continuous tone. */
.reading.thermal-freezing { --thermal-halo: #cfe2f1; }
.reading.thermal-cool { --thermal-halo: #dfe8ec; }
.reading.thermal-mild { --thermal-halo: #efe6cf; }
.reading.thermal-hot { --thermal-halo: #f1d3c4; }

.reading-label {
  margin: 0 0 clamp(1.1rem, 4vw, 2rem);
  color: var(--soft);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--label-track);
  line-height: 1.2;
  text-transform: uppercase;
}

.temperature {
  /* The numeral is sized against both axes so it never crowds a short screen. */
  --numeral: min(40vw, 38svh, 23rem);
  position: relative;
  isolation: isolate;
  display: inline-block;
  margin: 0;
  max-width: 100%;
  color: var(--ink);
  font-size: var(--numeral);
  font-weight: 200;
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: "ss01" 0;
  line-height: .8;
  letter-spacing: -.035em;
  white-space: nowrap;
}

.temperature[data-width="wide"] { --numeral: min(31vw, 34svh, 20rem); }
.temperature[data-width="extreme"] { --numeral: min(24vw, 30svh, 17rem); }

/* The air: tinted by temperature, diffused by humidity. */
.temperature::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  /* Measured in the numeral's own em, so the air scales with the figure it surrounds. */
  width: min(calc((1.75 + var(--humidity) * .65) * 1em), 100vw);
  aspect-ratio: 1;
  pointer-events: none;
  background: radial-gradient(
    closest-side,
    color-mix(in srgb, var(--thermal-halo) 92%, transparent) 0%,
    color-mix(in srgb, var(--thermal-halo) 62%, transparent) 38%,
    color-mix(in srgb, var(--thermal-halo) 20%, transparent) 70%,
    transparent 100%
  );
  filter: blur(calc(.75rem + var(--humidity) * 2rem));
  transform: translate(-50%, -50%);
  transition: background 1.2s ease, width 1.2s ease;
}

/* The unit hangs outside the numeral so the digits stay on the page's centre line. */
.unit {
  position: absolute;
  top: .02em;
  left: calc(100% + .09em);
  font-size: .155em;
  font-weight: 300;
  letter-spacing: 0;
  line-height: 1;
}

.heat-index {
  margin: clamp(1.4rem, 4.5vw, 2.4rem) 0 0;
  color: var(--heat);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--label-track);
  line-height: 1.4;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.heat-index.cold { color: var(--cold); }

.dewpoint {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  width: min(100%, 23rem);
  margin: clamp(1.9rem, 7vw, 3.4rem) auto 0;
}

.weather-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(.55rem, 2vw, .8rem);
  padding: .15rem .5rem;
  color: var(--soft);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--label-track);
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

.weather-metric strong {
  color: var(--ink);
  font-size: clamp(1.5rem, 6.2vw, 2rem);
  font-weight: 300;
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
  text-transform: none;
}

.weather-divider { width: 1px; background: var(--hairline); }

/* ── Warnings and failures ──────────────────────────────── */

.weather-alert {
  width: min(100%, 60rem);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .4rem 1rem;
  padding: .85rem 1.1rem;
  border-radius: 2px;
  background: var(--heat);
  color: #fff;
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: .14em;
  line-height: 1.4;
  text-decoration: none;
  text-transform: uppercase;
}
.weather-alert[hidden] { display: none; }
.weather-alert span { flex: 0 0 auto; font-weight: 400; white-space: nowrap; }

.error-card {
  width: min(100%, 34rem);
  padding: clamp(1.25rem, 4.5vw, 1.9rem) 0 0;
  border-top: 1px solid var(--ink);
  color: var(--ink);
  text-align: left;
}
.error-card[hidden] { display: none; }
.error-kicker {
  margin: 0 0 .9rem;
  color: var(--heat);
  font-size: var(--label-size);
  font-weight: 600;
  letter-spacing: var(--label-track);
  line-height: 1.4;
  text-transform: uppercase;
}
.error-card h1 {
  margin: 0 0 .8rem;
  font-size: clamp(1.7rem, 6.5vw, 2.5rem);
  font-weight: 300;
  letter-spacing: -.025em;
  line-height: 1.08;
  overflow-wrap: anywhere;
}
.error-card p:not(.error-kicker) { margin: 0 0 1rem; max-width: 34em; color: var(--soft); font-size: 1rem; line-height: 1.55; }
.error-detail { font-size: .88rem !important; overflow-wrap: anywhere; }
.error-detail:empty { display: none; }
.error-actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1.3rem; }
.noscript-card { display: block; }
body.fatal .reading { display: none; }
body.degraded .error-card { padding-top: 1rem; }
body.degraded .error-card h1 { font-size: clamp(1.25rem, 4.6vw, 1.6rem); }

/* ── Controls ───────────────────────────────────────────── */

.refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.9rem;
  padding: .7rem 1.45rem;
  border: 1px solid color-mix(in srgb, var(--ink) 48%, var(--paper));
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: .92rem;
  font-weight: 600;
  letter-spacing: -.005em;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.refresh:active { transform: translateY(1px); }
.refresh:disabled { cursor: wait; opacity: .45; }
.refresh.inverted { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.refresh.quiet { min-height: 2.75rem; padding: .5rem .2rem .5rem 1rem; border: 0; border-radius: 0; }

/* Hover only where a pointer can hover; on touch it would stick after a tap. */
@media (hover: hover) {
  .refresh:hover { border-color: var(--ink); background: var(--ink); color: var(--paper); }
  .refresh.inverted:hover { background: transparent; color: var(--ink); }
  .refresh.quiet:hover { background: transparent; color: var(--ink); text-decoration: underline; text-underline-offset: .3em; }
  .place-results button:hover { color: var(--cold); }
}

:focus-visible { outline: 2px solid var(--cold); outline-offset: 3px; }

/* ── Place ──────────────────────────────────────────────── */

.place-picker {
  min-width: 0;
  padding-top: clamp(1rem, 3vw, 1.4rem);
  border-top: 1px solid var(--hairline);
}

.place-now {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.meta {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: clamp(.82rem, 2.6vw, .92rem);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.place-now .refresh { flex: 0 0 auto; }

#placeForm { margin-top: clamp(1rem, 3vw, 1.3rem); }

.place-picker label {
  display: block;
  margin-bottom: .15rem;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.5;
}

/* A ruled line to write on, not a box to fill in. */
.place-inputs {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 48%, var(--paper));
  transition: border-color .18s ease;
}
.place-inputs:focus-within { border-bottom-color: var(--ink); }
.place-inputs input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 2.75rem;
  padding: .5rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 300;
  -webkit-appearance: none;
  appearance: none;
}
.place-inputs input::placeholder { color: var(--muted); opacity: 1; }
.place-inputs input:focus-visible { outline: none; }

#placeStatus { margin: .7rem 0 0; color: var(--soft); font-size: .85rem; line-height: 1.5; }
#placeStatus:empty { display: none; }

.place-results { display: grid; margin-top: .3rem; }
.place-results:empty { display: none; }
.place-results button {
  min-height: 2.9rem;
  padding: .75rem 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 400;
  text-align: left;
}

.place-picker details { margin-top: .9rem; }
.place-picker summary {
  display: inline-flex;
  align-items: center;
  min-height: 2.2rem;
  color: var(--muted);
  cursor: pointer;
  font-size: .78rem;
  line-height: 1.5;
  list-style: none;
}
.place-picker summary::-webkit-details-marker { display: none; }
.help-label::after { content: " +"; }
details[open] .help-label::after { content: " −"; }
.place-picker details p { max-width: 38em; margin: .6rem 0 0; color: var(--soft); font-size: .85rem; line-height: 1.6; }
.place-picker a { color: inherit; text-underline-offset: .2em; }

/* ── Motion ─────────────────────────────────────────────── */

@keyframes turn { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { opacity: .2; } }

/* ── Narrow screens ─────────────────────────────────────── */

@media (max-width: 23rem) {
  :root { --label-track: .14em; }
  .place-now { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

@media (forced-colors: active), print {
  body { background-image: none; }
  .temperature::before { display: none; }
  .weather-divider { background: CanvasText; }
}
