/* ---- design tokens ------------------------------------------------------
   Dark, elevated-trail palette: moss/slate ground, amber for sun & warmth,
   sky-blue for rain, a thin ambient glow rather than a purple/blue gradient.
   Space Grotesk for headings and numbers only — body copy stays on the
   system font stack so the page never blocks first paint on a webfont. */
:root {
  color-scheme: dark;
  --bg-page:        #0a100d;
  --bg-card:        rgba(17, 27, 22, 0.6);
  --bg-card-solid:  #101c17;
  --border:         rgba(140, 178, 150, 0.16);
  --border-amber:   rgba(240, 168, 96, 0.28);
  --text-primary:   #f2efe6;
  --text-secondary: #9db0a3;
  --text-muted:     #62766a;
  --moss:           #7ec98a;
  --sky:            #5cb6da;
  --amber:          #f0a860;
  --red:            #ef6b6b;
  --track:          rgba(255, 255, 255, 0.08);
  --glow-amber:     0 0 20px rgba(240, 168, 96, 0.16);
  --glow-sky:       0 0 20px rgba(92, 182, 218, 0.16);
  --radius:         12px;
  --font-display:   "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body:       -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
/* every tappable control gets this: removes the ~300ms tap delay mobile
   browsers otherwise add while they wait to see if a tap is the start of
   a double-tap-to-zoom gesture */
button, summary, input[type="range"] { touch-action: manipulation; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* ambient hill-light glow, fixed behind everything */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 900px 500px at 12% -8%, rgba(240, 168, 96, 0.08), transparent 60%),
    radial-gradient(ellipse 900px 500px at 92% 6%, rgba(92, 182, 218, 0.08), transparent 60%);
}

a { color: var(--sky); }
a:hover { color: var(--amber); }

/* mobile-first: base padding/gap fit a phone; both widen at the 640px
   breakpoint further down rather than starting wide and shrinking */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- header -------------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}
.subtitle {
  font-size: 12.5px;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 4px 0 0;
}
.head-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.conn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.lamp { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.conn.ready .lamp   { background: var(--moss); box-shadow: 0 0 8px var(--moss); }
.conn.ready          { color: var(--moss); }
.conn.error .lamp   { background: var(--red); box-shadow: 0 0 8px var(--red); }
.conn.error          { color: var(--red); }

/* day/night outlook switch — same segmented-button shape as the hourly
   "more detail" toggle, so header controls and panel controls read as one
   family rather than two different widget styles. */
.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.view-toggle-btn {
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: none;
  border: none;
  padding: 8px 14px;
  min-height: 36px;
  cursor: pointer;
}
.view-toggle-btn + .view-toggle-btn { border-left: 1px solid var(--border); }
.view-toggle-btn:hover { color: var(--text-primary); }
/* amber for day (matches the sun/warmth accent), sky for night (matches the
   night-hour tint already used on .hour-row.is-night) */
.view-toggle-btn.active[data-mode="day"] { color: var(--bg-page); background: var(--amber); }
.view-toggle-btn.active[data-mode="night"] { color: var(--bg-page); background: var(--sky); }

/* corner-bracket frame used on every panel, echoes an OS-map crop mark */
.frame {
  position: relative;
  background: var(--bg-card);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.frame::before, .frame::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0.85;
  pointer-events: none;
}
.frame::before { top: -1px; left: -1px; border-top: 2px solid var(--amber); border-left: 2px solid var(--amber); }
.frame::after  { bottom: -1px; right: -1px; border-bottom: 2px solid var(--sky); border-right: 2px solid var(--sky); }

h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--text-muted);
  margin: 0 0 10px;
}
h2::before { content: "// "; color: var(--text-muted); }

/* ---- date rail ------------------------------------------------------------ */
.date-rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.date-rail-head h2 { margin: 0; }
.date-readout {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--amber);
}
.date-slider {
  width: 100%;
  margin: 14px 0 6px;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  outline: none;
  touch-action: pan-y; /* keep the page vertically scrollable while dragging */
}
/* thumb sized for a thumb: 44px hit target is the touch-accessibility
   floor (WCAG 2.5.5 / iOS HIG), well above what a mouse cursor needs */
.date-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: var(--glow-amber);
  cursor: pointer;
  border: 2px solid var(--bg-page);
}
.date-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: var(--glow-amber);
  cursor: pointer;
  border: 2px solid var(--bg-page);
}
.date-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding: 0 2px;
}
.date-ticks span { flex: 1; text-align: center; }
.date-ticks span:first-child { text-align: left; }
.date-ticks span:last-child { text-align: right; }
.date-ticks span.today { color: var(--amber); font-weight: 600; }
/* mobile-first: 15 daily ticks don't fit a phone width, so only today/ends/
   selected show by default; the full run reappears at the 640px breakpoint */
.date-ticks span:not(.today):not(:first-child):not(:last-child) { display: none; }

