/* ============================================================
   PlinkExchange — Range weather card
   Lives as the first card in the profile page's right rail. Data is
   fetched client-side from Open-Meteo (no key, CC BY 4.0) at the
   range's own coordinates, looked up by slug in RANGE_DATA.

   Deliberately NOT rendered as a <section>: dev-base.css styles bare
   `section { padding: var(--section-y) 0 }`, which would leak ~144px
   of padding into the rail. Everything here is div/ul based.
============================================================ */

.wx-card {
  background: #fff;
  border: 1.5px solid var(--rule);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}

/* Skeleton while the fetch is in flight — same box, so the rail doesn't
   jump when data lands. */
.wx-card[data-state="loading"] .wx-body,
.wx-card[data-state="error"] .wx-body { display: none; }
.wx-card[data-state="ready"] .wx-skeleton,
.wx-card[data-state="error"] .wx-skeleton { display: none; }
.wx-card[data-state="ready"] .wx-error,
.wx-card[data-state="loading"] .wx-error { display: none; }

.wx-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.wx-eye {
  font-family: var(--mono);
  font-size: var(--t-eye);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange-deep);
}
.wx-localtime {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Now ---------- */
.wx-now {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}
.wx-now-icon { flex-shrink: 0; width: 44px; height: 44px; color: var(--orange); }
.wx-now-icon svg { width: 100%; height: 100%; display: block; }
.wx-now-main { min-width: 0; flex: 1; }
.wx-now-temp {
  display: block;
  font-family: var(--display);
  font-weight: 800;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
}
.wx-now-temp sup { font-size: 16px; font-weight: 700; vertical-align: super; margin-left: 1px; }
.wx-now-desc {
  display: block;
  font-size: var(--t-sm);
  color: var(--charcoal-3);
  margin-top: 5px;
  line-height: 1.3;
}
.wx-now-feels { color: var(--muted); font-size: var(--t-xs); }

/* ---------- Wind: the number that actually matters for pellets ---------- */
.wx-wind {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-4);
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: var(--r);
}
.wx-wind-arrow {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  color: var(--charcoal);
  /* rotated inline via style="--wx-dir:Ndeg" — the API gives the direction
     the wind blows FROM, and the arrow is drawn pointing "to". */
  transform: rotate(var(--wx-dir, 0deg));
  transition: transform 0.3s var(--ease-out);
}
.wx-wind-arrow svg { width: 100%; height: 100%; display: block; }
.wx-wind-text { min-width: 0; }
.wx-wind-val {
  font-family: var(--mono);
  font-size: var(--t-base);
  font-weight: 600;
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.wx-wind-lbl {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}
/* Wind severity — airgun-relevant thresholds, not meteorological ones. */
.wx-wind[data-wind="calm"]   { background: rgb(var(--tier-4-rgb) / .078); border-color: rgb(var(--tier-4-rgb) / .239); }
.wx-wind[data-wind="breezy"] { background: var(--orange-tint); border-color: rgb(var(--orange-rgb) / .22); }
.wx-wind[data-wind="windy"]  { background: rgb(var(--tier-1-rgb) / .078); border-color: rgb(var(--tier-1-rgb) / .239); }
.wx-wind[data-wind="windy"] .wx-wind-val { color: var(--tier-1); }

/* ---------- Secondary stats ---------- */
/* One inline row. Was a two-column stacked label/value grid ~60px tall; this
   carries the same two facts in ~22px, paying for the 5-day strip below. */
.wx-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px dashed var(--rule);
  font-size: var(--t-xs);
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
}
.wx-stat { font-weight: 600; }
.wx-stat i {
  font-style: normal;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 3px;
}

/* ---------- Forecast periods ---------- */
.wx-fc { margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px dashed var(--rule); }
.wx-fc-day + .wx-fc-day { margin-top: var(--s-3); }
.wx-fc-daylbl {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--charcoal-3);
  margin-bottom: 3px;
}
.wx-rows { display: flex; flex-direction: column; gap: 2px; }
.wx-row {
  display: grid;
  grid-template-columns: 46px 20px 1fr auto;
  align-items: center;
  gap: var(--s-2);
  padding: 3px 6px;
  border-radius: var(--r-sm);
}
.wx-row + .wx-row { border-top: 1px solid rgb(var(--rule-rgb) / .349); }
.wx-row.is-now { background: var(--orange-tint); }
/* Elapsed periods are de-emphasised with colour and weight, NOT a blanket
   opacity: 0.42 over already-muted grey lands around 1.9:1, which is
   unreadable. --charcoal-3 holds ~7.5:1 while still receding next to the
   full-strength rows; the icon (decorative, aria-hidden) carries the rest. */
