/* ── Tokens ──────────────────────────────────────────────────────
   Palette roles follow the data-viz reference palette: one series hue
   (blue) for the tide itself, orange as the second state colour, and
   recessive greys for chrome. Dark mode is stepped for the dark
   surface, not flipped. */
:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --ink:             #0b0b0b;
  --ink-2:           #52514e;
  --ink-muted:       #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --hairline:        rgba(11, 11, 11, 0.10);

  --series:          #2a78d6;   /* blue 450 — the tide curve */
  --series-soft:     #cde2fb;   /* blue 100 — meter track, area wash */
  --rising:          #2a78d6;   /* blue  */
  --falling:         #eb6834;   /* orange */

  /* Segmented control: the selected pill must read as nearer the eye than its
     track in BOTH themes, which a single surface colour cannot do. */
  --seg-track:   rgba(11, 11, 11, 0.06);
  --seg-on:      #ffffff;
  --seg-shadow:  0 1px 2px rgba(11, 11, 11, .14);

  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 6px 20px rgba(11,11,11,.05);
  --radius: 16px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --ink-muted:   #898781;
    --grid:        #2c2c2a;
    --axis:        #383835;
    --hairline:    rgba(255, 255, 255, 0.10);

    --series:      #3987e5;
    --series-soft: #184f95;
    --rising:      #3987e5;
    --falling:     #d95926;

    --seg-track:   rgba(255, 255, 255, 0.07);
    --seg-on:      rgba(255, 255, 255, 0.22);
    --seg-shadow:  none;

    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.fallback { padding: 3rem 1.25rem; text-align: center; color: var(--ink-2); }

/* ── Top bar ─────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--hairline);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 860px; margin: 0 auto;
  padding: .5rem 1rem .45rem;
}
.topbar-row {
  display: flex; align-items: center; gap: .6rem;
  justify-content: space-between;
}
.clock {
  margin: .2rem 0 0; font-size: .75rem; color: var(--ink-muted);
  white-space: nowrap;
}

/* m / ft — a segmented pair, so the current unit is visible without opening it. */
.units {
  flex: none; display: flex;
  background: var(--seg-track);
  border-radius: 10px; padding: 2px;
}
.units button {
  font: inherit; font-size: .8125rem; font-weight: 620;
  color: var(--ink-muted); background: none; border: 0;
  border-radius: 8px; padding: .3rem .6rem;
  min-width: 2.25rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.units button.is-on {
  color: var(--ink); background: var(--seg-on);
  box-shadow: var(--seg-shadow);
}
.units button:focus-visible { outline: 2px solid var(--series); outline-offset: 1px; }

.station-picker { min-width: 0; flex: 1 1 auto; }
.station-picker select {
  font: inherit; font-size: 1.0625rem; font-weight: 650; letter-spacing: -.015em;
  width: 100%; max-width: 15rem;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--hairline); border-radius: 12px;
  padding: .5rem 2.1rem .5rem .8rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23898781' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  background-size: 13px;
}
.station-picker select:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }

/* ── Cards ───────────────────────────────────────────────────── */
main { max-width: 860px; margin: 0 auto; padding: 1rem 1rem 2rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.15rem 1.25rem;
  margin-bottom: 1rem;
}
.card-head { margin-bottom: .9rem; }
.card h2 { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: -.005em; }
.card-sub { margin: .15rem 0 0; font-size: .8125rem; color: var(--ink-muted); }

/* ── Hero ────────────────────────────────────────────────────── */
.hero-state { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }

.dir-badge {
  flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.25rem; line-height: 1;
  color: #fff; font-weight: 700;
  background: var(--rising);
}
.dir-badge.is-falling { background: var(--falling); }

.dir-word {
  margin: 0; font-size: 1.25rem; font-weight: 680; letter-spacing: -.02em;
}

.countdown-label {
  margin: 0; font-size: .8125rem; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
}
.countdown {
  margin: .1rem 0 0;
  font-size: clamp(3rem, 15vw, 4rem);
  font-weight: 680; letter-spacing: -.035em; line-height: 1.02;
}
.countdown-detail { margin: .3rem 0 0; font-size: 1rem; color: var(--ink-2); }

/* Meter: fill and track are two steps of the one blue ramp. */
.meter { margin: 1.25rem 0 .25rem; }
.meter-track {
  height: 10px; border-radius: 999px;
  background: var(--series-soft); overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0;
  border-radius: 999px; background: var(--series);
  transition: width .6s cubic-bezier(.4, 0, .2, 1);
}
.meter-ends {
  display: flex; justify-content: space-between;
  margin-top: .4rem; font-size: .75rem; color: var(--ink-muted);
}

.facts {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: .5rem 1rem; margin: 1.25rem 0 0;
  padding-top: 1rem; border-top: 1px solid var(--hairline);
}
.facts > div { min-width: 0; }
.facts dt {
  font-size: .6875rem; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
}
.facts dd { margin: .15rem 0 0; font-size: .9375rem; font-weight: 600; }
.facts dd small { display: block; font-weight: 400; font-size: .8125rem; color: var(--ink-muted); }

/* ── Chart ───────────────────────────────────────────────────── */
.chart-card { padding-bottom: 1rem; }
.chart-wrap { position: relative; width: 100%; touch-action: pan-y; }
#chart { display: block; width: 100%; height: 260px; }
@media (min-width: 560px) { #chart { height: 300px; } }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  transform: translate(-50%, -125%);
  background: var(--ink); color: var(--page);
  border-radius: 9px; padding: .35rem .55rem;
  font-size: .75rem; line-height: 1.3; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
.tooltip b { font-weight: 650; }

/* ── Day list ────────────────────────────────────────────────── */
.day {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: .3rem .6rem;
  padding: .55rem 0;
  border-top: 1px solid var(--hairline);
  align-items: start;
}
.day:first-child { border-top: 0; padding-top: 0; }
.day.is-today .day-date strong { color: var(--series); }

.day-date { font-size: .75rem; color: var(--ink-muted); line-height: 1.25; }
.day-date strong { display: block; font-size: .875rem; color: var(--ink); font-weight: 650; }

/* Four tides across one phone row, two lines deep, so a month stays scannable. */
.events {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .3rem .4rem;
}
.event {
  display: flex; flex-direction: column; gap: .05rem;
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 0;
}
.event .t { font-weight: 620; letter-spacing: -.02em; }
.event .t i { font-style: normal; font-size: .625rem; margin-right: .18rem; }
.event.is-high .t i { color: var(--series); }
.event.is-low .t i { color: var(--ink-muted); }
.event .h { color: var(--ink-muted); font-size: .75rem; }
.event.is-past { opacity: .4; }

@media (max-width: 340px) { .event { font-size: .75rem; } }

/* ── Footer ──────────────────────────────────────────────────── */
.foot { color: var(--ink-muted); font-size: .75rem; line-height: 1.55; padding: 0 .25rem; }
.foot p { margin: 0 0 .6rem; }
.foot .about {
  color: var(--ink-2); font-size: .8125rem; line-height: 1.6;
  margin-bottom: .75rem;
}
.foot strong { color: var(--ink-2); }
.foot a { color: var(--ink-2); }
.offline-hint { color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
