/* Tokens from docs/design/DESIGN.md */
:root {
  --bg: #F3F5F4;
  --card: #FFFFFF;
  --text: #10202E;
  --text-2: #51616E;
  --line: #D5DCDF;
  --go-bg: #0B6E63;
  --go-fg: #FFFFFF;
  --marginal-bg: #F2B33D;
  --marginal-fg: #10202E;
  --no-bg: #C9D1D6;
  --no-fg: #10202E;
  --flag: #C2410C;
  --link: #0B5A7A;
  --link-hover: #083F56;
  --scrim: rgba(16, 32, 46, 0.72);
  --font-num: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --radius: 6px;
  --touch: 44px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); }
a:hover { color: var(--link-hover); }

button {
  appearance: none;
  margin: 0;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Frame: a flex column filling the viewport; only main scrolls. */
.frame {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.header {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 10px;
}

.wordmark {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0.03em;
}

.clock { font-size: 13px; color: var(--text-2); }

/* Spot bar */
.spots {
  flex: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

.spot {
  min-height: 56px;
  padding: 8px 6px 7px;
  border-bottom: 3px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.spot[aria-pressed="true"] {
  background: var(--card);
  border-bottom-color: var(--text);
}

.spot-name { font-size: 15px; font-weight: 600; }

.spot-verdict {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-2);
}

.verdict-square {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--card);
  border: 1px solid var(--line);
}

/* Content */
.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.now {
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
}

/* Main cam. Tapping, clicking or Enter/Space opens the full-size overlay. */
.cam-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--text);
  overflow: hidden;
  cursor: zoom-in;
}

.cam-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.cam-media[hidden] { display: none; }

.chip {
  position: absolute;
  top: 10px;
  padding: 3px 8px;
  border-radius: 2px;
  font-size: 12px;
  line-height: 1.4;
}

.chip-kind {
  left: 12px;
  background: var(--text);
  color: #FFFFFF;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0.06em;
}

.chip-age {
  right: 12px;
  background: var(--card);
  color: var(--text);
}

.chip-age.is-stale {
  background: var(--flag);
  color: #FFFFFF;
  font-weight: 600;
}

.cam-caption {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: calc(100% - 24px);
  padding: 4px 8px;
  border-radius: 2px;
  background: var(--scrim);
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cam-name { font-size: 15px; font-weight: 600; }
.cam-view { font-size: 12px; }

.cam-source {
  margin: 0;
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-2);
}

.cam-source a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  font-weight: 600;
}

/* Cam picker: one scrolling row on phones, a grid on wide screens. */
.cam-picker {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 12px 2px;
}

.thumb {
  flex: none;
  width: 112px;
  padding: 3px 0 6px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: var(--touch);
}

.thumb-img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 3px;
  background: var(--no-bg);
  outline: 3px solid transparent;
  outline-offset: -2px;
}

.thumb-name { font-size: 11px; line-height: 1.25; }

.thumb[aria-pressed="true"] .thumb-img { outline-color: var(--text); }
.thumb[aria-pressed="true"] .thumb-name { font-weight: 600; }

/* Stations */
.stations {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 12px 0;
}

.section-label {
  margin: 0;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.station-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.station {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
}

.station-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--text-2);
}

.station-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.station-wind {
  flex: none;
  width: 78px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.station-speed-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.station-speed {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 38px;
  line-height: 0.95;
}

.station-unit, .station-gust { font-size: 12px; color: var(--text-2); }
.station-unit { font-size: 13px; }

.station-dir {
  flex: none;
  width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
}

.station-arrow { display: block; color: var(--text); }
.station-arrow.is-missing { opacity: 0.25; }
.station-compass { font-weight: 600; }
.station-degrees { color: var(--text-2); }

.station-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}

.station-name { font-size: 13px; font-weight: 600; }
.station-note, .station-correction { color: var(--text-2); }
.station-correction { font-style: italic; }

.station-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 8px;
}

