:root {
  /* Evening-forest theme: deep moss surfaces, warm parchment ink, muted
     amber like low sun through trees. Same hue family as the old cream
     skin, just taken down into dusk. */
  color-scheme: dark;
  --ink: #d6cdb0;
  --ink-rgb: 214 205 176;
  --bg: #141a10;
  --bg-rgb: 20 26 16;
  --bg-elevated: #222b1a;
  --bg-panel: #29321c;
  --line: #a79e82;
  --text: #d6cdb0;
  --text-dim: #978d6d;
  --accent: #d9a83f;
  --accent-dim: #a5822f;
  --sun: #d9a83f;
  --sun-rgb: 217 168 63;
  --plant: #5a9668;
  --plant-rgb: 90 150 104;
  --warn: #c97a44;
  --danger: #b2543f;
  /* Text/icons drawn on top of saturated accent fills (amber chips, pads). */
  --on-accent: #1c140c;
  /* Text/icons drawn on top of instrument-colour fills (notes, lit pads). */
  --text-on-color: #f2ead4;
  /* Real shadows stay near-black on a dark surface — not light "ink". */
  --shadow-rgb: 7 9 4;
  --row-blocked: #151a0e;
  --sampler-hit: #574a78;
  --radius: 16px;
  --tap: 52px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-x: none;
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
}

body[data-view='role'] {
  height: auto;
  min-height: 100%;
}

body[data-view='host'],
body[data-view='controller'] {
  position: relative;
  width: 100%;
  min-height: 100%;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  min-height: 100%;
  display: none;
}

.screen:not([hidden]) {
  display: flex;
  flex-direction: column;
}

/* ---------- Экран выбора роли ---------- */

.screen--center {
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 32px 20px 24px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 8% 12%, rgb(var(--sun-rgb) / 0.55) 0 64px, transparent 66px),
    radial-gradient(circle at 92% 88%, rgb(var(--plant-rgb) / 0.5) 0 78px, transparent 80px),
    var(--bg);
}

.brand {
  text-align: center;
  max-width: 640px;
}

.brand__dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 24px var(--accent);
  margin-bottom: 18px;
}

.brand__title {
  margin: 0 0 10px;
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: -0.02em;
}

.brand__subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.5;
}

.role-grid {
  display: grid;
  gap: 18px;
  width: min(880px, 100%);
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.role-card {
  background: var(--bg-elevated);
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.role-card h2 {
  margin: 0;
  font-size: 22px;
}

.role-card p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.5;
  flex: 1;
}

.role-lite {
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-dim);
}

.role-lite input[type='checkbox'] {
  width: 26px;
  height: 26px;
}

.role-footnote {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  margin: 0;
  opacity: 0.8;
}

.role-disclosure {
  width: min(520px, 100%);
}

#ai-disclosure.fx-sheet {
  align-items: center;
}

.disclosure-card p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.55;
}

.share-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(880px, 100%);
}

.share-block__install {
  width: min(520px, 100%);
}

.share-block__hint {
  margin: -6px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}

.share-block__text {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
}

.share-block__qr {
  background: #fff;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  line-height: 0;
  color: var(--on-accent);
}

/* The role-screen QR paints at 132px — claim that square up front so the
   card doesn't jump when the image lands. */
.share-block__qr.qr-loading {
  width: 154px;
  height: 154px;
}

.share-block__qr img,
.share-block__qr canvas,
.share-block__qr table {
  display: block;
}

/* While the QR library downloads, the box shows a spinner instead of a
   blank white square — the QR used to pop in with no hint it was coming.
   Every QR box is a white card, so the spinner and label use --on-accent:
   the light --ink ring read as a static blank on white. */
.qr-loading {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 10px;
  line-height: 1.2;
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.qr-loading::before {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgb(28 20 12 / 0.15);
  border-top-color: var(--on-accent);
  animation: splash-spin 0.8s linear infinite;
}

/* A slow sweep crosses the placeholder — the card keeps moving even if the
   spinner stalls, so a cold connect never looks frozen. */
.qr-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 32%, rgb(28 20 12 / 0.1) 50%, transparent 68%);
  animation: qr-sweep 1.6s ease-in-out infinite;
}

@keyframes qr-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

/* Session placeholders pulse until the real code/link land — together with
   the QR sweep the header clearly reads as "still loading". */
.is-pending {
  animation: pending-pulse 1.4s ease-in-out infinite;
}

@keyframes pending-pulse {
  50% { opacity: 0.35; }
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.join-form__label {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.join-form__input {
  height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  border-width: 3px;
  color: var(--text);
  font-size: 28px;
  letter-spacing: 0.4em;
  text-align: center;
  text-transform: uppercase;
  font-weight: 600;
}

.join-form__input:focus {
  outline: 2px solid var(--accent-dim);
}

.join-form__error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Кнопки ---------- */

.btn,
.chip,
.step,
.mix-flag,
[role='button'] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  /* Taps still fire; a drag starts a scroll instead of eating the gesture.
     Real gesture surfaces (pad, roll keys/notes, sampler pads, sliders,
     .step) re-declare none/pan-y below. */
  touch-action: pan-x pan-y;
}

.btn:disabled,
.btn[aria-disabled='true'],
.chip[aria-disabled='true'],
.step[aria-disabled='true'],
.mix-flag[aria-disabled='true'],
[role='button'][aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.pad,
.pad__canvas,
.roll__note,
.roll__key,
input[type='range'] {
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.btn {
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 44px;
  height: auto;
  white-space: normal;
  overflow: visible;
  text-align: center;
  line-height: 1.15;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Busy state while a CDN script downloads (e.g. Tone.js before host entry). */
.btn.is-loading {
  gap: 10px;
}

.btn.is-loading::after {
  content: '';
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 3px solid rgb(var(--ink-rgb) / 0.18);
  border-top-color: var(--ink);
  animation: splash-spin 0.8s linear infinite;
}

.btn--primary,
.btn.is-on {
  background: var(--sun);
  color: var(--on-accent);
}

/* The Rec button's pip glows red only while a take is open. */
.btn.is-on .rec-dot {
  fill: var(--danger);
}

.btn--ghost {
  background: transparent;
  border-color: var(--line);
}

.btn--xl {
  min-height: var(--tap);
  height: auto;
  font-size: 17px;
}

.btn--sm {
  height: 34px;
  font-size: 13px;
  padding: 0 12px;
}

.btn--icon {
  width: 44px;
  padding: 0;
  font-size: 20px;
  background: transparent;
  border-color: var(--line);
}

.btn.has-icon {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  max-width: 100%;
  height: auto;
  min-height: 56px;
  padding: 8px 10px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.btn.has-icon .ico {
  width: 26px;
  height: 26px;
}

.btn.has-icon .chip-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  font-size: inherit;
  line-height: 1.15;
}

.roll-actions .btn.has-icon,
.fx-sheet__card > .btn.has-icon,
.seq-pages .btn.has-icon {
  width: 100%;
}

.chip {
  min-height: 48px;
  height: auto;
  padding: 6px 10px;
  border-radius: 18px;
  border: 3px solid var(--ink);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  white-space: normal;
  overflow: visible;
  text-align: center;
  cursor: pointer;
}

.chip.is-picked {
  box-shadow: inset 0 -5px 0 var(--sun);
}

.chip.is-on {
  background: var(--chip, var(--sun));
  color: var(--on-accent);
}

.chip.has-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.chip.has-swatch::before {
  content: '';
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: var(--chip, var(--sun));
  border: 2px solid var(--ink);
}

.chip.has-swatch.has-icon {
  flex-direction: column;
  gap: 2px;
}

.chip.has-swatch.has-icon::before {
  width: 10px;
  height: 10px;
}

.chip.is-on.has-swatch::before {
  background: var(--bg-elevated);
}

.ico {
  width: 28px;
  height: 28px;
  display: block;
  flex: 0 0 auto;
}

.chip-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  font-size: 13px;
  line-height: 1.1;
  text-align: center;
  white-space: normal;
  overflow: visible;
}

.chip-label small {
  font-size: 11px;
  font-weight: 700;
}

.chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.chips--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips--scroll::-webkit-scrollbar {
  display: none;
}

.chips__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  width: 100%;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.pill[data-state='online'] {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.pill[data-state='error'] {
  color: var(--danger);
  border-color: var(--danger);
}

/* "connecting…" pulses so a cold backend wake-up reads as progress, not a
   frozen label. */
.pill[data-state='pending'] {
  color: var(--accent-dim);
  border-color: var(--accent-dim);
  animation: pending-pulse 1.4s ease-in-out infinite;
}

/* ---------- Экран хоста ---------- */

.screen--host {
  position: relative;
  min-height: 100%;
  height: auto;
  overflow: visible;
  padding: 0;
}

.host-app {
  min-height: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Portrait phone: .host-tools is display:contents, so its children become
   flex items here and can order themselves between the header and the pad. */
.host-app > .topbar {
  order: 1;
}

.host-app > .play-bar {
  order: 3;
}

.host-app > .pad-stage {
  order: 4;
}

.host-tools > .tempo-panel {
  order: 2;
}

.host-tools > .tool-sec {
  order: 5;
}

.host-tools > #btn-master {
  order: 6;
}

.host-tools > .event-log {
  order: 7;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.qr-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
  border-radius: 12px;
}

.qr-card:active {
  filter: brightness(0.94);
}

.qr-card:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* Phones squeeze the header QR below scanning size, so the card is a button:
   one tap opens the share sheet with a big code. */
.qr-card__invite {
  display: none;
}

/* The stamp wrapper anchors the expand badge to the QR's corner — the badge
   is the "tap to enlarge" hint a plain thumbnail doesn't have. */
.qr-card__stamp {
  position: relative;
  flex: 0 0 auto;
}

.qr-card__zoom {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sun);
  color: var(--on-accent);
  border: 2px solid var(--bg-panel);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

/* Only a painted QR earns the badge — over the loading spinner it's noise. */
.qr-card__stamp:has(#host-qr img) .qr-card__zoom {
  opacity: 1;
  transform: scale(1);
}

#host-qr {
  background: #fff;
  padding: 4px;
  border-radius: 10px;
  line-height: 0;
  flex: 0 0 auto;
  color: var(--on-accent);
}

/* The loading placeholder holds the final stamp size from first paint —
   no collapsed sliver, no layout jump when the QR lands. */
#host-qr.qr-loading {
  width: 80px;
  height: 80px;
  line-height: 1.2;
}

/* qrcode.js paints a <canvas> first and swaps it for an <img>. Size the
   canvas too: if the swap stalls, a native-size canvas blows the header
   past the viewport. */
#host-qr img,
#host-qr canvas,
#host-qr table {
  width: 72px !important;
  height: 72px !important;
  display: block;
}

.qr-card__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar__status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.topbar__actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex: 0 0 auto;
}

