/* Hum: a chart recorder running through one day. Flat day surfaces, hairlines and one pen.
   Each state is a part of the day, and each token below means one thing in all four:
   --surface   the page, --sheet a panel on it, --lift a selected segment
   --ink       text and icons, --muted secondary text
   --pen       the trace and whatever is selected right now, nothing else
   --action    the primary button, --danger errors and deleting */

@property --surface { syntax: '<color>'; inherits: true; initial-value: #0b0d14; }
@property --sheet { syntax: '<color>'; inherits: true; initial-value: #12151f; }
@property --lift { syntax: '<color>'; inherits: true; initial-value: #1c2030; }
@property --ink { syntax: '<color>'; inherits: true; initial-value: #eef0f5; }
@property --muted { syntax: '<color>'; inherits: true; initial-value: #a3a9b8; }
@property --pen { syntax: '<color>'; inherits: true; initial-value: #a9b4ff; }
@property --action { syntax: '<color>'; inherits: true; initial-value: #252a3f; }
@property --on-action { syntax: '<color>'; inherits: true; initial-value: #eef0f5; }
@property --danger { syntax: '<color>'; inherits: true; initial-value: #ffb4a6; }

:root {
  --surface: #0b0d14; --sheet: #12151f; --lift: #1c2030;
  --ink: #eef0f5; --muted: #a3a9b8; --pen: #a9b4ff;
  --action: #252a3f; --on-action: #eef0f5; --danger: #ffb4a6;

  --hair: color-mix(in srgb, var(--ink) 12%, transparent);
  --edge: color-mix(in srgb, var(--ink) 55%, transparent); /* the outline of a control: 3:1 */
  --raised: color-mix(in srgb, var(--ink) 6%, transparent);
  --press: color-mix(in srgb, var(--ink) 12%, transparent);
  --grid: color-mix(in srgb, var(--ink) 7%, transparent);
  --track: color-mix(in srgb, var(--ink) 50%, transparent); /* an empty slider still reads: 3:1 */
  --picked: color-mix(in srgb, var(--pen) 12%, transparent);
  --scrim: rgba(11, 13, 20, 0.5);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --quick: 0.15s;
  --sheet-time: 0.28s;
  --day-time: 0.45s;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Bricolage Grotesque", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  color-scheme: dark;
  transition:
    --surface var(--day-time) var(--ease), --sheet var(--day-time) var(--ease), --lift var(--day-time) var(--ease),
    --ink var(--day-time) var(--ease), --muted var(--day-time) var(--ease), --pen var(--day-time) var(--ease),
    --action var(--day-time) var(--ease), --on-action var(--day-time) var(--ease), --danger var(--day-time) var(--ease);
}

/* Morning: paper and cobalt */
:root[data-state="focus"] {
  --surface: #e8ece6; --sheet: #f1f4ef; --lift: #f9faf7;
  --ink: #141a1c; --muted: #4a5458; --pen: #1f4fd8;
  --action: #141a1c; --on-action: #e8ece6; --danger: #a32a1e;
  color-scheme: light;
}
/* Afternoon: deeper paper and teal */
:root[data-state="relax"] {
  --surface: #dde7e1; --sheet: #e8f0eb; --lift: #f4f8f5;
  --ink: #141a1c; --muted: #465350; --pen: #0a6e5c;
  --action: #141a1c; --on-action: #dde7e1; --danger: #a32a1e;
  color-scheme: light;
}
/* Dusk: slate and amber */
:root[data-state="meditate"] {
  --surface: #262b33; --sheet: #2e343d; --lift: #3b424d;
  --ink: #eef0f3; --muted: #b7bdc7; --pen: #f0a24b;
  --action: #eef0f3; --on-action: #262b33; --danger: #ffb4a6;
}
/* Night: ink and moon. No big light fills, so nothing lights up the room. */
:root[data-state="sleep"] {
  --surface: #0b0d14; --sheet: #12151f; --lift: #1c2030;
  --ink: #eef0f5; --muted: #a3a9b8; --pen: #a9b4ff;
  --action: #252a3f; --on-action: #eef0f5; --danger: #ffb4a6;
  --grid: color-mix(in srgb, var(--ink) 5%, transparent);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--surface); height: 100%; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
/* On iPhone, text follows the size set in Settings. */
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  html { font: -apple-system-body; }
}
/* The page behind an open sheet stays still. */
html:has(dialog[open]) { overflow: hidden; }
.sprite { position: absolute; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--surface);
  color: var(--ink);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  justify-items: center;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
svg { width: 22px; height: 22px; display: block; flex: none; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

@keyframes fade-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ---------- header and states ---------- */

.top {
  display: flex; align-items: center; justify-content: space-between;
  width: min(560px, 100%);
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 700; font-size: 1.375rem; letter-spacing: -0.02em; }
.brand-mark { width: 28px; height: 16px; color: var(--pen); }
.top-actions { display: flex; }

.tool {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink);
  transition: background-color var(--quick) var(--ease), transform var(--quick) var(--ease);
}
@media (hover: hover) { .tool:hover { background: var(--raised); } }
.tool:active { background: var(--press); transform: scale(0.96); }

.states {
  position: relative;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(520px, calc(100% - 40px));
  margin-top: 8px; padding: 4px;
  border-radius: 12px;
  background: var(--raised);
}
.states .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / 4);
  border-radius: 8px;
  background: var(--lift);
  border: 1px solid var(--hair);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform var(--day-time) var(--ease);
}
.state-tab {
  position: relative; z-index: 1;
  min-height: 44px; padding: 8px 4px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  font-size: 0.9375rem; font-weight: 500;
  transition: color var(--quick) var(--ease);
  white-space: nowrap;
}
@media (hover: hover) { .state-tab:hover { color: var(--ink); } }
.state-tab[aria-checked="true"] { color: var(--ink); font-weight: 600; }

/* ---------- the chart ---------- */

.stage {
  display: flex; flex-direction: column; justify-content: center; gap: 16px;
  width: min(560px, 100%);
  min-height: 0;
  padding-top: 16px;
}
/* Engineering paper, edge to edge. Painted once: nothing on it moves but the pen. */
.chart {
  position: relative;
  flex: 1 1 200px;
  min-height: 96px; max-height: 48dvh;
  width: 100vw; margin-inline: calc(50% - 50vw);
  border-block: 1px solid var(--hair);
  background-color: transparent;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: center center;
}
#viz { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.breath {
  position: absolute; left: 20px; bottom: 12px;
  font-family: var(--display); font-size: 1.125rem; font-weight: 400; color: var(--ink);
  min-height: 1.5em;
}

.now {
  width: 100%;
  padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right));
  display: grid; gap: 4px;
}
.now-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pick {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  max-width: 100%; min-height: 44px; padding: 8px 8px 8px 12px;
  border: 1px solid var(--hair); border-radius: 10px;
  background: transparent; color: var(--ink);
  font-size: 0.9375rem; font-weight: 500;
  transition: background-color var(--quick) var(--ease), transform var(--quick) var(--ease);
}
@media (hover: hover) { .pick:hover { background: var(--raised); } }
.pick:active { background: var(--press); transform: scale(0.98); }
.pick svg { width: 16px; height: 16px; color: var(--muted); }
.pick.quiet {
  flex: 0 1 auto; display: block; min-width: 0; padding: 8px 12px;
  color: var(--muted); font-family: var(--mono); font-size: 0.875rem; font-weight: 400; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.track-title {
  font-family: var(--display); font-weight: 700; font-size: clamp(1.5rem, 7.4vw, 2rem); letter-spacing: -0.02em; line-height: 1.15;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; text-wrap: balance;
}
.meta {
  color: var(--muted); font-size: 0.875rem; line-height: 1.45; min-height: 1.45em;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.progress {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-family: var(--mono); font-size: 0.8125rem; font-variant-numeric: tabular-nums;
}
.progress input { flex: 1; min-width: 0; }

/* ---------- transport and dock ---------- */

.controls {
  width: min(560px, 100%);
  padding: 16px max(20px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.transport { display: flex; align-items: center; gap: 8px; }

.play {
  position: relative; flex: none;
  width: 68px; height: 68px; border-radius: 50%;
  border: 1px solid var(--edge); /* Sleep's button is nearly the page: the ring is what shows */
  background: var(--action); color: var(--on-action);
  display: grid; place-items: center;
  transition: transform var(--quick) var(--ease), opacity var(--quick) var(--ease);
}
@media (hover: hover) { .play:hover { opacity: 0.9; } }
.play:active { transform: scale(0.96); }
.play svg { width: 32px; height: 32px; }
.play[aria-label="Play"] svg { transform: translateX(1px); }
/* Waiting for a recording to arrive. The only thing here that turns, and it follows nothing in the audio. */
.play::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid transparent; opacity: 0; pointer-events: none;
  transition: opacity var(--quick) var(--ease);
}
.loading .play::after {
  opacity: 1; border-top-color: var(--pen); border-right-color: var(--pen);
  animation: turn 1.2s linear infinite;
}
@keyframes turn { to { transform: rotate(360deg); } }
.loading .meta { color: var(--ink); }

.volume { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); min-width: 0; padding-left: 4px; }
.volume svg { width: 20px; height: 20px; }

.dock {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  margin-top: 12px; padding-top: 8px;
  border-top: 1px solid var(--hair);
}
.dock-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; padding: 4px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink);
  font-size: 0.8125rem;
  transition: background-color var(--quick) var(--ease), transform var(--quick) var(--ease);
}
.dock-btn span { color: var(--muted); }
.dock-btn.has-note { position: relative; }
.dock-btn.has-note::after {
  content: ''; position: absolute; top: 8px; left: calc(50% + 8px);
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--pen); box-shadow: 0 0 0 2px var(--surface);
  animation: coach-pop 0.4s var(--ease) both;
}
@media (hover: hover) { .dock-btn:hover { background: var(--raised); } }
.dock-btn:active { background: var(--press); transform: scale(0.98); }

/* The slider: a thin track filled to the value (--fill is set from JS). */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 44px; margin: 0; background: transparent; cursor: pointer;
  touch-action: pan-y; /* a thumb scrolling the sheet shouldn't drag the slider */
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--ink) var(--fill), var(--track) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -8px; border-radius: 50%;
  background: var(--ink); border: 0;
  transition: transform var(--quick) var(--ease);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--ink); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--ink); }
