/* Layout: a 16:9 stage (figure left, cues right) with its transport below and the routine list to the right;
   the list drops below the player under 1080px, and under 760px the stage stacks the cues under the figure.
   Dark on purpose: it matches the site it lives on. Chapter colors are bumper-plate colors, by position.
   Amber is a fill (play, tempo progress, beat), never text. Spacing on 4/8/12/16/24; radii 6 / 4 / 2. */
/* tokens: css/tokens.css (linked first) */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-2) var(--ground); }
html, body { overflow-x: clip; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--on-accent); }
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding-block: 20px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 16px;
}

/* One label style for everything that names a thing; controls keep their condensed caps. */
.eyebrow, .label, .chip, .seg-label, .vol-label {
  margin: 0;
  color: var(--muted);
  font: 500 14px/1.2 var(--body);
  letter-spacing: 0;
  text-transform: none;
}

.summary {
  margin: 0;
  color: var(--muted);
  font: 500 14px/1.2 var(--body);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- top bar ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
}
.top .title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; min-width: 0; }
.top h1 {
  margin: 0;
  font: 700 30px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.keys {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  color: var(--quiet);
  font-size: 14px;
}
kbd {
  display: inline-block;
  margin-right: 4px;
  padding: 3px 5px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 2px;
  color: var(--muted);
  font: 500 12px/1 var(--mono);
}
kbd + kbd { margin-left: -1px; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
}
.player { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  width: 100%;                 /* fixed by the column; the 16:9 floor lives on .stage-figure, so a taller */
  min-width: 0;                /* text column makes the stage taller and never wider */
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: 6px;
  container-type: inline-size;
}

.stage-figure {
  position: relative;
  min-width: 0;
  aspect-ratio: 80 / 81;       /* 1.25 of 2.25 columns of a 16:9 stage */
  cursor: pointer;
  border-radius: 6px 0 0 6px;
  background: radial-gradient(60% 46% at 50% 80%, var(--stage-glow), transparent 72%);
  /* --stage and the --fig-* tokens (css/tokens.css) reach the figure's container by inheritance */
}
/* the figure's own element fills the region: the 3D <canvas> edge to edge (it frames itself), the 2D <svg> inset */
.fig-canvas { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; }
.fig-canvas > canvas, .fig-canvas > svg { display: block; width: 100%; height: 100%; }
.fig-canvas > svg { padding: 3% 1% 2% 3%; }
.fig-placeholder {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--quiet);
  font: 500 14px/1.2 var(--body);
}

/* The whole figure is the hit area; the visible control sits top-left so the start pose stays in view. */
.big-play {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;               /* a wrapping line is only as tall as its content, so the caption centers on the disc */
  align-content: flex-start;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, 1.4cqi, 16px);
  padding: clamp(12px, 3cqi, 32px);
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  pointer-events: none;          /* only the disc and caption take the pointer; drags elsewhere reach the canvas */
}
.big-play .disc, .big-play .cap { pointer-events: auto; }
.big-play .disc {
  display: grid;
  place-items: center;
  width: clamp(52px, 7cqi, 80px);
  aspect-ratio: 1;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: background var(--mid) var(--ease-out);
}
.big-play .disc svg { width: 42%; height: 42%; margin-left: 7%; }
.big-play:hover .disc { background: var(--accent-hi); }
.big-play:focus-visible { outline: none; }
.big-play:focus-visible .disc { outline: 2px solid var(--text); outline-offset: 6px; }
.big-play .cap {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6em;
  padding: 8px 12px;
  border-radius: 2px;
  background: var(--scrim);
  font: 600 clamp(14px, 1.5cqi, 17px)/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.big-play .cap-time { color: var(--muted); font-variant-numeric: tabular-nums; }

.stage-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.2cqi, 24px);
  padding: clamp(16px, 3.4cqi, 40px) clamp(16px, 3.4cqi, 40px) clamp(16px, 3cqi, 32px) clamp(4px, 1cqi, 12px);
}

