@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/static/fonts/bricolage-grotesque.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f4f2ea;
  --surface: #fffefa;
  --ink: #1b2620;
  --muted: #5d6a61;
  --line: #dcd9cb;
  --accent: #4d7a1f;
  --accent-ink: #ffffff;
  /* One colour per measure, shared by its tile and its chart. */
  --temp: #d0562b;
  --humidity: #0f8a8a;
  --pressure: #7a4fc0;
  --wind: #4d7a1f;
  --rain: #2b78b5;
  --solar: #c98a00;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1613;
    --surface: #18211c;
    --ink: #eef1e8;
    --muted: #9eaaa1;
    --line: #2b362f;
    --accent: #a4d15c;
    --accent-ink: #14200a;
    --temp: #f08a5f;
    --humidity: #4fc9c4;
    --pressure: #b596f0;
    --wind: #a4d15c;
    --rain: #66b2ec;
    --solar: #eebc3c;
  }
  /* The logo is dark ink on transparent, so flip it for dark backgrounds. */
  .logo img { filter: invert(1) hue-rotate(180deg); }
}

* { box-sizing: border-box; }

/* Menu links scroll smoothly from app.js. A CSS scroll-behavior would also
   animate the browser restoring the scroll position on "back", which shows. */
html { scroll-padding-top: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.6 var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, p, figure, dl, dd { margin: 0; }
small { font-size: 0.72em; font-weight: 400; color: var(--muted); }

.wrap {
  width: min(1180px, 100%);
  margin-inline: auto;
  padding-inline: clamp(16px, 3vw, 32px);
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 10px 6px;
}
.logo { display: block; flex: none; }
.logo img { display: block; width: auto; height: 112px; }
#site-menu a { text-decoration: none; color: var(--muted); }
#site-menu a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.menu-button { display: none; }

/* From tablet up the links sit in the header. `popover` would otherwise hide them. */
@media (min-width: 681px) {
  #site-menu {
    position: static;
    display: flex;
    gap: clamp(14px, 2.5vw, 28px);
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: visible;
    background: none;
    font-size: 0.95rem;
  }
}

/* First screen: data, webcam and forecast */
.updated { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 0.85rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6fb52c; flex: none; }
.is-stale .dot { background: #e8921c; }

.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.tile {
  min-width: 0;
  padding: 10px 14px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--tile);
  border-radius: 12px;
}
.tile-temp { --tile: var(--temp); }
.tile-humidity { --tile: var(--humidity); }
.tile-pressure { --tile: var(--pressure); }
.tile-wind { --tile: var(--wind); }
.tile-rain { --tile: var(--rain); }
.tile-solar { --tile: var(--solar); }
.tile h2 { display: flex; align-items: center; gap: 6px; font: 600 0.88rem/1.3 var(--text); white-space: nowrap; }
.tile-icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: var(--tile);
  stroke-width: 1.800;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.needle { fill: var(--tile); stroke: none; }
.tile-value {
  margin-top: 2px;
  font: 500 1.75rem/1.2 var(--display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tile-value small { margin-left: 3px; font: 400 0.8rem var(--text); }
.tile-note { min-height: 1.4em; font-size: 0.78rem; line-height: 1.4; color: var(--muted); font-variant-numeric: tabular-nums; }

.now-main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  align-items: start;
  gap: clamp(10px, 2vw, 24px);
  margin-top: clamp(10px, 2vw, 24px);
}
.webcam { display: block; border-radius: 12px; overflow: hidden; background: var(--line); cursor: zoom-in; }
.webcam img { display: block; width: 100%; height: auto; }

/* Enlarged webcam. The width keeps the image's 1200:705 shape within 86% of the
   screen height, so the image fills the dialog exactly and the close button
   fits in the space above it. */
.webcam-dialog {
  width: min(1400px, 96vw, calc(86vh * 1200 / 705));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  overflow: visible;
}
.webcam-dialog::backdrop { background: rgba(0, 0, 0, 0.82); }
.webcam-dialog img { display: block; width: 100%; height: auto; border-radius: 12px; }
/* Above the image's top-right corner, so it doesn't cover the picture. */
.dialog-close {
  position: absolute;
  top: -48px;
  right: 0;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  cursor: pointer;
}
.dialog-close svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.200; stroke-linecap: round; }

.forecast {
  --forecast-lines: 11;
  align-self: stretch;
  padding: 12px 18px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.forecast-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.forecast-head h2 { font: 500 1.2rem/1.3 var(--display); }
.forecast-meta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.forecast-text {
  font-size: 1rem;
  line-height: 1.55;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--forecast-lines);
  overflow: hidden;
}
.forecast-text.is-open { display: block; }
.forecast-empty { color: var(--muted); }
.forecast-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.forecast-edit { margin: 10px 0 0 auto; padding: 8px 14px; font-size: 0.9rem; }

/* Sections below the first screen */
.section-title { font: 500 clamp(1.4rem, 3vw, 1.8rem)/1.2 var(--display); letter-spacing: -0.01em; }
.summary, .charts, .about { margin-top: clamp(48px, 7vw, 88px); }
.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: clamp(48px, 7vw, 88px);
  padding-block: 20px 28px;
  font-size: 0.85rem;
  color: var(--muted);
}
/* The forecast editor's entrance: there for whoever knows it, unremarkable to everyone else. */
.footer-login { color: inherit; text-decoration: none; }
.footer-login:hover { text-decoration: underline; text-underline-offset: 3px; }

