/* Set Sail — a calm coastal theme.
   Sea-glass accent, readable neutral surfaces, restrained nautical language,
   large touch targets, labels as well as colour, and motion that gets out of
   the way when the phone asks it to. */

/* --------------------------------------------------------------- tokens
   Each hue has three roles, because one value cannot do all three jobs:

     --x         the FILL. Bars, rings, indicators, chips. Never type.
     --on-x      the label drawn ON that fill.
     --x-text    the same hue as TYPE on a page background.

   The palette used to have only the fill. Using it as text put the most-read
   copy in the app at about 3.5:1, and the accent at 2.9:1. The hues below are
   unchanged; the text roles are new, and every pair is checked by
   test/contrast.test.js, which resolves color-mix() the same way a browser
   does and fails the build if any pair drops below its floor. */

:root {
  color-scheme: light dark;

  --sea-deep:  #062534;
  --sea:       #0d4f68;
  --sea-mid:   #1b6f87;
  --seaglass:  #21a99a;
  --seaglass-2:#4fd0bd;
  --seaglass-wash: #e4f6f3;
  --sand:      #f6ecdd;
  --sand-deep: #e8d7bf;
  --coral:     #f2745a;
  --sun:       #f0ae53;
  --plum:      #6b5b95;

  --bg:        #eef5f6;
  --bg-2:      #e3eef0;
  --surface:   #ffffff;
  --surface-2: #f7fbfb;
  --line:      #d9e5e7;
  --line-soft: #e9f1f2;
  /* Borders that have to be SEEN rather than merely suggested: an input's
     edge, a chip's outline, an empty checkbox. --line is 1.2:1 and vanishes
     in daylight. */
  --line-strong: #78909a;
  --ink:       #0e2430;
  --ink-2:     #3d5a66;
  --ink-3:     #527079;
  --ink-inv:   #ffffff;

  --ok:        #2f9e6f;
  --warn:      #d98324;
  --bad:       #cf5147;
  --pending:   #7a8f99;

  /* Type roles. */
  --accent-text:  #0c746b;
  --ok-text:      #1b7450;
  --warn-text:    #8f5410;
  --bad-text:     #b53a30;
  --pending-text: #566d77;
  --plum-text:    #6b5b95;
  --xp-text:      #7d5a1c;
  --stamp-ink:    #a8452f;

  /* Filled surfaces and the label that sits on them. The gradient used to
     start at --seaglass, where white is 2.9:1 — the primary button, the
     countdown chip and the completed tick were all below it. */
  --grad-accent: linear-gradient(135deg, #12807a 0%, var(--sea-mid) 100%);
  --on-accent: #ffffff;
  --reward: var(--coral);
  --on-reward: #062534;

  --r-xs: 8px; --r-sm: 12px; --r: 16px; --r-lg: 22px; --r-xl: 28px; --r-pill: 999px;

  /* Spacing, on a 4pt grid. --pad stays as the screen gutter. */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px;
  --pad: var(--sp-4);

  /* Type. Nothing below --fs-caption is allowed to be a sentence, and nothing
     at all goes below 11px. The app's most common text was 11.2px. */
  --fs-overline: .6875rem;  /* 11px — uppercase labels only */
  --fs-caption:  .75rem;    /* 12px — tags, axis labels, timestamps */
  --fs-note:     .8125rem;  /* 13px — the floor for a sentence */
  --fs-body:     .9375rem;  /* 15px */
  --fs-md:       1rem;
  --fs-h3:       1.0625rem;
  --fs-h2:       1.25rem;
  --fs-h1:       1.75rem;
  --fs-display:  2rem;

  --shadow-1: 0 1px 2px rgba(6,37,52,.06), 0 2px 8px rgba(6,37,52,.05);
  --shadow-2: 0 2px 6px rgba(6,37,52,.07), 0 12px 28px rgba(6,37,52,.09);
  --shadow-up: 0 -2px 16px rgba(6,37,52,.07);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-display: ui-rounded, -apple-system, "SF Pro Rounded", "Segoe UI Variable Display", system-ui, sans-serif;

  --tap: 48px;
  --tap-min: 44px;
  --shell: 540px;

  /* Motion. One curve, four durations, so a press and a sheet do not have to
     invent their own timings. */
  --dur-1: 120ms;  /* press */
  --dur-2: 200ms;  /* state change */
  --dur-3: 320ms;  /* enter / sheet */
  --dur-4: 700ms;  /* progress sweep */
  --ease: cubic-bezier(.22,.68,.36,1);

  --z-mast: 30; --z-tab: 40; --z-sheet: 50; --z-toast: 60; --z-status: 100;
}

/* The dark palette is declared twice on purpose: the media query is what
   paints correctly before any JavaScript has run, and the attribute is what a
   deliberate Light/Dark choice sets. test/contrast.test.js asserts the two
   blocks stay identical — they had already drifted, leaving the status
   colours, plum and the link colour with no dark value at all. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #04151e;
    --bg-2:      #071e29;
    --surface:   #0b2734;
    --surface-2: #0f3040;
    --line:      #17404f;
    --line-soft: #123644;
    --line-strong: #4a7d8e;
    --ink:       #e6f2f3;
    --ink-2:     #a9c6ce;
    --ink-3:     #8aa9b3;
    --sand:      #241f14;
    --sand-deep: #3d3524;
    --seaglass-wash: #0d3b3a;
    --seaglass:  #45c3b2;
    --seaglass-2:#6fe0cd;
    --accent-text:  #6fe0cd;
    --ok-text:      #5fcf9f;
    --warn-text:    #f0b565;
    --bad-text:     #f28b81;
    --pending-text: #9db2bb;
    --plum-text:    #b9acdf;
    --xp-text:      #f3c988;
    --stamp-ink:    #ffb09b;
    --grad-accent: linear-gradient(135deg, var(--seaglass) 0%, var(--seaglass-2) 100%);
    --on-accent: #062534;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 2px 8px rgba(0,0,0,.45), 0 16px 32px rgba(0,0,0,.35);
    --shadow-up: 0 -2px 18px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg:        #04151e;
  --bg-2:      #071e29;
  --surface:   #0b2734;
  --surface-2: #0f3040;
  --line:      #17404f;
  --line-soft: #123644;
  --line-strong: #4a7d8e;
  --ink:       #e6f2f3;
  --ink-2:     #a9c6ce;
  --ink-3:     #8aa9b3;
  --sand:      #241f14;
  --sand-deep: #3d3524;
  --seaglass-wash: #0d3b3a;
  --seaglass:  #45c3b2;
  --seaglass-2:#6fe0cd;
  --accent-text:  #6fe0cd;
  --ok-text:      #5fcf9f;
  --warn-text:    #f0b565;
  --bad-text:     #f28b81;
  --pending-text: #9db2bb;
  --plum-text:    #b9acdf;
  --xp-text:      #f3c988;
  --stamp-ink:    #ffb09b;
  --grad-accent: linear-gradient(135deg, var(--seaglass) 0%, var(--seaglass-2) 100%);
  --on-accent: #062534;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 2px 8px rgba(0,0,0,.45), 0 16px 32px rgba(0,0,0,.35);
  --shadow-up: 0 -2px 18px rgba(0,0,0,.4);
}

/* Follows iOS "Increase Contrast". Secondary text becomes primary text, the
   soft borders become the strong one, and the blurred bars go opaque. */
@media (prefers-contrast: more) {
  :root {
    --ink-3: var(--ink-2);
    --line: var(--line-strong);
    --line-soft: var(--line-strong);
  }
  .masthead, .tabbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* iOS status bar.
   apple-mobile-web-app-status-bar-style is black-translucent, which is what
   gives the edge-to-edge layout and a non-zero safe-area inset — but it also
   makes the clock and battery white, over a masthead that is nearly white in
   the light theme. This paints the inset itself, so that text always has a
   dark surface under it. It collapses to nothing on desktop and in landscape. */
body::before {
  content: ''; position: fixed; inset: 0 0 auto 0;
  height: env(safe-area-inset-top); background: var(--sea-deep);
  z-index: 100; pointer-events: none;
}

html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
body {
  background-image:
    radial-gradient(120% 60% at 50% 0%, var(--bg-2) 0%, transparent 60%);
  background-attachment: fixed;
}

h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 650; letter-spacing: -.015em; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.02rem; }
p  { margin: 0; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
a.btn { text-decoration: none; }

/* The accent, and the status hues, as type. Screens used to set these inline
   with the fill colour, which CSS tokens could not reach. */
.text-accent { color: var(--accent-text); }
.text-warn { color: var(--warn-text); }
.text-bad { color: var(--bad-text); }
.text-pending { color: var(--pending-text); }

.app {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 var(--pad) calc(var(--tap) + 46px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------------------------------------------------------------- header */
.masthead {
  position: sticky; top: 0; z-index: 30;
  margin: 0 calc(var(--pad) * -1);
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s var(--ease);
}
.masthead.scrolled { border-bottom-color: var(--line-soft); }
.masthead-row { display: flex; align-items: center; gap: 10px; }
.wordmark {
  font-family: var(--font-display); font-weight: 700; font-size: 1.12rem;
  letter-spacing: -.02em; display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0;
}
.wordmark .mark { font-size: 1.2rem; }
.wordmark small { display: block; font-size: var(--fs-overline); font-weight: 500; color: var(--ink-3); letter-spacing: 0; }

.countdown-chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 6px 11px; border-radius: var(--r-pill);
  background: var(--grad-accent);
  color: var(--on-accent); font-weight: 650; font-size: var(--fs-caption);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--seaglass) 35%, transparent);
  white-space: nowrap;
}
.countdown-chip b { font-size: 1rem; font-family: var(--font-display); }

.icon-btn {
  width: var(--tap-min); height: var(--tap-min);
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  font-size: 1.05rem; position: relative;
  transition: transform .12s var(--ease), background .15s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn .dot {
  position: absolute; top: 4px; right: 5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--coral); border: 2px solid var(--surface);
}

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--pad);
  box-shadow: var(--shadow-1);
  margin-bottom: 12px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
