/* Wind planning page.
 *
 * THE ONE PLACE THE SITE'S COLOUR RULE IS SET ASIDE
 * -------------------------------------------------
 * Everywhere else on this site the rule is: data is white, colour means a
 * state and never a reading. On a raster wind map colour IS the reading, and
 * there is no version of this page that keeps the rule.
 *
 * So the exception is drawn tightly around the map canvas and nowhere else.
 * Inside the map, colour carries wind speed. Outside it - the readouts, the
 * scrubber, the station list, the outlook table - every number stays white on
 * --bg, and --accent still means selection and nothing else.
 *
 * The ramp is keyed to decisions rather than to a spectrum. The two hard ticks
 * on the legend are the bottom of the Small Craft Advisory range (22 kt) and
 * the bottom of gale (34 kt).
 */

:root {
  --sheet-bg: #0d1011;
  --tool-bg: rgba(13, 16, 17, .88);
}

/* The map fills the screen. 100dvh, not 100vh: on iOS Safari and Chrome for
 * Android the collapsing toolbar makes 100vh taller than the visible area, and
 * the scrubber ends up underneath the browser chrome where it cannot be
 * reached. dvh tracks the real viewport. */
.wind-shell {
  position: relative;
  /* --masthead-h is measured in JS. Without subtracting it, a 100dvh shell
     starts one full masthead below the fold and the reader has to scroll to
     see any of the map. The fallback keeps it sane before JS runs. */
  height: calc(100dvh - var(--masthead-h, 96px));
  min-height: 420px;
  background: var(--bg);
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: #04070a;
  /* Leaflet handles the gestures. Without this the browser tries to scroll the
   * page on a one finger drag and the map only pans about half the time. */
  touch-action: none;
}

.leaflet-container { background: #04070a; font-family: var(--sans); }

.wind-noscript {
  position: absolute; inset: auto 1rem 6rem 1rem; z-index: 700;
  background: var(--panel); border: 1px solid var(--line);
  padding: .8rem 1rem; color: var(--ink-2); font-size: .9rem;
}

/* ---------- legend ---------- */

.wind-legend {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + .55rem);
  left: .55rem;
  right: .55rem;
  z-index: 660;
  background: var(--tool-bg);
  border: 1px solid var(--line);
  padding: .4rem .55rem .3rem;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "bar unit" "ticks unit";
  column-gap: .55rem;
  align-items: center;
  pointer-events: none;
}
.wl-bar { grid-area: bar; height: 9px; }
.wl-ticks {
  grid-area: ticks;
  position: relative;
  height: 15px;
  font-size: .62rem;
  color: var(--ink-dim);
}
.wl-ticks span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  top: 1px;
}
/* The two that change what you do get the caution colour and a rule, so they
 * read as thresholds rather than as more numbers. */
.wl-ticks span.wl-hard { color: var(--warn); }
.wl-ticks span.wl-hard::before {
  content: ""; position: absolute; left: 50%; top: -8px;
  width: 1px; height: 7px; background: var(--warn);
}
.wl-unit {
  grid-area: unit;
  pointer-events: auto;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--ink);
  font: 600 .72rem var(--sans);
  padding: .3rem .5rem;
  min-width: 44px;
  min-height: 30px;
  cursor: pointer;
}
.wl-unit:hover { border-color: var(--accent); }

/* ---------- floating tools ---------- */

/* Top right, under the legend, on every screen size.
 * They used to be centred vertically for thumb reach, but the details sheet
 * rises from the bottom and covered them the moment it was expanded, which
 * made the gust and arrows toggles unreachable on a phone. The app this page
 * is modelled on puts its tool column top right for the same reason. */
