/* FDS-Weather page styles.
 *
 * First-party CSS only: no CDN, no framework, no build step, so a venue LAN with no internet still
 * gets the page. Same rule as the timing host's status page.
 *
 * Optimised for a phone held up in bright sun at a race:
 *   - Near-black background with pure-white figures. On a dark page in daylight the display is the
 *     light source, so contrast is what makes a figure readable; low-contrast grey-on-grey is
 *     unreadable outdoors even though it looks refined indoors.
 *   - Few, very large elements. Nothing important is smaller than a thumb.
 *   - The Current tab shows four figures and nothing else, each sized to fill its quarter of the
 *     screen. Anything smaller is unreadable at arm's length in sunlight.
 *   - Temperature, humidity, dew point, rain and battery are deliberately absent from Current. They
 *     are still recorded and still on the API.
 */

:root {
  --bg: #000000;
  --panel: #0c0f13;
  --panel-2: #14181e;
  --line: #39424f;
  --text: #ffffff;
  --muted: #a8b3c1;
  --accent: #7cc4ff;
  --warn: #ffb020;
  --bad: #ff4d4d;
  --mean: #7cc4ff;
  --gust: #ffa657;
  --band: rgba(124, 196, 255, 0.22);
  --arrow: #ffffff;
  /* The compass needle, deliberately a different red from --bad: this one means "the wind goes
   * this way", not "something is wrong". */
  --compass-arrow: #ff3b30;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h3 { margin: 0; font-weight: 700; }

/* --------------------------------------------------------------------------------------------
 * Header: the two tabs, and nothing else.
 *
 * A title row and a row of status pills used to sit above the tabs. On a phone they cost about
 * 45px - a whole row of the Current board - and the board is the reason the page exists, so they
 * are gone. The reading's age survives under the board, and a failed health fetch still outlines
 * it, so a frozen page cannot pass for calm weather.
 * ------------------------------------------------------------------------------------------ */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
  padding: max(8px, env(safe-area-inset-top)) 12px 0;
}

/* Tabs: two, full width, thumb-sized, and the first thing on the page. */
.tabs { display: flex; gap: 0; margin-top: 0; }

.tab {
  flex: 1 1 0;
  appearance: none;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 4px solid transparent;
  padding: 12px 8px;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main { padding: 12px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }

/* --------------------------------------------------------------------------------------------
 * Current: four figures filling the screen.
 * ------------------------------------------------------------------------------------------ */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: minmax(0, 1fr);
  gap: 10px;
  /* dvh, not vh: on a phone the browser chrome changes and vh overflows behind it. The subtraction
   * is what the tab bar, the freshness line and the note below the board actually take; it dropped
   * from 300px when the title and pills above the tabs were removed, so the reclaimed height goes
   * to the figures rather than to empty space. */
  min-height: calc(100dvh - 250px);
}

.tile {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 140px;
  overflow: hidden;
}