input[type="range"]:disabled { opacity: 0.4; cursor: default; }

/* ---------- sheets ---------- */

.sheet {
  border: 1px solid var(--hair); border-radius: 20px;
  background: var(--sheet);
  color: var(--ink);
  width: min(460px, calc(100% - 32px)); max-height: min(680px, 86dvh);
  --pad: 20px;
  padding: 0 var(--pad) max(24px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { animation: sheet-in var(--sheet-time) var(--ease); }
.sheet[open]::backdrop { animation: fade-in var(--sheet-time) var(--ease); }
.sheet.closing { animation: sheet-out var(--sheet-time) var(--ease) forwards; pointer-events: none; }
.sheet.closing::backdrop { animation: fade-out var(--sheet-time) var(--ease) forwards; }
@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } }
@keyframes sheet-out { to { transform: translateY(16px); opacity: 0; } }

.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 calc(var(--pad) * -1) 8px; padding: 16px 8px 8px var(--pad);
  background: var(--sheet);
}
.sheet h2 { margin: 0; font-family: var(--display); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.sheet h3 { margin: 0 0 8px; font-size: 0.875rem; font-weight: 500; color: var(--muted); }
.close {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted);
  transition: background-color var(--quick) var(--ease), color var(--quick) var(--ease);
}
@media (hover: hover) { .close:hover { background: var(--raised); color: var(--ink); } }
.close:active { background: var(--press); }
.close svg { width: 20px; height: 20px; }