.topbar__actions .btn {
  height: 44px;
  padding: 0 12px;
  font-size: 15px;
}

.topbar__actions .btn.has-icon {
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  gap: 6px;
  padding: 0 12px;
}

.topbar__actions .btn.has-icon .ico {
  width: 18px;
  height: 18px;
}

.export-hint {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

#export-repeats {
  width: 100%;
  min-height: 52px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--ink);
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  padding: 0 12px;
}

.roll__key {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.topbar__eyebrow {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.topbar__code {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--accent);
  line-height: 1.1;
}

.topbar__link {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px 0;
  touch-action: pan-y;
}

.play-bar[hidden],
.play-bar__modes[hidden] {
  display: none;
}

.play-bar__modes {
  display: flex;
  flex: 1.4 1 0;
  gap: 6px;
  min-width: 0;
}

.play-bar .chip,
.play-bar .btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  width: auto;
}

.play-bar .btn--icon {
  flex: 0 0 52px;
  width: 52px;
  padding: 0;
}

.play-bar .btn--icon .ico {
  margin: 0 auto;
}

/* Holding the clear button arms the all-loops wipe. */
.play-bar .btn--icon.is-arming,
.btn--icon.is-arming {
  background: rgba(196, 81, 44, 0.28);
  border-color: #c4512c;
  animation: clear-arm 0.6s linear forwards;
}

@keyframes clear-arm {
  from { box-shadow: inset 0 0 0 0 rgba(196, 81, 44, 0.7); }
  to { box-shadow: inset 0 0 0 26px rgba(196, 81, 44, 0.7); }
}

/* Holding a length control on a grow arms the copy: same timed fill as
   clear-all, but amber — it duplicates bars, it destroys nothing. */
.is-arming--dup {
  background: rgb(var(--sun-rgb) / 0.22);
  border-color: var(--sun);
  animation: dup-arm 0.6s linear forwards;
}

@keyframes dup-arm {
  from { box-shadow: inset 0 0 0 0 rgb(var(--sun-rgb) / 0.6); }
  to { box-shadow: inset 0 0 0 30px rgb(var(--sun-rgb) / 0.6); }
}

.play-bar .chip-label {
  font-size: 15px;
}

/* Narrow phones: Notes/Chords and Rec were clipping at the chip edges, so
   the mode pair takes its own row — second, right above the pad. */
