/* Night mode: near-black with dark reds, easy on dark-adapted eyes. */
:root {
  /* Fallback palette (dark red) for browsers without oklch(). */
  --bg: #050101;
  --surface: #110505;
  --surface-2: #1a0707;
  --border: #2c0c0c;
  --accent-900: #2a0606;
  --accent-800: #420a0b;
  --accent-700: #6b1013;
  --accent-600: #8f171b;
  --accent-500: #b52228;
  --accent-400: #d9474b;
  --text: #ecdad8;
  --text-muted: #a88582;
  --text-dim: #6f5352;
  --on-accent: #fff3f2;
  --glow: rgba(181, 34, 40, 0.5);
  --glow-soft: rgba(181, 34, 40, 0.18);
  --wash: var(--wash);
  --hairline: var(--hairline);
  --radius: 16px;
  --gutter: 20px;
  color-scheme: dark;
}

/* The whole palette follows one hue (set from the home-screen colour slider).
   oklch keeps lightness perceptually even, so every colour stays as dim and
   night-friendly as the default red. */
@supports (color: oklch(0 0 0)) {
  :root {
    --hue: 25;
    --bg: oklch(0.085 0.018 var(--hue));
    --surface: oklch(0.137 0.024 var(--hue));
    --surface-2: oklch(0.161 0.035 var(--hue));
    --border: oklch(0.208 0.053 var(--hue));
    --accent-900: oklch(0.193 0.061 var(--hue));
    --accent-800: oklch(0.251 0.085 var(--hue));
    --accent-700: oklch(0.344 0.124 var(--hue));
    --accent-600: oklch(0.421 0.154 var(--hue));
    --accent-500: oklch(0.503 0.182 var(--hue));
    --accent-400: oklch(0.605 0.182 var(--hue));
    --text: oklch(0.902 0.020 var(--hue));
    --text-muted: oklch(0.649 0.043 var(--hue));
    --text-dim: oklch(0.471 0.038 var(--hue));
    --on-accent: oklch(0.973 0.013 var(--hue));
    --glow: oklch(0.503 0.182 var(--hue) / 0.5);
    --glow-soft: oklch(0.503 0.182 var(--hue) / 0.18);
    --wash: oklch(0.344 0.124 var(--hue) / 0.28);
    --hairline: oklch(0.208 0.053 var(--hue) / 0.6);
  }
  .hue-slider {
    --spectrum: linear-gradient(to right,
      oklch(0.55 0.17 25), oklch(0.55 0.17 55), oklch(0.55 0.17 85), oklch(0.55 0.17 115),
      oklch(0.55 0.17 145), oklch(0.55 0.17 175), oklch(0.55 0.17 205), oklch(0.55 0.17 235),
      oklch(0.55 0.17 265), oklch(0.55 0.17 295), oklch(0.55 0.17 325), oklch(0.55 0.17 355),
      oklch(0.55 0.17 385));
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, var(--wash), transparent 60%),
    var(--bg);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-400); outline-offset: 2px; }
input[type=range]:focus-visible { outline-offset: 4px; border-radius: 10px; }

.app {
  max-width: 520px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + var(--gutter))
           calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + var(--gutter));
}
.screen.active { display: flex; animation: fade .25s ease-out; }
#screen-home { overflow-y: auto; -webkit-overflow-scrolling: touch; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

h1 { font-weight: 600; letter-spacing: .01em; }

/* Monk Apnea mark. icons/logo.svg is used as a stencil (mask) and filled with
   the user's hue, so the logo follows the colour slider. The glow breathes. */
.mark-wrap { animation: mark-breathe 8s ease-in-out infinite; }
.mark {
  display: block; width: 104px; height: 104px;
  background: linear-gradient(170deg, var(--accent-400), var(--accent-600) 75%);
  -webkit-mask: url(../icons/logo.svg) center / contain no-repeat;
  mask: url(../icons/logo.svg) center / contain no-repeat;
}
.mark-wrap.big .mark { width: 128px; height: 128px; }
@keyframes mark-breathe {
  0%, 100% { filter: drop-shadow(0 0 6px var(--glow-soft)); }
  50% { filter: drop-shadow(0 0 18px var(--glow)); }
}

/* Home ------------------------------------------------------------------ */
.home-header { text-align: center; padding: 20px 0 24px; display: grid; justify-items: center; gap: 4px; }
.home-header h1 { margin: 10px 0 0; font-size: 30px; letter-spacing: .04em; }
.subtitle { margin: 0; color: var(--text-muted); }