.wx-row.is-past .wx-row-temp { color: var(--charcoal-3); font-weight: 500; }
.wx-row.is-past .wx-row-icon { opacity: 0.45; }
.wx-row.is-past .wx-row-part,
.wx-row.is-past .wx-row-meta { color: var(--muted); }
.wx-row-part {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.wx-row.is-now .wx-row-part { color: var(--orange-deep); }
.wx-row-icon { width: 18px; height: 18px; color: var(--charcoal-3); }
.wx-row-icon svg { width: 100%; height: 100%; display: block; }
.wx-row-temp {
  font-family: var(--mono);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
}
.wx-row-meta {
  display: flex;
  gap: var(--s-3);
  justify-content: flex-end;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.wx-row-wind { color: var(--charcoal-3); font-weight: 600; }
.wx-row-wind[data-wind="windy"] { color: var(--tier-1); }
.wx-row-pop[data-wet="1"] { color: var(--orange-deep); font-weight: 600; }

/* ---------- Abbreviated 5-day ---------- */
.wx-5d { margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px dashed var(--rule); }
.wx-5d-lbl {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--charcoal-3);
  margin-bottom: 3px;
}
.wx-5d-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.wx-5d-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 2px 2px;
  border-radius: var(--r-sm);
  min-width: 0;
}
.wx-5d-day + .wx-5d-day { border-left: 1px solid rgb(var(--rule-rgb) / .5); }
.wx-5d-name {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.wx-5d-icon { width: 15px; height: 15px; color: var(--charcoal-3); }
.wx-5d-icon svg { width: 100%; height: 100%; display: block; }
.wx-5d-t {
  font-family: var(--mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.wx-5d-t b { font-weight: 600; color: var(--charcoal); }
.wx-5d-t i { font-style: normal; color: var(--muted); margin-left: 3px; }

/* Shown only when the coordinates are a town centroid, not the venue. */
.wx-approx {
  margin: var(--s-4) 0 0;
  padding: var(--s-3);
  background: var(--paper-warm);
  border-left: 2px solid var(--rule-2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--charcoal-3);
}

/* ---------- Footer / attribution ---------- */
.wx-foot {
  margin-top: var(--s-3);
  padding-top: var(--s-2);
  border-top: 1px solid var(--rule);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
}
.wx-foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.wx-foot a:hover { color: var(--orange-deep); }

/* ---------- Skeleton / error ---------- */
.wx-skeleton { display: flex; flex-direction: column; gap: var(--s-3); }
.wx-sk-bar {
  height: 12px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--paper-warm) 25%, var(--paper-deep) 37%, var(--paper-warm) 63%);
  background-size: 400% 100%;
  animation: wxShimmer 1.3s ease-in-out infinite;
}
.wx-sk-bar--lg { height: 34px; width: 60%; }
.wx-sk-bar--sm { width: 80%; }
@keyframes wxShimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .wx-sk-bar { animation: none; } }

.wx-error { font-size: var(--t-xs); color: var(--muted); line-height: 1.5; }

/* ---------- Compact variant: map pin popover on the directory ---------- */
/* [hidden] is only `display:none` in the UA sheet, so an author `display:flex`
   silently beats it — without this rule every popover renders an empty
   bordered strip until the fetch lands, and keeps it forever if it fails. */
.wx-mini[hidden] { display: none; }
.wx-mini {
  display: flex;
  align-items: center;
  /* The readings stay on one line; the attribution drops to its own line
     rather than squeezing "9mph SSW" into a two-line column. */
  flex-wrap: wrap;
  row-gap: 2px;
  gap: 7px;
  margin-top: 8px;
  padding: 6px 9px;
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--charcoal-3);
  font-variant-numeric: tabular-nums;
}
.wx-mini-icon { width: 15px; height: 15px; flex-shrink: 0; color: var(--orange); }
.wx-mini-icon svg { width: 100%; height: 100%; display: block; }
.wx-mini-temp { font-weight: 600; color: var(--charcoal); }
.wx-mini-sep { color: var(--rule-2); }
.wx-mini-attr {
  margin-left: auto;
  padding-left: 6px;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}
.wx-mini-attr:hover { color: var(--orange-deep); }
.wx-mini-wind { white-space: nowrap; }
.wx-mini-approx { font-style: italic; color: var(--muted); }
.wx-mini[data-wind="windy"] .wx-mini-wind { color: var(--tier-1); font-weight: 600; }

@media (max-width: 720px) {
  .wx-now-temp { font-size: 30px; }
  .wx-row { grid-template-columns: 44px 18px 1fr auto; }
}