@media (max-width: 480px) {
  .play-bar {
    flex-wrap: wrap;
  }

  .play-bar__modes {
    flex: 1 1 100%;
    order: 2;
  }

  .play-bar .chip {
    font-size: 13px;
    padding-left: 4px;
    padding-right: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .play-bar .chip-label,
  .play-bar .btn {
    font-size: 13px;
  }

  .play-bar .btn {
    padding-left: 6px;
    padding-right: 6px;
  }
}

.inst-carousel {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.inst-carousel__arrow {
  flex: 0 0 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
}

.inst-carousel__arrow .ico {
  margin: 0 auto;
}

.inst-carousel__name {
  flex: 1 1 auto;
  cursor: default;
}

/* In the export sheet the format name is the action button, not a label. */
.export-format .inst-carousel__name {
  cursor: pointer;
  justify-content: center;
}

.drum-sec__row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.drum-sec__mix {
  flex: 0 0 112px;
}

.drum-sec__open {
  flex: 1 1 auto;
  min-width: 0;
}

.host-pad {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.pad-stage {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-width: 0;
}

/* Must out-specify `.pad { height: 100% }` — otherwise the pad collapses to
   the canvas's intrinsic bitmap height and the grid stripes end early. */
.pad-stage .host-pad {
  flex: 0 0 auto;
  height: 56vh;
  min-height: 300px;
}

.pad-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-panel);
  border: 3px solid var(--ink);
  border-radius: 14px;
  touch-action: pan-y;
}

.pad-stage .pad-mode {
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
}

.pad-mode__chips {
  display: flex;
  flex: 1 1 auto;
  gap: 6px;
}

.pad-mode__chips .chip {
  flex: 1 1 0;
  min-width: 76px;
  min-height: 48px;
  padding: 6px 16px;
  font-weight: 800;
  gap: 8px;
}

.pad-mode__chips .chip .ico {
  width: 20px;
  height: 20px;
}

.pad-mode__chips .chip .chip-label {
  font-size: inherit;
}

/* Portrait: contents, not a box — the tempo panel lifts above the play-bar
   with flex order while every other child stays below the pad. */
.host-tools {
  display: contents;
  min-width: 0;
}

.host-tools > * {
  border-top: 1px solid rgb(var(--ink-rgb) / 0.28);
  padding: 10px;
  min-width: 0;
}

.host-tools > :first-child {
  border-top: none;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: stretch;
}

.tool-row .chip {
  flex: 1 1 72px;
  min-width: 0;
  min-height: 52px;
  height: auto;
  padding: 6px 6px;
}

/* Preset chips keep a readable minimum and wrap onto as many rows as the
   width allows — a squeezed single row clipped every label to letters. */
.drum-presets .chip {
  flex: 1 1 84px;
  min-width: 0;
  padding-left: 2px;
  padding-right: 2px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-row__label {
  flex: 0 0 auto;
  align-self: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tool-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.tool-block__head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tool-block__head .tool-row {
  flex: 1;
  justify-content: flex-end;
}

.tool-block__head .chip {
  flex: 0 1 auto;
  min-height: 40px;
}

.root-picker {
  display: none;
  align-items: center;
  gap: 8px;
}

.root-picker .chip {
  flex: 0 0 72px;
  min-height: 48px;
  font-size: 20px;
}

#root-name {
  flex: 1;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.host-tools .chips--roots {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.host-tools .chips--roots .chip {
  width: 100%;
  min-height: 44px;
  padding: 0;
}

@media (max-width: 899px) {
  .host-tools .root-picker {
    display: flex;
  }

  .host-tools .chips--roots {
    display: none;
  }
}

.tempo-panel {
  display: flex;
  align-items: stretch;
  gap: 6px;
  background: var(--bg-panel);
  touch-action: pan-y;
}

.tempo-panel__bars {
  flex: 0 0 auto;
  min-width: 104px;
}

.tempo-panel__bpm {
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
}

.tempo-panel__bpm .chip {
  min-height: 48px;
}

.effect-row {
  display: flex;
  gap: 6px;
  min-width: 0;
}

.effect-row > .tool-row {
  flex: 1;
  min-width: 0;
}

.seq-pages {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.seq-page {
  width: 100%;
  min-height: 44px;
}

#btn-drums {
  min-height: 52px;
  padding: 6px 10px;
  font-size: 17px;
  font-weight: 800;
}

@media (max-width: 899px) {
  .topbar {
    min-width: 0;
    /* Slimmer header chrome keeps the QR, code and Invite label on the row. */
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  /* On a phone only the room code stays: every status is already surfaced
     elsewhere (sound overlay, disabled Play), and the pills overflowed the
     header onto the code. */
  .topbar__eyebrow,
  .topbar__link,
  #host-socket-status,
  #host-audio-status,
  #host-peers,
  #drum-source {
    display: none;
  }

  .topbar__status {
    flex-wrap: wrap;
  }

  .qr-card__meta {
    overflow: hidden;
  }

  .qr-card__invite {
    display: inline-block;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-dim);
    white-space: nowrap;
  }

  #host-qr img,
  #host-qr canvas,
  #host-qr table {
    width: 56px !important;
    height: 56px !important;
  }

  #host-qr.qr-loading {
    width: 64px;
    height: 64px;
  }

  .topbar__code {
    font-size: 18px;
    letter-spacing: 0.1em;
  }

  .topbar__actions .btn {
    height: 40px;
    padding: 0 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .pill {
    height: 24px;
    font-size: 11px;
    flex: 0 0 auto;
  }

  .host-tools {
    padding-left: 8px;
    padding-right: 8px;
  }

}

/* Tight phones (≈420px and under): the stamp shrinks a notch and buttons
   squeeze so the QR, code and Invite label all stay visible on one row. */
@media (max-width: 420px) {
  .topbar {
    gap: 4px;
    padding-left: 6px;
    padding-right: 6px;
  }

  #host-qr img,
  #host-qr canvas,
  #host-qr table {
    width: 48px !important;
    height: 48px !important;
  }

  #host-qr.qr-loading {
    width: 56px;
    height: 56px;
  }

  .topbar > .btn--icon,
  .topbar__actions .btn--icon {
    width: 38px;
  }

  .topbar__actions {
    gap: 4px;
  }

  .topbar__actions .btn {
    padding: 0 7px;
    font-size: 12px;
  }
}

/* Narrow phones: a slimmer quiet zone lets the invite QR keep its width —
   at 28px padding it clamped well below the intended 72vw. */
@media (max-width: 560px) {
  .share-qr {
    padding: 16px;
  }

  .share-qr.qr-loading {
    width: calc(var(--qr-edge) + 38px);
  }
}

/* Desktop: header + play bar on top, pad fills the left column, the right
   column is the settings scroller (same section order as portrait). */
@media (min-width: 1024px) and (min-height: 640px) {
  .host-app {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.9fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100dvh;
  }

  .host-app > .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    order: 0;
    padding: 10px 16px;
  }

  .host-app > .play-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    order: 0;
  }

  .host-app > .pad-stage {
    grid-column: 1;
    grid-row: 3;
    order: 0;
    min-height: 0;
    flex: 1 1 auto;
  }

  #host-qr img,
  #host-qr canvas,
  #host-qr table {
    width: 104px !important;
    height: 104px !important;
  }

  #host-qr.qr-loading {
    width: 112px;
    height: 112px;
  }

  .topbar__actions .btn {
    height: 48px;
    font-size: 16px;
    padding: 0 16px;
  }

  .topbar__code {
    font-size: 28px;
  }

  .pad-stage .host-pad {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  .host-tools {
    display: flex;
    flex-direction: column;
    grid-column: 2;
    grid-row: 3;
    min-height: 0;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    overscroll-behavior: contain;
  }

  /* Same two columns for the guest screen. */
  #controller-screen:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.9fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100dvh;
  }

  .controller-bar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  #controller-play-bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .pad-wrap {
    grid-column: 1;
    grid-row: 3;
    height: auto;
    min-height: 0;
    max-height: none;
    padding-bottom: 12px;
  }

  .controller-foot {
    grid-column: 2;
    grid-row: 3;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    overscroll-behavior: contain;
    padding-bottom: 12px;
  }
}

.sequencer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  /* Steps start after the sticky label column: label width + row gap. */
  --seq-label-w: 132px;
}

.seq-tape {
  position: relative;
  min-width: 0;
  overflow: auto;
  /* The grid pans and pinch-zooms manually — the browser must not steal the gesture. */
  touch-action: none;
  overscroll-behavior: contain;
}

.seq-gridlines {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--seq-label-w, 132px);
  width: 0;
  pointer-events: none;
  z-index: 1;
}

.seq-beatline,
.seq-barline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  pointer-events: none;
}

.seq-beatline {
  border-left: 1px solid rgb(var(--ink-rgb) / 0.34);
  transform: translateX(-0.5px);
}

.seq-barline {
  border-left: 4px solid var(--ink);
  transform: translateX(-2px);
}

.seq-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  min-height: 48px;
}

.seq-ruler__marks,
.seq-row__steps {
  display: flex;
  gap: 3px;
  width: max-content;
}

.seq-ruler {
  height: 28px;
  align-items: flex-end;
}

.seq-ruler-spacer {
  height: 28px;
}

.seq-ruler__bar {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.seq-row__label {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 128px;
  flex: 0 0 128px;
  height: 48px;
  padding: 0 6px;
  background: var(--bg-elevated);
  border-right: 2px solid var(--ink);
  color: var(--ink);
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}

.seq-row__label .ico {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
}

.seq-row__short {
  display: none;
}

/* Taps write cells; drags on cells pan the tape manually — no native scroll. */
.seq-row__steps .step {
  touch-action: none;
}

.seq-scroll {
  display: block;
  box-sizing: border-box;
  width: calc(100% - var(--seq-label-w, 132px) - 4px);
  margin: 8px 4px 0 var(--seq-label-w, 132px);
  min-height: 18px;
  height: 18px;
}

.seq-scroll.is-empty {
  visibility: hidden;
}

.step {
  width: 44px;
  height: 48px;
  min-height: 48px;
  flex: 0 0 44px;
}

.roll {
  width: 100%;
  max-height: 46vh;
  min-height: 180px;
  overflow: auto;
  overscroll-behavior: contain;
  /* One finger pans both axes, two fingers pinch-zoom — handled in JS. */
  touch-action: none;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--bg-elevated);
  scroll-padding-top: 26px;
}

.roll__sheet {
  display: grid;
  position: relative;
}

.roll__corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 5;
  background: var(--bg-panel);
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.roll__keys {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--bg-panel);
  border-right: 2px solid var(--ink);
}

