/* =========================================================================
   start.css — the THRESHOLD. A living hero, a quiet "signed in" mark, ONE Gym
   pill, two quiet secondary links, and the cinematic launch into logging.
   Restraint is the aesthetic: this is a small, calm part of the app.
   ========================================================================= */

/* ---- GLOBAL MODE ACCENT (single source of truth) -----------------------
   The Normal/Advanced preference lives in Settings and is reflected as
   <html data-mode>. Advanced remaps the app accent token globally — the Gym
   pill, body-map heat, selection, every `var(--accent)` follows from here.
   Normal is the base lime already defined in styles.css, so it needs no rule. */
:root[data-mode="advanced"] {
  --accent:     var(--accent-advanced);
  --accent-ink: var(--accent-advanced-ink);
  --accent-dim: var(--accent-advanced-dim);
}

/* Auth-status green — denotes SIGNED IN, never training mode, so it is fixed
   regardless of Normal/Advanced. */
:root { --signal-green: #3ddc84; }

/* =======================================================================
   Start view — full-bleed, centered, phone-first.
   ======================================================================= */
#start-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(var(--s-6), env(safe-area-inset-top)) var(--s-5)
           max(var(--s-7), env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--bg);
}

/* ---- Living background. The CSS gradient paints INSTANTLY; the WebGL canvas
   sits on top at opacity 0 and fades in only once it has drawn a frame
   (.is-ready), so there is never a blank flash while the shader compiles, and
   a fallback/context-loss simply leaves this gradient on show. ---- */
.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  /* on-brand off-black field with a soft mode-accent bloom + a chrome sheen */
  background:
    radial-gradient(120% 90% at 50% 18%, color-mix(in oklab, var(--accent) 16%, transparent), transparent 60%),
    radial-gradient(90% 70% at 78% 88%, color-mix(in oklab, var(--surface-2) 70%, transparent), transparent 65%),
    radial-gradient(80% 80% at 20% 80%, color-mix(in oklab, var(--accent) 8%, transparent), transparent 60%),
    linear-gradient(160deg, var(--bg-2), var(--bg) 70%);
}
@media (prefers-reduced-motion: no-preference) {
  .hero-bg { animation: hero-drift 24s var(--ease) infinite alternate; }
  @keyframes hero-drift {
    from { background-position: 0 0, 0 0, 0 0, 0 0; filter: saturate(1); }
    to   { background-position: 0 -16px, 0 12px, 0 -8px, 0 0; filter: saturate(1.12); }
  }
}
.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 640ms var(--ease);
}
.hero-canvas.is-ready { opacity: 1; }
/* A readability scrim so ink always clears the moving chrome behind it. */
.hero-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(70% 55% at 50% 52%, transparent, color-mix(in oklab, var(--bg) 62%, transparent) 100%);
  pointer-events: none;
}

.start-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-5);
  text-align: center;
  width: 100%;
  max-width: 420px;
}

