/* Paint or Rain — fixed light theme, landscape only. No dark mode, no purple. */

:root {
  color-scheme: light;

  --label-w: 176px;
  --cell-w: 46px;
  --cell-h: 40px;
  --day-h: 26px;
  --hour-h: 26px;
  --group-h: 21px;

  --ink:        #17232e;
  --ink-2:      #4b5c6b;
  --ink-3:      #7e8d9a;
  --bg:         #ffffff;
  --bg-2:       #f1f4f6;
  --bg-3:       #e6ebee;
  --line:       #d5dde3;
  --line-2:     #b6c3cc;
  --line-3:     #6f8494;
  --accent:     #0a5b96;
  --accent-ink: #ffffff;

  /* rain: neutral -> deep blue */
  --r0: #f7f9fa;  --r1: #e8f1f8;  --r2: #d3e6f4;  --r3: #b6d7ee;
  --r4: #93c4e6;  --r5: #6aaddb;  --r6: #4191cb;  --r7: #1f74b1;
  --r8: #145a8c;  --r9: #0d4470;

  /* wind: neutral -> sand -> deep red */
  --w0: #f7f9fa;  --w1: #fbf3dd;  --w2: #f8e3b0;  --w3: #f4cd80;
  --w4: #eeaf51;  --w5: #e18c33;  --w6: #cc6726;  --w7: #a8431d;
}

* { box-sizing: border-box; }

/* `display` on a class beats the browser's rule for [hidden], so say it here
 * once and let the attribute win everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-2);
}

body {
  font: 400 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- layout */

#app {
  position: fixed;
  inset: 0;
  /* Installed full-screen on a notched phone the frame reaches the hardware
     edges, so keep the chrome out of the cutout and the home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  /* A single column that never grows to the width of the (very wide) hour
     grid inside it, so the header and footer stay on screen. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
}

/* Always landscape: if the device is held in portrait, rotate the whole app
   a quarter turn and swap its width and height. */
@media (orientation: portrait) {
  #app {
    inset: auto;
    top: 0;
    left: 0;
    width: 100vh;
    height: 100vw;
    transform-origin: 0 0;
    transform: translateX(100vw) rotate(90deg);
    /* The frame is turned a quarter turn, so the insets have to turn with
       it: what the app calls "top" is the screen's right edge. */
    padding: env(safe-area-inset-right) env(safe-area-inset-bottom)
             env(safe-area-inset-left) env(safe-area-inset-top);
  }
}
@supports (width: 100dvh) {
  @media (orientation: portrait) {
    #app {
      width: 100dvh;
      height: 100dvw;
      transform: translateX(100dvw) rotate(90deg);
    }
  }
}

/* ------------------------------------------------------------------- bar */

.bar {
  position: relative;
  min-width: 0;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.brand .sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--ink-3);
  max-width: 260px;
}

.where {
  min-width: 0;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.where strong { font-size: 13.5px; color: var(--ink); }
.where span { margin-left: 8px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.switch { display: flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; }
.seg {
  padding: 6px 15px;
  white-space: nowrap;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--bg);
  border: 0;
  border-right: 1px solid var(--line-2);
  cursor: pointer;
}
.seg:last-child { border-right: 0; }
.seg:hover { background: var(--bg-2); }
.seg.on { color: var(--accent-ink); background: var(--accent); }

.btn {
  padding: 6px 11px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); }
.btn:active { transform: translateY(1px); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  padding: 0;
  color: var(--ink-2);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-3); color: var(--ink); }