/* min-content, so a heading never breaks mid-word to keep a chip company —
   the chips wrap to the next line instead, which is what they are for. */
.card-head h2, .card-head h3 { flex: 1 1 auto; }
.card-note {
  font-size: var(--fs-note); color: var(--ink-3); line-height: 1.5; margin-top: 10px;
  padding-top: 10px; border-top: 1px dashed var(--line);
}

.section-title {
  font-family: var(--font-display); font-weight: 650; font-size: var(--fs-overline);
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-3);
  margin: 22px 2px 9px; display: flex; align-items: center; gap: 8px;
}
.section-title .rule { flex: 1; height: 1px; background: var(--line); }

/* ---------------------------------------------------------------- hero */
.hero {
  position: relative; overflow: hidden;
  border-radius: var(--r-xl);
  background: linear-gradient(170deg, var(--sea-deep) 0%, var(--sea) 52%, var(--sea-mid) 100%);
  color: #fff; padding: 20px var(--pad) 0;
  margin-bottom: 14px;
  box-shadow: var(--shadow-2);
  isolation: isolate;
}
.hero::before {
  content: ''; position: absolute; inset: -40% -20% auto -20%; height: 150%;
  background: radial-gradient(60% 50% at 78% 12%, rgba(240,174,83,.35), transparent 70%);
  z-index: -1;
}
.hero h1 { font-size: 1.85rem; line-height: 1.12; }
.hero .lede { color: rgba(255,255,255,.9); font-size: var(--fs-body); margin-top: 6px; }
.hero-waves { display: block; width: 100%; height: 54px; margin: 12px -16px -1px; width: calc(100% + 32px); }
.hero-stats { display: flex; gap: 18px; margin-top: 14px; flex-wrap: wrap; }
.hero-stat b { display: block; font-family: var(--font-display); font-size: 1.32rem; line-height: 1.1; }
.hero-stat span { font-size: var(--fs-caption); color: rgba(255,255,255,.88); text-transform: uppercase; letter-spacing: .07em; }