.head { display: grid; gap: clamp(8px, 1cqi, 12px); }
.head.enter { animation: rise var(--slow) var(--ease-out) both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* labels inside the stage scale with it */
.stage .eyebrow, .stage .label, .chip { font-size: clamp(14px, 1.3cqi, 16px); }

.chip {
  --plate: var(--ch, var(--fill));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.plate { width: 1.25em; height: 1.25em; flex: none; }
.plate .p-face { fill: var(--plate, var(--line-2)); }
.plate .p-ring { fill: none; stroke: var(--ground); stroke-opacity: 0.35; stroke-width: 1.1; }
.plate .p-hub { fill: var(--ground); }

.ex-name {
  margin: 0;
  font: 700 clamp(28px, 4.4cqi, 54px)/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.005em;
  text-wrap: balance;
}

/* load / sets × reps / tempo as three cells */
.ex-meta { margin: 0; display: flex; flex-wrap: wrap; row-gap: 8px; }
.ex-meta .cell { display: grid; gap: 2px; padding: 0 clamp(12px, 1.6cqi, 20px); border-left: 1px solid var(--line-2); }
.ex-meta .cell:first-child { padding-left: 0; border-left: 0; }
.ex-meta dt { color: var(--muted); font: 500 14px/1.2 var(--body); }
.ex-meta .is-unset dd { color: var(--quiet); font-weight: 500; }
.ex-meta dd {
  margin: 0;
  color: var(--text);
  font: 600 clamp(20px, 2.4cqi, 28px)/1.1 var(--display);
  font-variant-numeric: tabular-nums;
}

.works { margin: 0; color: var(--muted); font: 500 clamp(15px, 1.5cqi, 18px)/1.3 var(--body); }

/* live band: always on screen, because the figure always is repping */
.live { display: grid; gap: clamp(8px, 1.2cqi, 12px); }
.tempo { display: flex; gap: 4px; height: clamp(36px, 4.6cqi, 50px); }
.tseg {
  position: relative;
  flex: var(--sec) 1 0;
  min-width: 0;
  overflow: hidden;
  border-radius: 2px;
  background: var(--raise);
}
.tseg-label, .tfill {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 clamp(4px, 0.8cqi, 8px);
}
.tseg-label { color: var(--muted); }
.tseg.is-on .tseg-label { color: var(--text); }
.tfill {
  background: var(--accent);
  color: var(--on-accent);
  clip-path: inset(0 calc((1 - var(--k, 0)) * 100%) 0 0);
}
.tl {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: 600 clamp(12px, 1.2cqi, 15px)/1.05 var(--display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.ts { font: 500 clamp(11px, 1cqi, 12px)/1.25 var(--mono); opacity: 0.85; }

.phase { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; } /* the phase and its countdown share a line */
.phase-name {
  color: var(--text);
  font: 700 clamp(24px, 3.2cqi, 40px)/1 var(--display);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.countdown {
  min-height: 1em;
  color: var(--muted);
  font: 500 clamp(13px, 1.3cqi, 15px)/1 var(--mono);
  font-variant-numeric: tabular-nums;
}
/* track: set up, form, avoid take turns in one grid cell, so the column keeps its height as they change */
.track { display: grid; flex: 1 1 auto; min-height: 0; }
.sec {
  grid-area: 1 / 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.1cqi, 12px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 270ms var(--ease-in), transform 270ms var(--ease-in), visibility 0s linear 270ms;
}
.sec.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity var(--slow) var(--ease-out) 80ms, transform var(--slow) var(--ease-out) 80ms, visibility 0s;
}
.sec .eyebrow { display: flex; align-items: baseline; gap: 0.5em; }
.step { color: var(--quiet); font: 500 1em/1 var(--body); font-variant-numeric: tabular-nums; }
.label { display: block; margin-bottom: 4px; }
.equip { margin: 0; color: var(--muted); font-size: clamp(14px, 1.35cqi, 16px); line-height: 1.35; }

/* lists show their newest three lines; the newest is bright and fades in */
.cue-list, .mistake-list { list-style: none; margin: 0; padding: 0; display: grid; gap: clamp(6px, 0.9cqi, 10px); }
.cue-list { counter-reset: cue; }
.cue-list li, .mistake-list li {
  color: var(--muted);
  font-size: clamp(15px, 1.6cqi, 19px);
  line-height: 1.32;
  transition: color var(--mid) var(--ease-out);
}
.cue-list li { counter-increment: cue; display: grid; grid-template-columns: 1.4em minmax(0, 1fr); gap: 0.35em; }
.cue-list li::before { content: counter(cue); color: var(--quiet); font: 500 0.85em/1.6 var(--body); font-variant-numeric: tabular-nums; }
.cue-list li.current, .mistake-list li.current { color: var(--text); }
.cue-list li.current::before { color: var(--text); }
.cue-list li.fresh, .mistake-list li.fresh { animation: rise var(--slow) var(--ease-out) both; }
.mistake-list li { position: relative; padding-left: 1.6em; }
.mistake-list li::before, .mistake-list li::after {
  content: '';
  position: absolute;
  left: 0.15em;
  top: 0.62em;
  width: 0.8em;
  height: 2px;
  border-radius: 1px;
  background: var(--warn);
  transform: rotate(45deg);
}
.mistake-list li::after { transform: rotate(-45deg); }
.note { margin: auto 0 0; color: var(--muted); font-size: clamp(14px, 1.3cqi, 16px); line-height: 1.4; }

/* nothing to play: no rep counter, tempo bar or meta to show */
.stage[data-section="empty"] .live, .stage[data-section="empty"] .ex-meta, .stage[data-section="empty"] .works, .stage[data-section="empty"] .up-next { display: none; }

/* after the reps: a timed rest */
.rest-count {
  margin: 0;
  font: 700 clamp(44px, 7cqi, 88px)/0.95 var(--display);
  font-variant-numeric: tabular-nums;
}
.rest-bar { position: relative; height: 6px; overflow: hidden; border-radius: 2px; background: var(--raise); }
.rest-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--muted);
  transform: scaleX(var(--k, 0));
  transform-origin: left center;
}
.rest-next { margin: 0; color: var(--muted); font: 500 clamp(15px, 1.5cqi, 18px)/1.35 var(--body); }
.rest-next b { color: var(--text); font-weight: 600; }
.stage[data-section="rest"] .tempo { opacity: 0.4; }

/* during the final rep: what comes next */
.up-next {
  --plate: var(--next, var(--line-2));
  min-height: 1.4em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5em;
  color: var(--muted);
  font: 500 clamp(14px, 1.3cqi, 16px)/1.3 var(--body);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 270ms var(--ease-in), transform 270ms var(--ease-in);
}
.up-next.is-on { opacity: 1; transform: none; transition: opacity var(--slow) var(--ease-out), transform var(--slow) var(--ease-out); }
.up-next b { color: var(--text); font-weight: 600; }

/* ---------- transport ---------- */
.transport { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.scrub { position: relative; min-width: 0; padding-top: 8px; border-radius: 4px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.scrub:focus-visible { outline-offset: 4px; }
.scrub-track { display: flex; gap: 4px; height: 10px; }
.seg {
  position: relative;
  flex: var(--dur) 1 0;
  min-width: 0;
  overflow: hidden;
  border-radius: 2px;
  background: var(--raise);
  background: color-mix(in srgb, var(--plate) 24%, var(--raise));
}
.seg-fill {
  position: absolute;
  inset: 0;
  background: var(--plate);
  transform: scaleX(0);
  transform-origin: left center;
}
.seg-rest {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  background: repeating-linear-gradient(135deg, var(--ground) 0 3px, transparent 3px 6px);
  opacity: 0.7;
}
.seg-tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ground); opacity: 0.55; }
.scrub-head {
  position: absolute;
  top: 3px;
  left: 0;
  width: 4px;
  height: 20px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--fill);
  box-shadow: 0 0 0 3px var(--ground);
  pointer-events: none;
  will-change: transform;
}
/* Loop mode: a bracket over the part of the current chapter that repeats */
.scrub-loop {
  position: absolute;
  top: 1px;
  height: 6px;
  border: 2px solid var(--plate);
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  opacity: 0.85;
  pointer-events: none;
}
.scrub-labels { display: flex; gap: 4px; margin-top: 8px; }
.seg-label {
  flex: var(--dur) 1 0;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  color: var(--quiet);
  font-size: 13px;
}
.seg-label .n { color: inherit; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg-label .nm { overflow: hidden; text-overflow: ellipsis; }
/* many chapters: numbers only, and the current chapter's name on its own line; very many: just the current number */
.scrub-labels.is-crowded .nm { display: none; }
.scrub-labels.is-tight { height: 0; margin-top: 0; overflow: hidden; } /* the line below carries the current number */
.scrub-now { display: none; margin: 4px 0 0; color: var(--text); font: 500 var(--fs-sm)/1.3 var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scrub-labels.is-crowded + .scrub-now { display: block; }
.scrub-now .n { color: var(--plate, var(--quiet)); font-weight: 600; margin-right: 6px; font-variant-numeric: tabular-nums; }
.seg-label.is-current { color: var(--text); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.buttons { display: flex; align-items: center; gap: 8px; }
.btn-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}
.btn-icon:hover:not(:disabled) { background: var(--raise); border-color: var(--dim); }
.btn-icon:disabled { opacity: 0.35; cursor: default; }
.btn-icon svg { width: 18px; height: 18px; }
/* the one primary button */
.btn-play { width: 52px; height: 52px; border-radius: 50%; border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn-play:hover:not(:disabled) { border-color: var(--accent-hi); background: var(--accent-hi); }
.btn-play svg { width: 22px; height: 22px; }

.time { margin: 0; color: var(--muted); font: 500 14px/1 var(--mono); font-variant-numeric: tabular-nums; }
.time #elapsed { color: var(--text); }

.beats { display: flex; align-items: center; gap: 4px; }
.beats i { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); transition: background 80ms var(--ease-out); }
.beats i:first-child { width: 9px; height: 9px; }
.beats i.on { background: var(--accent); }

/* Routine / Loop: two radios drawn as one segmented switch */
.mode {
  position: relative;
  display: inline-flex;
  min-width: 0;
  margin: 0 0 0 auto;
  padding: 2px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
}
.mode input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.mode label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 2px;
  color: var(--muted);
  font: 600 14px/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--mid) var(--ease-out), color var(--fast) var(--ease-out);
}
.mode label svg { width: 14px; height: 14px; }
.mode label:hover { color: var(--text); }
.mode input:checked + label { background: var(--fill); color: var(--on-fill); }
.mode input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }

