/* ==========================================================================
   Tide — the moon moving the ocean, on a globe seen from the moon.
   Tier 1, pure static. Three optional keyless fetches (Open-Meteo marine,
   Open-Meteo geocoding, NOAA CO-OPS); the globe and astronomy are local.

   ART DIRECTION: UNDER THE MOON (+ two borrows). See
   docs/tide-art-direction.md — its spec, palette and banned list — before
   changing anything visual.

   The field is the interface. Chrome is words written onto it:
     · no border-radius (except the scrub knob — a circle)
     · no backdrop-filter / blur, no box-shadow (text-shadow for legibility
       is type, not a container — allowed)
     · Fraunces for words; Space Grotesk, tabular, for numerals
     · the readout is rows under a hairline, never a card
     · feedback is an underline + a dim, never a background wash
     · nothing pulses, glows or bounces
   ========================================================================== */

/* --- fonts (self-hosted, SIL OFL 1.1 — licences beside the woff2) ---- */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin-var.woff2") format("woff2");
  font-weight: 300 600; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin-ext-var.woff2") format("woff2");
  font-weight: 300 600; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/spacegrotesk-latin-var.woff2") format("woff2");
  font-weight: 300 700; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/spacegrotesk-latin-ext-var.woff2") format("woff2");
  font-weight: 300 700; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #0a1220;                       /* the space behind the Earth */
  --serif: "Fraunces", ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --num:   "Space Grotesk", "Fraunces", ui-serif, Georgia, serif;

  /* chrome — warm neutral at L 0.93 / 0.70 (art-direction palette) */
  --chrome:      rgba(243, 238, 228, 0.92);
  --chrome-soft: rgba(243, 238, 228, 0.66);
  --chrome-line: rgba(243, 238, 228, 0.28);
  --accent:      rgb(214, 190, 150);   /* the one accent: sea hue rotated 180°, L .75 */

  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem;
  --sp-4: 1rem;   --sp-5: 1.5rem; --sp-6: 2rem;

  --edge:  max(var(--sp-5), env(safe-area-inset-left));
  --ceil:  calc(env(safe-area-inset-top, 0px) + var(--sp-5));
  --floor: calc(env(safe-area-inset-bottom, 0px) + var(--sp-4));

  /* 1.25 modular scale off 16 px */
  --t-1: 0.8rem; --t0: 1rem; --t1: 1.25rem; --t2: 1.5625rem; --t3: 1.953rem; --t4: 2.441rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, p, ul, ol { margin: 0; }
html, body { height: 100%; }
input, button { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
ol, ul { list-style: none; padding: 0; }

body {
  background: var(--bg);
  color: var(--chrome);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
  font-synthesis: none;
}

/* focus: a thin square outline — never a rounded ring */
:focus-visible { outline: 1px solid var(--chrome); outline-offset: 3px; }

/* --- the globe ----------------------------------------------------- */
#globe {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#globe.dragging { cursor: grabbing; }

/* --- the moon's hit target (the disc itself is drawn on the canvas) ---
   A tracked marker, not fixed chrome: tide.js repositions it every frame
   via inline left/top from its real bearing (moonMarkerPos(), docs/
   tide-visibility-research.md §3). left/top/transform below are only the
   pre-first-paint fallback, overridden the instant paint() runs. */
.moon {
  position: fixed;
  z-index: 12;
  width: 44px; height: 44px;
  left: 50%; top: calc(var(--ceil) - 6px);
  transform: translateX(-50%);
  cursor: pointer;
}
.moon[hidden] { display: none; }
.moon:focus-visible { outline-offset: -2px; }

/* --- pick: a tethered preview after a long-press on the globe ------
   Same shape as Tonight's tap-to-select card: a hairline, not a box,
   positioned every frame from the tapped point's real screen position
   (paintPick(), tide.js) the way the moon marker already is. The
   container stays pointer-events:none so it never blocks the globe
   underneath it — but .pick-use is a real control and needs its own
   pointer-events:auto to be clickable at all. That line is load-bearing,
   not decorative: see the Detail-button bug, PROJECT_STATE.md 2026-09-17,
   for what happens when a button inherits none from its container. */
.pick-card {
  position: fixed;
  z-index: 13;
  width: min(15rem, calc(100vw - 2 * var(--edge)));
  display: grid;
  gap: 0.3em;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--chrome-line);
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.pick-card[hidden] { display: none; }
.pick-name { font-size: 1.1rem; color: var(--chrome); }
.pick-use { pointer-events: auto; font-size: 0.96rem; justify-self: start; }

/* --- a word that acts as a control -------------------------------- */
.word {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 400;
  color: var(--chrome);
  letter-spacing: 0.01em;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  position: relative;
  white-space: nowrap;
  transition: opacity 140ms ease, letter-spacing 160ms ease;
}
.word::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 11px;
  height: 1px; background: currentColor; opacity: 0.32;
  transition: opacity 150ms ease;
}
.word:hover { letter-spacing: 0.035em; }
.word:hover::after, .word:focus-visible::after { opacity: 0.8; }
.word:active { opacity: 0.55; }
.word[aria-pressed="true"]::after { opacity: 0.85; }
.word[hidden] { display: none; }
@media (hover: none) { .word::after { opacity: 0.5; } }