@media (prefers-reduced-motion: no-preference) {
  .wave-anim { animation: drift 14s linear infinite; }
  .wave-anim.slow { animation-duration: 22s; animation-direction: reverse; }
}
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-120px); } }

/* ---------------------------------------------------------------- mission */
.mission {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  margin-bottom: 9px; position: relative;
  transition: background .18s var(--ease), border-color .18s;
}
.mission.done { background: var(--seaglass-wash); border-color: color-mix(in srgb, var(--seaglass) 35%, transparent); }
.mission.rest { background: color-mix(in srgb, var(--plum) 10%, var(--surface-2)); border-color: color-mix(in srgb, var(--plum) 28%, transparent); }
.mission-check {
  flex: none; width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--surface);
  display: grid; place-items: center; font-size: 1.15rem; cursor: pointer;
  transition: transform .15s var(--ease), background .2s, border-color .2s;
}
.mission-check:active { transform: scale(.9); }
.mission.done .mission-check { background: var(--grad-accent); border-color: transparent; color: var(--on-accent); }
.mission.rest .mission-check { background: var(--plum); border-color: var(--plum); color: #fff; }
.mission-body { flex: 1; min-width: 0; }
.mission-title { font-weight: 620; font-size: 1rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mission-meta { font-size: var(--fs-note); color: var(--ink-3); margin-top: 3px; line-height: 1.5; }
.mission-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-caption); font-weight: 600; letter-spacing: .02em;
  padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--line-soft); color: var(--ink-2); white-space: nowrap;
}
.tag.xp { background: color-mix(in srgb, var(--sun) 22%, var(--surface)); color: var(--xp-text); }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok-text); }
.tag.warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--warn-text); }
.tag.bad { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad-text); }
.tag.pending { background: var(--line-soft); color: var(--pending-text); }
.tag.sim { background: color-mix(in srgb, var(--plum) 16%, var(--surface)); color: var(--plum-text); }

