/* Bleepr — custom styles. Colors come only from theme variables (js/themes.js). */

/* Layout: one-screen app. Header / roll / layers / toolbar stacked; the roll takes the free space. */
:root {
  --font-ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-lcd: "Doto", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
  --tap: 44px;
  --overlay: color-mix(in srgb, var(--key-black) 55%, transparent);
  --shadow: 0 12px 32px color-mix(in srgb, var(--key-black) 28%, transparent);
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- icons: hidden until the font is ready so ligature names never flash ---------- */
.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  width: 1em;
  height: 1em;
  overflow: hidden;
  display: inline-block;
  flex: none;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  visibility: hidden;
  color: currentColor;
}
.icons-ready .material-symbols-outlined { visibility: visible; }
/* If the icon font never loads, show the label text instead */
.icons-failed .icon-btn::after {
  content: attr(aria-label);
  font-size: 11px;
  line-height: 1.1;
  max-width: 64px;
  text-align: center;
}
.icons-failed .material-symbols-outlined { display: none; }

/* ---------- app shell ---------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.app-header {
  flex: none;
  padding-top: env(safe-area-inset-top, 0px);
  padding-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px));
}
.hdr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 6px;
  min-width: 0;
}
.hdr-row.settings { flex-wrap: wrap; padding-top: 0; }
.brand {
  margin: 0;
  font-family: var(--font-lcd);
  font-weight: 900;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.02em;
  flex: none;
}
.name-field { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 0 1 auto; }
.name-field .text-input { width: 13ch; }
.dirty { font-size: 12px; }
.hdr-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }

@media (min-width: 1400px) {
  .app-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .hdr-row { display: contents; }
  .hdr-actions { order: 3; }
  .hdr-row.settings > * { order: 2; }
  .app-header > .hdr-row:first-child > .brand,
  .app-header > .hdr-row:first-child > .name-field { order: 1; }
  .app-header { padding-block: 8px; }
}

/* ---------- controls ---------- */
.btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  position: relative;
  flex-direction: row;
}
.icons-failed .icon-btn { flex-direction: column; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.icon-text { padding: 0 12px 0 10px; }
.btn.text-btn { padding: 0 16px; font-weight: 700; }
.btn.icon-btn.small .material-symbols-outlined { font-size: 20px; }
.btn.toggle[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.btn.toggle[aria-pressed="true"]:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.btn.toggle[aria-pressed="true"] .material-symbols-outlined { font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }
.btn.danger-hover:hover:not(:disabled) { color: var(--danger); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:focus-visible { outline-offset: 1px; }

.text-input, .select {
  font: inherit;
  min-height: var(--tap);
  border-radius: var(--radius);
  padding: 0 10px;
}
.select { padding-right: 6px; cursor: pointer; }
.text-input::placeholder, textarea::placeholder { color: var(--fg-muted); opacity: 1; }

.lcd-group {
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  padding-left: 10px;
  min-height: 48px;
}
.lcd-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 2px;
}
.lcd {
  font-family: var(--font-lcd);
  font-weight: 900;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: 0;
  text-align: center;
  width: 3.4ch;
  padding: 0;
  color: inherit;
  -moz-appearance: textfield;
}
output.lcd { display: inline-block; width: 1.6ch; }
.lcd::-webkit-inner-spin-button, .lcd::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.lcd:focus-visible { outline-offset: 0; border-radius: 4px; }
.loop-secs {
  font-family: var(--font-lcd);
  font-weight: 700;
  font-size: 17px;
  padding: 0 12px 0 4px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.limit-msg { font-size: 13px; }

/* ---------- roll ---------- */
.roll-wrap {
  flex: 1 1 auto;
  min-height: 180px;
  position: relative;
  overflow: hidden;
}
#roll {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#roll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- layers ---------- */
.layers {
  flex: none;
  display: flex;
  flex-direction: column;
  max-height: min(270px, 32vh);
  padding-inline: max(8px, env(safe-area-inset-left, 0px)) max(8px, env(safe-area-inset-right, 0px));
}
.layers-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 0 6px;
}
.section-h {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.section-h .font-normal { letter-spacing: 0.02em; text-transform: none; }
.layer-list {
  list-style: none;
  margin: 0;
  padding: 0 0 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 10px;
  padding: 2px;
  border: 1px solid transparent;
  min-width: 0;
}
.layer-row.is-active {
  background: var(--surface);
  border-color: var(--border);
}
.layer-select {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 8px 0 6px;
  text-align: left;
}
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--surface);
}
.layer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-row.is-active .layer-name { font-weight: 700; }
.layer-names { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.layer-chip-sub { display: none; font-size: 12px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editing-tag {
  display: none;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.editing-tag .material-symbols-outlined { font-size: 16px; }
.layer-row.is-active .editing-tag { display: inline-flex; }
.chip-pill {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 190px;
  padding: 0 6px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 14px;
  min-height: 36px;
  margin-inline: 2px;
}
.chip-pill .chip-pill-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-pill .material-symbols-outlined { font-size: 18px; }
.vol {
  width: 110px;
  flex: none;
}
.range {
  accent-color: var(--accent);
  height: var(--tap);
  cursor: pointer;
  margin: 0;
}

/* ---------- toolbar ---------- */
.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tb-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tb-group + .tb-group { padding-left: 6px; border-left: 1px solid var(--border); }
.tb-label { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 0 4px; }
#btn-play { width: 52px; }

/* ---------- theme picker ---------- */
.tp { position: relative; }
.tp-button { padding: 0 6px 0 10px; gap: 8px; }
.tp-strip { display: inline-flex; border-radius: 5px; overflow: hidden; box-shadow: 0 0 0 1px var(--border); flex: none; }
.tp-sw { width: 9px; height: 20px; display: block; }
.tp-btn-icon { display: none; }
.tp-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 270px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
}
.tp-head { display: none; align-items: center; justify-content: space-between; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--border); }
.tp-title { font-weight: 700; }
.tp-search { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--fg-muted); }
.tp-search input { flex: 1; min-height: 36px; font: inherit; background: transparent; border: 0; color: var(--fg); }
.tp-list { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 6px; }
.tp-list:focus { outline: none; }
.tp-list:focus-visible .tp-opt.is-active { outline: 2px solid var(--accent); outline-offset: -2px; }
.tp-group {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  padding: 10px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.tp-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 0 12px 0 14px;
  cursor: pointer;
}
.tp-opt.is-active { background: var(--surface-2); }
.tp-opt-name { flex: 1; }
.tp-check { opacity: 0; color: var(--accent); display: inline-flex; }
.tp-opt[aria-selected="true"] .tp-check { opacity: 1; }
.tp-opt[aria-selected="true"] .tp-opt-name { font-weight: 700; }
.tp-backdrop { display: none; }

/* ---------- dialogs (sheets) ---------- */
dialog.sheet {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.sheet.small { width: min(420px, calc(100vw - 32px)); }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
dialog.sheet[open] { display: flex; }
.sheet-inner { display: flex; flex-direction: column; width: 100%; max-height: inherit; min-height: 0; margin: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 18px; flex: none; }
.sheet-title { margin: 0; font-size: 18px; font-weight: 700; }
.sheet-body { padding: 14px 18px 18px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.sheet-body p { margin: 0; }
.sheet-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 700; padding: 0; }
.field-label output { font-weight: 400; margin-left: 4px; font-variant-numeric: tabular-nums; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }

.chip-list #chip-options { display: flex; flex-direction: column; gap: 4px; }
.chip-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  min-height: 56px;
}
.chip-item:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--surface-2); }
.chip-item input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; margin: 0; }
.chip-item:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chip-name { font-weight: 700; }
.chip-desc { font-size: 13px; color: var(--fg-muted); }
.chip-preview .material-symbols-outlined { font-size: 28px; color: var(--accent); }
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.share-actions { display: flex; flex-direction: column; gap: 6px; }
.share-btn { justify-content: flex-start; text-align: left; padding: 8px 12px; gap: 12px; width: 100%; }
.share-text { display: flex; flex-direction: column; }
.share-name { font-weight: 700; }
.share-desc { font-size: 13px; }
.code-box {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
  border-radius: var(--radius);
  padding: 8px 10px;
  resize: vertical;
  word-break: break-all;
}
.import-result { font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.import-result ul { margin: 0; padding-left: 18px; color: var(--fg-muted); }
.import-result .err { color: var(--danger); font-weight: 700; display: flex; gap: 6px; align-items: flex-start; }
.import-result .okmsg { display: flex; gap: 6px; align-items: center; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper output.lcd { width: 2.4ch; }
.fade-row { flex-direction: row; align-items: center; gap: 12px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.warn { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.warn .material-symbols-outlined { font-size: 20px; }

.current-tune { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 14px; border-radius: 10px; flex-wrap: wrap; }
.current-text { display: flex; flex-direction: column; flex: 1; min-width: 120px; }
.current-name { font-family: var(--font-lcd); font-weight: 900; font-size: 22px; line-height: 1.1; }
.tune-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.tune-row { display: flex; align-items: center; gap: 4px; padding: 2px 0 2px 2px; border-bottom: 1px solid var(--border); min-height: 52px; }
.tune-row:last-child { border-bottom: 0; }
.tune-open { flex: 1; min-width: 0; justify-content: flex-start; text-align: left; padding: 4px 8px; flex-direction: column; align-items: flex-start; gap: 0; }
.tune-title { font-weight: 700; }
.tune-meta { font-size: 13px; color: var(--fg-muted); }
.tune-empty { color: var(--fg-muted); font-size: 14px; padding: 6px 2px; }
.tune-row .text-input { flex: 1; min-width: 0; }

/* ---------- welcome tour ---------- */
dialog.welcome { width: min(500px, calc(100vw - 32px)); }
.welcome-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 0 20px; flex: none; }
.welcome-brand { font-family: var(--font-lcd); font-weight: 900; font-size: 20px; color: var(--fg-muted); }
.welcome-track {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  flex: 1 1 auto;
  min-height: 0;
}
.welcome-track::-webkit-scrollbar { display: none; }
.welcome-track:focus { outline: none; }
.welcome-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 22px 4px;
  overflow-y: auto;
  min-width: 0;
}
.welcome-art {
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px;
  max-width: 100%;
}
.welcome-art svg { display: block; width: 100%; height: auto; }
/* the first card also holds the theme list, so its picture stays short */
.welcome-art-welcome { padding: 4px; }
.welcome-art-welcome svg { max-height: 120px; width: auto; max-width: 100%; margin: 0 auto; }
.welcome-title { margin: 8px 0 0; font-size: 24px; line-height: 1.2; font-weight: 700; text-wrap: balance; }
.welcome-lead { margin: 0; color: var(--fg-muted); max-width: 46ch; }
.welcome-tips { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.welcome-tips li { display: grid; grid-template-columns: 24px 1fr; gap: 12px; align-items: start; }
.welcome-tips .material-symbols-outlined { color: var(--accent); }
.welcome-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex: none;
}
.welcome-dots { display: flex; align-items: center; }
.welcome-dot {
  appearance: none;
  background: transparent;
  border: 0;
  width: 28px;
  height: var(--tap);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.welcome-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  transition: width 160ms ease, background-color 160ms ease;
}
.welcome-dot[aria-current="step"]::before { width: 20px; background: var(--accent); }
.welcome-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: -6px; border-radius: 8px; }
.welcome-next { min-width: 96px; white-space: nowrap; }

/* theme choice on the first card */
.welcome-theme { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.welcome-theme-h { margin: 0; font-size: 16px; font-weight: 700; }
.welcome-theme-note { margin: 0 0 4px; font-size: 13px; color: var(--fg-muted); }
.theme-inline {
  position: relative;
  max-height: min(188px, 26dvh);
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding-bottom: 4px;
}
.theme-inline:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-inline .tp-opt.is-active { background: var(--surface-2); }

/* illustration parts, all from theme tokens */
.w-surface { fill: var(--surface); }
.w-line { stroke: var(--border); stroke-width: 0.6; opacity: 0.7; }
.w-beat { stroke: var(--border); stroke-width: 1.2; }
.w-key { fill: var(--key-white); stroke: var(--border); }
.w-black { fill: var(--key-black); }
.w-note { fill: var(--note); stroke: var(--note-selected); stroke-width: 1; }
.w-accent { fill: var(--accent); }
.w-ghost { fill: none; stroke: var(--note); stroke-width: 1.5; stroke-dasharray: 4 3; }
.w-arrow { fill: none; stroke: var(--fg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.w-tap { fill: none; stroke: var(--accent); stroke-width: 2; }
.w-tapdot { fill: var(--accent); }
.w-dim1 .w-note { fill: var(--layer-2); stroke: var(--layer-2); opacity: 0.35; stroke-dasharray: 3 2; }
.w-dim2 .w-note { fill: var(--layer-3); stroke: var(--layer-3); opacity: 0.35; stroke-dasharray: 3 2; }
.w-lcd { fill: var(--surface); stroke: var(--border); }
.w-lcd-num { font-family: var(--font-lcd); font-weight: 900; font-size: 34px; fill: var(--fg); }
.w-lcd-sec { font-family: var(--font-lcd); font-weight: 700; font-size: 20px; fill: var(--fg-muted); }
.w-lcd-cap { font-family: var(--font-ui); font-weight: 700; font-size: 12px; fill: var(--fg-muted); }
.w-loopline { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.w-loophead { fill: var(--accent); }
.w-code { font-family: var(--font-mono); font-size: 15px; fill: var(--fg); }
.w-code-notes { fill: var(--note-selected); }
.w-chip { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; }
.w-chip-text { font-family: var(--font-ui); font-weight: 700; font-size: 13px; fill: var(--fg); }
.w-playhead { animation: w-sweep 3.2s linear infinite; }
@keyframes w-sweep { from { transform: translateX(0); } to { transform: translateX(268px); } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
  font-size: 14px;
}
.toast-action {
  appearance: none;
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  font: inherit;
  font-weight: 700;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  cursor: pointer;
}

/* ---------- phone menu ---------- */
.menu-wrap { position: relative; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  padding: 6px 0;
  display: flex;
  flex-direction: column;
}
.menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.menu-check { margin-left: auto; color: var(--accent); opacity: 0; }
.menu-item[aria-checked="true"] .menu-check { opacity: 1; }
.menu-backdrop:not([hidden]) { position: fixed; inset: 0; z-index: 59; }

@media (min-width: 768px) {
  .phone-only { display: none !important; }
}

/* ---------- phones / portrait ---------- */
@media (max-width: 767px) {
  .desk-only { display: none !important; }
  .btn.icon-text .label { display: none; }
  .hdr-actions { gap: 0; }
  .lcd-group { position: relative; margin-top: 6px; padding-left: 0; }
  .lcd-label {
    position: absolute;
    top: -8px;
    left: 10px;
    font-size: 9px;
    line-height: 14px;
    padding: 0 4px;
    margin: 0;
    background: var(--surface);
    border-radius: 4px;
  }
  .lcd { width: 3ch; }
  .layer-select { gap: 8px; padding-right: 4px; }
  .layer-chip-sub { display: block; }
  .chip-pill { min-width: var(--tap); max-width: none; padding: 0; border: 0; margin: 0; }
  .chip-pill .chip-pill-name { display: none; }
  .chip-pill .material-symbols-outlined { font-size: 22px; }
  .btn.icon-text { padding: 0; }
  #btn-speaker.icon-text { padding: 0; }
  .brand { font-size: 24px; }
  .name-field .text-input { width: 11.5ch; padding: 0 8px; }
  .hdr-row { gap: 4px; }
  .hdr-row.settings { gap: 6px; }
  .lcd-group { min-height: 44px; padding-left: 8px; }
  .lcd { font-size: 21px; }
  .loop-secs { font-size: 15px; padding-right: 8px; }
  .limit-msg { flex-basis: 100%; }
  .layers { max-height: min(186px, 27vh); }
  /* Collapsed: only the layer being edited is shown */
  .layers.collapsed .layer-row:not(.is-active) { display: none; }
  .layers:not(.collapsed) { max-height: min(340px, 48vh); }
  .layers-head { gap: 0; }
  .layers-head .section-h { margin-right: auto; }
  .btn.layers-toggle { padding: 0 10px 0 6px; font-size: 14px; font-weight: 700; gap: 2px; }
  .vol { width: 64px; }
  .chip-pill { max-width: 104px; font-size: 13px; padding-left: 10px; }
  .editing-tag { display: none !important; }
  .brand { font-size: 22px; }
  .name-field { flex: 1 1 auto; }
  .name-field .text-input { width: 100%; max-width: 10.5ch; min-width: 0; }
  .toolbar { justify-content: flex-start; gap: 4px; }
  .tb-group + .tb-group { padding-left: 4px; }
  .tb-label { display: none; }
  #btn-play { width: 48px; }

  .tp-strip-current { display: none; }
  .tp-btn-icon { display: inline-flex; }
  .tp-current-name { display: none; }
  .tp-button { padding: 0; min-width: var(--tap); }
  .tp-button > .material-symbols-outlined:last-child { display: none; }
  .tp-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 59; }
  .tp-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: auto;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tp-head { display: flex; }

  dialog.sheet, dialog.sheet.small {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0 0;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    max-height: 90dvh;
  }
  .sliders { grid-template-columns: 1fr; gap: 4px; }
  dialog.welcome { max-height: 92dvh; }
  .welcome-title { font-size: 21px; }
  .welcome-slide { padding-inline: 18px; }
}

@media (max-width: 380px) {
  .brand { font-size: 20px; }
  .name-field .text-input { padding: 0 6px; }
  .vol { width: 48px; }
  #btn-play { width: var(--tap); }
  .toolbar { padding-inline: 4px; gap: 2px; }
  .tb-group + .tb-group { padding-left: 2px; }
  .toolbar .select { padding: 0 2px 0 6px; }
}
@media (max-width: 340px) {
  .vol { display: none; }
}

/* short landscape screens: keep room for the roll */
@media (min-width: 768px) and (max-height: 560px) {
  .layers { max-height: 96px; }
  .hdr-row { padding-block: 2px; }
  .lcd-group { min-height: 44px; }
  .roll-wrap { min-height: 110px; }
}

/* short, wide screens (phones in landscape): picture beside the text */
@media (min-width: 600px) and (max-height: 520px) {
  dialog.welcome { width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 16px); }
  .welcome-slide { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr); column-gap: 20px; row-gap: 6px; align-content: start; }
  .welcome-art { grid-column: 1; grid-row: 1 / span 6; align-self: start; }
  .welcome-slide > :not(.welcome-art) { grid-column: 2; }
  .welcome-art-welcome { display: none; }
  /* first card: text left, theme list right */
  .welcome-slide > .welcome-art-welcome ~ * { grid-column: 1; }
  .welcome-slide > .welcome-art-welcome ~ .welcome-theme { grid-column: 2; grid-row: 1 / span 4; margin-top: 0; }
  .welcome-theme .theme-inline { max-height: calc(100dvh - 190px); }
  .welcome-title { margin-top: 0; font-size: 20px; }
  .welcome-tips { gap: 6px; }
  .welcome-head { padding-top: 2px; }
  .welcome-foot { padding-block: 6px; }
}

/* short phones: the theme list matters more than the first illustration */
@media (max-width: 767px) and (max-height: 740px) {
  .welcome-art-welcome { display: none; }
  .welcome-slide { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