/* --- readout: rows under a hairline, top-left --------------------- */
.readout {
  position: fixed;
  left: var(--edge);
  top: var(--ceil);
  z-index: 11;
  width: min(21rem, calc(100vw - 2 * var(--edge)));
  display: grid;
  gap: 0.15em;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.42);
}
.readout[hidden] { display: none; }
/* "Hide" (controls bar): a plain viewing preference, not a panel to
   dismiss, so it's its own class rather than reusing [hidden] — About
   already borrows the hidden attribute to share "one column of words
   at a time" (showAbout()) and un-hides it again on close, which would
   otherwise silently override this. !important guarantees this wins
   regardless of what else toggles the hidden attribute underneath it. */
.readout.force-hidden { display: none !important; }
.ro-rule {
  height: 1px;
  background: var(--chrome-line);
  margin-bottom: var(--sp-2);
  /* the Strandline borrow: drifts a few px up when rising, down when falling */
  transition: transform 20s linear;
}
.ro-rule.rising  { transform: translateY(-2px); }
.ro-rule.falling { transform: translateY(2px); }
.ro-place {
  display: block;
  width: 100%;
  text-align: left;
  font-size: clamp(1.6rem, 5vw, var(--t3));
  font-weight: 430;
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--chrome);
  pointer-events: auto;   /* the readout itself is inert; this is a real control (phase 10: cycles saved places) */
}
.ro-place:hover, .ro-place:focus-visible { opacity: 0.85; }
.ro-state {
  font-size: var(--t1);
  color: var(--chrome);
  margin-top: 0.2em;
}
.ro-state .n { font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: 500; }
/* small text beside the big info: air/water temperature, always in the
   glance (not a minor fact worth hiding behind Detail) but visually
   subordinate to the state line above it — the answer stays the answer. */
.ro-temp {
  font-size: 0.85rem;
  color: var(--chrome-soft);
  margin-top: 0.15em;
  font-variant-numeric: tabular-nums lining-nums;
}
.ro-temp .n { font-family: var(--num); }
.ro-temp:empty { display: none; }

/* today's curve — a hairline, not a chart: no axes, no gridlines, no fill.
   Pointer-draggable (a shortcut into the nearby hours); the <input
   type=range> scrub remains the keyboard-accessible way to move in time,
   so this canvas is aria-hidden and purely a progressive enhancement. */
.ro-curve {
  display: block;
  width: 100%;
  height: 5.5rem;
  margin: 0.5em 0 0.3em;
  pointer-events: auto;      /* the readout itself is inert; this isn't */
  cursor: pointer;
  touch-action: none;        /* we own the drag */
}
.ro-curve[hidden] { display: none; }

/* Detail — everything past the glance (curve + state already say the
   thing that matters): the rest of the turns, range/springs, moon, sun.
   Collapsed by default so the readout never crowds a small screen — see
   docs/tide-panel-research.md (Option C, decided 2026-09-16). Source and
   the hand-off line stay outside it, always visible: short, and safety-
   relevant. Sized in JS (sizeDetail()) to whatever room is actually left
   above the controls; this is the static fallback. */