.group { margin-top: 24px; }
.sheet-head + .group { margin-top: 4px; }
.hint { color: var(--muted); font-size: 0.875rem; line-height: 1.5; margin: 8px 0 0; }
.trial-hint {
  margin: 0 0 16px; padding: 8px 12px; border-radius: 10px;
  background: var(--picked); color: var(--ink); font-size: 0.875rem; line-height: 1.45;
}

.list { display: grid; gap: 8px; }
.sheet[open] .list > .row:nth-child(-n+6) { animation: fade-rise 0.3s var(--ease) backwards; }
.sheet[open] .list > .row:nth-child(2) { animation-delay: 40ms; }
.sheet[open] .list > .row:nth-child(3) { animation-delay: 80ms; }
.sheet[open] .list > .row:nth-child(4) { animation-delay: 120ms; }
.sheet[open] .list > .row:nth-child(5) { animation-delay: 160ms; }
.sheet[open] .list > .row:nth-child(6) { animation-delay: 200ms; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; min-height: 56px; text-align: left;
  padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--hair); background: var(--raised); color: var(--ink);
  font-size: 1rem; font-weight: 500; text-decoration: none;
  transition: background-color var(--quick) var(--ease), border-color var(--quick) var(--ease), transform var(--quick) var(--ease);
}
@media (hover: hover) { button.row:hover, a.row:hover, .row:has(.row-main:hover) { background: var(--press); } }
button.row:active { transform: scale(0.99); background: var(--press); }
.row small { display: block; color: var(--muted); font-size: 0.8125rem; font-weight: 400; margin-top: 4px; line-height: 1.35; }
.row[aria-current="true"] { border-color: var(--pen); background: var(--picked); }
.row[aria-current="true"]::after {
  content: ""; width: 20px; height: 20px; flex: none; background: var(--pen);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5.5 12.5l4 4 9-9' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5.5 12.5l4 4 9-9' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
/* A row with its own actions: the whole left side is the button, with no dead padding around it. */
.row.split { padding: 0 4px 0 0; gap: 0; }
.row.split[aria-current="true"]::after { margin: 0 8px 0 4px; order: 1; }
.row-main {
  flex: 1; min-width: 0; min-height: 56px; padding: 12px 8px 12px 16px;
  border: 0; border-radius: 11px; background: transparent; color: inherit;
  font: inherit; text-align: left;
}
.row-main:focus-visible { outline-offset: -2px; }
.row .icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  transition: background-color var(--quick) var(--ease), color var(--quick) var(--ease);
}
.row .icon-btn:active { background: var(--press); }
@media (hover: hover) { .row .icon-btn:hover { background: var(--press); color: var(--ink); } }
.row .icon-btn.kept { color: var(--ink); }
.row.removed { color: var(--muted); font-weight: 400; font-size: 0.9375rem; padding: 4px 4px 4px 16px; animation: fade-in 0.15s var(--ease); }
.undo {
  flex: none; min-height: 44px; min-width: 64px; padding: 8px 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink); font-weight: 600; font-size: 0.9375rem;
  text-decoration: underline; text-underline-offset: 3px;
}
@media (hover: hover) { .undo:hover { background: var(--press); } }
.empty { color: var(--muted); text-align: center; padding: 32px 8px; line-height: 1.5; margin: 0; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0;
  padding: 4px; border-radius: 12px; background: var(--raised);
}
.segmented button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  min-height: 44px; padding: 8px 4px; border-radius: 8px;
  font-size: 0.875rem; font-weight: 500;
  transition: background-color var(--quick) var(--ease), color var(--quick) var(--ease);
}
@media (hover: hover) { .segmented button:hover { color: var(--ink); } }
.segmented button[aria-pressed="true"] { background: var(--lift); border-color: var(--hair); color: var(--ink); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 44px;
  min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--hair); background: var(--raised); color: var(--ink);
  font-size: 0.875rem; font-weight: 400;
  transition: background-color var(--quick) var(--ease), border-color var(--quick) var(--ease), transform var(--quick) var(--ease);
}
@media (hover: hover) { .chip:hover { background: var(--press); } }
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"] { background: var(--picked); border-color: var(--pen); box-shadow: inset 0 0 0 1px var(--pen); font-weight: 600; }