.roll__key {
  position: absolute;
  left: 0;
  right: 0;
  height: 28px;
  display: flex;
  align-items: center;
  padding-left: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.roll__key.is-c {
  font-weight: 800;
}

.roll__key.is-sharp {
  color: rgb(var(--ink-rgb) / 0.55);
  background: rgb(var(--ink-rgb) / 0.06);
}

.roll__key.is-blocked {
  opacity: 0.38;
  color: rgb(var(--ink-rgb) / 0.4);
}

.roll__row {
  position: absolute;
  left: 0;
  right: 0;
  height: 28px;
  background: var(--bg-elevated);
  border-bottom: 1px solid rgb(var(--ink-rgb) / 0.16);
  pointer-events: none;
  z-index: 0;
}

.roll__row.is-blocked {
  background:
    repeating-linear-gradient(-45deg, transparent 0 7px, rgb(var(--ink-rgb) / 0.06) 7px 9px),
    var(--row-blocked);
  border-bottom: none;
}

.roll__ruler {
  position: sticky;
  top: 0;
  /* Above every strip — a dragged or selected note slides under the ruler. */
  z-index: 4;
  height: 26px;
  background: var(--bg-panel);
  border-bottom: 2px solid var(--ink);
}

.roll__bar {
  position: absolute;
  top: 2px;
  font-size: 13px;
  font-weight: 700;
  padding-left: 6px;
}

.roll__beat {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgb(var(--ink-rgb) / 0.22);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
}

.roll__beat--bar {
  width: 2px;
  background: rgb(var(--ink-rgb) / 0.55);
}

.roll__grid {
  position: relative;
  background: var(--bg-elevated);
  /* Strips stay inside the note field — a drag or a wrap-around tail never
     paints over the time ruler or the keys column. */
  overflow: hidden;
}

.roll__empty {
  margin: 12px;
  font-size: 16px;
  pointer-events: none;
}

.roll__note.is-selected {
  outline: 3px solid var(--ink);
  outline-offset: 1px;
  z-index: 3;
}

.roll__note.is-remote {
  border-style: dashed;
  opacity: 0.78;
}

.roll__note.is-undo-preview {
  outline: 3px solid rgb(var(--sun-rgb) / 0.9);
  outline-offset: 1px;
  z-index: 3;
}

.roll__marquee {
  position: absolute;
  z-index: 5;
  border: 2px solid var(--ink);
  background: rgba(224, 161, 46, 0.28);
  pointer-events: none;
}

.roll__note {
  position: absolute;
  z-index: 2;
  justify-content: flex-start;
  height: 22px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  color: var(--text-on-color);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  padding: 0 18px 0 4px;
  touch-action: none;
  overflow: hidden;
  white-space: nowrap;
}

.roll__resize {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 22px;
  touch-action: none;
  z-index: 1;
}

.roll__resize::before {
  content: '';
  position: absolute;
  top: 3px;
  bottom: 3px;
  right: 4px;
  width: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
}

.roll__playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: #c4512c;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 4;
}

.roll-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.roll-actions .btn {
  min-height: 56px;
  font-size: 18px;
}

.note-tape {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 72px;
}

.note-tape__empty {
  margin: 0;
  font-size: 16px;
}

.note-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  height: auto;
  padding: 8px 12px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  background: var(--bg-elevated);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  white-space: normal;
  line-height: 1.2;
}

.note-card .chip-label {
  flex: 1;
  min-width: 0;
}

.note-card__x {
  flex: 0 0 auto;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--sun);
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  border-width: 3px;
  padding: 0;
  cursor: pointer;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.step[data-beat='true'] {
  background: var(--bg-panel);
}

.step[data-bar='true'] {
  box-shadow: none;
}

.step.is-on {
  background: var(--sun);
  border-color: var(--ink);
  color: var(--on-accent);
}

.step.is-triplet {
  background: var(--warn);
  border-color: var(--ink);
}

.step.is-playing {
  outline: 2px solid var(--warn);
  outline-offset: 1px;
}

.seq-row[data-track] { --row-soft: color-mix(in srgb, var(--row) 20%, var(--bg-elevated)); }
.seq-row[data-track='kick'] { --row: #c4473a; }
.seq-row[data-track='snare'] { --row: #e0a12e; }
.seq-row[data-track='hat'] { --row: #2f8f55; }
.seq-row[data-track='openhat'] { --row: #1c7c88; }
.seq-row[data-track='clap'] { --row: #e07a3d; }
.seq-row[data-track='tom'] { --row: #7a4ea3; }
.seq-row[data-track='cowbell'] { --row: #3a6ea5; }
.seq-row[data-track='rimshot'] { --row: #c14f8f; }

.seq-row[data-track] .seq-row__label {
  background: var(--row-soft);
  color: var(--ink);
  box-shadow: inset 7px 0 0 var(--row);
}

.seq-row[data-track] .step,
.seq-row[data-track] .step[data-beat='true'] {
  background: var(--row-soft);
  border: 3px solid var(--ink);
  color: var(--ink);
}

.seq-row[data-track] .step.is-on {
  background: var(--row);
  border-color: var(--ink);
  color: var(--text-on-color);
}

.seq-row[data-track='snare'] .step.is-on {
  color: var(--on-accent);
}

.seq-row[data-track] .step.is-triplet {
  background: var(--ink);
  color: var(--row-soft);
  border-color: var(--ink);
}

/* Repeat mode: cells past the source bars are mirror copies. */
.seq-row[data-track] .step.is-mirror {
  border-style: dashed;
}

.seq-ruler__bar.is-mirror {
  opacity: 0.55;
}

.seq-hint {
  margin: 2px 0 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  opacity: 0.65;
}

/* Big tappable checkbox row that opens the advanced drum controls. */
.adv-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  font-weight: 800;
  font-size: 16px;
  touch-action: manipulation;
  cursor: pointer;
}

.adv-check input[type='checkbox'] {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--ink);
}

.drum-adv {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--bg-elevated);
}

.drum-adv[hidden] {
  display: none;
}

.drum-pitch {
  margin: 0;
}

.event-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 34px;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
}

.event-log li b {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Экран контроллера ---------- */

.screen--controller {
  position: relative;
  min-height: 100dvh;
  height: auto;
  overflow: visible;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  gap: 0;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.controller-bar,
.controller-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  flex: 0 0 auto;
}

.controller-bar__modes {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.controller-foot {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding-bottom: 12px;
}

.controller-foot > * {
  border-top: 1px solid rgb(var(--ink-rgb) / 0.28);
  padding-top: 10px;
  padding-bottom: 10px;
}

.pad-wrap {
  flex: 0 0 auto;
  height: 56vh;
  min-height: 280px;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pad-wrap > .pad {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

.pad {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgb(var(--plant-rgb) / 0.18) 0%, transparent 42%),
    var(--bg-elevated);
  border: 4px solid var(--ink);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pad__canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pad__pulse {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: min(52%, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255, 220, 130, 0.55) 0%, rgb(var(--sun-rgb) / 0.3) 46%, rgb(var(--sun-rgb) / 0) 76%);
  filter: blur(30px);
  opacity: 0;
  transform: translate(-50%, -50%);
  animation-name: none;
}

.pad.is-pulsing .pad__pulse {
  animation-name: pad-beat;
  animation-duration: calc(var(--beat-seconds, 0.625s) * 4);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: var(--pulse-delay, 0s);
}

/* While a take is open the pad heart burns red-pink instead of sun —
   the same beat-locked pulse, so recording reads at a glance. */
.pad.is-recording .pad__pulse {
  background: radial-gradient(circle, rgba(255, 105, 152, 0.6) 0%, rgba(255, 64, 118, 0.3) 46%, rgba(255, 64, 118, 0) 76%);
  animation-name: pad-beat;
  animation-duration: calc(var(--beat-seconds, 0.625s) * 4);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: var(--pulse-delay, 0s);
}

@keyframes pad-beat {
  0% { opacity: 0.94; transform: translate(-50%, -50%) scale(0.9); }
  9% { opacity: 0.28; transform: translate(-50%, -50%) scale(1.06); }
  20% { opacity: 0.06; transform: translate(-50%, -50%) scale(1.12); }
  25% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.92); }
  34% { opacity: 0.16; transform: translate(-50%, -50%) scale(1.04); }
  45% { opacity: 0.04; transform: translate(-50%, -50%) scale(1.1); }
  50% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.92); }
  59% { opacity: 0.16; transform: translate(-50%, -50%) scale(1.04); }
  70% { opacity: 0.04; transform: translate(-50%, -50%) scale(1.1); }
  75% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.92); }
  84% { opacity: 0.16; transform: translate(-50%, -50%) scale(1.04); }
  95% { opacity: 0; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.1); }
}