.ro-detail-toggle { justify-self: start; margin: 0.35em 0 0.1em; pointer-events: auto; }   /* the readout itself is inert; this is a real control */
.ro-detail {
  display: grid;
  gap: 0.15em;
  max-height: 70svh;         /* JS tightens this to the real space available */
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;      /* the readout itself is inert; this scrolls */
  scrollbar-width: thin;                          /* Firefox */
  scrollbar-color: var(--chrome-line) transparent;
}
.ro-detail[hidden] { display: none; }
.ro-detail::-webkit-scrollbar { width: 3px; }      /* a hairline, not a UI-kit bar */
.ro-detail::-webkit-scrollbar-track { background: transparent; }
.ro-detail::-webkit-scrollbar-thumb { background: var(--chrome-line); }

.ro-turns { display: grid; gap: 0.05em; margin-top: 0.45em; }
.ro-turns li {
  display: grid;
  grid-template-columns: 5.4rem 3.2rem 1fr;
  align-items: baseline;
  white-space: nowrap;
  font-family: var(--num);
  font-variant-numeric: tabular-nums lining-nums;
  font-weight: 400;
  font-size: var(--t0);
  color: var(--chrome-soft);
  letter-spacing: 0.01em;
}
.ro-turns li.next { color: var(--chrome); }
.ro-turns li .k { font-family: var(--serif); font-variant: small-caps; letter-spacing: 0.06em; font-size: 0.92rem; }
.readout .u { font-family: var(--serif); font-variant: small-caps; font-size: 0.86em; margin-left: 0.25em; opacity: 0.85; }
.ro-turns li .d { font-family: var(--serif); font-size: 0.78rem; opacity: 0.7; margin-left: 0.4em; }

/* phase 7: the week — the same row grammar as .ro-turns, grouped under a
   small-caps day label; collapses to today + tomorrow with "This week". */
.ro-week-day { margin-top: 0.5em; }
.ro-week-day[hidden] { display: none; }
.ro-week-day .ro-turns { margin-top: 0.15em; }
.ro-week-label {
  font-family: var(--serif); font-variant: small-caps; letter-spacing: 0.06em;
  font-size: 0.86rem; color: var(--chrome-soft);
}
.ro-week-toggle { justify-self: start; margin: 0.4em 0 0.1em; }

/* phase 8: datum + units — two smaller word controls on their own line,
   below the primary Detail/This-week controls in visual weight. */
.ro-units-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3em; margin-top: 0.5em; }
.ro-units-line .word { font-size: 0.92rem; }
.ro-line {
  font-size: 0.95rem;
  color: var(--chrome-soft);
  font-variant-numeric: tabular-nums lining-nums;
}
.ro-line:first-of-type { margin-top: 0.4em; }
.ro-line .n { font-family: var(--num); }
.ro-src {
  font-size: 0.8rem;
  color: var(--chrome-soft);
  letter-spacing: 0.01em;
  margin-top: 0.3em;
}
.ro-src + .ro-src { margin-top: 0; }
.ro-src a { color: inherit; pointer-events: auto; }
.readout:empty { display: none; }
.ro-turns:empty, .ro-line:empty, .ro-src:empty { display: none; }

/* --- time: a hairline scrub across the bottom ---------------------- */
.controls {
  position: fixed;
  left: var(--edge); right: var(--edge);
  bottom: var(--floor);
  z-index: 15;
  display: flex; align-items: center;
  gap: var(--sp-5);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.42);
}
.controls[hidden] { display: none; }
#btn-play { min-width: 3.1rem; justify-content: center; }

.scrub {
  flex: 1 1 auto; min-width: 3rem; height: 44px;
  -webkit-appearance: none; appearance: none;
  background: transparent; cursor: pointer;
  --p: 16.6%;     /* the present, at load */
  --now: 16.6%;
}
.scrub::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(90deg,
    var(--chrome) 0 var(--p), var(--chrome-line) var(--p));
}
.scrub::-moz-range-track    { height: 1px; background: var(--chrome-line); }
.scrub::-moz-range-progress { height: 1px; background: var(--chrome); }
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--chrome); margin-top: -4px;
}
.scrub::-moz-range-thumb { width: 9px; height: 9px; border: 0; border-radius: 50%; background: var(--chrome); }

.clock {
  flex: none;
  color: var(--chrome-soft);
  font-family: var(--num);
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-size: 0.95rem;
}
.clock.now { color: var(--accent); }

.ctl-icon {
  flex: none; min-height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem; color: var(--chrome-soft);
  transition: color 140ms ease;
}
.ctl-icon:hover, .ctl-icon:focus-visible { color: var(--chrome); }