/* ---- "Signed in" mark — a small, calm, self-drawing GREEN check. ---- */
.signed-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill);
  background: color-mix(in oklab, var(--signal-green) 9%, transparent);
  border: 1px solid color-mix(in oklab, var(--signal-green) 26%, transparent);
  font-size: var(--t--1);
  letter-spacing: -0.01em;
  color: var(--ink-dim);
}
.signed-text b, .signed-mark #start-who { color: var(--ink); }
.signed-check { width: 18px; height: 18px; flex: none; overflow: visible; }
.signed-ring {
  fill: none;
  stroke: color-mix(in oklab, var(--signal-green) 55%, transparent);
  stroke-width: 1.6;
}
.signed-tick {
  fill: none;
  stroke: var(--signal-green);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (prefers-reduced-motion: no-preference) {
  /* The check draws itself, then gives a single gentle pulse. Replays whenever
     the start view is (re)shown, since display:none→flex restarts animations. */
  .signed-tick {
    stroke-dasharray: 22;
    stroke-dashoffset: 22;
    animation: tick-draw 560ms var(--ease) 120ms both;
  }
  .signed-check { animation: signed-pulse 2.8s var(--ease) 900ms infinite; }
  @keyframes tick-draw { to { stroke-dashoffset: 0; } }
  @keyframes signed-pulse {
    0%, 70%, 100% { transform: scale(1); }
    78% { transform: scale(1.12); }
  }
}

.start-wordmark {
  font-size: var(--t-4);
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 0.95;
  margin: 0;
}
.start-wordmark b { color: var(--accent); }

/* ---- THE HERO: Gym pill. The single, unmistakable primary action. Colour is
   the mode accent (lime / red) via --accent; a soft idle breathing glow; a
   satisfying press. ---- */
.gym-pill {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 76px;
  padding: var(--s-3) var(--s-8);
  border: none;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow:
    0 18px 50px -16px color-mix(in oklab, var(--accent) 70%, transparent),
    0 2px 0 0 color-mix(in oklab, var(--accent-ink) 12%, transparent) inset;
  cursor: pointer;
  transition: transform var(--fast) var(--ease), box-shadow var(--med) var(--ease), filter var(--fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.gym-pill-label {
  font-size: var(--t-2);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}
.gym-pill-sub {
  font-size: var(--t--1);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.72;
}
.gym-pill:hover { filter: brightness(1.04); }
.gym-pill:active { transform: scale(0.96); filter: brightness(0.98); }
.gym-pill:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}
@media (prefers-reduced-motion: no-preference) {
  .gym-pill { animation: pill-breathe 3.6s var(--ease) infinite; }
  @keyframes pill-breathe {
    0%, 100% { box-shadow: 0 16px 44px -18px color-mix(in oklab, var(--accent) 60%, transparent), 0 2px 0 0 color-mix(in oklab, var(--accent-ink) 12%, transparent) inset; }
    50%      { box-shadow: 0 22px 62px -14px color-mix(in oklab, var(--accent) 85%, transparent), 0 2px 0 0 color-mix(in oklab, var(--accent-ink) 12%, transparent) inset; }
  }
}

/* ---- Secondary links — quieter than the pill (muted ink + weight), but still
   clearly legible and a full thumb target over the moving background. ---- */
.start-secondary {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-2);
}
.start-link {
  background: none;
  border: none;
  min-height: var(--tap);
  padding: 0 var(--s-3);
  font-family: var(--font-ui);
  font-size: var(--t-0);
  font-weight: 500;
  color: var(--ink-dim);            /* lower-emphasis, but meets contrast over the scrim */
  letter-spacing: -0.01em;
  cursor: pointer;
  border-radius: var(--r-1);
  transition: color var(--fast) var(--ease);
}
.start-link:hover { color: var(--ink); }
.start-link:focus-visible { outline: 2px solid var(--ink-dim); outline-offset: 3px; color: var(--ink); }
.start-sep { color: var(--ink-faint); }

/* =======================================================================
   Logo-as-home — the topbar wordmark is now a real button. Strip the default
   button chrome; keep a clear focus/press state (it IS a control).
   ======================================================================= */
.topbar button.brand {
  background: none;
  border: none;
  min-height: auto;
  padding: var(--s-1) var(--s-2);
  margin: calc(-1 * var(--s-1)) calc(-1 * var(--s-2));
  border-radius: var(--r-1);
  cursor: pointer;
  color: var(--ink);
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.topbar button.brand:hover { opacity: 0.82; }
.topbar button.brand:active { transform: scale(0.97); }
.topbar button.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The topbar now carries three actions (Settings · End of day · Sign out) next
   to the logo. Keep them compact so the row never overflows on a small phone;
   the redundant "Signed in" text (the start screen already shows it) folds away
   first on the narrowest widths. */
.topbar #settings-open,
.topbar #eod-open,
.topbar #logout {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  font-size: var(--t--1);
}
/* The logo wordmark is the lowest-priority text — let it truncate before it can
   ever shove the action controls off-screen (it never should, but it's the
   ultimate guard at extreme widths). */
.topbar .brand .wordmark {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 460px) {
  .topbar { gap: var(--s-2); }
  .topbar .who-wrap { display: none; }
}
/* Phone-narrow: the three action controls collapse to their glyph so the header
   row (logo · ⚙ · ◐ · →) never collides or overflows down to ~320px. Each stays
   a full thumb target; the accessible name lives on the button's aria-label. */
@media (max-width: 400px) {
  .topbar .btn-label { display: none; }
  .topbar #settings-open,
  .topbar #eod-open,
  .topbar #logout {
    width: var(--tap);
    min-width: var(--tap);
    padding: 0;
    gap: 0;
  }
}