.pad__hint {
  position: absolute;
  inset: auto 10px 10px;
  z-index: 2;
  margin: 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.2;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.pad.is-active .pad__hint,
.pad.is-locked .pad__hint {
  opacity: 0;
}

.pad.is-locked {
  pointer-events: none;
}

.bar-readout {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.bar-label {
  margin: 0;
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 3px 3px 0 var(--bg-elevated);
}

.beat-dots {
  display: flex;
  gap: 10px;
}

.beat-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-sizing: border-box;
  background: var(--bg-elevated);
  border: 3px solid var(--ink);
}

.beat-dot.is-on {
  background: var(--ink);
}

.harmony-label {
  position: absolute;
  inset: 0 12% 8%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: clamp(40px, 9vw, 84px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 0.95;
  text-align: center;
  pointer-events: none;
  text-shadow: 3px 3px 0 var(--bg-elevated);
}

.y-zones {
  position: absolute;
  top: 12px;
  right: 10px;
  bottom: 12px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.y-zones span.is-active {
  color: var(--ink);
  font-weight: 700;
  text-shadow: 0 0 10px rgb(var(--sun-rgb) / 0.9);
}

/* ---------- Sampler pads ---------- */

/* The grid replaces the touchpad surface; it must win over [hidden]. */
.sampler {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.sampler[hidden] {
  display: none;
}

/* License strip — the pad's own hint owns the top; this sits in the
   12px bottom padding of the grid, under the last pad row. */
.sampler-note {
  position: absolute;
  bottom: 1px;
  left: 12px;
  right: 12px;
  margin: 0;
  text-align: center;
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--danger);
  pointer-events: none;
}

.sampler-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 12px;
  padding-top: 44px;
  box-sizing: border-box;
}

.sampler-pad {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: clamp(13px, 3.4vw, 18px);
  letter-spacing: 0.04em;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  transition:
    transform 0.06s ease,
    background 0.06s ease,
    color 0.06s ease,
    box-shadow 0.06s ease;
}

.sampler-pad__badge {
  font-size: 11px;
  font-weight: 700;
  color: rgb(var(--ink-rgb) / 0.6);
  min-height: 13px;
}

/* Gate pads: a soft pill at the bottom hints that the sound lasts only
   while the pad is held — a quick tap would otherwise look broken. */
.sampler-pad__hold {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  padding: 1px 7px 2px;
  border-radius: 999px;
  background: rgba(124, 83, 184, 0.32);
  color: #e4d7f7;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.4;
  pointer-events: none;
}

.sampler-pad--empty {
  background: rgb(var(--ink-rgb) / 0.05);
  border-style: dashed;
  border-color: rgb(var(--ink-rgb) / 0.35);
  opacity: 0.55;
  cursor: default;
}

/* Held finger: the pad sinks and lights — the classic sampler look. */
.sampler-pad.is-lit {
  background: #7c53b8;
  color: var(--text-on-color);
  transform: scale(0.95);
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.22);
}

.sampler-pad.is-lit .sampler-pad__badge {
  color: rgba(255, 246, 228, 0.85);
}

.sampler-pad.is-lit .sampler-pad__hold {
  background: rgba(255, 246, 228, 0.22);
  color: var(--text-on-color);
}

/* Amber SOLO: light pill + dark text keeps the hint readable. */
.sampler-pad--solo.is-lit .sampler-pad__hold {
  background: rgba(255, 246, 228, 0.35);
  color: var(--on-accent);
}

/* Trigger flash from loop playback or remote hits — lighter than the hold. */
.sampler-pad.is-hit:not(.is-lit) {
  background: var(--sampler-hit);
}

.sampler-pad--solo {
  background: var(--ink);
  color: var(--bg);
}

.sampler-pad--solo.is-lit {
  background: #e0a12e;
  color: var(--on-accent);
}

.sampler-pad.is-bump {
  animation: pad-bump 0.16s ease;
}

@keyframes pad-bump {
  0% { transform: scale(1); }
  40% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

/* Tune mode: tunable pads get a violet ring; the dragged pad stays raised. */
.sampler.is-editing .sampler-pad--sample {
  box-shadow: inset 0 0 0 2px rgba(124, 83, 184, 0.55);
}

.sampler.is-editing .sampler-pad.is-editing {
  border-color: #7c53b8;
  box-shadow:
    inset 0 0 0 2px #7c53b8,
    0 4px 0 rgb(var(--shadow-rgb) / 0.3);
}

/* Edit mode: the selected pad keeps its ring, the rest stay plain tappable
   pickers — every tap re-aims the editor panel. */

/* Edit mode's erase handle: a corner ✕ on every sample pad. It is a real
   element (not ::after) so taps are hit-tested separately from the pad's
   tuning drag — and the grid ignores it mid-gesture. */
.sampler-pad__x {
  display: none;
  position: absolute;
  top: -9px;
  right: -9px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 3px solid #c4512c;
  background: var(--bg-elevated);
  color: #c4512c;
  font-size: 17px;
  font-weight: 900;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 2px 0 rgb(var(--shadow-rgb) / 0.28);
  z-index: 2;
}

/* The ✕ only shows on pads that actually hold recorded hits — an empty
   pad has nothing to wipe, so it stays clean for tuning. */
.sampler.is-editing .sampler-pad--sample.has-hits .sampler-pad__x {
  display: block;
}

.sampler-pad__x:active {
  background: #c4512c;
  color: var(--text-on-color);
}

.sampler-pad.is-erase {
  animation: pad-erase 0.22s ease;
}

/* The sampler edit button carries only the pencil — it covers both the
   tune drag and the hit wipe, so no ✕ needed. */
.sample-edit-btn .ico {
  width: 20px;
  height: 20px;
}

@media (max-width: 480px) {
  .sample-edit-btn .chip-label {
    display: none;
  }
}

@keyframes pad-erase {
  0% { background: var(--bg-elevated); }
  40% { background: #c4512c; color: var(--text-on-color); transform: scale(0.94); }
  100% { background: var(--bg-elevated); }
}

/* The pad can never record while an edit layer is up — Rec reads as off. */
.btn.is-off {
  opacity: 0.38;
}

/* ---------- Sample editor panel ----------
   Fixed overlay that rides over the tools column in landscape/desktop and
   docks as a bottom sheet in portrait. Lives outside .pad (which clips) so
   quiet-touch can reach its buttons and sliders. */
/* Portrait (default): a plain block right below the pad — it scrolls with
   the page and can never cover a cell. Landscape/desktop docks it inside
   the tools column (sticky at its top) via the media query below; the JS
   remounts the node on the same breakpoint. */
.sampler-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px calc(14px + env(safe-area-inset-right)) 14px calc(14px + env(safe-area-inset-left));
  background: var(--bg-elevated);
  border: 4px solid var(--ink);
  border-left: none;
  border-right: none;
}

/* Ordered like the pad block, later in the DOM → lands right under it. The
   pad-mode strip already carries the divider border — no double line. */
.host-app > .sampler-editor {
  order: 4;
  border-top: none;
}

.sampler-editor[hidden] {
  display: none;
}

/* Sample picker: ◀ name ▶ — tapping the name auditions the pick. */
.sampler-editor__carousel {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex: 0 0 auto;
}

.sampler-editor__arrow {
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sampler-editor__arrow .ico {
  width: 22px;
  height: 22px;
}

.sampler-editor__name {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--sun);
  color: var(--on-accent);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.sampler-editor__name:active {
  transform: scale(0.97);
}

/* Sampler violet on the slider tracks, same family as the pad rings. */
.sampler-editor .fx-slider {
  --chip: #7c53b8;
  flex: 0 0 auto;
}

.sampler-editor .fx-slider input[type='range']:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* Reset | Done sit on one bottom row — Done reads as the primary action. */
.sampler-editor__actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.sampler-editor__actions > * {
  flex: 1 1 0;
  min-width: 0;
}

/* Wide portrait: a centered card instead of an edge-to-edge strip. */
@media (orientation: portrait) and (min-width: 600px) {
  .sampler-editor {
    width: min(560px, calc(100vw - 24px));
    margin: 0 auto;
    border: 4px solid var(--ink);
    border-radius: 20px;
  }
}

/* Short landscape screens: compress the panel so Reset/Done stay inside. */
@media (orientation: landscape) and (max-height: 560px) {
  .sampler-editor {
    gap: 6px;
  }

  .sampler-editor__name,
  .sampler-editor__arrow {
    min-height: 40px;
  }

  .sampler-editor__arrow {
    flex-basis: 40px;
  }

  .sampler-editor .fx-slider {
    font-size: 13px;
  }

  .sampler-editor .fx-slider input[type='range'] {
    height: 36px;
  }

  .sampler-editor .fx-slider input[type='range']::-webkit-slider-runnable-track {
    height: 20px;
  }

  .sampler-editor .fx-slider input[type='range']::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
    margin-top: -8px;
  }

  .sampler-editor .btn {
    min-height: 40px;
  }

  .sampler-editor .btn.has-icon {
    min-height: 40px;
  }
}

/* Landscape phone or desktop: the tools column sits right of the pad — the
   editor is its first item, pinned to the column's top by position: sticky
   while the rest of the tools scroll underneath. It never covers the pad,
   so the pad keeps filling its side of the grid. */
@media (min-width: 1024px) and (min-height: 640px), (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .sampler-editor {
    position: sticky;
    top: 6px;
    z-index: 6;
    flex: 0 0 auto;
    margin: 8px;
    border: 4px solid var(--ink);
    border-radius: 20px;
    box-shadow: -6px 0 0 rgb(var(--shadow-rgb) / 0.25);
    padding: 12px 14px 14px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* As the column's new first child it would lose its top border to the
     `.host-tools > :first-child` cleanup — put the frame back. */
  .host-tools > .sampler-editor:first-child {
    border-top: 4px solid var(--ink);
  }
}

/* In sampler mode the pad's note chrome would sit on top of the pads. */
.pad.is-sampler .bar-readout,
.pad.is-sampler .harmony-label,
.pad.is-sampler .y-zones {
  display: none;
}

/* The hint moves up top, over the empty first pad row. */
.pad.is-sampler .pad__hint {
  inset: 8px 10px auto;
}

/* Lane rows in the note roll: pad names instead of pitch labels. */
.roll__key--lane {
  justify-content: center;
  padding-left: 0;
  color: #7c53b8;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Collapsible settings sections: the head always shows the current value,
   the chevron flips on .is-open, bodies are plain scrollable areas. Heads
   are plain divs (not role=button) so touch scrolls can start on them. */
.tool-sec {
  min-width: 0;
}

.tool-sec__head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  cursor: pointer;
  touch-action: pan-y;
}

.tool-sec__head:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -3px;
  border-radius: 8px;
}

.tool-sec__title {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tool-sec__value {
  min-width: 0;
  font-size: 17px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-sec__chev {
  margin-left: auto;
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid var(--ink);
  transition: transform 0.15s ease;
}

.tool-sec.is-open .tool-sec__chev {
  transform: rotate(180deg);
}

.tool-sec__body {
  display: none;
}

.tool-sec.is-open .tool-sec__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

.tool-sec__mini {
  display: none;
}

.tool-sec:not(.is-open) .tool-sec__mini {
  display: flex;
}

/* Compact button living inside a section head, next to the current value —
   Edit notes for the instruments section. */
.tool-sec__edit {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 4px 12px;
  font-size: 13px;
}

.inst-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 8px;
  min-width: 0;
}

.inst-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--bg-elevated);
  touch-action: pan-x pan-y;
}

.inst-card[data-card='pad'] { --inst: #2f8f55; }
.inst-card[data-card='bass'] { --inst: #c4512c; }
.inst-card[data-card='organ'] { --inst: #3d6f9a; }
.inst-card[data-card='kalimba'] { --inst: #e0a12e; }
.inst-card[data-card='synth'] { --inst: #6b4423; }

/* The selected card fills with its instrument colour, but the frame stays
   the plain black border every card has — colour lives only inside. */
.inst-card.is-on {
  background: color-mix(in srgb, var(--inst, #e2b43a) 30%, var(--bg-elevated));
}

/* The card is the frame; the name inside stays plain text with a swatch.
   Selection is the card's gold ring, so the pick keeps no fill either. */
.inst-card__pick,
.inst-card__pick.is-on {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* The pick chip stays transparent when the card is on, so the generic
   is-on rule that dims a swatch onto --bg-elevated would erase the
   instrument colour here — the square keeps --chip inside cards. */
.inst-card .chip.is-on.has-swatch::before {
  background: var(--chip, var(--sun));
}

.inst-card__mix {
  gap: 6px;
}

/* MORE keeps the plain beige button look even on the tinted selected card —
   the ghost background would otherwise pick up the instrument colour. */
.inst-card__more {
  width: 100%;
  min-height: 48px;
  background: var(--bg-elevated);
}

.mix-flags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.mix-flag {
  min-height: 36px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
}

.mix-flag.is-on[data-mix='solo'] {
  background: #e0a12e;
  color: var(--on-accent);
}

.mix-flag.is-on[data-mix='mute'] {
  background: #c4512c;
  color: var(--text-on-color);
}

.fx-slider--master span {
  font-size: 20px;
}

.fx-slider--master input[type='range'] {
  height: 44px;
}

.master-repeat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.master-repeat__label {
  font-size: 20px;
  font-weight: 800;
}

.key-pill {
  font-weight: 700;
}

.splash {
  position: fixed;
  z-index: 8;
  left: 0;
  right: 0;
  bottom: 0;
  top: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgb(var(--bg-rgb) / 0.92);
}

.splash--guest {
  top: 64px;
}

.splash--full {
  top: 0;
  z-index: 60;
}

.splash__card {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: var(--bg-elevated);
  border: 4px solid var(--ink);
  border-radius: 20px;
  padding: 24px 20px;
}

.splash__card h2 {
  margin: 0;
  font-size: 24px;
}

.splash__card p {
  margin: 0;
  color: var(--text-dim);
  line-height: 1.45;
}

.splash__error {
  color: var(--danger) !important;
  font-weight: 600;
}

.splash__spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: splash-spin 0.8s linear infinite;
}

.splash .btn {
  width: 100%;
}

@keyframes splash-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 900px) {
  .splash {
    top: 132px;
  }
}

@media (max-height: 920px) {
  .event-log {
    display: none;
  }
}

#btn-erase-notes,
#controller-erase {
  grid-column: 1 / -1;
}

.fx-sheet {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgb(var(--bg-rgb) / 0.72);
}

.fx-sheet--stage {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  background: var(--bg);
}

.fx-sheet--stage .fx-sheet__card {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: 100%;
  border: 0;
  border-radius: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  /* The card itself scrolls when the header stack (presets, Advanced panel)
     outgrows the screen — the grid keeps a floor so it never collapses. */
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
}

.fx-sheet--stage .roll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: auto;
}

.fx-sheet--stage .sequencer {
  flex: 1 1 auto;
  /* Rows must stay tappable even when the Advanced panel eats the height —
     below the floor the card scrolls instead of the tape vanishing. */
  min-height: 280px;
}

.fx-sheet--stage .seq-tape {
  flex: 1 1 auto;
  height: 100%;
  max-height: 100%;
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.stage-head h2 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-head .btn {
  min-height: 48px;
  min-width: 88px;
}

@media (max-width: 400px) {
  .stage-head .btn {
    min-width: 64px;
  }
}

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 0 0 auto;
}

.select-move {
  flex: 1 1 100%;
  height: auto;
  max-height: none;
  min-height: 44px;
  white-space: normal;
  font-size: 16px;
}

.select-move.is-on,
#host-notes-sheet .stage-bar .select-move.is-on,
#controller-notes-sheet .stage-bar .select-move.is-on {
  background: var(--sun);
  color: var(--on-accent);
  border-color: var(--ink);
}

.stage-bar .btn,
.stage-bar .btn.has-icon,
#host-notes-sheet .stage-bar .btn,
#controller-notes-sheet .stage-bar .btn {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  min-height: 44px;
  height: 44px;
  max-height: 44px;
  padding: 0 6px;
  font-size: 14px;
  overflow: hidden;
}

/* Icon over a short label beats a wrapped word at 44px. */
.stage-bar .btn.has-icon {
  flex-direction: column;
  gap: 0;
  padding: 2px;
}

.stage-bar .btn.has-icon .ico {
  width: 16px;
  height: 16px;
}

.stage-bar .btn .chip-label {
  font-size: 11px;
  line-height: 1.15;
  white-space: nowrap;
}

#host-notes-sheet .stage-bar .select-move,
#controller-notes-sheet .stage-bar .select-move {
  flex: 1 1 100%;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: 48px;
  font-size: 16px;
  white-space: normal;
}

.fx-sheet__card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-elevated);
  border: 4px solid var(--ink);
  border-radius: 20px;
  padding: 16px;
}