.summary { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px 32px; }
.table-wrap { overflow-x: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap thead th { font-weight: 500; color: var(--muted); font-size: 0.88rem; }
.table-wrap tbody th { text-align: left; font-weight: 500; padding-left: 0; }
.table-wrap tbody td { font-size: 1.05rem; }

.charts-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.ranges { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); }
.ranges button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 14px;
  min-height: 36px;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
}
.ranges button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.charts-message { margin-bottom: 12px; color: var(--muted); }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 10px 8px; min-width: 0; }
.chart-wide { grid-column: 1 / -1; }
.chart figcaption { font-weight: 500; padding: 0 8px 6px; }
/* A drawn chart's height (24 h, the default), reserved before the data arrives
   so the page doesn't grow afterwards. Otherwise "back" can't restore a scroll
   position below the charts, as the page is still too short at that point. */
.chart [data-chart] { min-height: 231px; }
.u-legend { font-size: 0.8rem; color: var(--muted); }
/* uPlot's legend marker is a square, which only suits the rain chart's bars.
   !important is needed because uPlot sets these styles inline. */
[data-chart]:not([data-chart="rain"]) .u-marker {
  width: 16px;
  height: 0;
  border-width: 2px 0 0 !important;
  background: none !important;
  vertical-align: middle;
}
/* On band charts, max and min are swatches of the band with the line along
   their top or bottom edge, so they don't look like the average's line. */
[data-chart].has-band .u-series:nth-child(2) .u-marker,
[data-chart].has-band .u-series:nth-child(3) .u-marker {
  height: 11px;
  background: var(--band-fill) !important;
}
[data-chart].has-band .u-series:nth-child(3) .u-marker { border-width: 0 0 2px !important; }
.u-select { background: rgba(127, 127, 127, 0.15); }

.about { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: clamp(24px, 4vw, 48px); }
.about .section-title { margin-bottom: 12px; }
.about p + p { margin-top: 8px; }
.station-intro { margin-bottom: 8px; }
/* Justified running text. Hyphenation (Catalan, from <html lang="ca">) narrows
   the gaps between words where the browser supports it. The station intro is
   left out: it's short, with long words, so it opened very wide gaps on phones. */
.forecast-text, .about p:not(.station-intro), .forecast-log p { text-align: justify; hyphens: auto; }
.about dl div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.about dt { color: var(--muted); }
.about dd { text-align: right; white-space: nowrap; }
.contact-link { color: var(--accent); font-weight: 500; overflow-wrap: anywhere; }

/* Admin */
.admin { width: min(720px, 100%); margin-inline: auto; padding: 32px 16px 64px; }
.admin-narrow { width: min(380px, 100%); padding-top: 12vh; }
.admin h1 { font: 500 2rem/1.2 var(--display); margin-bottom: 16px; }
.admin h2 { font: 500 1.25rem var(--display); margin: 40px 0 12px; }
.admin-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 4px; font-size: 0.92rem; color: var(--muted); }
input, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  /* 16px stops iOS zooming into the field when it's focused. */
  font: 1rem/1.5 var(--text);
}
/* Tall enough for a full week's forecast without scrolling inside the box. */
textarea { min-height: 50vh; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button {
  display: inline-block;
  justify-self: start;
  padding: 11px 20px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 500 1rem var(--text);
  text-decoration: none;
  cursor: pointer;
}
.link-button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.9rem; text-decoration: underline; cursor: pointer; padding: 6px 0 0; }
.form-error { color: #c0392b; margin-bottom: 14px; }
.forecast-log { list-style: none; margin: 0; padding: 0; }
.forecast-log li { padding: 12px 0; border-top: 1px solid var(--line); }
.forecast-log p { white-space: pre-line; }
.forecast-log-meta { font-size: 0.84rem; color: var(--muted); }

@media (max-width: 1000px) {
  .logo img { height: 88px; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary { grid-template-columns: minmax(0, 1fr); }
  .about { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 680px) {
  /* Every pixel counts here to fit the first screen on a phone. */
  /* Stops section headers landing under the fixed menu button. */
  html { scroll-padding-top: 56px; }
  .logo { display: none; }
  .topbar { padding: 0; }
  /* Tall enough to hold the fixed menu button, which sits level with this line. */
  .updated { min-height: 52px; margin-bottom: 0; font-size: 0.78rem; }
  /* Fixed so the sections stay one tap away from anywhere on the long page. */
  .menu-button {
    position: fixed;
    top: 6px;
    right: 16px;
    z-index: 10;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    cursor: pointer;
  }
  .menu-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  #site-menu {
    inset: 52px 16px auto auto;
    margin: 0;
    padding: 6px;
    min-width: 180px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  }
  #site-menu a { display: block; padding: 10px 14px; border-radius: 8px; color: var(--ink); }
  .tiles, .now-main { gap: 6px; }
  .now-main { grid-template-columns: minmax(0, 1fr); margin-top: 6px; }
  .tile { padding: 6px 8px; }
  .tile h2 { font-size: 0.74rem; gap: 4px; }
  .tile-icon { width: 15px; height: 15px; }
  .tile-value { font-size: 1.25rem; }
  .tile-value small { margin-left: 2px; font-size: 0.68rem; }
  .tile-note { font-size: 0.66rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .forecast { --forecast-lines: 6; padding: 8px 12px 10px; }
  .forecast-head { margin-bottom: 2px; }
  .forecast-head h2 { font-size: 1.05rem; }
  .forecast-text { font-size: 0.92rem; line-height: 1.45; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .ranges button { padding-inline: 11px; }
  .table-wrap th, .table-wrap td { padding-inline: 5px; }
  .table-wrap tbody td { font-size: 0.98rem; }
}