.slider-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 0.875rem; }
.slider-label { flex: none; width: 68px; }
.slider-value { flex: none; width: 56px; text-align: right; font-family: var(--mono); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.speed { margin-top: 12px; }
.sub-head { margin-top: 16px !important; }

/* ---------- library ---------- */

.lib-pane { display: none; margin-top: 12px; }
.lib-pane.show { display: grid; gap: 12px; animation: fade-in 0.2s var(--ease); }
.lib-pane > * { min-width: 0; }
.coach-page { display: grid; gap: 12px; margin-top: 4px; }
.coach-page > * { min-width: 0; }
.search {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--edge); background: var(--raised); color: var(--ink);
  font: inherit; font-size: 1rem;
}
.search::placeholder { color: var(--muted); opacity: 1; }
/* One swipeable line per filter row instead of a wall of chips. */
.scroller { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--pad) * -1); padding: 2px var(--pad); }
.scroller::-webkit-scrollbar { display: none; }
.scroller .chip { flex: none; }
.primary.compact { margin-top: 0; min-height: 44px; padding: 8px 12px; font-size: 0.9375rem; }
.primary.compact[hidden] { display: none; }
.lib-actions { display: grid; gap: 8px; }
.lib-actions:has(.primary:not([hidden])) { grid-template-columns: auto minmax(0, 1fr); align-items: stretch; }
.lib-actions .primary { white-space: nowrap; }
/* Other languages' labels need the whole width. */
html:not([lang="en"]) .lib-actions:has(.primary:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
.lib-count { margin: 0; font-family: var(--mono); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }

.stat-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-card { padding: 12px; border-radius: 12px; background: var(--raised); border: 1px solid var(--hair); }
.stat-card b { display: block; font-family: var(--mono); font-size: 1.125rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-card span { color: var(--muted); font-size: 0.8125rem; }
.stat-bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 120px; align-items: end; }
.stat-bar { display: grid; grid-template-rows: 1fr auto; gap: 4px; height: 100%; text-align: center; color: var(--muted); font-family: var(--mono); font-size: 0.8125rem; }
.stat-bar i {
  display: block; align-self: end; min-height: 2px; border-radius: 2px 2px 0 0; background: var(--track);
  transform-origin: bottom; animation: grow 0.4s var(--ease) backwards;
}
.stat-bar:last-child i { background: var(--pen); }

/* A page from the site, read on a sheet. */
.reader { margin-top: 8px; font-size: 0.9375rem; line-height: 1.5; overflow-wrap: anywhere; }
.reader h2 { margin: 24px 0 8px; font-size: 1.0625rem; }
.reader h3 { margin: 16px 0 4px; font-size: 0.9375rem; }
.reader p, .reader ul, .reader ol { margin: 0 0 12px; }
.reader ul, .reader ol { padding-left: 20px; }
.reader dl { margin: 0 0 12px; }
.reader dl > div { padding-block: 8px; border-bottom: 1px solid var(--hair); }
.reader dt { font-weight: 500; }
.reader dd { margin: 4px 0 0; color: var(--muted); }
.reader .keep { display: block; margin-top: 4px; font-size: 0.8125rem; }
.reader a { color: inherit; }

/* The focus coach. Colours come from the state's tokens, so it dresses for wherever it's opened. */
.coach { display: grid; gap: 12px; }
.coach-hero { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 8px; align-items: center; }
.coach-say {
  position: relative; margin: 0; padding: 12px 16px;
  border: 1px solid var(--hair); border-radius: 16px; background: var(--lift);
  font-size: 1.0625rem; font-weight: 500; line-height: 1.35;
  transform-origin: left center;
  animation: coach-speak 0.45s var(--ease) calc(var(--sheet-time) + 0.1s) both;
}
.coach-say::before {
  content: ''; position: absolute; top: 50%; left: -7px;
  width: 12px; height: 12px; margin-top: -6px;
  border-left: 1px solid var(--hair); border-bottom: 1px solid var(--hair);
  background: var(--lift); transform: rotate(45deg);
}
.coach-body { display: grid; gap: 12px; }
.coach-body > * { min-width: 0; margin: 0; }
.coach-in { animation: fade-rise 0.45s var(--ease) calc(var(--sheet-time) + 0.25s + var(--i) * 0.09s) both; }
.coach-note { color: var(--muted); font-size: 0.9375rem; }
.coach-small { color: var(--muted); font-size: 0.8125rem; }

.coach-dots { display: flex; flex-wrap: wrap; gap: 8px; }
.coach-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--press); }
.coach-dots i.on { background: var(--pen); animation: coach-pop 0.4s var(--ease) calc(var(--sheet-time) + 0.3s + var(--i) * 0.06s) both; }