.station-meta a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  font-weight: 600;
}

.station-age { color: var(--text-2); }

/* Same flag as the stale cam age chip. */
.station-age.is-stale {
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--flag);
  color: #FFFFFF;
  font-weight: 600;
}

.station-error { color: var(--flag); font-weight: 600; overflow-wrap: anywhere; }
.station-error[hidden] { display: none; }

.sparkline {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 6px;
  overflow: visible;
}

.sparkline path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.sparkline-wind { stroke: var(--text); stroke-width: 1.5; }
.sparkline-gust { stroke: var(--text-2); stroke-width: 1; opacity: 0.45; }

/* Cards: Plan placeholder and errors */
.card {
  margin: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

.card h2 {
  margin: 0 0 6px;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.card p { margin: 0; }

.card-error { border-color: var(--flag); }
.card-error pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

/* View switch */
.views {
  flex: none;
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding-bottom: env(safe-area-inset-bottom);
}

.view {
  flex: 1;
  min-height: 56px;
  border-top: 3px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.view-label {
  font-family: var(--font-num);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.view-sub { font-size: 11px; color: var(--text-2); }

.view[aria-pressed="true"] { border-top-color: var(--text); }
.view[aria-pressed="true"] .view-label { font-weight: 700; }

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* Phone in landscape: 375 px of height for three bars and a 16:9 cam. The
   header goes, the spot and view bars become single rows, and the cam is
   sized to fit the remaining height whole, as on desktop. */
@media (max-height: 500px) and (orientation: landscape) {
  .header { display: none; }

  .spot {
    min-height: 40px;
    padding: 4px 6px;
    flex-direction: row;
    gap: 8px;
  }

  /* No home-indicator padding here: it would be a 21 px empty strip under
     a 40 px bar. The indicator overlaps the bar's lower edge instead, below
     the labels. */
  .views { padding-bottom: 0; }

  .view {
    min-height: 40px;
    flex-direction: row;
    gap: 8px;
  }

  .view-label { font-size: 16px; }

  .now { padding: 6px 12px 16px; gap: 4px; }

  .cam-frame {
    width: min(100%, calc((100dvh - 120px) * 16 / 9));
    margin: 0 auto;
    border-radius: var(--radius);
  }

  .cam-source { padding: 0; text-align: center; }
}

@media (min-width: 900px) {
  .frame {
    max-width: 1100px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .now { padding: 12px 12px 24px; gap: 4px; }

  /* Keep the whole main cam visible above the fold. */
  .cam-frame {
    width: min(100%, calc((100dvh - 360px) * 16 / 9));
    margin: 0 auto;
    border-radius: var(--radius);
  }

  .cam-source { padding: 0; text-align: center; }

  .cam-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    overflow: visible;
    padding: 0;
  }

  .thumb { width: auto; }
  .thumb-name { font-size: 13px; }

  .stations { padding: 12px 0 0; }

  .station-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }
}

/* Verdict fills, shared by the spot bar, day picker, grid and hour detail. */
.is-go { background: var(--go-bg); color: var(--go-fg); }
.is-marginal { background: var(--marginal-bg); color: var(--marginal-fg); }
.is-no { background: var(--no-bg); color: var(--no-fg); }
.verdict-square.is-go, .verdict-square.is-marginal, .verdict-square.is-no { border-color: transparent; }

.gust-note { font-weight: 600; color: var(--flag); }

/* Forecast line in the Now view */
.forecast-line-slot { padding: 12px 12px 0; }

.forecast-line {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--card);
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.forecast-line-text { display: flex; flex-direction: column; gap: 1px; }
.forecast-line-label { font-size: 12px; color: var(--text-2); }
.forecast-line-value { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; font-size: 14px; }
.forecast-line-window { font-weight: 600; }
.forecast-line-go { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }

/* Plan view */
.plan {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 12px 20px;
}

.plan .card { margin: 0; }
.card-quiet { color: var(--text-2); }

.plan-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.day-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.day {
  min-height: 58px;
  padding: 6px 0;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-bottom-color: transparent;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.day[aria-pressed="true"] {
  background: var(--card);
  border-bottom-color: var(--text);
}

.day-weekday { font-size: 12px; color: var(--text-2); }

.day-date {
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 18px;
  line-height: 1;
}

.day-squares { display: flex; gap: 2px; }

.day-square {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid var(--line);
}

.day-square.is-go, .day-square.is-marginal, .day-square.is-no { border-color: transparent; }

.day-square.is-past { opacity: 0.4; }

.grid-card {
  padding: 10px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grid-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 8px;
  margin-bottom: 4px;
}

.grid-spot { font-size: 16px; font-weight: 600; }
.grid-window { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--text-2); }

.grid-row {
  display: grid;
  grid-template-columns: 62px repeat(14, minmax(0, 1fr));
  gap: 1px;
  align-items: center;
}

.grid-hours { align-items: end; }
.grid-label { font-size: 11px; color: var(--text-2); }

.grid-head {
  height: 18px;
  border-bottom: 3px solid transparent;
  border-radius: 2px 2px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 16px;
  color: var(--text-2);
}

.grid-head.is-dark { border-bottom-color: var(--text); }
.grid-head.is-now { background: var(--text); color: #FFFFFF; }
.grid-head.is-selected { font-weight: 700; }

.grid-section { margin-top: 4px; font-size: 12px; font-weight: 600; }

.grid-wind {
  position: relative;
  height: 28px;
  border-radius: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 14px;
}

.grid-wind.is-empty { color: var(--text-2); }
.grid-wind.is-selected { z-index: 1; box-shadow: 0 0 0 2px var(--text); }

.grid-gust {
  text-align: center;
  font-size: 11px;
  line-height: 14px;
  color: var(--text-2);
}

.grid-gust.is-gusty { font-weight: 700; color: var(--flag); }

.grid-dir {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 14px;
  color: var(--text-2);
}

.grid-slider {
  display: flex;
  flex-direction: column;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.grid-slider label { font-size: 12px; color: var(--text-2); }

.hour-slider {
  width: 100%;
  height: var(--touch);
  margin: 0;
  accent-color: var(--text);
}

.hour-detail { display: flex; flex-direction: column; gap: 8px; }

.detail-heading {
  margin: 0;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 20px;
  line-height: 1.1;
}

.detail-card {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

.detail-verdict { display: flex; gap: 10px; align-items: stretch; }

.detail-label {
  flex: none;
  width: 96px;
  min-height: 48px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.02em;
}

.detail-reason {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 20px;
  line-height: 1.1;
}

.detail-values {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
}

.detail-values dt { color: var(--text-2); }
.detail-values dd { margin: 0; font-weight: 600; }
.detail-values dd.is-gusty { color: var(--flag); }

.cross-check {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 18px;
  font-size: 12px;
}

.cross-check span { color: var(--text-2); }

.cross-check a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  font-size: 13px;
  font-weight: 600;
}

.quiet { margin: 0; color: var(--text-2); }

.attribution { margin: 0; font-size: 12px; color: var(--text-2); }

/* Full-size zoom overlay (src/zoom.js) */
.zoom {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--scrim);
}

@media (prefers-reduced-motion: no-preference) {
  .zoom { animation: zoom-fade 0.15s ease-out; }
}

@keyframes zoom-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* The stage owns every gesture (touch-action: none), so the browser's own
   viewport zoom never moves the close button and caption out of view. */
.zoom-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
}

.zoom.is-zoomed .zoom-img { cursor: grab; }

.zoom-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
}

.zoom-caption {
  position: absolute;
  left: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  max-width: calc(100% - 24px);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--scrim);
  color: #FFFFFF;
  font-size: 13px;
}

.zoom-caption-name { font-weight: 600; }
.zoom-caption-source { color: #FFFFFF; font-weight: 600; }