.wind-tools {
  position: absolute;
  right: .55rem;
  top: calc(env(safe-area-inset-top, 0px) + 4.1rem);
  z-index: 660;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.wt {
  /* 44px is the smallest target that is reliably hittable with a thumb. */
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--tool-bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  cursor: pointer;
  padding: 0;
}
.wt svg { width: 21px; height: 21px; fill: none; stroke: currentColor;
          stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.wt:hover { color: var(--ink); border-color: var(--line-2); }
.wt[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.wt.wt-busy { opacity: .5; }

.wind-fade {
  background: var(--tool-bg);
  border: 1px solid var(--line);
  width: 44px;
  height: 116px;
  display: grid;
  place-items: center;
}
/* A NATIVE vertical range, not a rotated horizontal one.
 * The rotate(-90deg) version needed overflow:hidden to contain a 96px input
 * inside a 44px box, and that clipped the track away and left only a sliver
 * of the thumb showing. writing-mode gives a real vertical slider with no
 * transform and nothing to clip; slider-vertical is the older WebKit spelling. */
.wind-fade input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  width: 22px;
  height: 92px;
  margin: 0;
  accent-color: var(--accent);
  background: transparent;
}

/* ---------- time scrubber ---------- */

.wind-time {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 670;
  background: linear-gradient(to top, rgba(6,8,8,.97) 62%, rgba(6,8,8,0));
  padding: .7rem .55rem calc(env(safe-area-inset-bottom, 0px) + .5rem);
}
.wt-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 .2rem .35rem;
}
.wt-day { color: var(--ink); font-size: .95rem; font-weight: 500; }
.wt-src { color: var(--ink-dim); font-size: .7rem; }
.wt-strip {
  display: flex;
  gap: .3rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* pan-x, so a horizontal drag scrubs time and a vertical one is left to the
   * page. The map has touch-action:none; if this had it too, the strip would
   * be undraggable on a phone. */
  touch-action: pan-x;
  padding-bottom: .2rem;
}
.wt-strip::-webkit-scrollbar { display: none; }
.wt-chip {
  flex: 0 0 auto;
  scroll-snap-align: center;
  min-width: 46px;
  min-height: 44px;
  padding: .3rem .1rem;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--ink-dim);
  font: 500 .84rem var(--sans);
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1.15;
}
.wt-chip small { display: block; font-size: .58rem; color: var(--ink-dim); }
.wt-chip:hover { color: var(--ink-2); }
.wt-chip[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.wt-chip.wt-now small { color: var(--accent-2); }
.wt-daybreak { border-left: 1px solid var(--line-2); margin-left: .2rem; padding-left: .4rem; }

/* The scrub slider. Full width under the chips, with a thumb big enough to
 * grab with a finger. */
.wt-range {
  width: 100%;
  margin: .35rem 0 0;
  height: 30px;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: pan-x;
}
.wt-range::-webkit-slider-runnable-track {
  height: 3px; background: var(--line-2);
}
.wt-range::-moz-range-track { height: 3px; background: var(--line-2); }
.wt-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -8.5px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg);
}
.wt-range::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg);
}
.wt-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- the details popup ----------
 *
 * It opens at the spot that was clicked or tapped, on every screen size, and
 * follows that point when the map is panned. positionSheet() in wind.js sets
 * left and top; everything here is shape only.
 */

.wind-sheet {
  position: absolute;
  left: 0; top: 0;
  z-index: 690;
  width: min(320px, calc(100vw - 1rem));
  max-height: 62%;
  background: var(--sheet-bg);
  border: 1px solid var(--line-2);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .55);
  padding: .1rem .9rem .8rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.wind-sheet[hidden] { display: none; }

.ws-head { display: flex; justify-content: space-between; align-items: flex-start;
           padding-top: .35rem; }
.ws-pos { color: var(--ink); font-size: .92rem; font-variant-numeric: tabular-nums; }
.ws-place { color: var(--ink-dim); font-size: .75rem; margin-top: .1rem; }
.ws-close {
  background: transparent; border: 0; color: var(--ink-dim);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
  min-width: 44px; min-height: 44px; margin: -.5rem -.5rem 0 0;
}
.ws-close:hover { color: var(--ink); }

.ws-now {
  display: flex; align-items: center; gap: .9rem;
  padding: .4rem 0 .6rem;
  border-bottom: 1px solid var(--line);
}
.ws-arrow svg { width: 38px; height: 38px; fill: none; stroke: var(--ink);
                stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ws-speed { color: var(--ink); font-size: 1.65rem; font-weight: 500; line-height: 1; }
.ws-dir { color: var(--ink-dim); font-size: .78rem; margin-top: .2rem; }
.ws-gust { margin-left: auto; text-align: right; }
.ws-label { color: var(--ink-dim); font-size: .68rem; }
.ws-gustval { color: var(--ink); font-size: 1.05rem; }

.ws-trace { margin-top: .5rem; }
.ws-trace svg { width: 100%; height: 78px; display: block; }
.ws-note { color: var(--ink-dim); font-size: .72rem; margin: .45rem 0 0; }

/* ---------- content under the map ---------- */

.wind-notes { padding-top: 1.1rem; padding-bottom: 2rem; }
.wind-notes .card { margin-bottom: 1rem; }
.prose.dim { color: var(--ink-dim); }

.wind-key { list-style: none; margin: .7rem 0 0; padding: 0; }
.wind-key li {
  display: flex; align-items: center; gap: .55rem;
  color: var(--ink-2); font-size: .86rem; padding: .22rem 0;
}
.wk-swatch { width: 16px; height: 16px; flex: 0 0 auto; }

.station-list { display: grid; gap: .1rem; margin-top: .6rem; }
.st-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  column-gap: .7rem;
  row-gap: .15rem;
  align-items: baseline;
  padding: .5rem .1rem;
  border-bottom: 1px solid var(--line);
}
.st-name { color: var(--ink-2); font-size: .88rem; }
.st-name a { color: var(--accent); text-decoration: none; }
.st-name a:hover { text-decoration: underline; }
.st-sub { display: block; color: var(--ink-dim); font-size: .68rem; }
.st-val { color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; }
.st-dir { color: var(--ink-dim); font-size: .8rem; min-width: 4.5rem; text-align: right; }