/* ---------------------------------------------------------------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: var(--r-pill); padding: 10px 16px;
  font-weight: 600; font-size: var(--fs-body); cursor: pointer; min-height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .12s var(--ease), background .16s, border-color .16s, opacity .16s;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: var(--grad-accent);
  border-color: transparent; color: var(--on-accent);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--seaglass) 32%, transparent);
}
.btn.coral { background: var(--reward); border-color: transparent; color: var(--on-reward); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-3); padding: 8px 10px; }
/* Smaller type and tighter padding read as secondary; the touch target stays
   the 44px inherited from .btn, because a thumb is the same size either way. */
.btn.sm { padding: 7px 12px; font-size: var(--fs-note); }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad-text); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.stretch .btn { flex: 1; }

/* ---------------------------------------------------------------- ring */
.ring-wrap { display: flex; align-items: center; gap: 14px; }
.ring { flex: none; position: relative; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring .ring-track { stroke: var(--line); }
.ring .ring-fill { stroke: url(#ringGrad); stroke-linecap: round; transition: stroke-dashoffset .7s var(--ease); }
.ring-label {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  font-family: var(--font-display); line-height: 1;
}
.ring-label b { font-size: 1.15rem; display: block; }
.ring-label span { font-size: var(--fs-overline); color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }

/* ---------------------------------------------------------------- bars */
.bar { height: 10px; border-radius: var(--r-pill); background: var(--line-soft); overflow: hidden; position: relative; }
.bar > i {
  display: block; height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--seaglass) 0%, var(--seaglass-2) 100%);
  transition: width .7s var(--ease);
}
.bar.coral > i { background: linear-gradient(90deg, var(--coral) 0%, var(--sun) 100%); }
.bar.thin { height: 6px; }
.bar-legend { display: flex; justify-content: space-between; font-size: var(--fs-caption); color: var(--ink-3); margin-top: 6px; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-note); }
/* .tiny is a LABEL size. Sentence-length copy that used it has moved to
   .small, which is the 13px floor for anything with a verb in it. */
.tiny { font-size: var(--fs-caption); }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- member */
.member {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-soft);
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 1.25rem;
  background: var(--seaglass-wash); border: 1px solid var(--line);
}
.avatar.coral { background: color-mix(in srgb, var(--coral) 16%, var(--surface)); }
.avatar.sm { width: 28px; height: 28px; font-size: .85rem; }
.avatar-stack { display: flex; }
.avatar-stack .avatar + .avatar { margin-left: -10px; }