.icon-btn[aria-expanded="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.stamp {
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--ink-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.stamp-n { display: block; }

#q {
  flex: 0 1 210px;
  min-width: 116px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 4px;
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.icon-btn.net {
  color: #8a5210;
  background: #fbe7c4;
  border-color: #e3bc79;
}
.icon-btn.net:hover { background: #fbe7c4; color: #8a5210; }
.icon-btn.net .cut-bg { stroke: #fbe7c4; }

/* --------------------------------------------------------- boot splash */

.boot {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fdfdfd;
  transition: opacity 260ms ease;
}
.boot.going { opacity: 0; }
.boot img {
  width: min(76%, 720px);
  height: auto;
}
.boot-note {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
}

/* the same artwork introduces the first-run chooser */
.panel-art { display: none; }
body.firstrun .panel-art {
  display: block;
  width: 100%;
  /* Capped so the whole chooser still fits a phone held sideways, where the
     app has only ~390px of height to work with. */
  max-height: 148px;
  height: auto;
  object-fit: contain;
  margin-bottom: -2px;
}

/* ------------------------------------------------------- update toast */

.toast {
  position: absolute;
  z-index: 65;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 13px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  box-shadow: 0 8px 22px rgba(23, 35, 46, 0.2);
}
.toast-txt { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.btn.ghost { background: var(--bg); font-weight: 500; color: var(--ink-2); }

.install-hint { font-size: 12px; color: var(--ink-2); }

/* ------------------------------------------------------ settings panel */

/* Wide screens keep these controls out in the open, so the panel is simply
   part of the bar and the gear is unnecessary. Narrow screens fold the same
   markup into a popover. */
.panel {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
/* Wide screens ignore the attribute: these controls are always on show. */
.panel[hidden] { display: flex !important; }
.panel-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.panel-row.find { position: relative; }
#search { display: flex; gap: 6px; }
.panel-title { display: none; }
.panel-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.panel-row.quick { display: none; }

.results {
  position: absolute;
  z-index: 60;
  top: 34px;
  left: 0;
  width: 320px;
  max-height: 216px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(23, 35, 46, 0.16);
}
.results button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.results button:last-child { border-bottom: 0; }
.results button:hover { background: var(--bg-2); }
.results .muted { color: var(--ink-3); }

#gear { display: none; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(23, 35, 46, 0.28);
}

/* ---- narrow screens: the gear takes over */

@media (max-width: 1100px) {
  #gear { display: flex; }
  .panel[hidden] { display: none !important; }
  .brand .sub { display: none; }
  .where span { display: none; }
  .stamp-n { display: none; }
  .bar { gap: 10px; padding: 6px 10px; }
  .brand h1 { font-size: 16px; }

  .panel {
    position: absolute;
    z-index: 55;
    top: calc(100% + 5px);
    right: 8px;
    width: 322px;
    max-width: calc(100vw - 16px);
    flex-direction: column;
    align-items: stretch;
    gap: 11px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--line-2);
    border-radius: 6px;
    box-shadow: 0 10px 28px rgba(23, 35, 46, 0.22);
  }
  .panel-row { justify-content: space-between; }
  .panel-row.find { flex-direction: column; align-items: stretch; gap: 7px; }
  #search { flex-wrap: wrap; }
  #q { flex: 1 1 100%; min-width: 0; }
  .results { top: 66px; width: auto; right: 0; }
  .panel-row.refresh { justify-content: flex-start; }
  .toast { right: 8px; bottom: 8px; }
}

/* ---- first run: choose a place before anything else */

body.firstrun .panel {
  /* the artwork's paper colour, so its edges vanish into the card */
  background: #fdfdfd;
  position: fixed;
  z-index: 60;
  /* percentages, not vh: inside the rotated portrait frame the app's height
     is the viewport's width */
  max-height: 94%;
  overflow-y: auto;
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  gap: 13px;
  width: 372px;
  max-width: calc(100vw - 28px);
  padding: 16px 17px 17px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 7px;
  box-shadow: 0 14px 40px rgba(23, 35, 46, 0.3);
}
body.firstrun .panel[hidden] { display: flex !important; }
body.firstrun .panel-title {
  display: block;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
body.firstrun .panel-row.find { flex-direction: column; align-items: stretch; gap: 7px; }
body.firstrun #search { flex-wrap: wrap; }
body.firstrun #q { flex: 1 1 100%; min-width: 0; }
body.firstrun .results { top: 66px; width: auto; right: 0; }
body.firstrun .panel-row.quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}
body.firstrun .panel-row.quick .panel-label { flex: 1 1 100%; }
body.firstrun .panel-row.quick .btn { padding: 5px 9px; font-size: 12.5px; }
body.firstrun .panel-row.view,
body.firstrun .panel-row.refresh,
body.firstrun .where,
body.firstrun .controls { display: none; }

/* ----------------------------------------------------------------- graph */

.chart {
  position: relative;
  height: 100%;
  min-width: 0;
  padding: 6px 10px 2px;
  background: var(--bg);
}

.plot { display: block; }
.plot:focus { outline: none; }
.plot:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.chart-msg { margin: 26px 4px; font-size: 14px; color: var(--ink-2); }

.g-day {
  font: 700 12.5px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  fill: var(--ink);
}
.g-day-sub { font-weight: 500; fill: var(--ink-2); }

.g-ytick, .g-xtick, .g-end, .g-peak, .g-panel-label {
  font: 500 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  fill: var(--ink-3);
}
.g-ytick { text-anchor: end; }
.g-xtick { text-anchor: middle; }
.g-end {
  font-weight: 700;
  font-size: 11.5px;
  fill: var(--ink);
  dominant-baseline: middle;
}
.g-peak { text-anchor: middle; font-size: 10px; fill: #5b7d95; }
.g-panel-label { font-size: 10px; font-weight: 600; fill: var(--ink-3); }

/* readout on hover or arrow keys */
.tip {
  position: absolute;
  z-index: 30;
  min-width: 178px;
  padding: 7px 9px 8px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  box-shadow: 0 5px 16px rgba(23, 35, 46, 0.16);
  pointer-events: none;
}
.tip-head {
  margin-bottom: 5px;
  padding-bottom: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.tip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--ink-2);
}
.tip-row.extra { color: var(--ink-3); }
.tip-row.extra:first-of-type { margin-top: 3px; border-top: 1px solid var(--line); padding-top: 3px; }
.tip-name { flex: 1 1 auto; }
.tip-val {
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tip-row.extra .tip-val { font-weight: 600; }

/* legend keys for the graph */
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
}
.legend .key + .key { margin-left: 13px; }
.legend .key svg { flex: none; }
.legend .key.off { color: var(--ink-3); opacity: 0.75; }
.legend .key em { font-style: normal; color: var(--ink-3); }

/* ----------------------------------------------------------------- board */

.board { min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-2); }

.scroll {
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.grid {
  display: grid;
  grid-template-columns: var(--label-w) repeat(var(--hours, 48), var(--cell-w));
  width: max-content;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

/* ---- header rows */

.hcell, .dcell {
  position: sticky;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.dcell {
  top: 0;
  height: var(--day-h);
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--bg-2);
}
.dlab {
  position: sticky;
  left: calc(var(--label-w) + 11px);
  display: flex;
  align-items: center;
  gap: 7px;
  padding-left: 11px;
}
.dcell .d2 { font-weight: 500; color: var(--ink-2); }
.hcell {
  top: var(--day-h);
  height: var(--hour-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
}
.hcell.tick { color: var(--ink); background: var(--bg); }
.hcell.past, .cell.past { opacity: 0.42; }

.corner {
  position: sticky;
  left: 0;
  z-index: 30;
  background: var(--bg);
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line);
}
.corner.a { top: 0; height: var(--day-h); background: var(--bg-2); }
.corner.b {
  top: var(--day-h);
  height: var(--hour-h);
  display: flex;
  align-items: center;
  padding-left: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---- source label column */

.label {
  position: sticky;
  left: 0;
  z-index: 15;
  height: var(--cell-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 9px 0 10px;
  background: var(--bg);
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.label .n {
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label .r {
  font-size: 10.5px;
  color: var(--ink-3);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label.sum { background: var(--bg-2); }
.label.sum .n { color: var(--accent); }
.label.dead .n { color: var(--ink-3); }

/* ---- group headings */

.glabel {
  position: sticky;
  left: 0;
  z-index: 15;
  height: var(--group-h);
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-2);
  white-space: nowrap;
  background: var(--bg-3);
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  border-top: 1px solid var(--line-2);
}
.gspan {
  height: var(--group-h);
  background: var(--bg-3);
  border-bottom: 1px solid var(--line-2);
  border-top: 1px solid var(--line-2);
}

/* ---- data cells */

.cell {
  height: var(--cell-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-right: 1px solid rgba(23, 35, 46, 0.07);
  border-bottom: 1px solid var(--line);
  background: var(--r0);
}
.cell .v {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.2px;
}
.cell .s {
  font-size: 9.5px;
  font-weight: 600;
  line-height: 1.15;
  opacity: 0.82;
}
.cell.na { background: repeating-linear-gradient(135deg, #fafbfc 0 5px, #eef2f4 5px 10px); }
.cell.na .v { font-weight: 500; color: var(--ink-3); }
.cell.dark { color: #ffffff; }
.cell.est .v { text-decoration: underline dotted rgba(255, 255, 255, 0.55) 1px; text-underline-offset: 2px; }
.cell.row-sum { border-bottom: 2px solid var(--line-2); }

.dcell.day1, .hcell.d1, .cell.d1 { border-left: 2px solid var(--line-3); }
.now { box-shadow: inset 2px 0 0 var(--accent); }

.cell:hover { outline: 2px solid var(--ink); outline-offset: -2px; z-index: 5; }

.rowline .label, .rowline .cell { border-bottom: 2px solid var(--line-2); }

/* rain + wind ramps */
.r0{background:var(--r0)} .r1{background:var(--r1)} .r2{background:var(--r2)}
.r3{background:var(--r3)} .r4{background:var(--r4)} .r5{background:var(--r5)}
.r6{background:var(--r6)} .r7{background:var(--r7)} .r8{background:var(--r8)}
.r9{background:var(--r9)}
.w0{background:var(--w0)} .w1{background:var(--w1)} .w2{background:var(--w2)}
.w3{background:var(--w3)} .w4{background:var(--w4)} .w5{background:var(--w5)}
.w6{background:var(--w6)} .w7{background:var(--w7)}

/* ------------------------------------------------------------------ foot */

.foot {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 7px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.legend { display: flex; align-items: center; gap: 14px; flex-wrap: nowrap; min-width: 0; overflow: hidden; }
.legend .grp { display: flex; align-items: center; gap: 7px; }
.legend .cap {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.legend .ramp { display: flex; border: 1px solid var(--line-2); border-radius: 3px; overflow: hidden; }
.legend .sw {
  width: 31px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--ink-2);
  border-right: 1px solid rgba(23, 35, 46, 0.1);
  font-variant-numeric: tabular-nums;
}
.legend .sw:last-child { border-right: 0; }
.legend .sw.dark { color: #fff; }
.legend .note {
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Narrow screens keep the colour ramp and drop the prose. */
@media (max-width: 1440px) {
  .legend .note { display: none; }
  .credits { max-width: 62%; }
}

@media (max-width: 1280px) {
  .credits { display: none; }
}

.credits {
  margin: 0 0 0 auto;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--ink-3);
  text-align: right;
  max-width: 46%;
}
.credits b { color: var(--ink-2); font-weight: 600; }

/* Short viewports (phone in landscape): tighten everything by a notch. */
@media (max-height: 460px) {
  :root { --cell-h: 31px; --cell-w: 42px; --label-w: 150px; --day-h: 21px; --hour-h: 21px; --group-h: 17px; }
  .brand h1 { font-size: 15px; }
  .bar { padding: 5px 9px; gap: 9px; }
  .icon-btn { height: 28px; width: 32px; }
  .foot { padding: 4px 10px; }
  .credits { display: none; }
  .cell .v { font-size: 12px; }
  .cell .s { font-size: 9px; }
  .label .n { font-size: 11.5px; }
  .label .r { font-size: 10px; }
  .legend .sw { width: 27px; height: 16px; }
  .legend .key { font-size: 10px; }
  .legend .key + .key { margin-left: 9px; }
  .glabel { font-size: 9px; letter-spacing: 0.05em; }
  .chart { padding: 4px 8px 0; }
  .btn, .seg, #q { padding-top: 4px; padding-bottom: 4px; }
  .seg { padding-left: 10px; padding-right: 10px; }
  .btn { padding-left: 8px; padding-right: 8px; }
}