/* ---- main grid: map + detail panel -----------------------------------------
   mobile-first: single column, map above detail panel (matches the natural
   tap-marker-then-read-panel flow on a phone); becomes a 2-column layout at
   the 880px breakpoint further down */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
.map-panel { box-shadow: var(--glow-amber); }
#map {
  height: 320px;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 10px;
  border: 1px solid var(--border);
  touch-action: pan-x pan-y; /* one-finger pan works; pinch-zoom still does too */
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
/* swatch fill colour is set inline from app.js's RATINGS table, so map
   markers and legend dots can never drift out of sync */
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.swatch-rain-ring { background: transparent; border: 2px solid #5cb6da; box-shadow: 0 0 6px rgba(92,182,218,0.6); }

/* leaflet popups restyled to match rather than default whiteboxes */
.leaflet-popup-content-wrapper {
  background: var(--bg-card-solid);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.leaflet-popup-tip { background: var(--bg-card-solid); }
.leaflet-popup-content { font-family: var(--font-body); font-size: 12.5px; margin: 10px 12px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }

/* ---- detail panel ---------------------------------------------------------- */
.detail-panel {
  box-shadow: var(--glow-sky);
  display: flex;
  flex-direction: column;
}
.detail-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 0 10px;
}
.detail-empty p { margin: 4px 0; }
.detail-empty .hint { font-size: 12px; color: var(--text-secondary); }

.detail-loc {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.detail-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 3px 0 14px;
  letter-spacing: 0.02em;
}
.detail-condition {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: -8px 0 14px;
}
.condition-icon { width: 16px; height: 16px; flex: none; }

/* ---- weather icons ------------------------------------------------------
   Shared shape set (see weatherIcon() in app.js). Clouds are drawn in a
   fixed grey inside the SVG itself; these classes tint only the accent
   (sun, rain lines, snowflakes, bolt…) via currentColor. */
/* every wrapper that holds an icon (.condition-icon, .hour-icon-wrap,
   .snapshot-icon) sets an explicit pixel width/height, so the icon just
   fills it rather than sizing off an inherited font-size */
.wx-icon { width: 100%; height: 100%; display: block; }
.wx-icon-clear, .wx-icon-part-cloud, .wx-icon-thunder { color: var(--amber); }
.wx-icon-clear.wx-icon-night, .wx-icon-part-cloud.wx-icon-night { color: var(--sky); }
.wx-icon-cloud, .wx-icon-fog { color: var(--text-secondary); }
.wx-icon-drizzle, .wx-icon-rain, .wx-icon-sleet { color: var(--sky); }
.wx-icon-snow { color: var(--text-primary); }

/* ---- day-at-a-glance snapshot -------------------------------------------
   The combined ideal/okay/challenging/poor rating (dayScore() in app.js)
   plus the three numbers behind it, up front before the temp/rain tiles —
   point-specific, so it lives in the detail panel rather than the header. */
.day-snapshot {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.2);
}
.day-snapshot .snapshot-icon { width: 34px; height: 34px; flex: none; }
.day-snapshot .snapshot-icon .wx-icon { width: 100%; height: 100%; }
.snapshot-rating {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 3px;
}
.snapshot-sub { font-size: 11.5px; color: var(--text-secondary); }
.day-snapshot.rating-ideal { border-color: rgba(126, 201, 138, 0.32); box-shadow: 0 0 16px rgba(126, 201, 138, 0.12); }
.day-snapshot.rating-ideal .snapshot-rating { color: var(--moss); }
.day-snapshot.rating-okay { border-color: var(--border-amber); box-shadow: var(--glow-amber); }
.day-snapshot.rating-okay .snapshot-rating { color: var(--amber); }
.day-snapshot.rating-challenging { border-color: rgba(92, 182, 218, 0.32); box-shadow: var(--glow-sky); }
.day-snapshot.rating-challenging .snapshot-rating { color: var(--sky); }
.day-snapshot.rating-poor { border-color: rgba(239, 107, 107, 0.35); box-shadow: 0 0 16px rgba(239, 107, 107, 0.16); }
.day-snapshot.rating-poor .snapshot-rating { color: var(--red); }

/* the two headline numbers the brief calls for: temp and rain */
.headline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.headline-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.2);
}
.headline-tile.temp { border-color: var(--border-amber); box-shadow: var(--glow-amber); }
.headline-tile.rain { border-color: rgba(92, 182, 218, 0.28); box-shadow: var(--glow-sky); }
.headline-label {
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.headline-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}
.headline-tile.temp .headline-value { color: var(--amber); text-shadow: 0 0 14px rgba(240,168,96,0.4); }
.headline-tile.rain .headline-value { color: var(--sky); text-shadow: 0 0 14px rgba(92,182,218,0.4); }
.headline-sub {
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.see-more {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}
.see-more summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  list-style: none;
  min-height: 44px; /* touch target floor, not just a text line */
  display: flex;
  align-items: center;
}
.see-more summary::-webkit-details-marker { display: none; }
.see-more summary::before { content: "+ "; color: var(--amber); }
.see-more[open] summary::before { content: "\2212 "; }
.see-more[open] summary { margin-bottom: 10px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.detail-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
}
.detail-row .k {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.detail-row .v { color: var(--text-primary); font-weight: 600; }

/* ---- hour-by-hour section ---------------------------------------------
   Temp, night flag, rain and wind stay visible on every row (the brief's
   "highlight for each hour"); feels-like/gusts are the one thing tucked
   behind a toggle, applying to all 24 rows at once rather than 24 separate
   disclosures. */
.hourly {
  margin: 4px 0 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.hourly-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--text-muted);
  margin: 0;
}
.section-label::before { content: "// "; color: var(--text-muted); }