.coach-bars { display: grid; gap: 12px; padding: 12px; border: 1px solid var(--hair); border-radius: 12px; background: var(--raised); }
.coach-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; align-items: baseline; font-size: 0.875rem; }
.coach-bar strong { font-family: var(--mono); font-size: 1.125rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.coach-bar i { grid-column: 1 / -1; display: block; height: 8px; border-radius: 4px; background: var(--press); overflow: hidden; }
.coach-bar b { display: block; height: 100%; border-radius: 4px; background: var(--track); transform-origin: left; animation: coach-grow 0.8s var(--ease) calc(var(--sheet-time) + 0.3s) both; }
.coach-bar.lead b { background: var(--pen); }
.coach-bar small { grid-column: 1 / -1; color: var(--muted); font-size: 0.8125rem; }

.coach-try { display: grid; gap: 4px; padding: 12px; border-left: 3px solid var(--pen); background: var(--picked); border-radius: 0 12px 12px 0; }
.coach-try b { font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.coach-try p { margin: 0; }
.coach-try .primary { justify-self: start; margin-top: 8px; }
.coach-try .coach-bars { margin: 8px 0 4px; }

.selftest-figures { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px 12px; margin: 8px 0; font-size: 0.875rem; }
.selftest-figures dt { color: var(--muted); }
.selftest-figures dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.coach-try > .coach-dots { margin: 8px 0 4px; }
.coach-try > .link { justify-self: start; }
.check-offer { display: block; margin-top: 8px; }
.check-body { display: grid; gap: 12px; }
.check-body p { margin: 0; }
.check-pad {
  display: grid; place-items: center; width: 100%; min-height: min(52vh, 360px);
  border: 1px solid var(--hair); border-radius: 12px; background: var(--raised); color: var(--ink);
  font-family: var(--mono); font-size: 4.5rem; font-variant-numeric: tabular-nums;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.check-body .link { justify-self: start; }
.coach-rhythm { display: grid; gap: 12px; }
.coach-rhythm > * { min-width: 0; margin-block: 0; }
.day-grid { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 4px; margin-inline: -4px; width: calc(100% + 8px); }
.day-grid th { padding: 4px 0; font-size: 0.72rem; letter-spacing: -0.01em; font-weight: 500; color: var(--muted); text-align: center; hyphens: auto; overflow-wrap: anywhere; }
.day-grid thead td { width: 21%; }
.day-grid thead th.now { color: var(--ink); text-decoration: underline; text-decoration-color: var(--pen); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.day-grid tbody th { text-align: left; font-size: 0.8125rem; line-height: 1.2; color: var(--ink); }
.day-all th { font-weight: 600; }
.day-cell { height: 48px; padding: 0; border-radius: 8px; background: var(--raised); text-align: center; }
.day-cell span { display: grid; justify-items: center; animation: fade-in 0.4s var(--ease) calc(var(--sheet-time) + var(--i) * 0.025s) both; }
.day-cell b { font-family: var(--mono); font-size: 0.9375rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.day-cell small { min-height: 1em; color: var(--ink); opacity: 0.75; font-size: 0.6875rem; line-height: 1; }
.day-tasks { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; }
.day-tasks li { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; }
.day-tasks b { font-weight: 500; }
.day-tasks span { color: var(--muted); }

/* The character. Blinks and breathes all the time; data-mood on .coach picks its face and manner. */
.buddy { width: 104px; height: 104px; overflow: visible; cursor: pointer; animation: coach-pop 0.6s var(--ease) var(--sheet-time) both; }
.buddy.hop .buddy-all { animation: buddy-hop 0.5s var(--ease); }
.buddy-all { animation: buddy-breathe 3.2s ease-in-out infinite; transform-origin: 60px 104px; }
.buddy-shadow { fill: var(--press); animation: buddy-shadow 3.2s ease-in-out infinite; transform-origin: 60px 110px; }
.buddy-body, .buddy-foot { fill: var(--pen); }
.buddy-foot { filter: brightness(0.9); }
.buddy-cheek { fill: var(--sheet); opacity: 0.22; }
.buddy-eyes { fill: var(--sheet); transform-origin: 60px 62px; animation: buddy-blink 4.8s linear infinite; }
.buddy-mouth { display: none; fill: none; stroke: var(--sheet); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.buddy-mouth.grin { fill: var(--sheet); stroke-width: 2; }
.buddy-band { fill: none; stroke: var(--ink); stroke-width: 6; stroke-linecap: round; }
.buddy-cup { fill: var(--ink); }
.buddy-arm, .buddy-arm-rest { fill: none; stroke: var(--pen); stroke-width: 8; stroke-linecap: round; }
.buddy-arm { transform-origin: 92px 78px; }
.buddy-waves { fill: none; stroke: var(--pen); stroke-width: 3; stroke-linecap: round; }
.buddy-waves path { opacity: 0; animation: buddy-wave 2.4s ease-out infinite; }
.buddy-waves path + path { animation-delay: 0.3s; }
.buddy-dots { display: none; fill: var(--muted); }
.buddy-dots circle { animation: buddy-dot 1.8s ease-in-out infinite; }
.buddy-dots circle:nth-child(2) { animation-delay: 0.2s; }
.buddy-dots circle:nth-child(3) { animation-delay: 0.4s; }

[data-mood="curious"] .buddy-mouth.smile,
[data-mood="wave"] .buddy-mouth.grin,
[data-mood="happy"] .buddy-mouth.grin,
[data-mood="calm"] .buddy-mouth.smile,
[data-mood="think"] .buddy-mouth.hmm { display: block; }
[data-mood="curious"] .buddy-all { animation: buddy-tilt 4s ease-in-out infinite; }
[data-mood="happy"] .buddy-all { animation: buddy-bounce 1.6s var(--ease) 3 calc(var(--sheet-time) + 0.3s), buddy-breathe 3.2s ease-in-out 5.5s infinite; }
[data-mood="happy"] .buddy-arm { animation: buddy-wave-arm 0.8s ease-in-out 4 calc(var(--sheet-time) + 0.3s); }
[data-mood="wave"] .buddy-arm { animation: buddy-wave-arm 0.8s ease-in-out infinite; }
[data-mood="calm"] .buddy-all { animation-duration: 5s; }
[data-mood="calm"] .buddy-eyes { transform: scaleY(0.55); animation: none; }
[data-mood="calm"] .buddy-waves path { animation-duration: 4s; }
[data-mood="think"] .buddy-eyes { translate: 3px -4px; }
[data-mood="think"] .buddy-dots { display: block; }

@keyframes coach-pop { from { opacity: 0; transform: scale(0.4); } }
@keyframes coach-speak { from { opacity: 0; transform: scale(0.85); } }
@keyframes coach-grow { from { transform: scaleX(0); } }
@keyframes buddy-breathe { 50% { transform: translateY(-3px) scale(1.015, 0.985); } }
@keyframes buddy-shadow { 50% { transform: scaleX(0.88); opacity: 0.7; } }
@keyframes buddy-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } }
@keyframes buddy-tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-5deg) translateY(-2px); } 70% { transform: rotate(5deg) translateY(-2px); } }
@keyframes buddy-bounce { 0%, 100% { transform: translateY(0); } 20% { transform: translateY(0) scale(1.06, 0.94); } 50% { transform: translateY(-14px) scale(0.97, 1.03); } 80% { transform: translateY(0) scale(1.04, 0.96); } }
@keyframes buddy-hop { 40% { transform: translateY(-18px) rotate(-6deg); } 70% { transform: translateY(0) scale(1.06, 0.94); } }
@keyframes buddy-wave-arm { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-28deg); } }
@keyframes buddy-wave { 0% { opacity: 0; } 30% { opacity: 0.7; } 100% { opacity: 0; } }
@keyframes buddy-dot { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes felt-draw { from { stroke-dashoffset: 1; } }

.felt-head { margin: 8px 0 0; font-size: 1.0625rem; font-weight: 500; }
.felt-chart { width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.felt-grid { stroke: var(--hair); stroke-width: 1; }
.felt-tick { fill: var(--muted); font-family: var(--mono); font-size: 13px; }
.felt-tick.end { text-anchor: end; }
.felt-line { stroke: var(--pen); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 1; animation: felt-draw 0.35s linear calc(var(--sheet-time) + var(--i) * 0.08s) both; }
.felt-dot { fill: var(--pen); stroke: var(--sheet); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: coach-pop 0.3s var(--ease) calc(var(--sheet-time) + var(--i) * 0.08s) both; }
.felt-hit { fill: transparent; }
.felt-readout { margin: 4px 0 0; color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.felt-numbers { margin-top: 8px; color: var(--muted); font-size: 0.875rem; }
.felt-numbers summary { min-height: 44px; padding-block: 12px; cursor: pointer; }
.felt-numbers table { width: 100%; border-collapse: collapse; }
.felt-numbers th { text-align: left; font-weight: 500; font-size: 0.8125rem; }
.felt-numbers th, .felt-numbers td { padding: 4px 0; border-bottom: 1px solid var(--hair); }
.felt-numbers td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.felt-link { display: inline-block; margin-top: 8px; padding-block: 12px; color: var(--muted); font-size: 0.875rem; }
@keyframes grow { from { transform: scaleY(0); } }

.timer-opts { display: none; gap: 12px; margin-top: 16px; }
.timer-opts.show { display: grid; animation: fade-in 0.2s var(--ease); }
.stepper {
  display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 1rem;
  padding: 4px 8px 4px 16px; border-radius: 12px; background: var(--raised);
}
.stepper span:first-child { flex: 1; color: var(--ink); font-weight: 500; }
.stepper input {
  width: 84px; min-height: 44px; padding: 8px; border-radius: 8px; text-align: center;
  border: 1px solid var(--edge); background: transparent; color: var(--ink);
  font-family: var(--mono); font-size: 1rem; font-variant-numeric: tabular-nums;
}
.stepper span:last-child { width: 32px; }

.primary {
  margin-top: 24px; width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--action); color: var(--on-action);
  font-weight: 600; font-size: 1.0625rem;
  transition: opacity var(--quick) var(--ease), transform var(--quick) var(--ease);
}
@media (hover: hover) { .primary:hover { opacity: 0.88; } }
.primary:active { transform: scale(0.98); }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; top: max(8px, env(safe-area-inset-top));
  transform: translate(-50%, -8px);
  background: var(--action); border: 1px solid var(--hair);
  color: var(--on-action); font-size: 0.9375rem; font-weight: 500; line-height: 1.35;
  padding: 12px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.3s var(--ease);
  max-width: calc(100% - 32px); text-align: center; z-index: 10;
  margin: 0; right: auto; bottom: auto; display: block; width: max-content;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- collapsing settings ---------- */

.fold > summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px;
  list-style: none; cursor: pointer; -webkit-user-select: none; user-select: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary h3 { margin: 0; color: var(--ink); font-size: 0.9375rem; }
.fold-value { flex: 1; min-width: 0; text-align: right; color: var(--muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fold > summary svg { width: 20px; height: 20px; margin-left: auto; color: var(--muted); transition: transform var(--quick) var(--ease); }
.fold-value + svg { margin-left: 0; }
.fold[open] > summary svg { transform: rotate(180deg); }
.fold[open] > summary { margin-bottom: 8px; }
.fold[open] > :not(summary) { animation: fade-in 0.2s var(--ease); }
.fold + .fold, .group + .fold { margin-top: 4px; border-top: 1px solid var(--hair); padding-top: 4px; }
.fold[open] { padding-bottom: 12px; }

/* ---------- account and forms ---------- */

.pane { display: none; }
.pane.show { display: block; animation: fade-in 0.2s var(--ease); }
.pane-lead { margin: 0 0 12px; }
.form { display: grid; gap: 12px; margin-top: 16px; }
.fold .form { margin-top: 4px; padding-bottom: 12px; }
.field { display: grid; gap: 4px; font-size: 0.875rem; color: var(--muted); }
.field input {
  width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--edge); background: var(--raised); color: var(--ink);
  font: inherit; font-size: 1rem; /* under 16px, iOS zooms the page on focus */
}
.field input:focus { outline: 2px solid var(--pen); outline-offset: 0; border-color: transparent; }
.field input[aria-invalid="true"] { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.field-hint { font-size: 0.8125rem; color: var(--muted); }
.field-hint[hidden] { display: none; }
.password { position: relative; display: block; }
.password input { padding-right: 52px; }
.reveal {
  position: absolute; top: 2px; right: 2px; width: 44px; height: 44px; border-radius: 8px;
  display: grid; place-items: center; border: 0; background: transparent; color: var(--muted);
}
.reveal[aria-pressed="true"] { color: var(--ink); }
.form-error { margin: 0; color: var(--danger); font-size: 0.875rem; line-height: 1.4; font-weight: 500; }
.form-error:empty { display: none; }
.form .primary { margin-top: 4px; }
.primary:disabled { opacity: 0.6; }
.primary.destructive { background: var(--danger); color: var(--surface); }
.link {
  display: block; margin: 8px auto 0; min-height: 44px; padding: 8px 12px;
  border: 0; background: transparent; color: var(--muted); font-size: 0.875rem; text-decoration: underline; text-underline-offset: 3px;
}
.code-input { font-family: var(--mono); font-variant-numeric: tabular-nums; text-transform: uppercase; }
.code-input::placeholder { color: var(--muted); opacity: 1; text-transform: none; }
.code-box {
  display: block; padding: 16px 12px; border-radius: 12px; text-align: center;
  background: var(--raised); border: 1px solid var(--edge);
  font: 500 1.0625rem/1.5 var(--mono);
  overflow-wrap: anywhere; -webkit-user-select: all; user-select: all;
}
.code-copy { display: block; margin: 8px auto 0; }
.account-card { padding: 12px 16px; border-radius: 12px; background: var(--raised); border: 1px solid var(--hair); }
.account-card b { display: block; font-size: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.account-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8125rem; }
.plan-retake { margin-top: 8px; }
.account-actions { display: grid; gap: 8px; }
.row[hidden] { display: none; }
.verify-lead { margin: 0 0 8px; }
.verify-resend:disabled { opacity: 0.6; }
#verifyNote:empty { display: none; }
#accountBtn.attention { position: relative; }
#accountBtn.attention::after {
  content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--pen);
}
.offer-included { margin: 0 0 16px; padding: 0 0 0 20px; color: var(--muted); font-size: 0.875rem; line-height: 1.5; }
.offer { display: grid; gap: 4px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--hair); background: var(--raised); }
.offer-name { font-size: 1rem; font-weight: 500; }
.offer-price { font-family: var(--display); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.offer-terms { color: var(--muted); font-size: 0.8125rem; line-height: 1.35; margin-bottom: 8px; }
.paywall-error { margin-top: 12px; }
.paywall-manage { margin-top: 12px; }
#paywallSheet .form { margin-top: 24px; border-top: 1px solid var(--hair); padding-top: 16px; }
#paywallSheet .primary:disabled { cursor: progress; }
#paywallSmall a { color: inherit; text-underline-offset: 3px; }
.fold.danger > summary h3 { color: var(--danger); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- survey ---------- */

.why-list { display: grid; gap: 8px; margin-top: 12px; }
.why { padding: 12px 16px; border-radius: 12px; background: var(--raised); border: 1px solid var(--hair); }
.why b { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 0.9375rem; font-weight: 600; }
.why b span { flex: none; color: var(--muted); font-size: 0.875rem; font-weight: 500; }
.why p { margin: 4px 0 0; color: var(--muted); font-size: 0.875rem; line-height: 1.45; }
.why small { display: block; margin-top: 8px; color: var(--muted); font-size: 0.8125rem; line-height: 1.4; }

/* ---------- check-in and plan updates, inside the now section ---------- */

.checkin {
  display: grid; gap: 8px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--hair);
  font-size: 0.875rem; animation: fade-rise 0.36s var(--ease);
}
.checkin-q { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink); font-size: 0.9375rem; font-weight: 500; }
.checkin-q .link { margin: -8px -12px -8px 0; flex: none; }
.checkin-scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.checkin-scale .chip { padding: 8px 4px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.checkin-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8125rem; }
.checkin > .link { margin: 0 auto; font-size: 0.875rem; }
.checkin p { margin: 0; color: var(--ink); line-height: 1.45; }
.checkin-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.checkin-q span { min-width: 0; overflow-wrap: anywhere; }
.intention { display: grid; gap: 8px; }
.intention .chip { padding-inline: 4px; white-space: nowrap; }
.intention p { color: var(--muted); font-size: 0.8125rem; }
.intention-line {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--edge); border-radius: 10px;
  background: transparent; color: var(--ink); font: inherit; font-size: 16px;
}
.intention-line::placeholder { color: var(--muted); }
.intention-line:focus { outline: 2px solid var(--pen); outline-offset: 0; border-color: transparent; }