.outlook { margin-top: .6rem; overflow-x: auto; }
.ol-day { border-bottom: 1px solid var(--line); padding: .5rem 0; }
.ol-day h3 {
  margin: 0 0 .35rem; color: var(--ink-2); font-size: .82rem; font-weight: 500;
}
.ol-hours { display: flex; gap: .18rem; }
.ol-hour { flex: 1 1 0; min-width: 26px; text-align: center; }
.ol-bar { height: 40px; display: flex; align-items: flex-end; }
.ol-bar i { display: block; width: 100%; }
.ol-hr { color: var(--ink-dim); font-size: .58rem; margin-top: .2rem; }
.ol-sp { color: var(--ink); font-size: .68rem; font-variant-numeric: tabular-nums; }

.past { margin-top: .6rem; }
/* Drawn at its real pixel size in JS, so no CSS sizing: stretching it is what
   made axis labels impossible before. */
.past svg { display: block; overflow: visible; max-width: 100%; }
.past-empty { color: var(--ink-dim); font-size: .85rem; }

.src-list { list-style: none; margin: .5rem 0 .8rem; padding: 0; }
.src-list li {
  color: var(--ink-2); font-size: .86rem; padding: .25rem 0;
  border-bottom: 1px solid var(--line);
}
.src-list strong { color: var(--ink); font-weight: 500; }

/* ---------- map furniture ---------- */

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--sheet-bg); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 0; box-shadow: none;
}
.leaflet-popup-content { margin: .6rem .8rem; font-size: .85rem; }
.leaflet-control-attribution {
  background: rgba(6,8,8,.75) !important; color: var(--ink-dim) !important;
  font-size: .62rem !important;
}
.leaflet-control-attribution a { color: var(--ink-dim) !important; }
/* No zoom buttons on a phone: pinch is the gesture, and they would land under
   the details sheet anyway. */
.leaflet-bottom.leaflet-left { display: none; }
/* Clear of the scrubber, which occupies the bottom of the map. */
@media (min-width: 900px) {
  .leaflet-bottom.leaflet-left {
    display: block;
    bottom: calc(var(--timebar-h, 96px) + 2.4rem);
  }
}
.leaflet-bar a {
  background: var(--tool-bg); color: var(--ink-2);
  border-bottom-color: var(--line);
}
.leaflet-bar a:hover { background: var(--panel-2); color: var(--ink); }

/* Station and camera markers. Deliberately flat and small: they mark a place,
 * they are not a reading. */
.wm-dot {
  /* display:block is load bearing. These are <span>s inside a Leaflet
     divIcon, and width/height are ignored on an inline element, so without
     it every marker draws as a thin black sliver over the map. */
  display: block;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink); border: 2px solid #04070a;
  box-sizing: content-box;
}
.wm-dot.wm-cam { background: var(--accent); }
.wm-dot.wm-station { background: var(--accent-2); }

/* ---------- landscape on a phone ----------
 * There is not enough height for a legend, a scrubber and a sheet, so the
 * legend loses its tick labels and the scrubber tightens up. */

@media (max-height: 500px) and (orientation: landscape) {
  .wind-shell { height: 100dvh; }
  .wl-ticks { height: 0; overflow: hidden; }
  .wind-time { padding-top: .35rem; }
  .wt-head { padding-bottom: .15rem; }
  .wt-chip { min-height: 38px; }
  .wind-fade { display: none; }
  .wind-tools { top: calc(env(safe-area-inset-top, 0px) + 3rem); flex-direction: row; }
  .wind-fade { display: none; }
}

@media (max-width: 560px) {
  .wind-shell { min-height: 380px; }
  .wt-src { display: none; }
  .st-row { grid-template-columns: 1fr auto; }
  .st-dir { grid-column: 2; }
}

/* On a wide screen the map does not need the whole window; the reader can see
 * the first card under it without scrolling, which is how they find out what
 * the colours mean. */
@media (min-width: 900px) {
  .wind-shell { height: min(78dvh, 780px); }
  .wind-sheet { width: 340px; }
}