.music { display: flex; align-items: center; gap: 8px; }
.music .btn-icon[aria-pressed="false"] { color: var(--quiet); }
#volume { width: 110px; accent-color: var(--accent); }
.music.is-muted #volume { opacity: 0.4; }

/* ---------- shared controls ---------- */
.btn-text {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: 600 14px/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}
.btn-text:hover:not(:disabled) { border-color: var(--dim); color: var(--text); }
.btn-text:active:not(:disabled) { transform: translateY(1px); }
.btn-text:disabled, .btn-add:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-danger { color: var(--warn); }
.btn-danger:hover:not(:disabled) { border-color: var(--warn); color: var(--warn); }

/* the panel's main action: filled, but chalk, so amber stays the stage's */
.btn-add {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--fill);
  border-radius: 4px;
  background: var(--fill);
  color: var(--on-fill);
  font: 600 15px/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}
.btn-add:hover:not(:disabled) { background: var(--fill-hi); border-color: var(--fill-hi); }
.btn-add:active:not(:disabled) { transform: translateY(1px); }

.btn-link {
  min-height: 32px;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 14px/1.2 var(--body);
  text-decoration: underline;
  text-decoration-color: var(--line-2);
  text-underline-offset: 3px;
  cursor: pointer;
}
.btn-link:hover { color: var(--text); text-decoration-color: var(--muted); }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}
.icon-btn::before { content: ''; position: absolute; inset: -4px; } /* a 44px target around a 36px mark */
.icon-btn:hover { border-color: var(--line-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.field-label { display: block; margin-bottom: 4px; color: var(--muted); font: 500 14px/1.2 var(--body); }
.field {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--dim);
  border-radius: 4px;
  background: var(--ground);
  color: var(--text);
  font: 500 16px/1.3 var(--body);
  outline: 2px solid transparent;
  outline-offset: -3px;
  font-variant-numeric: tabular-nums;
}
.field::placeholder { color: var(--quiet); }
.field:hover { background: var(--stage); }
.field:focus-visible { outline-color: var(--accent); border-color: var(--muted); }
.field-sm { width: auto; min-width: 9ch; max-width: 16ch; min-height: 36px; padding: 6px 8px; }
.inline-edit { display: inline-flex; }
.person-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.body-pick { display: inline-flex; margin: 0; padding: 2px; border: 1px solid var(--line-2); border-radius: 4px; }
.body-pick input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.body-pick label { padding: 6px 10px; border-radius: 2px; color: var(--muted); font: 500 14px/1 var(--body); cursor: pointer; }
.body-pick input:checked + label { background: var(--fill); color: var(--on-fill); }
.body-pick input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- header: who is training ---------- */
.people { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-right: auto; }
.person {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: 600 15px/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--mid) var(--ease-out), color var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}
.person:hover { color: var(--text); border-color: var(--dim); }
.person[aria-pressed="true"] { border-color: var(--fill); background: var(--fill); color: var(--on-fill); }