/* --- locate: a prompt written into the field ----------------------- */
.locate {
  position: fixed;
  left: var(--edge); right: var(--edge);
  bottom: calc(var(--floor) + 0.5rem);
  z-index: 20;
  max-width: 25rem;
  max-height: calc(100dvh - var(--floor) - 3rem);
  overflow-y: auto; overscroll-behavior: contain;
  display: grid; gap: var(--sp-3);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.42);
}
.locate[hidden] { display: none; }
.locate h1 {
  font-size: clamp(2.4rem, 11vw, 4rem);
  font-weight: 430; line-height: 1; letter-spacing: -0.02em;
  color: var(--chrome); margin-bottom: 0.1em;
}
.locate p { color: var(--chrome-soft); font-size: 0.98rem; max-width: 24rem; }
.field {
  width: 100%; background: transparent; border: 0;
  border-bottom: 1px solid var(--chrome-line);
  padding: var(--sp-2) 0; color: var(--chrome); font-size: 1.2rem;
  transition: border-color 140ms ease;
}
.field::placeholder { color: var(--chrome-soft); }
.field:focus { outline: none; border-bottom-color: var(--chrome); }
.place-results { display: grid; }
.place-results[hidden] { display: none; }
.place-pick {
  width: 100%; text-align: left; min-height: 44px;
  display: flex; align-items: baseline; gap: var(--sp-2);
  padding: var(--sp-1) 0; border-bottom: 1px solid transparent;
  transition: border-color 140ms ease;
}
.place-pick:hover, .place-pick:focus-visible { border-bottom-color: var(--chrome-line); outline: none; }
.place-pick .p-name { color: var(--chrome); }
.place-pick .p-sub  { color: var(--chrome-soft); font-size: 0.86rem; }
.locate-actions { display: flex; gap: var(--sp-5); flex-wrap: wrap; }
.locate-msg { color: var(--chrome-soft); font-size: 0.92rem; }
.locate-msg[hidden] { display: none; }

/* --- about ---------------------------------------------------------- */
.about {
  position: fixed;
  left: var(--edge); right: var(--edge);
  bottom: calc(var(--floor) + 3.4rem);
  z-index: 18;
  max-width: 30rem;
  max-height: calc(100dvh - var(--floor) - 6rem);
  overflow-y: auto; overscroll-behavior: contain;
  display: grid; gap: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--chrome-line);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.42);
}
.about[hidden] { display: none; }
.about h2 { font-size: var(--t2); font-weight: 430; letter-spacing: -0.015em; }
.about p { font-size: 0.95rem; color: var(--chrome); }
.about .about-src { font-size: 0.8rem; color: var(--chrome-soft); }
.about .word { justify-self: start; }

/* --- responsive ------------------------------------------------------ */
@media (max-width: 30rem) {
  /* two rows: the scrub alone on top, the words and icons beneath */
  .controls { gap: 0 var(--sp-4); flex-wrap: wrap; }
  .scrub { flex: 1 1 calc(100% - 88px - 2 * var(--sp-4)); order: -1; }
  .ctl-icon { order: -1; }
  .clock { margin-left: auto; }
  .about { top: var(--ceil); bottom: auto; max-height: calc(100dvh - var(--ceil) - var(--floor) - 6.5rem); }
  .readout { width: calc(100vw - 2 * var(--edge)); }
  .ro-turns li { grid-template-columns: 5rem 2.9rem 1fr; }
}
@media (max-width: 22rem) {
  .controls { gap: var(--sp-3); }
  .word { font-size: 0.96rem; }
  .clock { font-size: 0.82rem; }
  .ro-state { font-size: var(--t0); }
}
@media (max-height: 34rem) {
  .ro-place { font-size: 1.5rem; }
  .ro-curve { height: 3.4rem; }
  /* Detail is collapsed by default now, so it no longer needs to truncate
     turns or hide moon/sun to fit a short screen — when it IS opened,
     sizeDetail() caps it above the controls and it scrolls internally. */
  .locate h1 { font-size: clamp(1.8rem, 9vh, 2.6rem); }
}

/* --- reduced motion: nothing drifts, nothing eases ---------------- */
@media (prefers-reduced-motion: reduce) {
  .ro-rule { transition: none; }
  .word, .word::after, .field, .place-pick, .ctl-icon { transition: none; }
}
