/* wearable — the day sheet, stage bar, strain arc, zone ring, state marks. Tokens only; both themes; reduce-motion.

   The band's numbers are drawn in the sea: deep water for deep sleep, the
   mid-channel blue for light sleep, sea-glass for REM and a driftwood grey
   for awake — no coral, no plum, and no red or amber anywhere near a body
   reading. Zones are one sea-glass ramp that darkens (or, on the dark theme,
   brightens) as the heart works harder; zone 0 is neutral. Every mark has its
   words beside it.

   Every fill here is a mark on a card, so each one reaches 3:1 against
   --surface in both themes (WCAG 1.4.11) — a pale shallows-green or a sand
   that vanished into the white card read as a gap, not a stage. The four
   stages also differ from each other in hue, not only in lightness.

   Motion: the stage bar, the strain arc and the zone ring each draw in once,
   when the person opens the sheet themselves. The app-wide reduce-motion
   switch (app.css) and the rules at the foot of this file make them simply
   be there. */

:root {
  --stage-deep:  var(--sea-deep);
  --stage-rem:   color-mix(in srgb, var(--seaglass) 86%, var(--sea));
  --stage-light: var(--sea-mid);
  --stage-awake: color-mix(in srgb, var(--sand-deep) 34%, var(--ink-2));
  --zone-far:    var(--sea-deep);
  --z0: var(--line-strong);
  --z1: color-mix(in srgb, var(--seaglass) 88%, var(--zone-far));
  --z2: color-mix(in srgb, var(--seaglass) 70%, var(--zone-far));
  --z3: color-mix(in srgb, var(--seaglass) 50%, var(--zone-far));
  --z4: color-mix(in srgb, var(--seaglass) 31%, var(--zone-far));
  --z5: color-mix(in srgb, var(--seaglass) 14%, var(--zone-far));
  /* Calibrating: neutral, not a hue — and still a mark you can see. */
  --neutral-fill: var(--line-strong);
}
/* The dark sea is darker than the card, so the deep end of each ramp turns
   toward the light instead. Declared twice, like app.css: the media query
   paints before any script runs; the attribute is a deliberate choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --stage-deep:  color-mix(in srgb, var(--sea-mid) 72%, var(--ink-2));
    --stage-rem:   var(--seaglass);
    --stage-light: color-mix(in srgb, var(--seaglass-2) 55%, var(--ink));
    --stage-awake: color-mix(in srgb, var(--sand-deep) 45%, var(--ink));
    --zone-far:    var(--ink);
  }
}
:root[data-theme="dark"] {
  --stage-deep:  color-mix(in srgb, var(--sea-mid) 72%, var(--ink-2));
  --stage-rem:   var(--seaglass);
  --stage-light: color-mix(in srgb, var(--seaglass-2) 55%, var(--ink));
  --stage-awake: color-mix(in srgb, var(--sand-deep) 45%, var(--ink));
  --zone-far:    var(--ink);
}

/* ------------------------------------------------------------ state marks */
/* measured solid · waiting / still counting dashed · calibrating neutral fill ·
   not scorable a short neutral bar · no data a faint tick. The word is
   always there too. The 44px hit area comes from button.tag. */
.tag.state-mark { gap: 6px; }
.state-glyph {
  flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  background: var(--seaglass);
}
.state-mark.is-pending .state-glyph { background: var(--surface); border: 1.5px dashed var(--pending); }
.state-mark.is-calibrating .state-glyph { background: var(--neutral-fill); }
.state-mark.is-unscorable .state-glyph { height: 3px; border-radius: 2px; background: var(--line-strong); }
.state-mark.is-none .state-glyph { height: 2px; border-radius: 1px; background: var(--line-strong); opacity: .6; }

.tag.ship-tag {
  gap: 5px; background: color-mix(in srgb, var(--sand) 80%, var(--surface));
  color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--sand-deep);
}

/* ------------------------------------------------------------- usual pip */
.usual-pip {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0;
  font-size: var(--fs-caption); color: var(--ink-2); line-height: 1.35;
}
.usual-pip.is-learning { font-size: var(--fs-note); color: var(--ink-3); }
.pip-track { flex: none; overflow: visible; }
.pip-line { fill: var(--line); }
.pip-usual { fill: var(--seaglass-wash); stroke: color-mix(in srgb, var(--seaglass) 45%, transparent); stroke-width: 1; }
.pip-dot { fill: var(--seaglass); stroke: var(--surface); stroke-width: 2; }

/* --------------------------------------------------------------- day sheet */
.day-sheet .day-nav {
  display: flex; justify-content: space-between; gap: var(--sp-2);
  margin: calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)) var(--sp-2);
}
.day-step { gap: 4px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day-step svg { flex: none; }

.day-prov {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; margin: 0 2px var(--sp-3);
  font-size: var(--fs-note); color: var(--ink-3); line-height: 1.5;
}
.day-prov-lock { display: inline-grid; place-items: center; color: var(--ink-3); }
.day-loading { padding: var(--sp-6) 0; text-align: center; font-size: var(--fs-note); color: var(--ink-3); }
.day-error {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4); border: 1px dashed var(--line-strong); border-radius: var(--r);
  background: var(--surface-2); font-size: var(--fs-body); color: var(--ink-2);
}