/* ---------- routine panel ---------- */
.routine {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 16px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.view-routine { display: grid; gap: 12px; min-width: 0; }
/* the routine picker and its actions stay in view while the list scrolls */
.routine-top { position: sticky; top: 0; z-index: 2; display: grid; gap: 12px; margin: -16px -12px 0; padding: 16px 12px 8px; border-radius: var(--r-lg) var(--r-lg) 0 0; background: var(--surface); box-shadow: 0 1px 0 var(--line); }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 4px; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: 600 16px/1 var(--display);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--mid) var(--ease-out), color var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}
.tab:hover { color: var(--text); border-color: var(--dim); }
.tab[aria-pressed="true"] { border-color: var(--line-2); background: var(--raise); color: var(--text); box-shadow: inset 0 -2px 0 var(--text); }
.tab-new { border-style: dashed; }
.tab-new svg { width: 14px; height: 14px; }

.routine-bar { display: grid; gap: 4px; padding: 0 4px; }
.catalog-link { justify-self: start; min-height: 32px; display: inline-flex; align-items: center; color: var(--text); font: 600 var(--fs-label)/1.2 var(--body); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.catalog-link:hover { text-decoration-color: var(--text); }
.routine-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; min-height: 36px; }
.confirm { display: grid; gap: 8px; width: 100%; padding: 12px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--raise); }
.confirm-text { margin: 0; font-size: 15px; line-height: 1.4; }
.confirm-acts { display: flex; flex-wrap: wrap; gap: 8px; }