/* =======================================================================
   Cinematic LAUNCH — start recedes/dissolves as logging rises in, so it feels
   like ENTERING the app. ~500ms, eased. Reduced motion → instant swap.
   ======================================================================= */
@media (prefers-reduced-motion: no-preference) {
  #start-view.is-launching .start-inner { animation: start-recede 460ms var(--ease-exit) both; }
  #start-view.is-launching .hero-bg     { animation: hero-recede 520ms var(--ease-exit) both; }
  #app-view.is-entering                 { animation: app-rise 520ms var(--ease) both; }

  @keyframes start-recede { to { opacity: 0; transform: scale(1.06); } }
  @keyframes hero-recede  { to { opacity: 0; transform: scale(1.22); filter: blur(8px); } }
  @keyframes app-rise     { from { opacity: 0; transform: translateY(20px) scale(0.985); } }
}

/* =======================================================================
   Settings modal — the ONE home for the Normal/Advanced toggle + body-map
   default. Reachable from the small ⚙ control in the topbar.
   ======================================================================= */
.set-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--s-4);
  background: color-mix(in oklab, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
@media (min-width: 560px) { .set-overlay { align-items: center; } }
@media (prefers-reduced-motion: no-preference) {
  .set-overlay { animation: set-scrim var(--dur-exit) var(--ease) both; }
  .set-overlay .set-card { animation: set-rise var(--dur-enter) var(--ease) both; }
  @keyframes set-scrim { from { opacity: 0; } }
  @keyframes set-rise { from { opacity: 0; transform: translateY(16px); } }
}
.set-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  padding: var(--s-5);
  padding-bottom: max(var(--s-5), env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-3);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.9);
}
.set-head { margin-bottom: var(--s-5); }
.set-head h2 { font-size: var(--t-3); }
.set-close {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0;
  font-size: var(--t-2);
  line-height: 1;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  color: var(--ink-dim);
}
.set-close:hover { color: var(--ink); }

.set-field { margin-top: var(--s-5); }
.set-field:first-of-type { margin-top: 0; }
.set-label { font-size: var(--t-1); margin-bottom: var(--s-1); }
.set-hint { margin: 0 0 var(--s-3); font-size: var(--t--1); color: var(--ink-dim); }

.set-seg {
  display: flex;
  gap: var(--s-2);
}
.set-seg-opt {
  flex: 1 1 0;
  min-width: 0;            /* let the two options share the row and shrink to fit
                             — without this their content keeps "Advanced"/"Female"
                             off the right edge below ~360px */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: var(--tap);
  padding: var(--s-3);
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  color: var(--ink-dim);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.set-seg-opt:hover { color: var(--ink); }
.set-seg-opt.is-on {
  background: color-mix(in oklab, var(--accent) 16%, var(--surface-2));
  border-color: var(--accent);
  color: var(--ink);
}
.set-seg-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.set-seg-name { font-size: var(--t-0); font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.set-seg-desc { font-size: var(--t--1); color: var(--ink-faint); overflow-wrap: anywhere; }
.set-seg-opt.is-on .set-seg-desc { color: var(--ink-dim); }