/* Nothing to use until signed in: just the brand and the background behind the sign-in sheet. */
body.gated .top-actions, body.gated .states, body.gated .stage, body.gated .controls { visibility: hidden; }
.sheet[data-locked] .sheet-head::before { display: none; } /* no grabber on a sheet that can't be dismissed */
/* Room for the question without pushing the controls off the screen. */
.stage:has(.checkin:not([hidden])) .chart { flex-basis: 96px; }
.now:has(.intention) .meta, .now:has(.outcome-choices) .meta { display: none; }

/* ---------- touch screens ---------- */

@media (pointer: coarse) {
  .sheet::backdrop { background: rgba(11, 13, 20, 0.6); }
}

/* ---------- small screens ---------- */

@media (max-width: 520px) {
  .sheet {
    margin: auto 0 0; width: 100%; max-width: 100%;
    max-height: 90dvh;
    border-radius: 20px 20px 0 0; border-width: 1px 0 0;
  }
  .sheet-head { padding-top: 20px; touch-action: none; border-radius: 20px 20px 0 0; }
  .sheet-head::before { /* grabber */
    content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--track);
  }
  .sheet[open] { animation-name: slide-up; }
  .sheet.closing { animation-name: slide-down; }
  @keyframes slide-up { from { transform: translateY(100%); } }
  @keyframes slide-down { to { transform: translateY(100%); } }
}