.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rows:empty { display: none; }
.row {
  display: grid;
  grid-template-columns: 12px 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  transition: background var(--mid) var(--ease-out), border-color var(--mid) var(--ease-out);
}
@media (hover: hover) { .row:hover { background: var(--raise); } }
.row.is-current { border-color: var(--line-2); background: var(--raise); }
.row.dragging { position: relative; z-index: 2; border-color: var(--accent); background: var(--raise); box-shadow: 0 8px 24px var(--shadow); }

.handle {
  justify-self: center;
  width: 12px;
  height: 24px;
  cursor: grab;
  touch-action: none;
  background-image: radial-gradient(circle, var(--dim) 1.2px, transparent 1.6px);
  background-size: 6px 6px;
}
.handle:hover { background-image: radial-gradient(circle, var(--muted) 1.2px, transparent 1.6px); }
body.is-dragging .handle { cursor: grabbing; }

.inc { display: grid; place-items: center; width: 24px; height: 36px; cursor: pointer; }
.inc input {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1.5px solid var(--dim);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
}
.inc input:checked { border-color: var(--plate, var(--fill)); background: var(--plate, var(--fill)); }
.inc input:checked::after {
  content: '';
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--on-fill);
  border-bottom: 2px solid var(--on-fill);
  transform: translateY(-1px) rotate(-45deg);
}
.inc input:disabled { opacity: 0.55; cursor: not-allowed; }