.fx-sheet__card h2 {
  margin: 0;
  font-size: 22px;
}

/* Invite sheet: the header QR is too small to scan on a phone, so the
   full-size code lives here on a white card with a wide quiet zone. */
#host-share-sheet.fx-sheet {
  align-items: center;
  /* Above the "Sound is off" splash: a scanned QR must never hide under it. */
  z-index: 9;
}

.fx-sheet__card.share-sheet {
  align-items: center;
  text-align: center;
}

/* Help sheet: one card for every topic section, icon rows kept sparse. */
.help-card {
  gap: 12px;
}

.help-card .stage-head {
  flex: 0 0 auto;
}

.help-body {
  overflow-y: auto;
  min-height: 0;
}

.help-sec + .help-sec {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 2px solid rgb(var(--ink-rgb) / 0.14);
}

.help-sec__title {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.help-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-item {
  display: grid;
  grid-template-columns: 26px 64px 1fr;
  align-items: center;
  gap: 10px;
}

.help-item .ico {
  width: 22px;
  height: 22px;
  color: var(--sun);
}

.help-item__keys {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1.5px solid rgb(var(--sun-rgb) / 0.45);
  border-radius: 8px;
  padding: 3px 0;
  text-align: center;
}

.help-item__text {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
}

.share-qr {
  /* The QR edge is a var so the box, the painted image and the loading
     placeholder all agree on the same size. */
  --qr-edge: min(72vw, 60dvh, 320px);
  background: #fff;
  padding: 28px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  line-height: 0;
  color: var(--on-accent);
  /* Edge + padding could outgrow the card on a narrow phone — clamp instead
     of letting the QR clip under the card's overflow. */
  max-width: 100%;
}

#host-qr-big img,
#host-qr-big canvas,
#host-qr-big table {
  width: var(--qr-edge) !important;
  max-width: 100%;
  /* Square source: auto height keeps the aspect when max-width clamps. */
  height: auto !important;
  aspect-ratio: 1;
  display: block;
}