@media (max-width: 340px) {
  .state-tab { font-size: 0.875rem; padding-inline: 2px; }
}

/* Another language's tab can have a long word, so each takes the room its word needs and the thumb
   follows: see placeThumb. In English they stay equal. */
html:not([lang="en"]) .states { grid-template-columns: repeat(4, auto); }
html:not([lang="en"]) .states .thumb {
  left: 0; width: var(--thumb-width, 25%);
  transform: translateX(var(--thumb-x, 0));
  transition: transform var(--day-time) var(--ease), width var(--day-time) var(--ease);
}
@media (max-width: 400px) { html:not([lang="en"]) .state-tab { font-size: 0.875rem; padding-inline: 2px; } }
@media (max-width: 340px) { html:not([lang="en"]) .state-tab { font-size: 0.78125rem; } }

/* Short phones in portrait: the player has to fit without scrolling. */
@media (max-height: 700px) and (orientation: portrait) {
  .stage { padding-top: 12px; gap: 12px; }
  .chart { flex-basis: 96px; }
  .now-row { margin-bottom: 4px; }
  .track-title { font-size: 1.5rem; -webkit-line-clamp: 1; }
  .meta { -webkit-line-clamp: 1; }
  .controls { padding-top: 8px; }
  .play { width: 56px; height: 56px; }
  .play svg { width: 28px; height: 28px; }
  .dock { margin-top: 8px; padding-top: 4px; }
  .dock-btn { min-height: 48px; gap: 0; }
}