.row-main {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.row-main:disabled { cursor: default; }
.row-num { min-width: 1ch; color: var(--muted); font: 600 15px/1 var(--body); font-variant-numeric: tabular-nums; }
.row-text { min-width: 0; display: grid; gap: 4px; }
.row-name {
  font: 600 17px/1.1 var(--display);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-wrap: balance;
}
.row-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  text-wrap: balance;
}
.unset { color: var(--quiet); font-style: italic; }
.rest-note { margin-left: 0.5em; color: var(--quiet); white-space: nowrap; }
.row-dur { color: var(--quiet); font: 500 13px/1 var(--mono); font-variant-numeric: tabular-nums; }
.row.is-skipped .row-main { opacity: 0.55; }
.row.is-missing .row-meta { color: var(--quiet); }
.row-edit svg { transition: transform var(--mid) var(--ease-out); }
.row-edit[aria-expanded="true"] svg { transform: rotate(180deg); }

.row-editor {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  margin: 4px 0 4px 44px;
  padding: 12px 0 8px;
  border-top: 1px solid var(--line);
}
.ed-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ed-help { margin: -4px 0 0; color: var(--quiet); font-size: 14px; line-height: 1.4; }
.ed-field { min-width: 0; }
.ed-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.ed-acts .btn-danger { margin-left: auto; }

.empty { display: grid; gap: 8px; justify-items: start; padding: 16px 4px; }
.empty-title { margin: 0; font: 600 17px/1.3 var(--body); }

.routine-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--line);
}
.hint { flex: 1 1 200px; margin: 0; color: var(--quiet); font-size: 14px; line-height: 1.4; }
/* where changes live: a dot and a line, with sign in or out beside it */
.sync { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.sync-text { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.3; }
.sync-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.sync[data-state="synced"] .sync-dot { background: var(--plate-4); }
.sync[data-state="syncing"] .sync-dot { background: var(--muted); }
.sync-out { flex: 1 1 100%; display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--raise); }
.sync-out .note { margin: 0; }
.sync-out-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* sign in: a small native dialog */
.signin {
  width: min(26rem, calc(100vw - 32px));
  max-height: min(80dvh, 40rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 48px var(--shadow);
}
.signin::backdrop { background: var(--scrim); }
.signin-form { display: grid; gap: 16px; padding: 24px; }
.signin-title { margin: 0; font: 700 24px/1 var(--display); letter-spacing: 0.01em; text-transform: uppercase; }
.signin .note { margin: 0; }
.field[aria-invalid="true"] { border-color: var(--warn); }
.field-error { min-height: 1.4em; margin: 4px 0 0; color: var(--warn); font-size: 14px; line-height: 1.4; }
.signin-acts { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- library ---------- */
.view-library { display: grid; gap: 12px; min-width: 0; align-content: start; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 4px; }
.lib-title { margin: 0; font: 700 24px/1 var(--display); letter-spacing: 0.01em; text-transform: uppercase; }
.lib-search { padding: 0 4px; }
.lib-filters { display: grid; gap: 8px; padding: 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-btn {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: 500 14px/1.2 var(--body);
  cursor: pointer;
  transition: background var(--fast) var(--ease-out), color var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}
.chip-btn:hover { border-color: var(--dim); color: var(--text); }
.chip-btn[aria-pressed="true"] { border-color: var(--fill); background: var(--fill); color: var(--on-fill); }
.lib-count { margin: 0; padding: 0 4px; color: var(--quiet); font-size: 14px; font-variant-numeric: tabular-nums; }
.lib-list { display: grid; gap: 16px; }
.lib-region { display: grid; gap: 4px; }
.lib-region-title { margin: 0; padding: 0 4px; font: 700 20px/1.1 var(--display); letter-spacing: 0.01em; text-transform: uppercase; }
.lib-pattern-title { margin: 8px 0 0; padding: 0 4px; color: var(--muted); font: 500 14px/1.2 var(--body); }
.lib-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.lib-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-top: 1px solid var(--line);
}
.lib-text { min-width: 0; display: grid; gap: 2px; }
.lib-name { margin: 0; font: 600 17px/1.15 var(--display); letter-spacing: 0.01em; text-transform: uppercase; }
.lib-meta { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.3; }
.lib-in { margin: 0; color: var(--text); font-size: 14px; line-height: 1.3; }
.lib-in::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--fill); vertical-align: 1px; }
.lib-acts { display: flex; gap: 6px; }
.lib-acts .btn-add { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.lib-empty { display: grid; gap: 8px; justify-items: start; padding: 16px 4px; }
.lib-empty-title { margin: 0; font: 600 17px/1.3 var(--body); }

/* ---------- preview bar and toast ---------- */
.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 12px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--raise);
}
.preview-text { margin: 0; color: var(--muted); font-size: 15px; }
.preview-text b { color: var(--text); font-weight: 600; }
.preview-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.preview-lib { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--raise);
  box-shadow: 0 8px 24px var(--shadow);
  color: var(--text);
  font-size: 15px;
  transform: translateX(-50%);
}