/* Same trick as the header stamp: the loading box pre-claims the painted
   size so the sheet doesn't reflow when the QR lands. */
.share-qr.qr-loading {
  width: calc(var(--qr-edge) + 62px);
  max-width: 100%;
  aspect-ratio: 1;
  line-height: 1.2;
}

.share-sheet__code {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--accent-dim);
  line-height: 1.1;
}

.share-sheet__link {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--text-dim);
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}

.fx-sliders {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fx-slider {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 700;
}

.fx-slider__group {
  margin: 6px 0 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fx-slider input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 48px;
  background: transparent;
}

.fx-slider input[type='range']::-webkit-slider-runnable-track {
  height: 28px;
  background: var(--chip, var(--sun));
  border: 3px solid var(--ink);
  border-radius: 999px;
}

.fx-slider input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 44px;
  height: 44px;
  margin-top: -11px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 3px solid var(--ink);
}

.fx-slider--octave span {
  font-size: 22px;
}

.fx-slider--octave input[type='range'] {
  height: 68px;
}

.fx-slider--octave input[type='range']::-webkit-slider-runnable-track {
  height: 36px;
}

.fx-slider--octave input[type='range']::-webkit-slider-thumb {
  width: 58px;
  height: 58px;
  margin-top: -14px;
}

@media (max-height: 740px) {
  .controller-foot .chip,
  .inst-card__more {
    min-height: 52px;
  }
}

.pad.host-pad {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.controller-bar {
  flex-wrap: wrap;
  min-height: 56px;
}

#controller-transport {
  margin-left: auto;
}

#controller-transport .ico {
  margin: 0 auto;
}

#controller-transport.is-on {
  box-shadow: 0 0 0 2px var(--sun), 0 0 16px var(--sun);
}

.controller-bar .chip,
.controller-foot .chip {
  min-height: 52px;
  height: auto;
  font-size: 14px;
}

.controller-bar__modes .chip {
  min-width: 76px;
}

#controller-status,
#controller-key {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#controller-status {
  max-width: 42vw;
}