/* ---------------------------------------------------------------- nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.5) blur(18px);
  -webkit-backdrop-filter: saturate(1.5) blur(18px);
  border-top: 1px solid var(--line-soft);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: var(--shadow-up);
}
.tabbar-inner { display: flex; width: 100%; max-width: var(--shell); }
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px; min-height: var(--tap);
  color: var(--ink-3); font-size: var(--fs-caption); font-weight: 600; letter-spacing: .01em;
  position: relative; transition: color .18s;
}
.tab .glyph { font-size: 1.22rem; line-height: 1.1; transition: transform .22s var(--ease); }
.tab[aria-current="page"] { color: var(--accent-text); }
.tab[aria-current="page"] .glyph { transform: translateY(-1px) scale(1.08); }
.tab[aria-current="page"]::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--seaglass);
}
.tab .pip {
  position: absolute; top: 6px; right: 50%; margin-right: -16px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--coral);
}

/* ---------------------------------------------------------------- sheet */
/* A real <dialog>, so focus containment, focus return, Escape and inertness
   behind it are the platform's job rather than ours. The grip is gone: it
   signalled a drag-to-dismiss that was never implemented, and on an installed
   app people try it. There is a 44px close button instead. */
.sheet-host {
  border: 0; padding: 0; margin: 0 auto auto; max-width: none; max-height: none;
  width: 100%; height: 100%; background: transparent; color: inherit;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-host::backdrop {
  background: rgba(6,24,34,.45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.sheet-host[open] { animation: fade .18s var(--ease); }
body.sheet-open { overflow: hidden; }

.sheet {
  width: 100%; max-width: var(--shell);
  /* Leave room for whatever the keyboard is covering (--kb, from
     visualViewport), or the footer sits underneath it. */
  max-height: calc(92dvh - var(--kb, 0px));
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.28);
  animation: rise var(--dur-3) var(--ease);
  overflow: hidden;
}
.sheet-head {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--pad) 0;
}
.sheet-body {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--sp-2) var(--pad) var(--sp-4);
}
.sheet-foot {
  flex: none; padding: var(--sp-3) var(--pad) calc(var(--sp-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft); background: var(--bg);
}
.sheet:not(:has(.sheet-foot)) .sheet-body {
  padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
}
.sheet-close { flex: none; }
.sheet h2 { margin-bottom: 4px; }
.sheet-sub { color: var(--ink-3); font-size: var(--fs-body); margin-bottom: 14px; line-height: 1.5; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { transform: translateY(16px); opacity: .4 } to { transform: none; opacity: 1 } }
@media (prefers-reduced-motion: reduce) {
  .sheet-host, .sheet { animation: none; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
/* The same switch, driven by the in-app setting. It used only to set --ease to
   linear, which does not stop an animation, and never reverted without a
   reload — so "Reduce animation" reduced nothing anyone could see. */
:root[data-reduce-motion] .sheet-host,
:root[data-reduce-motion] .sheet { animation: none; }
:root[data-reduce-motion] *,
:root[data-reduce-motion] *::before,
:root[data-reduce-motion] *::after {
  animation-duration: .001ms !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}
:root[data-reduce-motion] .wave-anim { animation: none !important; }

/* ---------------------------------------------------------------- forms */
/* A field is a label only when it holds exactly one control and no buttons;
   otherwise it is a role=group (see fieldRow in ui.js). Both are styled the
   same, and the selectors match either element and either hint tag — the old
   `label.field > span.hint` rule left every p.hint unstyled. */
.field { display: block; margin-bottom: 13px; }
.field > .lbl {
  display: block; font-size: var(--fs-note); font-weight: 640; color: var(--ink-2);
  margin-bottom: 5px; letter-spacing: .01em;
}
.field > .hint { display: block; font-size: var(--fs-note); color: var(--ink-3); margin-top: 5px; line-height: 1.5; }

/* A checkbox row is a real label on purpose: the whole row should toggle it. */
.check-row { display: block; }
.check-row > .row { align-items: flex-start; }
.check-row .check-label { font-size: var(--fs-body); line-height: 1.5; }
.check-row input[type=checkbox] { flex: none; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 12px 13px; min-height: var(--tap);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-size: 16px; /* no iOS zoom */
  appearance: none; transition: border-color .16s, box-shadow .16s;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--ink); outline-offset: 2px; border-color: var(--accent-text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--seaglass) 22%, transparent);
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: var(--r-pill); padding: 9px 13px; min-height: var(--tap-min);
  font-size: var(--fs-note); font-weight: 580;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: transform var(--dur-1) var(--ease), background var(--dur-2), border-color var(--dur-2), color var(--dur-2);
}
.chip:active { transform: scale(.95); }
.chip[aria-pressed="true"] {
  background: var(--seaglass-wash); border-color: var(--seaglass); color: color-mix(in srgb, var(--seaglass) 78%, var(--ink));
}
.chip.day { min-width: var(--tap-min); justify-content: center; padding: 9px 4px; }

.seg { display: flex; background: var(--line-soft); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: var(--r-pill); padding: 8px 6px;
  font-size: var(--fs-note); font-weight: 620; color: var(--ink-3); cursor: pointer; min-height: var(--tap-min);
  transition: background .18s var(--ease), color .18s;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------------------------------------------------------------- voyage */
.voyage { position: relative; border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-2); margin-bottom: 14px; }
.voyage svg { display: block; width: 100%; height: auto; }
.port-list { display: flex; flex-direction: column; gap: 8px; }
.port {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  border-radius: var(--r); border: 1px solid var(--line-soft); background: var(--surface-2);
}
.port.reached { background: var(--seaglass-wash); border-color: color-mix(in srgb, var(--seaglass) 34%, transparent); }
.port .glyph { font-size: 1.4rem; width: 34px; text-align: center; flex: none; }
.port.locked .glyph { filter: grayscale(1); opacity: .45; }

/* ---------------------------------------------------------------- passport */
/* Passport ink is themed: the same dark teal that reads well on paper is
   unreadable on the dark page, so both stamp colours flip with the theme. */
.passport {
  --stamp-ink: color-mix(in srgb, var(--coral) 85%, var(--ink));
  --stamp-edge: color-mix(in srgb, var(--coral) 60%, transparent);
  --stamp-crew-ink: var(--sea-mid);
  --stamp-crew-edge: color-mix(in srgb, var(--sea-mid) 60%, transparent);
  background:
    repeating-linear-gradient(0deg, transparent 0 22px, color-mix(in srgb, var(--sand-deep) 40%, transparent) 22px 23px),
    var(--sand);
  border: 1px solid var(--sand-deep); border-radius: var(--r-lg); padding: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .passport {
    --stamp-ink: #ffb09b; --stamp-edge: rgba(255, 176, 155, .55);
    --stamp-crew-ink: var(--seaglass-2); --stamp-crew-edge: color-mix(in srgb, var(--seaglass-2) 55%, transparent);
  }
}
:root[data-theme="dark"] .passport {
  --stamp-ink: #ffb09b; --stamp-edge: rgba(255, 176, 155, .55);
  --stamp-crew-ink: var(--seaglass-2); --stamp-crew-edge: color-mix(in srgb, var(--seaglass-2) 55%, transparent);
}
.stamp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
.stamp {
  aspect-ratio: 1; border-radius: 50%; display: grid; place-content: center; text-align: center;
  border: 2px dashed var(--stamp-edge);
  color: var(--stamp-ink);
  background: color-mix(in srgb, var(--stamp-ink) 8%, transparent);
  padding: 6px; gap: 2px;
}
.stamp .glyph { font-size: 1.5rem; }
.stamp .nm { font-size: var(--fs-overline); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; line-height: 1.15; }
.stamp .dt { font-size: var(--fs-overline); }
.stamp.crew { border-color: var(--stamp-crew-edge); color: var(--stamp-crew-ink); background: color-mix(in srgb, var(--stamp-crew-ink) 8%, transparent); }
@media (prefers-reduced-motion: no-preference) { .stamp { transform: rotate(var(--tilt, -4deg)); } }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.chart .bar-rect { fill: var(--seaglass); transition: height .5s var(--ease), y .5s var(--ease); }
.chart .bar-rect.muted { fill: var(--line); }
.chart .line-path { fill: none; stroke: var(--seaglass); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart .area-path { fill: url(#areaGrad); }
.chart .point { fill: var(--surface); stroke: var(--seaglass); stroke-width: 2; }
.chart .gap { stroke: var(--line); stroke-dasharray: 2 3; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(94px, 1fr)); gap: 9px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 11px 12px;
}
.stat b { display: block; font-family: var(--font-display); font-size: 1.25rem; line-height: 1.15; }
.stat span { font-size: var(--fs-overline); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.stat .sub { font-size: var(--fs-caption); color: var(--ink-3); text-transform: none; letter-spacing: 0; margin-top: 3px; }

/* ---------------------------------------------------------------- misc */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--tap) + 60px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 var(--pad); }
.toast {
  background: var(--sea-deep); color: #fff; padding: 11px 16px; border-radius: var(--r-pill);
  font-size: var(--fs-body); font-weight: 560; box-shadow: var(--shadow-2); max-width: 100%;
  animation: rise .25s var(--ease); display: flex; align-items: center; gap: 8px; pointer-events: auto;
}
.toast.win { background: var(--grad-accent); color: var(--on-accent); }
/* A failure has to look different from a confirmation, not just read
   differently — the two were identical pills. */
.toast.bad { background: var(--bad); }
.toast-action {
  flex: none; margin: -6px -8px -6px 4px; padding: 6px 12px; min-height: 32px;
  border: 0; border-radius: var(--r-pill); cursor: pointer;
  background: rgba(255,255,255,.18); color: #fff;
  font: inherit; font-size: var(--fs-note); font-weight: 650;
}
.toast-action:active { transform: scale(.96); }

.empty { text-align: center; padding: 26px 16px; color: var(--ink-3); }
.empty .glyph { font-size: 2.2rem; display: block; margin-bottom: 8px; opacity: .8; }
.empty p { font-size: var(--fs-body); line-height: 1.55; }

.banner {
  display: flex; gap: 10px; padding: 12px 13px; border-radius: var(--r);
  background: color-mix(in srgb, var(--sun) 15%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--sun) 40%, transparent);
  font-size: var(--fs-note); line-height: 1.5; margin-bottom: 12px;
}
.banner.info { background: var(--seaglass-wash); border-color: color-mix(in srgb, var(--seaglass) 32%, transparent); }
.banner.bad { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 32%, transparent); }
.banner .glyph { font-size: 1.15rem; flex: none; }