/* ---------- responsive ---------- */
@media (min-width: 1080px) {
  /* the header already names the routine and its length */
  #routine-summary { display: none; }
  /* beside the stage, the panel keeps to the screen's height and scrolls inside itself */
  .routine { position: sticky; top: 16px; max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
  .view-library { max-height: none; }
}
@media (max-width: 1079px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .app { padding-block: 12px 40px; gap: 12px; }
  .top { flex-wrap: nowrap; align-items: center; }
  .top h1 { font-size: 24px; }
  .top .summary { display: none; }
  .people { margin-right: 0; justify-content: flex-end; }
  .person { min-height: 34px; padding: 5px 10px; font-size: 14px; }
  .stage { aspect-ratio: auto; grid-template-columns: minmax(0, 1fr); }
  .stage-figure { aspect-ratio: 16 / 9; border-radius: 6px 6px 0 0; } /* a notch shorter, so the people switcher fits above it and Play stays above the fold */
  .stage-text { gap: 8px; padding: 0 16px 12px; }
  .head { gap: 4px; }
  .ex-meta dd { font-size: 20px; }
  .sec { gap: 8px; }
  .cue-list, .mistake-list { gap: 4px; }
  .cue-list li, .mistake-list li { font-size: 15px; line-height: 1.3; }
  .live { gap: 8px; }
  .tempo { height: 34px; }
  /* these two keep Play above the fold on a phone: the set-up lines name the kit, and note labels run inline */
  .equip { display: none; }
  .note .label { display: inline; margin: 0 0.4em 0 0; }
  .keys { display: none; }
  .mode { margin-left: 0; }
  .player { gap: 12px; }
  .ed-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .row-editor { margin-left: 0; }

  /* the library is a full-screen sheet on a phone */
  .view-library {
    position: fixed;
    inset: 0;
    z-index: 30;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px));
    background: var(--surface);
  }
  .lib-head { position: sticky; top: calc(-1 * max(12px, env(safe-area-inset-top, 0px))); z-index: 1; padding: 12px 4px; background: var(--surface); }
  body.lib-open { overflow: hidden; }
  body.lib-open.lib-peek { overflow: auto; }
  body.lib-peek .view-library { display: none; }
  .preview-lib { display: inline-block; }
}
@media (max-width: 560px) {
  .seg-label .nm { display: none; }
  #volume { width: 84px; }
  .row-dur { display: none; }
  .lib-item { grid-template-columns: minmax(0, 1fr); }
}

@media (pointer: coarse) {
  .btn-icon { min-width: 44px; min-height: 44px; }
  .inc { width: 44px; height: 44px; }
  .row { grid-template-columns: 12px 44px minmax(0, 1fr) auto; }
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn::before { inset: 0; }
  .chip-btn, .btn-text, .btn-add, .tab, .person { min-height: 44px; }
}

/* the first frame renders at rest: nothing fades in on load */
.no-anim, .no-anim * { transition: none !important; animation: none !important; }

@media (prefers-reduced-motion: reduce) {
  .sec, .sec.is-active, .up-next, .up-next.is-on, .cue-list li, .mistake-list li { transform: none; transition: none; }
  .head.enter, .cue-list li.fresh, .mistake-list li.fresh { animation: none; }
  .rest-bar::after { transition: none; }
  .big-play .disc, .beats i, .row-edit svg { transition: none; }
}