.controller-foot .chips--roots {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.controller-foot .chips--roots .chip {
  width: 100%;
  min-height: 48px;
  padding: 0 2px;
}

.chips--scales {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  gap: 6px;
}

.chips--scales .chip {
  width: 100%;
}

/* Phone lying on its side: a compact header + play bar + pad in the left
   column, the settings sections in a scrollable right column. pointer:coarse
   keeps a short desktop window out of this layout. */
@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .host-app {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(240px, 3fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  /* Portrait-only chrome: the whole topbar (QR, statuses, Export) is hidden
     in landscape — JS moves Play and Back into the play-bar instead. */
  .host-app > .topbar {
    display: none;
  }

  .host-app > .play-bar {
    grid-column: 1;
    grid-row: 1;
    order: 0;
  }

  .host-app > .pad-stage {
    grid-column: 1;
    grid-row: 2;
    order: 0;
    min-height: 0;
    flex: 1 1 auto;
  }

  .pad-stage .host-pad {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  .host-tools {
    display: flex;
    flex-direction: column;
    grid-column: 2;
    grid-row: 1 / -1;
    min-height: 0;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    overscroll-behavior: contain;
  }

  .host-tools > :first-child {
    border-top: none;
  }

  /* Moved into the play-bar in landscape: Back, Play, Rec, the mode chips
     and the sampler Edit all read as square icon buttons — the row stays
     airy and nothing clips. 44px squares keep the whole row visible. */
  .play-bar {
    gap: 4px;
    padding: 4px 6px 0;
  }

  .play-bar [data-action='back'],
  .play-bar #btn-transport,
  .play-bar #controller-transport,
  .play-bar #btn-loop,
  .play-bar #controller-loop,
  .play-bar #host-sample-edit,
  .play-bar #controller-sample-edit {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    padding: 0;
    margin-left: 0;
  }

  .play-bar__modes {
    flex: 0 0 auto;
    gap: 4px;
  }

  .play-bar__modes .chip {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    padding: 0;
  }

  .play-bar__modes .chip .chip-label,
  .play-bar #btn-transport .chip-label,
  .play-bar #controller-transport .chip-label,
  .play-bar #btn-loop .chip-label,
  .play-bar #controller-loop .chip-label,
  .play-bar #host-sample-edit .chip-label,
  .play-bar #controller-sample-edit .chip-label {
    display: none;
  }

  /* Narrow side column: instruments read as a plain list there. The Edit
     notes head button goes icon-only so the fold chevron stays on screen. */
  .host-app .inst-list,
  .screen--controller .inst-list {
    grid-template-columns: 1fr;
  }

  .tool-sec__edit {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
  }

  .tool-sec__edit .chip-label {
    display: none;
  }

  /* The tempo strip stacks in the narrow column: loop length on its own
     row, then the BPM chips wrapped under it. */
  .host-app .tempo-panel {
    flex-wrap: wrap;
  }

  .host-app .tempo-panel__bars {
    flex: 1 1 100%;
    min-width: 0;
  }

  .host-app .tempo-panel__bpm {
    flex: 1 1 100%;
    flex-wrap: nowrap;
  }

  .host-app .tempo-panel__bpm .chip {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
  }

  /* Guest screen: same split. The controller bar (session name, key pill)
     is portrait-only — Play and Back are moved into the play-bar by JS. */
  .screen--controller:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(240px, 3fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .controller-bar {
    display: none;
  }

  #controller-play-bar {
    grid-column: 1;
    grid-row: 1;
  }

  .pad-wrap {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 0 8px 8px;
  }

  .controller-foot {
    grid-column: 2;
    grid-row: 1 / -1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    overscroll-behavior: contain;
    padding-bottom: 12px;
  }

  .controller-foot > :first-child {
    border-top: none;
  }

  .controller-foot .chip,
  .pad-mode__chips .chip,
  .seq-page,
  .btn.has-icon {
    min-height: 44px;
    height: auto;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  /* Slimmer pad-mode row buys the pad extra height while staying tappable. */
  .pad-mode {
    padding: 3px 8px;
  }

  .pad-mode__chips .chip {
    min-height: 40px;
    min-width: 64px;
    padding: 3px 10px;
  }

  .tool-block,
  .sequencer,
  .seq-tape,
  .seq-labels,
  .roll,
  .fx-row {
    min-width: 0;
    max-width: 100%;
  }

  /* Stage sheets: chrome shrinks so the editor grid owns the space. */
  .fx-sheet--stage .fx-sheet__card {
    gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }

  .fx-sheet--stage .inst-carousel__arrow {
    flex-basis: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .fx-sheet--stage .inst-carousel__name {
    min-height: 40px;
  }

  .fx-sheet--stage .stage-head .btn {
    min-height: 40px;
    min-width: 64px;
  }

  #host-notes-sheet .stage-bar .btn,
  #controller-notes-sheet .stage-bar .btn,
  .fx-sheet--stage .stage-bar .btn {
    min-height: 40px;
    height: 40px;
    max-height: 40px;
  }

  #host-notes-sheet .stage-bar .select-move,
  #controller-notes-sheet .stage-bar .select-move {
    flex: 1 1 0;
    width: auto;
    min-height: 40px;
    font-size: 13px;
  }

  /* Stage sheets split like the host screen: the editor grid owns the left
     column at full height, its controls ride a right rail. The editor is
     sticky so an open Advanced panel scrolls only the rail. */
  .fx-sheet--stage .fx-sheet__card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(196px, 30%);
    column-gap: 10px;
  }

  .fx-sheet--stage .fx-sheet__card > * {
    grid-column: 2;
    min-width: 0;
    align-self: start;
  }

  .fx-sheet--stage .roll,
  .fx-sheet--stage .sequencer {
    grid-column: 1;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    height: calc(100dvh - 12px - env(safe-area-inset-bottom));
    min-height: 0;
    max-height: none;
  }

  #host-notes-sheet .fx-sheet__card,
  #controller-notes-sheet .fx-sheet__card {
    grid-template-rows: min-content minmax(0, 1fr);
  }

  #host-drums-sheet .fx-sheet__card,
  #controller-drums-sheet .fx-sheet__card {
    grid-template-rows: repeat(5, min-content) minmax(0, 1fr);
  }

  .fx-sheet--stage .stage-head {
    flex-wrap: wrap;
  }

  .fx-sheet--stage .stage-bar {
    align-content: flex-start;
  }

  /* The rail is ~1/3 of the card: buttons go two-up, the mode toggle keeps
     a full row. These must restate the id-scoped portrait flex values. */
  #host-notes-sheet .stage-bar .btn,
  #controller-notes-sheet .stage-bar .btn,
  .fx-sheet--stage .stage-bar .btn {
    flex: 1 1 40%;
  }

  #host-notes-sheet .stage-bar .select-move,
  #controller-notes-sheet .stage-bar .select-move {
    flex: 1 1 100%;
  }

  .splash {
    top: 0;
    padding: 8px;
  }
}

/* Any short landscape window: keep the sheets usable — two-column invite,
   capped note roll, tighter cards. */
@media (orientation: landscape) and (max-height: 560px) {
  .fx-sheet {
    padding: 8px;
  }

  .fx-sheet__card {
    max-height: calc(100dvh - 16px);
    overflow: auto;
  }

  /* Sideways invite: stack the QR beside the code, link, and Done —
     a tall single column would push them below the fold. */
  .fx-sheet__card.share-sheet {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 16px;
    align-items: center;
  }

  .fx-sheet__card.share-sheet h2,
  .fx-sheet__card.share-sheet .seq-hint {
    grid-column: 1 / -1;
  }

  .share-qr {
    grid-row: 3 / span 3;
    padding: 16px;
    --qr-edge: min(30vw, 52dvh, 320px);
  }

  .share-qr.qr-loading {
    width: calc(var(--qr-edge) + 38px);
  }

  .roll {
    max-height: min(40dvh, 210px);
    min-height: 112px;
  }

  .fx-sheet.fx-sheet--stage {
    padding: 0;
  }

  .fx-sheet--stage .fx-sheet__card {
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .fx-sheet--stage .roll {
    max-height: none;
    min-height: 0;
  }

  .fx-sheet--stage .sequencer {
    min-height: 200px;
  }
}

@media (max-width: 899px) {
  .seq-row__label {
    width: 128px;
    flex-basis: 128px;
    font-size: 13px;
  }
}

/* Small screens: short voice names, narrow label column, more room for steps. */
@media (max-width: 640px) {
  .sequencer {
    --seq-label-w: 60px;
  }

  .seq-row__label {
    width: 56px;
    flex-basis: 56px;
    gap: 4px;
    padding: 0 4px;
    font-size: 12px;
  }

  .seq-row__label .ico {
    width: 16px;
    height: 16px;
  }

  .seq-row__name {
    display: none;
  }

  .seq-row__short {
    display: inline;
  }
}

.seq-tape.edge-left,
.roll.edge-left {
  box-shadow: inset 14px 0 0 -9px rgb(var(--shadow-rgb) / 0.85), inset 28px 0 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

.seq-tape.edge-right,
.roll.edge-right {
  box-shadow: inset -14px 0 0 -9px rgb(var(--shadow-rgb) / 0.85), inset -28px 0 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

.seq-tape.edge-left.edge-right,
.roll.edge-left.edge-right {
  box-shadow:
    inset 14px 0 0 -9px rgb(var(--shadow-rgb) / 0.85),
    inset -14px 0 0 -9px rgb(var(--shadow-rgb) / 0.85),
    inset 28px 0 18px -14px rgb(var(--shadow-rgb) / 0.35),
    inset -28px 0 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

.host-tools.edge-top,
.controller-foot.edge-top {
  box-shadow: inset 0 14px 0 -9px rgb(var(--shadow-rgb) / 0.85), inset 0 28px 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

.host-tools.edge-bottom,
.controller-foot.edge-bottom {
  box-shadow: inset 0 -14px 0 -9px rgb(var(--shadow-rgb) / 0.85), inset 0 -28px 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

.host-tools.edge-top.edge-bottom,
.controller-foot.edge-top.edge-bottom {
  box-shadow:
    inset 0 14px 0 -9px rgb(var(--shadow-rgb) / 0.85),
    inset 0 -14px 0 -9px rgb(var(--shadow-rgb) / 0.85),
    inset 0 28px 18px -14px rgb(var(--shadow-rgb) / 0.35),
    inset 0 -28px 18px -14px rgb(var(--shadow-rgb) / 0.35);
}

body.page-edge-top::before,
body.page-edge-bottom::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  height: 22px;
  z-index: 6;
  pointer-events: none;
}

body.page-edge-top::before {
  top: 0;
  background: linear-gradient(to bottom, rgb(var(--shadow-rgb) / 0.4), transparent);
}

body.page-edge-bottom::after {
  bottom: 0;
  background: linear-gradient(to top, rgb(var(--shadow-rgb) / 0.4), transparent);
}