.day-sec { margin-bottom: var(--sp-3); }
.day-sec-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.day-sec-head h3 { flex: 1 1 auto; font-size: var(--fs-h3); }
.day-sec-tags { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.day-sec .overline { margin-top: var(--sp-4); }

.day-state-line { font-size: var(--fs-body); line-height: 1.5; color: var(--ink-2); }
.day-note { margin-top: var(--sp-3); font-size: var(--fs-note); line-height: 1.5; color: var(--ink-3); }

.day-night-top {
  display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap;
  gap: 2px var(--sp-3); margin-bottom: var(--sp-3);
}
.day-big { font-size: var(--fs-body); color: var(--ink-2); }
.day-big b { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
.day-times { font-size: var(--fs-note); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day-state-line + .day-times { margin-top: var(--sp-1); }

.day-facts { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.day-facts li {
  padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  font-size: var(--fs-caption); color: var(--ink-2); font-variant-numeric: tabular-nums;
}

.day-naps { display: grid; gap: var(--sp-3); }
.day-nap-title { font-size: var(--fs-note); font-weight: 650; color: var(--ink); }
.day-nap-title .num { font-weight: 500; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day-nap-sub { font-size: var(--fs-caption); color: var(--ink-3); margin-bottom: 6px; }

.day-morning { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-4); }
.day-ring { flex: none; }
.day-ring .ring-label span { text-transform: none; letter-spacing: 0; }
.day-readings { flex: 1 1 150px; display: grid; gap: var(--sp-3); min-width: 0; }
.day-readings.is-wide { margin-top: var(--sp-3); }
.day-reading { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 2px var(--sp-2); }
.day-reading-name { font-size: var(--fs-note); font-weight: 600; color: var(--ink-2); }
.day-reading-value { font-family: var(--font-display); font-size: var(--fs-h3); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.day-reading .usual-pip { grid-column: 1 / -1; }

.day-strain { display: flex; align-items: center; flex-wrap: wrap; gap: 0 var(--sp-4); }
.day-strain .day-note { flex: 1 1 140px; margin-top: 0; }

.day-workout {
  display: flex; align-items: flex-start; flex-wrap: wrap; gap: var(--sp-3);
  padding: var(--sp-3) 0;
}
.day-workout + .day-workout { border-top: 1px solid var(--line-soft); }
.day-workout:first-of-type { padding-top: 0; }
.day-w-text { flex: 1 1 150px; min-width: 0; }
.day-w-title { font-size: var(--fs-md); font-weight: 650; color: var(--ink); line-height: 1.35; }
.day-w-meta { margin-top: 2px; font-size: var(--fs-note); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day-w-source { margin-top: 2px; font-size: var(--fs-note); color: var(--ink-3); }
.day-workout .zone-ring { flex: 0 1 auto; }

.day-foot { padding: var(--sp-3) 0 var(--sp-1); text-align: center; }
.day-plan { font-size: var(--fs-body); }

/* --------------------------------------------------------------- stage bar */
.stage { margin: 0; }
.stage-bar {
  display: flex; gap: 2px; height: 44px; overflow: hidden; cursor: pointer;
  border-radius: 12px; background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  animation: ss-stage-in var(--dur-4) var(--ease) both;
}
.stage-seg { flex: 0 0 0; transition: opacity var(--dur-2) var(--ease); }
.stage-seg.is-deep, .stage-sw.is-deep { background: var(--stage-deep); }
.stage-seg.is-rem, .stage-sw.is-rem { background: var(--stage-rem); }
.stage-seg.is-light, .stage-sw.is-light { background: var(--stage-light); }
.stage-seg.is-awake, .stage-sw.is-awake { background: var(--stage-awake); }
/* No data is an unfilled gap — not dashed, because nothing is on its way.
   Its key and the readout name it in words. */
.stage-seg.is-nodata, .stage-sw.is-nodata { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.stage-bar.has-pick .stage-seg:not(.is-picked) { opacity: .32; }
.stage.is-compact .stage-bar { height: 10px; border-radius: 5px; cursor: default; animation: none; gap: 1px; }
@keyframes ss-stage-in {
  from { clip-path: inset(0 100% 0 0 round 12px); }
  to   { clip-path: inset(0 0 0 0 round 12px); }
}

.stage-caption { margin-top: 6px; font-size: var(--fs-note); color: var(--ink-3); line-height: 1.5; }
.stage-keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: var(--sp-3); }
.stage-key {
  appearance: none; font: inherit; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: var(--sp-2); min-width: 0; min-height: var(--tap-min);
  padding: 7px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft); background: var(--surface-2); color: var(--ink);
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.stage-key:active { transform: scale(.97); }
.stage-key:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.stage-key[aria-pressed="true"] {
  background: var(--seaglass-wash);
  border-color: color-mix(in srgb, var(--seaglass) 60%, transparent);
}
/* The no-data key names the gap; it is not a button, so it does not look
   pressable. */
.stage-keys.is-static { margin-top: 6px; }
.stage-key.is-static { cursor: default; background: transparent; }
.stage-key.is-static:active { transform: none; }
.stage-sw { flex: none; width: 12px; height: 12px; border-radius: 4px; }
.stage-key-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.stage-key-name { font-size: var(--fs-note); font-weight: 650; }
.stage-key-val { font-size: var(--fs-caption); color: var(--ink-2); white-space: nowrap; }
.stage-key-val b { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.stage-readout {
  display: block; min-height: 1.5em; margin-top: var(--sp-2);
  font-size: var(--fs-note); line-height: 1.5; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.stage-note { margin-top: var(--sp-1); font-size: var(--fs-note); line-height: 1.5; color: var(--ink-3); }

/* -------------------------------------------------------------- strain arc */
.strain-arc { margin: 0; flex: none; }
.strain-arc svg { display: block; overflow: visible; }
.arc-track { fill: none; stroke: var(--line); stroke-width: 10; stroke-linecap: round; }
.arc-track.pending { stroke: var(--pending); stroke-width: 2; stroke-dasharray: 4 5; }
.arc-fill {
  fill: none; stroke: var(--seaglass); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 0;
  animation: ss-draw var(--dur-4) var(--ease) both;
}
.arc-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; fill: var(--ink); font-variant-numeric: tabular-nums; }
.arc-sub, .arc-end { font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.arc-open { font-size: 13px; font-weight: 600; fill: var(--ink-2); }
@keyframes ss-draw { from { stroke-dashoffset: 100; } }

/* --------------------------------------------------------------- zone ring */
.zone-ring { margin: 0; min-width: 0; }
.zone-art { display: flex; align-items: center; gap: var(--sp-4); }
.zone-svg { flex: none; display: block; overflow: visible; }
.zone-track { fill: none; stroke: var(--line-soft); stroke-width: 12; }
.zone-arc {
  fill: none; stroke-width: 12; stroke-dasharray: 100; stroke-dashoffset: 0;
  animation: ss-draw var(--dur-3) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}
.zone-arc.z0, .zone-sw.z0 { stroke: var(--z0); background: var(--z0); }
.zone-arc.z1, .zone-sw.z1 { stroke: var(--z1); background: var(--z1); }
.zone-arc.z2, .zone-sw.z2 { stroke: var(--z2); background: var(--z2); }
.zone-arc.z3, .zone-sw.z3 { stroke: var(--z3); background: var(--z3); }
.zone-arc.z4, .zone-sw.z4 { stroke: var(--z4); background: var(--z4); }
.zone-arc.z5, .zone-sw.z5 { stroke: var(--z5); background: var(--z5); }
.zone-center { font-family: var(--font-display); font-size: 15px; font-weight: 700; fill: var(--ink); font-variant-numeric: tabular-nums; }
.zone-sub { font-size: 11px; fill: var(--ink-3); }
.zone-outline { fill: none; stroke: var(--line-strong); stroke-width: 2; }
.zone-ring.is-pending .zone-outline { stroke: var(--pending); stroke-dasharray: 4 4; }
.zone-ring.is-partial,
.zone-ring.is-pending { display: flex; align-items: center; gap: var(--sp-3); }
.zone-ring.is-partial .zone-caption,
.zone-ring.is-pending .zone-caption { margin-top: 0; max-width: 16em; }

.zone-legend {
  list-style: none; margin: 0; padding: 0; min-width: 0;
  display: grid; gap: 3px; font-size: var(--fs-caption); color: var(--ink-2);
}
.zone-legend li { display: flex; align-items: center; gap: 6px; }
.zone-legend li.is-zero { color: var(--ink-3); }
.zone-sw { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.zone-mins { margin-left: auto; padding-left: var(--sp-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.zone-caption { margin-top: var(--sp-2); font-size: var(--fs-note); line-height: 1.45; color: var(--ink-3); }

/* ----------------------------------------------------------- reduce motion */
@media (prefers-reduced-motion: reduce) {
  .stage-bar, .arc-fill, .zone-arc { animation: none !important; }
  .stage-seg, .stage-key { transition: none; }
}
:root[data-reduce-motion] .stage-bar,
:root[data-reduce-motion] .arc-fill,
:root[data-reduce-motion] .zone-arc { animation: none !important; }
:root[data-reduce-motion] .stage-seg,
:root[data-reduce-motion] .stage-key { transition: none; }