.type-list { display: grid; gap: 14px; }
.type-card {
  display: flex; align-items: center; gap: 16px;
  width: 100%; text-align: left;
  padding: 18px;
  background: linear-gradient(145deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, transform .1s;
}
.type-card:active { transform: scale(.985); border-color: var(--accent-700); }
.type-badge {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-900); border: 1px solid var(--accent-800);
  color: var(--accent-400); font-weight: 700; font-size: 17px;
}
.type-text { flex: 1; min-width: 0; }
.type-name { display: block; font-size: 18px; font-weight: 600; }
.type-tagline { display: block; color: var(--text-muted); font-size: 14px; margin-top: 3px; }
.chev { width: 20px; height: 20px; fill: none; stroke: var(--text-dim); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hue-slider {
  --spectrum: linear-gradient(to right, #b52228, #b5a022, #22b538, #22b5b5, #2238b5, #a022b5, #b52228);
}
/* Music picker */
.music { margin-top: 26px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 10px; }
.section-head h2 { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.section-hint { font-size: 12px; color: var(--text-dim); }
.music-list {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.track {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 12px 16px; text-align: left;
  background: none; border: 0;
}
.track + .track { border-top: 1px solid var(--border); }
.track:active { background: var(--surface-2); }
.track-text { flex: 1; min-width: 0; }
.track-name { display: block; font-size: 16px; font-weight: 600; }
.track-blurb { display: block; font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.track-mark {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--accent-800);
  display: flex; align-items: center; justify-content: center; gap: 2px;
}
.track[aria-checked="true"] .track-mark { border-color: var(--accent-500); background: radial-gradient(circle, var(--accent-500) 38%, transparent 42%); }
.track[aria-checked="true"] .track-name { color: var(--accent-400); }
/* Equalizer bars while a sample plays. */
.track.playing .track-mark { border-color: transparent; background: none; }
.track-mark i { display: none; width: 3px; height: 14px; border-radius: 2px; background: var(--accent-400); transform-origin: bottom; animation: eq .9s ease-in-out infinite; }
.track.playing .track-mark i { display: block; }
.track-mark i:nth-child(2) { animation-delay: -.3s; }
.track-mark i:nth-child(3) { animation-delay: -.6s; }
@keyframes eq { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

.colour {
  margin-top: 16px; padding: 12px 16px 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.colour-head { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.colour-head span { display: flex; align-items: center; gap: 10px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; background: var(--accent-500); box-shadow: 0 0 8px var(--glow); }
.link-btn { background: none; border: 0; padding: 6px 0 6px 12px; color: var(--text-muted); font-size: 13px; }
.link-btn:disabled { visibility: hidden; }
input[type=range].hue-slider::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--spectrum); }
input[type=range].hue-slider::-moz-range-track { height: 10px; border-radius: 5px; background: var(--spectrum); }
input[type=range].hue-slider::-moz-range-progress { background: transparent; }
input[type=range].hue-slider::-webkit-slider-thumb { margin-top: -7px; border-color: var(--accent-500); }
input[type=range].hue-slider::-moz-range-thumb { border-color: var(--accent-500); }

.safety { margin-top: auto; padding-top: 24px; text-align: center; color: var(--text-dim); font-size: 13px; line-height: 1.45; }

/* Setup ----------------------------------------------------------------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.topbar h1 { margin: 0; font-size: 22px; }
.icon-btn {
  width: 44px; height: 44px; margin-left: -10px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 12px;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--surface-2); }

.scroll { flex: 1; overflow-y: auto; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter) 12px; -webkit-overflow-scrolling: touch; }
.setup-desc { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin: 4px 0 18px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.fields { display: grid; gap: 10px; }
.field {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.field.invalid { border-color: var(--accent-600); }
.field-label { font-size: 15px; }
.field-hint { grid-column: 1; font-size: 12px; color: var(--text-dim); min-height: 1em; }
.field.invalid .field-hint { color: var(--accent-400); }
.field.noted .field-hint { color: var(--text-muted); }
.field-input {
  grid-row: 1 / span 2; grid-column: 2;
  display: flex; align-items: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 0 12px 0 4px;
}
.field-input:focus-within { border-color: var(--accent-600); }
.field-input input {
  width: 4.2em; padding: 10px 6px; text-align: right;
  background: none; border: 0; outline: none;
  font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.field-input input::-webkit-outer-spin-button,
.field-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit { color: var(--text-muted); font-size: 14px; min-width: 3.4em; }

.preview { margin: 16px 0; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 8px; }
.preview-title { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.preview-total { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.preview table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.preview th, .preview td { padding: 8px 14px; text-align: right; }
.preview th:first-child, .preview td:first-child { text-align: left; color: var(--text-muted); }
.preview th { font-size: 12px; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.preview tr + tr td { border-top: 1px solid var(--hairline); }
.preview td.vary { color: var(--accent-400); font-weight: 600; }
.preview .interval { padding: 14px; display: grid; gap: 10px; }
.interval-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--bg); }
.interval-bar .hold { background: var(--accent-600); }
.interval-bar .rec { background: var(--accent-900); }
.interval-legend { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.interval-legend b { color: var(--text); font-weight: 600; }
.preview-empty { padding: 14px; color: var(--text-dim); font-size: 14px; }

.sliders { padding: 6px 14px; }
.slider { display: grid; gap: 6px; padding: 10px 0; }
.slider + .slider { border-top: 1px solid var(--border); }
.slider-head { display: flex; justify-content: space-between; font-size: 15px; }
.slider-note { margin: 0 0 8px; font-size: 12px; line-height: 1.45; color: var(--text-dim); }
.slider-head output { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Drag-only sliders (see dragOnly in js/app.js): the wrapper handles touches,
   vertical swipes still scroll the page, the input only draws and takes keys. */
.range-wrap { display: block; touch-action: pan-y; cursor: pointer; }
.range-wrap input[type=range] { pointer-events: none; }
.range-wrap.dragging input[type=range]::-webkit-slider-thumb { transform: scale(1.15); }
.range-wrap.dragging input[type=range]::-moz-range-thumb { transform: scale(1.15); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; margin: 0;
  --pct: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent-600) var(--pct), var(--accent-900) var(--pct));
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--accent-900); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent-600); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%;
  background: var(--text); border: 4px solid var(--accent-600);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--text); border: 4px solid var(--accent-600);
}