.hourly-extra-toggle {
  font: inherit;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  min-height: 36px;
  cursor: pointer;
}
.hourly-extra-toggle:hover,
.hourly-extra-toggle[aria-expanded="true"] { color: var(--amber); border-color: var(--border-amber); }

.hour-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* on mobile this just extends the page — a nested scroll box on top of
     page scroll is a common mobile-usability trap. The desktop breakpoint
     below gives it its own scroll region instead, since there it sits
     beside a fixed-height map rather than in normal document flow. */
  max-height: none;
  overflow: visible;
}
.hour-row {
  display: grid;
  grid-template-columns: 50px 1fr 1fr 1fr;
  align-items: center;
  gap: 6px 8px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--t-color, var(--border));
  background: rgba(0, 0, 0, 0.16);
  font-size: 12px;
}
/* a cool blue-black tint, not just "darker", so it reads as a distinct
   night state rather than a rounding difference against the day rows */
.hour-row.is-night { background: rgba(18, 32, 46, 0.55); border-color: rgba(92, 182, 218, 0.16); }
.hour-row.is-night .hour-clock { color: var(--text-secondary); }
.hour-row.is-wet { box-shadow: inset 0 0 0 1px rgba(92, 182, 218, 0.3); }
.hour-row.is-coldest { border-left-color: var(--sky); }

/* icon + temp read first (BBC/Apple Weather-style scan pattern); rain and
   wind are secondary, already smaller/muted below */
.hour-time { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.hour-clock { font-family: var(--font-display); font-weight: 600; color: var(--text-primary); font-size: 12px; }
.hour-icon-wrap { width: 19px; height: 19px; }

.hour-temp {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-primary);
}
.hour-dip { font-size: 10px; }

.hour-rain { color: var(--text-secondary); font-size: 11.5px; }
.hour-rain.hot { color: var(--sky); font-weight: 600; }
.hour-rain-mm { color: var(--text-muted); font-size: 10.5px; }

.hour-wind { color: var(--text-secondary); text-align: right; font-size: 11.5px; white-space: nowrap; }
.hour-wind .unit { color: var(--text-muted); font-size: 9.5px; margin-right: 1px; }

.hour-extra {
  grid-column: 1 / -1;
  display: none;
  font-size: 10.5px;
  color: var(--text-muted);
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px dashed var(--border);
}
.hourly.show-extra .hour-extra { display: block; }

.detail-close {
  align-self: flex-end;
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  min-height: 36px;
  min-width: 44px;
  cursor: pointer;
  margin-bottom: 8px;
}
.detail-close:hover { color: var(--amber); border-color: var(--amber); }

/* ---- marker styling (applied via inline style from app.js, kept here for
   the pulse animation on high rain-probability points) ---------------------- */
.wx-marker-rain {
  animation: pulse-rain 1.6s ease-in-out infinite;
}
@keyframes pulse-rain {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(92, 182, 218, 0.5)); }
  50%      { filter: drop-shadow(0 0 8px rgba(92, 182, 218, 0.9)); }
}

footer {
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  padding-top: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .wx-marker-rain { animation: none; }
}

/* ---- responsive --------------------------------------------------------
   Mobile-first: everything above this point is the phone layout. These
   min-width layers add space back in as the viewport grows, rather than
   the old approach of starting from a desktop layout and cramming it down
   with max-width overrides. */

/* small tablet / large phone landscape: header and type get room to breathe */
@media (min-width: 560px) {
  .wrap { padding: 22px 24px 32px; gap: 16px; }
  .brand { font-size: 26px; }
  #map { height: 400px; }
}

/* desktop: map and detail panel sit side by side again */
@media (min-width: 880px) {
  .main-grid { grid-template-columns: 1.7fr 1fr; gap: 16px; }
  #map { height: 520px; }
  .detail-panel { min-height: 520px; }
  /* full 15-day tick run only fits once each tick has real room */
  .date-ticks span:not(.today):not(:first-child):not(:last-child) { display: block; }
  /* beside a fixed-height map, let the hour list scroll in place instead
     of pushing the panel taller than the map next to it */
  .hour-list { max-height: 360px; overflow-y: auto; padding-right: 4px; }
}