.tile-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* The figure itself: as large as will fit a quarter-screen tile. */
.tile-value {
  font-size: clamp(44px, 17vw, 104px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.tile-unit {
  font-size: 0.3em;
  font-weight: 700;
  color: var(--text);
  margin-left: 0.15em;
  letter-spacing: 0;
}

.tile-sub { font-size: 13px; color: var(--muted); font-weight: 600; }

.tile.hero { border-color: #4b5666; }
.tile.wide { grid-column: 1 / -1; }
.tile.empty { justify-content: center; }
.tile.empty .tile-value { font-size: clamp(30px, 11vw, 60px); }

/* The compass gets its own tile, sized to the space rather than to a font. */
.tile-compass { align-items: stretch; }
.compass-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.compass { width: 100%; height: 100%; max-height: 100%; display: block; }

.compass-reading {
  font-size: clamp(20px, 6.5vw, 34px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: 0.01em;
}

.compass-ring { fill: var(--panel-2); stroke: #5b6675; stroke-width: 5; }
.compass-inner { fill: none; stroke: var(--line); stroke-width: 2; }
.compass-shaft { fill: none; stroke: var(--compass-arrow); stroke-width: 11; stroke-linecap: round; }
.compass-head { fill: var(--compass-arrow); stroke: none; }
.compass-hub { fill: var(--compass-arrow); }
.compass-cardinal { fill: var(--muted); font-size: 26px; font-weight: 800; }
/* The four principals carry more weight than the four intercardinals, so the card still orients a
 * glance that does not stop to read. */
.compass-cardinal-major { fill: var(--text); font-size: 31px; }
.compass-none { fill: var(--muted); font-size: 17px; }
.compass-label { fill: var(--text); font-size: 24px; font-weight: 800; }

/* Freshness: small, but always present, so a frozen page is never mistaken for calm weather. */
.freshness {
  margin: 10px 2px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

body.stale .freshness { color: var(--warn); }
body.stale .tile-value, body.stale .compass-reading { opacity: 0.6; }
body.offline .grid { outline: 3px dashed var(--bad); outline-offset: 3px; }

/* --------------------------------------------------------------------------------------------
 * History: the controls, then the charts one under another.
 *
 * Phone-first like Current. Everything is a card so the sections are separable by eye outdoors,
 * the pickers are full-width and thumb-sized, and the charts are stacked - a phone has no room
 * beside anything.
 * ------------------------------------------------------------------------------------------ */

.card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.card-head { display: flex; justify-content: flex-start; margin-bottom: 10px; }
.card h3 { font-size: 17px; }

/* Picker row: two selects that stack on a phone and sit side by side when there is room. */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.controls label { display: flex; flex-direction: column; gap: 5px; }

.controls select {
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 10px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  width: 100%;
  min-height: 48px;
}

figure.chart {
  margin: 0 0 12px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.chart figcaption { font-size: 14px; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.chart .unit { color: var(--text); }
.chart .hint { display: block; font-size: 12px; font-weight: 400; margin-top: 2px; }

/* Nothing sits beside anything on a phone; side by side only when there is real width. */
.two-up { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 900px) { .two-up { grid-template-columns: minmax(300px, 420px) 1fr; } }

/* The rose is square, so cap it and let it centre rather than stretch to a tall column. */
.rose-svg { max-width: 420px; margin: 0 auto; }

.chart-svg { width: 100%; height: auto; display: block; }
.gust-svg { max-height: 220px; }

.band { fill: var(--band); stroke: none; }
.mean-line { fill: none; stroke: var(--mean); stroke-width: 2.5; }
.gust-line { fill: none; stroke: var(--gust); stroke-width: 1.8; stroke-dasharray: 4 3; }
.factor-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.gust-dot { fill: var(--accent); }
.dir-arrow { fill: none; stroke: var(--arrow); stroke-width: 1.6; }

.grid-line, .grid { stroke: var(--line); stroke-width: 1; opacity: 0.7; }
.axis-line { stroke: var(--line); stroke-width: 1.5; }
.axis, .axis-unit, .legend, .rose-axis, .rose-count, .rose-empty {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.rose-empty { font-size: 14px; }
.rose-ring { fill: none; stroke: var(--line); stroke-width: 1.5; }

.petal { stroke: var(--bg); stroke-width: 1; }
.band-0 { fill: #1f6feb; }
.band-1 { fill: #2ea043; }
.band-2 { fill: #d29922; }
.band-3 { fill: #f85149; }
.swatch { rx: 2; }

table.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
table.summary th, table.summary td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
table.summary th { color: var(--muted); font-weight: 600; white-space: nowrap; width: 36%; }
table.summary td { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.range-note { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

.chart-message { font-size: 14px; color: var(--muted); margin: 6px 0; }
.chart-message.warn { color: var(--warn); }
.muted { color: var(--muted); }
.note { font-size: 12px; color: var(--muted); max-width: 90ch; margin-top: 16px; }

/* On a narrow screen a two-column table gives the value about half a phone's width, which after a
 * date-time pair is nothing. Stacking the label above its value keeps each row readable; the
 * markup stays a table, so nothing here is doing a screen's job. */
@media (max-width: 700px) {
  table.summary, table.summary tbody, table.summary tr, table.summary th, table.summary td {
    display: block;
    width: 100%;
  }
  table.summary tr {
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
  }
  table.summary th, table.summary td {
    border: 0;
    padding: 1px 0;
  }
  table.summary th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  table.summary td { font-size: 15px; }
}