/* Countdown: beeps / voice */
.seg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 10px; border-top: 1px solid var(--border); font-size: 15px; }
.segmented { display: flex; padding: 3px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); }
.segmented button {
  min-width: 72px; padding: 7px 12px; border-radius: 9px; border: 0; background: none;
  color: var(--text-muted); font-size: 14px; font-weight: 600;
}
.segmented button[aria-checked="true"] { background: var(--accent-700); color: var(--on-accent); }

/* Breathing exercises: the guide is the shape itself. */
.breath-view { width: min(86vw, 46vh, 360px); aspect-ratio: 1; margin: auto; }
.breath-view[hidden], .dial[hidden], .seg-row[hidden], .voice-card[hidden] { display: none; }
.bs { display: block; width: 100%; height: 100%; overflow: visible; }
.bs-track { fill: none; stroke: var(--accent-900); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.bs-lit { fill: none; stroke: var(--accent-500); stroke-width: 7; stroke-linecap: round; filter: drop-shadow(0 0 6px var(--glow)); }
.bs-dot { fill: var(--accent-400); stroke: var(--bg); stroke-width: 3; filter: drop-shadow(0 0 10px var(--glow)); }
.bs-label { fill: var(--text-dim); font-size: 11px; letter-spacing: .04em; }
.bs-label.active { fill: var(--accent-400); }
.bs-word { fill: var(--accent-400); font-size: 15px; letter-spacing: .16em; text-transform: uppercase; }
.bs-secs { fill: var(--text); font-size: 48px; font-weight: 200; font-variant-numeric: tabular-nums; }
.shape-badge svg { width: 30px; height: 30px; fill: none; stroke: var(--accent-400); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.shape-badge circle { fill: var(--accent-900); }
.choice-field { grid-template-columns: 1fr; }
.choice-field .segmented { width: 100%; }
.choice-field .segmented button { flex: 1; }
.breath-preview { display: flex; align-items: center; gap: 16px; padding: 14px; }
.breath-preview-shape { flex: none; width: 92px; height: 92px; }
.breath-preview .bs-label { display: none; }
.breath-preview .bs-track, .breath-preview .bs-lit { stroke-width: 12; }
.breath-preview .bs-dot { r: 16; }
.breath-preview-pattern { font-size: 15px; line-height: 1.4; }
.breath-preview-sub { margin-top: 4px; font-size: 13px; color: var(--text-muted); }

/* Custom tables (in the Breathing exercises menu) */
.custom-tables { margin-top: 26px; }
.custom-tables .type-list:empty { display: none; }
.add-table {
  display: block; width: 100%; margin-top: 10px; padding: 16px; border-radius: var(--radius);
  background: none; border: 1px dashed var(--accent-800); color: var(--accent-400); font-size: 16px; font-weight: 600;
}
.table-bases { margin-top: 10px; padding: 14px; }
.table-bases[hidden] { display: none; }
.table-bases-title { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.table-bases-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.table-bases-buttons button {
  padding: 12px 6px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--accent-800);
  color: var(--text); font-size: 15px; font-weight: 600;
}
.table-bases-note { margin: 10px 0 0; font-size: 13px; color: var(--text-dim); line-height: 1.4; }

.name-field .name-input {
  grid-row: 1 / span 2; grid-column: 2; width: 12em; padding: 10px 12px; font-size: 17px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.name-field .name-input:focus { border-color: var(--accent-600); }
.rounds-editor { padding: 6px 12px 10px; }
.re-row { display: grid; grid-template-columns: 30px 1fr 1fr 78px; align-items: start; gap: 8px; padding: 8px 0; }
.re-row + .re-row { border-top: 1px solid var(--hairline); }
.re-head { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); padding-bottom: 4px; }
.re-num { padding-top: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.re-cell { display: grid; grid-template-columns: 1fr auto; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding-right: 8px; }
.re-cell:focus-within { border-color: var(--accent-600); }
.re-cell.invalid { border-color: var(--accent-500); }
.re-cell input {
  width: 100%; min-width: 0; padding: 9px 6px 9px 10px; background: none; border: 0; outline: none;
  font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.re-cell input::-webkit-outer-spin-button, .re-cell input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.re-cell .unit { min-width: 0; font-size: 13px; }
.re-hint { grid-column: 1 / -1; padding: 0 10px 6px; font-size: 11px; color: var(--text-dim); margin-top: -4px; }
.re-hint:empty { display: none; }
.re-cell.invalid .re-hint { color: var(--accent-400); }
.re-tools { display: flex; gap: 6px; padding-top: 2px; }
.re-tools .icon-small:disabled { opacity: .35; }
.rounds-editor .add-cue { padding-bottom: 0; }
.table-bars { padding: 14px 14px 10px; }
.tb-hold { fill: var(--accent-500); }
.tb-rec { fill: var(--accent-800); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.tb-hold-sw { background: var(--accent-500); }
.tb-rec-sw { background: var(--accent-800); }

/* Lung volume */
.lung-row { margin: -4px 0 14px; }
.lung-row[hidden] { display: none; }
.segmented.lung-tabs { width: 100%; }
.segmented.lung-tabs button { flex: 1; min-width: 0; }
.lung-note { margin: 8px 2px 0; font-size: 13px; line-height: 1.45; color: var(--text-muted); }
#history-body > .lung-tabs { margin: 4px 0 12px; }

/* Voice cues */
.voice-card { margin-top: 14px; padding: 14px; }
.voice-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.voice-title { font-size: 16px; font-weight: 600; }
.voice-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.voice-body { margin-top: 8px; }
.voice-body[hidden] { display: none; }
.switch { position: relative; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 16px; background: var(--accent-900); border: 1px solid var(--border);
  transition: background-color .15s; pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--text-muted); transition: transform .15s, background-color .15s;
}
.switch input:checked + span { background: var(--accent-600); border-color: var(--accent-500); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--on-accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent-400); outline-offset: 2px; }

.cue-list { display: grid; gap: 8px; margin-top: 4px; }
.cue { padding: 10px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); display: grid; gap: 8px; }
.cue-selects { display: grid; grid-template-columns: 1.25fr .85fr 1.15fr; gap: 6px; }
.cue select {
  width: 100%; min-width: 0; padding: 9px 6px; border-radius: 10px; font-size: 15px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.cue select:focus { border-color: var(--accent-600); outline: none; }
.cue-foot { display: flex; align-items: center; gap: 8px; }
.cue-say { flex: 1; min-width: 0; font-size: 13px; color: var(--text-muted); line-height: 1.35; }
.cue-say b { color: var(--text); font-weight: 500; }
.cue-say .never { color: var(--accent-400); }
.icon-small {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
}
.icon-small svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-small.play svg { fill: currentColor; stroke: none; }
.add-cue { display: block; padding: 12px 0 4px; color: var(--accent-400); font-size: 15px; }
.add-cue:disabled { visibility: visible; opacity: .4; }

/* Caption shown while the notification preview plays. */
.beep-toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  width: min(360px, calc(100% - 2 * var(--gutter)));
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: var(--surface-2); border: 1px solid var(--accent-700); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 24px var(--glow-soft);
  z-index: 10;
}
.beep-toast[hidden] { display: none; }
.beep-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent-500); animation: beep-pulse .6s ease-out infinite; }
.beep-toast.low .beep-dot { background: var(--accent-700); }
.beep-text { display: grid; gap: 2px; }
.beep-text b { font-size: 17px; font-weight: 600; }
.beep-text small { font-size: 13px; color: var(--text-muted); }
@keyframes beep-pulse { 0% { box-shadow: 0 0 0 0 var(--glow); } 100% { box-shadow: 0 0 0 10px transparent; } }