/* Phones on their side: the chart on the left, everything else on the right. */
@media (orientation: landscape) and (max-height: 520px) {
  body {
    height: 100dvh; min-height: 0;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
  }
  .top { grid-column: 1; grid-row: 1; width: 100%; padding: max(4px, env(safe-area-inset-top)) 0 0 max(16px, env(safe-area-inset-left)); }
  .brand { font-size: 1.125rem; gap: 4px; }
  .brand-mark { width: 24px; height: 14px; }
  .states { grid-column: 2; grid-row: 1; width: calc(100% - 12px); margin: max(4px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 0; justify-self: start; padding: 2px; }
  .states .thumb { top: 2px; bottom: 2px; left: 2px; width: calc((100% - 4px) / 4); }
  .state-tab { padding-block: 4px; }
  .stage { display: contents; }
  .chart {
    grid-column: 1; grid-row: 2; width: 100%; margin: 4px 0 0; min-height: 0; max-height: none;
    align-self: stretch; border-inline-end: 1px solid var(--hair);
  }
  .breath { left: max(16px, env(safe-area-inset-left)); bottom: 4px; }
  .now {
    grid-column: 2; grid-row: 2; align-self: center; width: 100%; max-height: 100%; overflow-y: auto; gap: 0;
    padding: 4px max(12px, env(safe-area-inset-right)) 0 12px;
  }
  .now-row { margin-bottom: 0; }
  .track-title { font-size: 1.25rem; -webkit-line-clamp: 1; }
  .meta { font-size: 0.8125rem; -webkit-line-clamp: 1; }
  .controls { display: contents; }
  .transport { grid-column: 1; grid-row: 3; padding: 4px 0 max(4px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); gap: 4px; }
  .play { width: 44px; height: 44px; }
  .play svg { width: 22px; height: 22px; }
  .dock {
    grid-column: 2; grid-row: 3; margin: 0; padding: 4px max(12px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) 12px;
    border-top: 0;
  }
  .dock-btn { flex-direction: row; gap: 4px; min-height: 44px; }
  .sheet { margin: auto; width: min(560px, 100% - 32px); max-height: 94dvh; border-radius: 16px; border-width: 1px; }
  .sheet-head { padding-top: 8px; border-radius: 0; touch-action: auto; }
  .sheet-head::before { display: none; }
  .sheet[open] { animation-name: sheet-in; }
  .sheet.closing { animation-name: sheet-out; }
}

/* Wide windows: a little more room for the figures. */
@media (min-width: 720px) and (min-height: 700px) {
  .chart { max-height: 44dvh; }
  .track-title { font-size: 2.25rem; }
}

/* ---------- system preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  :root { transition: none !important; }
  /* Still says it's waiting, without turning. */
  .loading .play::after { border-color: var(--pen); }
}

@media (prefers-reduced-transparency: reduce) {
  :root { --scrim: rgba(11, 13, 20, 0.85); }
  .sheet::backdrop { background: rgba(11, 13, 20, 0.85); }
}

@media (prefers-contrast: more) {
  :root {
    --muted: var(--ink);
    --hair: color-mix(in srgb, var(--ink) 55%, transparent);
    --edge: var(--ink);
    --track: color-mix(in srgb, var(--ink) 70%, transparent);
    --grid: transparent;
  }
  :root[data-state="sleep"] { --grid: transparent; }
  .chip[aria-pressed="true"], .row[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--ink); border-color: var(--ink); }
  .state-tab[aria-checked="true"], .segmented button[aria-pressed="true"] { text-decoration: underline; text-underline-offset: 3px; }
  .states .thumb { border-color: var(--ink); }
}

@media (forced-colors: active) {
  .states .thumb, .segmented button[aria-pressed="true"], .chip[aria-pressed="true"] { border: 2px solid Highlight; }
  input[type="range"]::-webkit-slider-runnable-track { background: CanvasText; }
  input[type="range"]::-webkit-slider-thumb { background: Highlight; }
}

/* Until the page's words are in the person's language: see js/boot.js. */
.i18n-wait body { visibility: hidden; }

.language-pick { min-height: 44px; padding: 0 10px; font: inherit; color: var(--ink); background: transparent; border: 1px solid var(--hair); border-radius: 10px; }
.language-field { margin-top: 24px; }