.list-row {
  display: flex; align-items: center; gap: 11px; padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.list-row:last-child { border-bottom: 0; }
.list-row .glyph { font-size: 1.25rem; width: 28px; text-align: center; flex: none; }

.skeleton {
  background: linear-gradient(90deg, var(--line-soft) 25%, var(--line) 37%, var(--line-soft) 63%);
  background-size: 400% 100%; border-radius: var(--r-sm); animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

.auth-wrap { max-width: 400px; margin: 0 auto; padding-top: 6vh; }
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .mark { font-size: 3rem; display: block; }
.auth-logo h1 { margin-top: 6px; }
.auth-logo p { color: var(--ink-3); font-size: var(--fs-body); margin-top: 6px; }

.progress-steps { display: flex; gap: 5px; margin-bottom: 18px; }
.progress-steps i { flex: 1; height: 4px; border-radius: 3px; background: var(--line); transition: background .3s; }
.progress-steps i.on { background: var(--seaglass); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--seaglass); outline-offset: 2px; border-radius: 4px; }

.screen { animation: enter .26s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ------------------------------------------------- stale / offline notice */
/* Shown when a background refresh failed and what is on screen is the last
   good copy. Deliberately slim: the content behind it is still usable. */
.stale-note {
  position: sticky; top: 0; z-index: 29;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 calc(var(--pad) * -1) 10px;
  padding: 7px var(--pad);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  color: var(--ink-2); font-size: var(--fs-note); line-height: 1.4;
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.stale-note .btn { min-height: var(--tap-min); padding: 4px 10px; }

/* -------------------------------------------- saving, and failing to save */
.field-saved {
  margin-left: 8px; font-size: var(--fs-caption); font-weight: 600;
  color: var(--ok-text); transition: opacity var(--dur-2);
}
.field-saved.fading { opacity: 0; }
.field-error {
  margin-top: 5px; font-size: var(--fs-note); line-height: 1.45;
  color: var(--bad-text);
}
[aria-busy="true"] { opacity: .6; cursor: progress; }
button[aria-busy="true"] { position: relative; }

/* ---------------------------------------------------------- today: hero */
/* Compact. The old hero spent a whole phone screen on a second countdown, a
   whole-week percentage that reads as failure on a Monday, and a crew figure
   that gave away a number the other person may have withheld — so the first
   mission check, the one thing anyone opens this screen for, sat at the fold. */
.hero-row { display: flex; align-items: flex-start; gap: var(--sp-4); }
.hero h1 { font-size: var(--fs-h1); line-height: 1.12; }
.hero-ring { flex: none; text-align: center; }
.hero-ring .ring-label b { color: #fff; }
.hero-ring .ring-label span { color: rgba(255,255,255,.8); }
.hero-ring .ring-track { stroke: rgba(255,255,255,.25); }
.hero-ring-label {
  display: block; margin-top: 4px;
  font-size: var(--fs-overline); text-transform: uppercase; letter-spacing: .06em;
  color: rgba(255,255,255,.8);
}
/* As the pier gets closer the sky warms. Scenery, never pressure: no copy
   anywhere counts down "only N days left to…". */
.hero[data-phase="landfall"]::before { background: radial-gradient(60% 50% at 78% 12%, rgba(240,174,83,.45), transparent 70%); }
.hero[data-phase="departure-week"]::before { background: radial-gradient(65% 55% at 74% 14%, rgba(242,116,90,.42), transparent 72%); }
.hero[data-phase="departure-day"]::before,
.hero[data-phase="bon-voyage"]::before { background: radial-gradient(70% 60% at 70% 16%, rgba(255,206,133,.5), transparent 74%); }

/* ------------------------------------------------------- today: feeling */
/* The person's own answer sits above the band, because the app says out loud
   that it takes precedence. */
.feel-card { padding-bottom: var(--sp-3); }
.feel-row { display: flex; gap: var(--sp-2); }
.feel-row .chip { flex: 1; justify-content: center; text-transform: capitalize; }

.card-done { border-color: color-mix(in srgb, var(--seaglass) 40%, transparent); }
.card.paper { background: var(--sand); border-color: var(--sand-deep); }
.card.paper .stat { background: color-mix(in srgb, var(--surface) 55%, transparent); }

/* --------------------------------------------------- today: energy strip */
/* A <details> rather than a permanently open card: the band stays visible with
   its framing and its provenance, and the ring, chips, sync and disclaimer are
   one tap in. Nothing is deleted — it moves. */
.disclose > summary {
  display: flex; align-items: center; gap: var(--sp-3);
  cursor: pointer; list-style: none; min-height: var(--tap-min);
}
.disclose > summary::-webkit-details-marker { display: none; }
.disclose > summary::after {
  content: '⌄'; flex: none; color: var(--ink-3); font-size: var(--fs-h3);
  line-height: 1; transition: transform var(--dur-2) var(--ease);
}
.disclose[open] > summary::after { transform: rotate(180deg); }
.disclose > summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: var(--r-xs); }
.energy-summary .block { display: block; }
.energy-summary .grow { min-width: 0; }
.energy-meta {
  display: flex; align-items: center; gap: var(--sp-2);
  flex-wrap: wrap; margin-top: 3px;
}
.energy-dot {
  flex: none; width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
}
.energy-dot.band-green { background: var(--ok); }
.energy-dot.band-yellow { background: var(--sun); }
.energy-dot.band-red { background: var(--coral); }
.energy-dot.band-unknown { background: var(--line-strong); }