.bottom { padding-top: 12px; }
.btn {
  width: 100%; min-height: 56px; border-radius: 28px;
  font-size: 18px; font-weight: 600; letter-spacing: .02em;
  border: 1px solid transparent;
  transition: background-color .15s, transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent-600); border-color: var(--accent-500); color: var(--on-accent); }
.btn.primary:disabled { opacity: .35; }
.btn.danger { background: transparent; border-color: var(--accent-700); color: var(--accent-400); }
.btn.danger.armed { background: var(--accent-700); color: var(--on-accent); }

/* Session --------------------------------------------------------------- */
.session-top { text-align: center; padding-top: 12px; }
.session-type { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); }
.round { margin-top: 6px; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.dial { position: relative; width: min(82vw, 44vh, 340px); aspect-ratio: 1; margin: auto; }
.dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dial-track { fill: none; stroke: var(--accent-900); stroke-width: 6; }
.dial-progress {
  fill: none; stroke: var(--accent-500); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 628.32; stroke-dashoffset: 0;
  filter: drop-shadow(0 0 6px var(--glow));
}
.dial.recovery .dial-progress, .dial.prepare .dial-progress, .dial.prep .dial-progress { stroke: var(--accent-700); filter: none; }
.dial.beyond .dial-progress { stroke: var(--accent-400); filter: drop-shadow(0 0 10px var(--glow)); }
/* Flash when a contraction is logged. */
.dial.tapped .dial-track { animation: tap-flash .45s ease-out; }
@keyframes tap-flash { 0% { stroke: var(--accent-400); stroke-width: 14; } 100% { stroke: var(--accent-900); stroke-width: 6; } }
.contractions { margin-top: 6px; min-height: 1.3em; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.contractions.hint { color: var(--text-dim); font-size: 13px; }
/* The session screen handles its own taps and swipes (no scrolling or zoom). */
#screen-session { touch-action: none; -webkit-user-select: none; user-select: none; }

/* "Swipe up to breathe": shown during holds; rises and brightens as the
   finger travels up (--pull 0 → 1). */
.swipe-hint {
  --pull: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 2px; color: var(--text-muted); font-size: 14px; letter-spacing: .02em;
  visibility: hidden; pointer-events: none;
  transform: translateY(calc(var(--pull) * -14px));
  opacity: calc(0.75 + var(--pull) * 0.25);
}
.swipe-hint.show { visibility: visible; }
.swipe-hint svg {
  width: 26px; height: 26px; fill: none; stroke: var(--accent-400); stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
  animation: nudge-up 1.8s ease-in-out infinite;
}
@keyframes nudge-up { 0%, 100% { transform: translateY(3px); opacity: .55; } 50% { transform: translateY(-3px); opacity: 1; } }
.dial-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.phase { font-size: 15px; letter-spacing: .16em; text-transform: uppercase; color: var(--text-muted); }
.dial.hold .phase { color: var(--accent-400); }
.time { font-size: clamp(56px, 19vw, 96px); font-weight: 200; font-variant-numeric: tabular-nums; line-height: 1.05; }

.next {
  display: flex; justify-content: center; align-items: baseline; gap: 10px;
  padding: 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.next-label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); }
.next-value { font-size: 17px; font-variant-numeric: tabular-nums; }
.remaining { text-align: center; color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; min-height: 1.2em; }

/* Done ------------------------------------------------------------------ */
.done {
  flex: 1; overflow-y: auto; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
}
.done > :first-child { margin-top: auto; }
.done > :last-child { margin-bottom: auto; }
.done h1 { margin: 20px 0 0; font-size: 26px; }
.done p { margin: 0; color: var(--text-muted); line-height: 1.5; }
.done-detail { width: 100%; margin-top: 10px; padding-bottom: 8px; }
.hero-time { font-size: clamp(64px, 22vw, 104px); font-weight: 200; font-variant-numeric: tabular-nums; line-height: 1.05; }
.done-note { margin-top: 4px !important; }

.rounds-card table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rounds-card th, .rounds-card td { padding: 8px 9px; text-align: right; }
.rounds-card th:first-child, .rounds-card td:first-child { text-align: left; color: var(--text-muted); }
.rounds-card th { font-size: 12px; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.rounds-card tr + tr td { border-top: 1px solid var(--hairline); }
.rounds-card tr.cut td:nth-child(2) { color: var(--accent-400); }
.rounds-card .of { color: var(--text-dim); font-size: 12px; }

/* Setup: fill from personal best */
.pb-fill { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 14px; }
.pb-fill[hidden] { display: none; }
.pb-fill-text { flex: 1; display: grid; gap: 2px; font-size: 14px; }
.pb-fill-text span { color: var(--text-muted); font-size: 13px; }
.btn-small {
  flex: none; min-height: 40px; padding: 0 18px; border-radius: 20px;
  background: var(--accent-600); border: 1px solid var(--accent-500); color: var(--on-accent);
  font-size: 15px; font-weight: 600;
}

/* Home: history entry */
.history-card { margin-top: 14px; }
.history-card .type-badge svg { width: 26px; height: 26px; fill: none; stroke: var(--accent-400); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* History */
.pb-card { padding: 16px; margin: 4px 0 14px; }
.pb-top { display: flex; justify-content: space-between; align-items: flex-start; }
.pb-label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.pb-value { font-size: 44px; font-weight: 300; font-variant-numeric: tabular-nums; line-height: 1.15; }
.pb-meta { font-size: 13px; color: var(--text-dim); }
.pb-form { margin-top: 12px; display: grid; gap: 10px; }
.pb-form[hidden] { display: none; }
.pb-inputs { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.pb-inputs input {
  width: 4em; padding: 8px 10px; text-align: right; font-size: 20px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; outline: none;
  -moz-appearance: textfield; appearance: textfield;
}
.pb-inputs input:focus { border-color: var(--accent-600); }
.pb-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.chips { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 11px; border-radius: 16px; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
}
.chip[aria-pressed="true"] { background: var(--accent-800); border-color: var(--accent-600); color: var(--text); }

.chart-card { padding: 14px 14px 8px; margin-bottom: 14px; }
.chart-head { display: grid; gap: 2px; }
.chart-title { margin: 0; font-size: 16px; font-weight: 600; }
.chart-sub { font-size: 12px; color: var(--text-dim); }
.chart-empty { margin: 8px 0 8px; font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.chart { margin-top: 6px; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.ch-grid { stroke: var(--border); stroke-width: 1; }
.ch-axis { fill: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.ch-line { fill: none; stroke: var(--accent-500); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-dot { fill: var(--accent-500); stroke: var(--surface); stroke-width: 2; }
.ch-dot-active { fill: var(--accent-400); }
.ch-label { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ch-cross { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 3 3; }
.ch-tip-bg { fill: var(--surface-2); stroke: var(--accent-700); }
.ch-tip-text { fill: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Second series: dashed line, hollow points (identity never by colour alone). */
.ch-line.s1 { stroke: var(--text-muted); stroke-dasharray: 5 4; stroke-width: 2; }
.ch-dot.s1 { fill: var(--surface); stroke: var(--text-muted); stroke-width: 2; }
.ch-label.muted { fill: var(--text-muted); font-weight: 500; }
.ch-highlight { stroke: var(--accent-700); stroke-width: 1; stroke-dasharray: 2 3; }
.ch-ring { fill: none; stroke: var(--accent-400); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item svg { width: 22px; height: 10px; overflow: visible; }

/* Session analysis */
.analysis { display: grid; gap: 12px; margin-top: 12px; text-align: left; }
.analysis .chart-card, .analysis .rounds-card { margin: 0; }
.insights { padding: 14px 16px; }
.insight-list { margin: 8px 0 0; padding-left: 18px; }
.insight-list li { font-size: 14px; line-height: 1.45; color: var(--text); }
.insight-list li + li { margin-top: 6px; }
.map-track { fill: var(--surface-2); stroke: var(--border); stroke-dasharray: 3 3; }
.map-held { fill: var(--accent-900); }
.map-struggle { fill: var(--accent-700); opacity: .65; }
.map-dot { fill: var(--accent-400); stroke: var(--surface); stroke-width: 1.5; }
.map-cut { stroke: var(--accent-400); stroke-width: 2; stroke-linecap: round; }
.map-row .hit { fill: transparent; }
.map-row.active .map-held { stroke: var(--accent-500); stroke-width: 1.5; }
.map-readout { margin: 6px 2px 4px; min-height: 1.3em; font-size: 13px; line-height: 1.4; color: var(--text-muted); }
.gap-bar { fill: var(--accent-600); }
.s-detail .card { background: var(--bg); }
.s-detail .analysis { margin-top: 0; }

.session-list { display: grid; gap: 8px; padding-bottom: 8px; }
.session-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.session-item.open { border-color: var(--accent-800); }
.session-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; background: none; border: 0; }
.s-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.s-title { font-size: 16px; font-weight: 600; }
.s-date { font-size: 12px; color: var(--text-dim); }
.s-sub { font-size: 13px; color: var(--text-muted); }
.s-result { flex: none; text-align: right; font-size: 20px; font-weight: 300; font-variant-numeric: tabular-nums; display: grid; }
.s-result small { font-size: 11px; color: var(--text-dim); }
.s-result.ended { color: var(--text-muted); }
.s-detail { padding: 0 10px 10px; }
.s-detail .rounds-card { background: var(--bg); }
.s-delete { display: block; margin: 8px 4px 0 auto; padding: 8px 4px; }
.s-delete.armed { color: var(--accent-400); }

/* Phone on its side: the session screen never scrolls (swipes are gestures),
   so put the dial on the left and everything else on the right. */
@media (orientation: landscape) and (max-height: 540px) {
  .app:has(#screen-session.active) { max-width: 920px; }
  #screen-session.active {
    display: grid; grid-template-columns: auto 1fr; column-gap: 28px;
    grid-template-rows: 1fr auto auto auto auto 1fr; align-items: center;
  }
  #screen-session .dial { grid-column: 1; grid-row: 1 / -1; width: min(calc(100dvh - 48px), 46vw); margin: 0; }
  #screen-session .session-top { grid-column: 2; grid-row: 2; padding-top: 0; }
  #screen-session .next { grid-column: 2; grid-row: 3; margin-top: 12px; }
  #screen-session .remaining { grid-column: 2; grid-row: 4; }
  #screen-session .swipe-hint { grid-column: 2; grid-row: 5; }
  #screen-session .bottom { grid-column: 2; grid-row: 6; align-self: end; }
  #screen-session .time { font-size: clamp(48px, 11vh + 20px, 88px); }
}

@media (prefers-reduced-motion: reduce) {
  .mark-wrap, .screen.active, .beep-dot, .track-mark i, .dial.tapped .dial-track, .swipe-hint svg { animation: none; }
}

/* Home: today's planned training */
.today { padding: 14px 16px 12px; margin-bottom: 14px; border-color: var(--accent-800); }
.today[hidden] { display: none; }
.today-head { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 4px; }
.today-label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.today-main { display: flex; align-items: center; gap: 12px; }
.today-text { flex: 1; min-width: 0; }
.today-name { font-size: 19px; font-weight: 600; }
.today-sub { margin-top: 2px; font-size: 14px; color: var(--text-muted); }
.today-done { flex: none; font-size: 15px; font-weight: 600; color: var(--accent-400); }
.notice .beep-dot { animation: none; }
.today-week { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--hairline); font-size: 13px; color: var(--text-dim); }

/* Schedule */
.segmented.freq { margin-bottom: 22px; }
.segmented.freq button { flex: 1; min-width: 0; padding: 9px 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.week { padding: 2px 14px; margin-bottom: 22px; }
.day-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); align-items: center; gap: 8px 10px; padding: 10px 0; }
.day-row + .day-row { border-top: 1px solid var(--hairline); }
.day-name { font-size: 15px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.day-row.rest .day-name { color: var(--text-muted); }
.day-today {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-400);
  border: 1px solid var(--accent-700); border-radius: 8px; padding: 0 6px;
}
.day-select {
  width: 100%; min-width: 0; padding: 9px 8px; border-radius: 10px; font-size: 15px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
}
.day-row.rest .day-select { color: var(--text-muted); }
.day-select:focus { border-color: var(--accent-600); outline: none; }
.segmented.day-lungs { grid-column: 2; }
.segmented.day-lungs button { flex: 1; min-width: 0; padding: 5px 0; font-size: 13px; }
.load { padding: 4px 14px; margin-bottom: 14px; }
.load-empty { margin: 10px 0; font-size: 14px; color: var(--text-dim); line-height: 1.45; }
.load-item { display: flex; gap: 10px; padding: 10px 0; font-size: 14px; line-height: 1.45; }
.load-item + .load-item { border-top: 1px solid var(--hairline); }
.load-icon {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; margin-top: 1px;
}
.load-item.warn .load-icon { background: var(--accent-700); color: var(--on-accent); }
.load-item.ok .load-icon { border: 1px solid var(--accent-600); color: var(--accent-400); }
.load-item.ok .load-text { color: var(--text-muted); }
.guide { padding: 0 14px; }
.guide summary { padding: 13px 0; font-size: 15px; font-weight: 600; cursor: pointer; }
.guide ul { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 8px; font-size: 14px; line-height: 1.45; color: var(--text-muted); }
.schedule-note { margin: 16px 4px; font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.clear-schedule { margin-top: 4px; }

/* Heart rate */
.hr-card { margin-top: 14px; padding: 14px; }
.hr-card[hidden] { display: none; }
.hr-note { margin: 10px 0 0; }
.hr-note:empty { display: none; }
.btn-small.secondary { background: transparent; color: var(--accent-400); border-color: var(--accent-700); }
.btn-small:disabled { opacity: .6; }
.hr-live { margin-top: 4px; font-size: 15px; color: var(--accent-400); font-variant-numeric: tabular-nums; }
.hr-live[hidden] { display: none; }
.hr-live.lost { color: var(--text-dim); }
.hr-hold { fill: var(--accent-900); opacity: .7; }
.hr-chart .insight-list { margin: 8px 0 0; }

/* Backup */
.backup-card { padding: 14px; margin-top: 18px; }
.backup-text { margin: 6px 0 12px; font-size: 13px; line-height: 1.45; color: var(--text-muted); }
.backup-actions { display: flex; gap: 10px; }
.hr-hold { cursor: pointer; }
.hr-hold.other { opacity: .3; }
.hr-legend svg { width: 10px; height: 12px; }
.hr-legend .hr-legend-zoom svg[viewBox$="16 12"] { width: 16px; }
.hr-legend .hr-legend-zoom { display: none; }
.hr-legend.zoomed .hr-legend-zoom { display: inline-flex; }
.hr-mark { stroke-width: 1.5; }
.hr-mark.start { stroke: var(--accent-500); }
.hr-mark.end { stroke: var(--accent-500); stroke-dasharray: 4 3; }
.hr-mark-label { fill: var(--accent-400); }
.hr-base { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 2 4; }
.hr-contraction { fill: var(--text); stroke: var(--surface); stroke-width: 1.5; }
.hr-chips { margin: 10px 0 0; }
.rounds-card.pickable tbody tr { cursor: pointer; }
.rounds-card .rounds-hint { padding: 0 14px 8px; margin: 0; }
.hr-chart .map-readout { margin-top: 8px; }
.hr-howto { padding: 8px 0 0; color: var(--accent-400); }
.hr-howto[hidden] { display: none; }
.hr-help { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.hr-help[hidden] { display: none; }
.hr-help-title { font-size: 15px; font-weight: 600; }
.hr-help-intro { margin: 4px 0 10px; font-size: 13px; line-height: 1.45; color: var(--text-muted); }
.hr-step { display: flex; gap: 10px; margin-top: 10px; font-size: 14px; line-height: 1.45; }
.hr-step-n {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-700); color: var(--on-accent); font-size: 12px; font-weight: 700; margin-top: 1px;
}
.hr-step ul { margin: 6px 0 0; padding-left: 16px; display: grid; gap: 6px; color: var(--text-muted); font-size: 13px; }
.hr-step ul b { color: var(--text); font-weight: 500; }
.hr-help-foot { margin: 12px 0 0; font-size: 12px; line-height: 1.45; color: var(--text-dim); }
.hr-help-actions { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
