/* KamalDrum styles. Colours and type follow docs/ui-ux-spec.md, "Visual language". */

@font-face {
  font-family: 'Nunito';
  src: url('../fonts/nunito-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/fraunces-latin.woff2') format('woff2');
  font-weight: 400 600;
  font-display: swap;
}

:root {
  --font-ui: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-title: 'Fraunces', Georgia, 'Times New Roman', serif;
  --live: #D8B98A;
  --loop: #6F93A6;
}

/* Dim is the default theme. --panel-text is the text colour of Settings and other panels. */
[data-theme='dim'] {
  --ground: #15181C;
  --shell: #2A2F36;
  --shell-light: #343A43;
  --shell-dark: #22262C;
  --card: #1D2126;
  --slot: #0E1013;
  --slot-edge: rgba(255, 255, 255, 0.05);
  --text: #C9C4BA;
  --panel-text: #C9C4BA;
}
[data-theme='day'] {
  --ground: #E4E0D8;
  --shell: #8C9097;
  --shell-light: #999DA4;
  --shell-dark: #7E8289;
  --card: #EDEAE4;
  --slot: #4A4D52;
  --slot-edge: rgba(255, 255, 255, 0.18);
  --text: #2E3034;
  --panel-text: #2E3034;
}
/* Dark keeps text quiet on the drum, but panels use full contrast so a change can still be read. */
[data-theme='dark'] {
  --ground: #070809;
  --shell: #121417;
  --shell-light: #16191C;
  --shell-dark: #0F1113;
  --card: #0D0F11;
  --slot: #050606;
  --slot-edge: rgba(255, 255, 255, 0.03);
  --text: #6D6A64;
  --panel-text: #C9C4BA;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.fade-in .stage { animation: fade-in 0.6s ease-out; }
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ---------- Controls: icon plus word, 44 px targets, quiet until hovered or focused ---------- */

.control, .chip, .plain, .link, .icon-button {
  background: none;
  border: 0;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0.65;
  border-radius: 10px;
  transition: opacity 0.2s ease-out;
}
.control:hover, .chip:hover, .plain:hover, .link:hover, .icon-button:hover,
.control:focus-visible, .chip:focus-visible, .plain:focus-visible, .link:focus-visible, .icon-button:focus-visible {
  opacity: 1;
}
:focus-visible {
  outline: 2px solid color-mix(in srgb, currentColor 55%, transparent);
  outline-offset: 2px;
}
.control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
}
.icon { flex: none; }
/* A page's Help: a small, quiet pill beside its title; the tap area stays 44 px tall. */
.help-button {
  position: relative;
  min-height: 30px;
  gap: 5px;
  padding: 0 10px 0 7px;
  font-size: 13px;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  border-radius: 999px;
}
.help-button::after { content: ''; position: absolute; inset: -7px -2px; }
.help-button .icon { width: 16px; height: 16px; }
.title-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 12px; margin: 14px 0 4px; }
.title-row .title { margin: 0; }
/* The narrowest phones: a smaller title keeps Help beside it; if it still can't fit, Help goes just under it. */
@media (max-width: 359px) { .title-row .title { font-size: 28px; } }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
}
.plain {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
}
.link {
  min-height: 44px;
  padding: 0 10px;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 4px;
}
.primary {
  min-height: 48px;
  padding: 0 24px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--text) 45%, transparent);
  background: color-mix(in srgb, var(--text) 12%, transparent);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.primary:hover { background: color-mix(in srgb, var(--text) 18%, transparent); }

/* Segmented controls: native radio buttons, drawn as a row of chips. */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  border: 0;
  margin: 0;
  padding: 0;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.segmented span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  white-space: nowrap;
  opacity: 0.75;
}
.segmented input:checked + span {
  opacity: 1;
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: color-mix(in srgb, currentColor 55%, transparent);
  font-weight: 600;
}
.segmented input:focus-visible + span {
  outline: 2px solid color-mix(in srgb, currentColor 55%, transparent);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: 0 0 64px;
  display: grid;
  /* The chip stays centred when there's room; the sides never squeeze it. */
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  column-gap: 20px;
  align-items: center;
  padding: 0 16px 0 24px;
}
/* Narrower laptop windows: tighter buttons and gaps, so nothing is cut off (every button keeps its word). */
@media (max-width: 1180px) {
  .topbar { column-gap: 14px; padding-left: 20px; }
  .topbar .actions .control { padding-left: 8px; padding-right: 8px; }
}
/* Below 1024 px (rare on laptops) the buttons wrap onto a second row rather than lose their words. */
@media (max-width: 1023px) {
  .topbar { flex-basis: auto; min-height: 64px; padding-top: 6px; padding-bottom: 6px; grid-template-columns: max-content max-content minmax(0, 1fr); }
  .topbar .actions { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
}
.wordmark {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0.85;
}
.chip {
  font-size: 15px;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--text) 25%, transparent);
}
.actions {
  justify-self: end;
  display: flex;
  gap: 2px;
}

/* ---------- Drum ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 16px;
  container-type: size;
}
.drum {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  outline: none;
  touch-action: none; /* the drum never scrolls, zooms or double-tap-zooms under a finger */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* Holding the centre softens: the boss darkens with a lighter ring while held. */
.drum-base .boss { transition: fill 0.3s ease-out, stroke 0.3s ease-out; }
.drum.softening .drum-base .boss {
  fill: color-mix(in srgb, var(--shell-dark) 70%, black);
  stroke: color-mix(in srgb, var(--text) 60%, transparent);
  stroke-width: 2.5;
}
.drum > svg,
.drum > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.drum-base .shell { stroke: color-mix(in srgb, var(--text) 10%, transparent); stroke-width: 1.5; }
.drum-base .slot { fill: none; stroke: var(--slot); stroke-width: 3; stroke-linecap: round; }
.drum-base .slot-shadow { fill: none; stroke: var(--slot-edge); stroke-width: 3; stroke-linecap: round; transform: translate(1.2px, 1.2px); }
.drum-base .boss { stroke: var(--slot); stroke-width: 1; }
.drum-base .halo {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  opacity: 0.12;
  transition: opacity 0.6s ease-out;
}

.drum-top .tongue-hit { fill: transparent; cursor: pointer; outline: none; }
.drum-top .label text {
  fill: var(--text);
  font-size: 26px;
  font-weight: 600;
}
.drum-top .label .keypair {
  font-size: 15px;
  font-weight: 700;
  opacity: 0.75;
  letter-spacing: 0.08em;
}
.drum-top .octave-dot { fill: var(--text); }
.drum-top .keycap {
  opacity: 0.7;
  transition: opacity 1.2s ease-out;
}
.drum-top .keycap rect {
  fill: color-mix(in srgb, var(--text) 6%, transparent);
  stroke: color-mix(in srgb, var(--text) 40%, transparent);
  stroke-width: 1;
}
.drum-top .keycap text {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.caps-off .keycap, .caps-off .keypair { display: none; }

/* Resting: focus elsewhere. Slightly dimmed, no halo, key caps at 35%. Never an alarm. */
.resting .drum-base { opacity: 0.8; transition: opacity 0.6s ease-out; }
.resting .drum-base .halo { opacity: 0; }
.resting .drum-top .keycap { opacity: 0.35; }

/* ---------- Status strip ---------- */

.strip {
  flex: 0 0 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
}
.strip-centre {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  opacity: 0.7;
}
.strip-right { justify-self: end; }
/* The sound can't start: a calm sentence in the usual text colour (never red), wrapping if it must. */
.strip-centre.sound-failed { white-space: normal; opacity: 1; text-align: center; max-width: 720px; }
.listen-start .sound-failed { margin: 0 0 12px; }
.speaker-note {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  max-width: 330px;
}
.speaker-note span { opacity: 0.75; }
.breath {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.35;
  animation: breathe 6s ease-in-out infinite;
}
.resting .breath { visibility: hidden; }
@keyframes breathe {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.45; }
}
.reduce-motion .breath { animation: none; }
.reduce-motion .fade-in .stage { animation-duration: 0.3s; }

/* ---------- Focus mode: the drum only ---------- */

.focus-mode .topbar,
.focus-mode .strip { display: none; }
.focus-mode .stage { padding: 12px; }
.focus-mode.reveal-bar .topbar {
  display: grid;
  position: absolute;
  inset: 0 0 auto 0;
  height: 64px;
  background: var(--ground);
  z-index: 2;
}
.focus-caps-hidden .keycap { opacity: 0 !important; }
.focus-hint {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 14px;
  white-space: nowrap;
  opacity: 0.7;
  transition: opacity 2s ease-out;
}
.focus-hint.fading { opacity: 0; }
.focus-hint span { display: block; text-align: center; }
@media (max-width: 599px) { .focus-hint { white-space: normal; width: calc(100% - 32px); } }

/* ---------- Tune the drum ---------- */

.tune-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 24px 16px;
}
.tune-glyph { width: 96px; height: 96px; margin-top: 8px; }
.drum-glyph { width: 100%; height: 100%; }
.drum-glyph .glyph-shell { fill: var(--shell); }
.drum-glyph .glyph-boss { fill: var(--shell-dark); }
.drum-glyph .glyph-tongue { fill: var(--shell); stroke: var(--slot); stroke-width: 10; }
.drum-glyph .glyph-tongue.lit { animation: glyph-light 1.4s ease-out; }
@keyframes glyph-light {
  from { fill: var(--live); }
  to { fill: var(--shell); }
}
.title {
  font-family: var(--font-title);
  font-weight: 500;
  font-size: 34px;
  margin: 14px 0 4px;
  white-space: nowrap;
}
.tune-line { margin: 0 0 20px; opacity: 0.8; }
.continue { margin-bottom: 20px; }
.cards {
  display: grid;
  grid-template-columns: repeat(4, 228px);
  gap: 16px;
  max-width: 960px;
}
.card {
  position: relative;
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 24px 16px 18px;
  text-align: left;
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent);
  border-radius: 16px;
  cursor: pointer;
  transition: border-color 0.3s ease-out, background 0.3s ease-out;
}
.card:hover { border-color: color-mix(in srgb, var(--text) 40%, transparent); }
.card.tuning { border-color: var(--live); }
.returning .card { height: 190px; }
.card-name { font-size: 18px; font-weight: 700; white-space: nowrap; }
.card-description { line-height: 1.4; opacity: 0.85; }
.card-meta { margin-top: auto; font-size: 14px; opacity: 0.7; white-space: nowrap; }
.card-tag {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 12px;
  opacity: 0.7;
  white-space: nowrap;
}
.card.tuning .card-tag { color: var(--live); opacity: 1; }
.keys {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 0;
  margin: 22px 0 0;
  padding: 0;
}
.keys-label { float: left; padding: 0; opacity: 0.8; white-space: nowrap; }
.keys-options { gap: 4px; }
.keys-options span { min-width: 40px; justify-content: center; padding: 0 8px; }
.tune-hint { margin: 16px 0 0; font-size: 14px; opacity: 0.7; white-space: nowrap; }
.tune-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px 14px;
}
@media (max-width: 1010px) {
  .cards { grid-template-columns: repeat(2, 228px); }
}

/* ---------- Settings, How to use, About ---------- */

.panel { color: var(--panel-text); }
.panel .control, .panel .plain, .panel .link { opacity: 0.8; }
.panel-bar {
  flex: 0 0 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 24px;
  border-bottom: 1px solid color-mix(in srgb, var(--panel-text) 12%, transparent);
}
.tabs { display: flex; gap: 4px; }
.tabs [role='tab'] {
  min-height: 44px;
  padding: 0 14px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0.7;
}
.tabs [role='tab'][aria-selected='true'] {
  opacity: 1;
  font-weight: 700;
  border-bottom-color: currentColor;
}
.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 24px 48px;
  user-select: text;
  -webkit-user-select: text;
}
.page { max-width: 760px; margin: 0 auto; }
.page h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 30px 0 10px;
}
.row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: start;
  padding: 10px 0;
}
.row-label { padding-top: 10px; white-space: nowrap; }
.row-control { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.row-control .value { padding-top: 10px; }
.row-control .value + .plain { margin-top: 4px; }
.note { margin: 0; font-size: 13px; opacity: 0.75; }
.note.body-note { font-size: inherit; }
input[type='range'] { width: min(320px, 100%); accent-color: currentColor; min-height: 40px; }
.prose p { line-height: 1.6; max-width: 64ch; margin: 0 0 12px; }
.prose ul { line-height: 1.6; max-width: 64ch; margin: 0 0 12px; padding-left: 1.4em; }
.prose li { margin-bottom: 4px; }
.about-name { font-family: var(--font-title); font-weight: 500; font-size: 28px; margin-top: 24px; }
.about-tagline { font-weight: 600; }
.version { opacity: 0.7; }

/* Only shown with ?debug in the address, for checking latency. */
.debug {
  position: fixed;
  left: 12px;
  bottom: 12px;
  font: 12px/1.5 ui-monospace, monospace;
  opacity: 0.6;
  white-space: pre;
  pointer-events: none;
}

/* ---------- Recording and looping (only the strip changes; never red) ---------- */

.rec-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.6px solid currentColor;
  flex: none;
}
.record-button.is-ready { opacity: 1; }
.record-button.is-ready .rec-mark { border-color: var(--live); border-width: 2px; }
.record-button.is-recording { opacity: 1; }
.record-button.is-recording .rec-mark {
  width: 14px;
  height: 14px;
  background: var(--live);
  border-color: var(--live);
  animation: breathe-strong 6s ease-in-out infinite;
}
.reduce-motion .record-button.is-recording .rec-mark { animation: none; }
.reduce-motion .rec-dot { animation: none; opacity: 0.8; }
.record-button[aria-disabled='true'] { opacity: 0.35; cursor: default; }

.strip-mode { opacity: 1; gap: 10px; }
.strip-mode > span { opacity: 0.85; }
.rec-ring, .rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.rec-ring { border: 1.6px solid var(--live); }
.rec-dot { background: var(--live); animation: breathe-strong 6s ease-in-out infinite; }
@keyframes breathe-strong {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.reduce-motion .rec-dot { animation: none; }
.strip-mode .control { min-height: 40px; }
.apart { margin-left: 14px; }

.title-field {
  width: 190px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--text) 30%, transparent);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  user-select: text;
  -webkit-user-select: text;
}
.title-field::placeholder { color: inherit; opacity: 0.55; }

.strip-loop { flex-direction: column; gap: 0; }
/* A strip held invisibly while another recording strip shows (record-panel.js): on a laptop
   it takes no room; in the phone layouts it shares the strip's place, keeping its height. */
.strip-held { display: none !important; }
.loop-row { display: flex; align-items: center; gap: 10px; }
.loop-note { margin: 0; font-size: 12px; opacity: 0.65; white-space: nowrap; }
.legend { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.legend-you { background: var(--live); opacity: 0.8; }
.legend-loop { border: 1.6px solid var(--loop); margin-left: 6px; }

/* Toast: a brief line with an optional Undo, just above the strip. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(640px, calc(100vw - 32px));
  padding: 6px 8px 6px 18px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--text) 22%, transparent);
  color: var(--panel-text);
  z-index: 5;
}
.toast .control { opacity: 1; font-weight: 700; }
.toast .toast-dismiss { opacity: 0.8; font-size: 22px; line-height: 1; min-width: 40px; min-height: 40px; }

/* ---------- Songbook ---------- */

.songbook-bar { gap: 16px; }
.bar-left, .bar-right { display: flex; align-items: center; gap: 12px; position: relative; }
.songbook-heading {
  font-family: var(--font-title);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
  white-space: nowrap;
}
.songbook-drum { opacity: 0.75; white-space: nowrap; }
.new-song-anchor { position: relative; display: flex; }
/* Under 480 px: New song leads the list, as an action rather than a song (dashed, muted). */
.new-song-anchor.in-list { margin: 4px 0 6px; }
.new-song-anchor.in-list #new-song {
  flex: 1;
  border: 1px dashed color-mix(in srgb, currentColor 40%, transparent);
  padding: 0 12px;
}
.new-song-anchor.in-list { flex-direction: column; }
/* In the list, the menu opens in place and pushes the songs down rather than covering them. */
.new-song-anchor.in-list .menu { position: static; margin-top: 4px; }
.menu {
  position: absolute;
  top: 48px;
  right: 0;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--panel-text) 20%, transparent);
  border-radius: 12px;
  z-index: 3;
}
.menu button {
  min-height: 44px;
  padding: 0 16px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: color-mix(in srgb, var(--panel-text) 10%, transparent); }
/* The moon button's menu of the three themes, in the drum screen's own colours. */
.menu-anchor { position: relative; display: inline-flex; }
.theme-menu { top: 46px; min-width: 132px; background: var(--ground); color: var(--text); border-color: color-mix(in srgb, var(--text) 20%, transparent); }
.theme-menu button { color: inherit; font: inherit; display: flex; align-items: center; gap: 10px; }
.theme-menu button::before { content: ''; width: 7px; height: 7px; border-radius: 50%; }
.theme-menu button[aria-checked='true'] { font-weight: 600; }
.theme-menu button[aria-checked='true']::before { background: var(--live); }

.songbook-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}
.song-list {
  overflow-y: auto;
  padding: 8px 12px 32px 16px;
  border-right: 1px solid color-mix(in srgb, var(--panel-text) 12%, transparent);
}
.song-list h2 { font-size: 13px; font-weight: 700; opacity: 0.7; margin: 20px 8px 6px; letter-spacing: 0.02em; }
.song-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.song-row:hover { background: color-mix(in srgb, var(--panel-text) 5%, transparent); }
.song-row[aria-current='true'] { background: color-mix(in srgb, var(--panel-text) 10%, transparent); }
.song-row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.song-row-meta { font-size: 13px; opacity: 0.7; white-space: nowrap; }
.quiet { opacity: 0.7; font-size: 14px; margin: 6px 8px; }

.song-detail {
  overflow-y: auto;
  padding: 20px 32px 48px;
  user-select: text;
  -webkit-user-select: text;
}
.song-title { font-size: 24px; font-weight: 700; margin: 4px 0 2px; }
.rename-field, .text-field {
  font-size: 18px;
  min-height: 44px;
  padding: 0 12px;
  width: min(420px, 100%);
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--panel-text) 35%, transparent);
  background: color-mix(in srgb, var(--panel-text) 5%, transparent);
}
.rename-field { font-size: 22px; font-weight: 700; }
.owner-tag { margin: 0; font-size: 13px; opacity: 0.7; }
.song-meta { margin: 4px 0 14px; opacity: 0.85; }
.song-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
.scale-note {
  margin: 8px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-text) 6%, transparent);
  max-width: 64ch;
}
.scale-note p { margin: 0 0 10px; line-height: 1.5; }

/* Numbered notation: a dot above for the upper octave, an underline for half a beat, dashes for held beats. */
.notation {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px 2px;
  padding: 14px 0;
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
}
.notation .nnote {
  background: none;
  border: 0;
  padding: 10px 6px 6px;
  border-radius: 8px;
  cursor: default;
}
.notation button.nnote { cursor: pointer; }
.notation button.nnote:hover { background: color-mix(in srgb, var(--panel-text) 7%, transparent); }
.notation .nnote.selected { background: color-mix(in srgb, var(--panel-text) 14%, transparent); outline: 1.5px solid color-mix(in srgb, var(--panel-text) 55%, transparent); }
.notation .nnote.sounding .digit { color: var(--live); }
.note-wrap { display: inline-flex; align-items: flex-end; gap: 8px; }
.glyph { position: relative; display: inline-block; padding-bottom: 4px; }
.glyph.half { border-bottom: 2px solid currentColor; }
.glyph .high-dot {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: currentColor;
}
.glyph .dotted { margin-left: 2px; }
.glyph.outside { opacity: 0.3; }
.glyph.skipped { opacity: 0.4; text-decoration: underline dotted; text-underline-offset: 6px; }
.hold { opacity: 0.6; padding-bottom: 6px; }
.notation .bar { opacity: 0.35; padding: 0 6px 8px; font-weight: 400; }
.bar-group { display: inline-flex; align-items: flex-end; gap: 2px; white-space: nowrap; }

.edit-panel, .trim-panel {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-text) 16%, transparent);
  max-width: 760px;
}
.trim-panel h3 { margin: 0 0 8px; font-size: 15px; }
.edit-title { margin: 0 0 10px; font-weight: 600; }
.tongue-choices { display: flex; flex-wrap: wrap; gap: 6px; font-size: 20px; font-weight: 600; margin-bottom: 10px; }
.tongue-choice {
  min-width: 44px;
  min-height: 48px;
  padding: 10px 8px 4px;
  background: none;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  border-radius: 10px;
  cursor: pointer;
}
.tongue-choice.chosen { background: color-mix(in srgb, currentColor 14%, transparent); border-color: color-mix(in srgb, currentColor 55%, transparent); }
.edit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.trim-row { display: grid; grid-template-columns: 170px 1fr; align-items: center; gap: 12px; max-width: 560px; white-space: nowrap; }
.plain[aria-disabled='true'] { opacity: 0.35; cursor: default; }

.song-typed .field-label { display: block; margin: 16px 0 6px; font-weight: 600; }
.notation-field {
  width: min(640px, 100%);
  min-height: 90px;
  padding: 10px 12px;
  font-size: 20px;
  font-family: var(--font-ui);
  resize: vertical;
}
code { font-size: 0.95em; padding: 0 3px; border-radius: 4px; background: color-mix(in srgb, currentColor 10%, transparent); }
.typed-preview { min-height: 56px; gap: 6px 14px; }

/* ---------- Play along ---------- */

/* The next tongue: a steady outline in the strong text colour that fades in and never pulses. */
.drum-base .target-outline {
  fill: none;
  stroke: var(--panel-text);
  stroke-width: 3.5;
  opacity: 0;
}
.drum-base .target-outline.on { opacity: 0.85; transition: opacity 1.2s ease-out; }
.reduce-motion .drum-base .target-outline.on { transition-duration: 0.3s; }
.drum-top .keycap.target { opacity: 1 !important; }

/* The play-along strip uses the full width; the side columns step aside. */
.strip.wide-mode .strip-side { display: none; }
.strip-wide {
  grid-column: 1 / -1;
  display: grid;
  /* The controls never wrap: the title shortens (…) first, then the notes window narrows. */
  grid-template-columns: minmax(64px, 1fr) minmax(110px, 3fr) auto;
  align-items: center;
  gap: 18px;
  min-width: 0;
}
.strip-pa-end { display: flex; justify-content: center; gap: 10px; }
.pa-done { font-weight: 600; margin-right: 8px; white-space: nowrap; }
.pa-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.pa-notation {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 20px;
  font-weight: 600;
  padding-top: 8px;
}
.pa-notation .bar { opacity: 0.3; font-weight: 400; }
.pa-note { position: relative; padding-bottom: 6px; }
.pa-note .high-dot {
  position: absolute;
  top: -6px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: currentColor;
}
.pa-note.played { opacity: 0.35; }
.pa-note.skipped { opacity: 0.4; text-decoration: underline dotted; text-underline-offset: 6px; } /* as in typed entry */
.pa-note.current { color: var(--live); }
.pa-note.current::after {
  content: '';
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: 0;
  height: 2px;
  border-radius: 1px;
  background: var(--live);
}
.pa-controls { display: flex; align-items: center; gap: 10px; }
.pa-controls .segmented { flex-wrap: nowrap; }
.segmented.compact span { min-height: 34px; padding: 0 10px; font-size: 14px; }

/* ---------- Dialogs ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: color-mix(in srgb, var(--ground) 70%, transparent);
  z-index: 10;
}
.dialog {
  width: min(600px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 24px 22px;
  border-radius: 16px;
  background: var(--card);
  color: var(--panel-text);
  border: 1px solid color-mix(in srgb, var(--panel-text) 18%, transparent);
  user-select: text;
  -webkit-user-select: text;
}
.dialog h2 { font-size: 20px; margin: 0 0 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.dialog .field-label { display: block; margin: 8px 0 6px; font-weight: 600; }
.dialog .text-field { width: 100%; }
.receive-scale p { margin: 6px 0 10px; line-height: 1.5; }

.share-tabs { margin: 10px 0 14px; border-bottom: 1px solid color-mix(in srgb, var(--panel-text) 12%, transparent); }
.share-page { display: flex; flex-direction: column; gap: 8px; }
.share-page .note { margin: 0; }
.share-actions { margin: 4px 0 6px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
.text-field.mono { font-size: 13px; }
.notation-text { font-size: 16px; padding: 10px 12px; resize: none; font-family: var(--font-ui); }
.file-line { margin: 4px 0; }
.share-footer { margin: 18px 0 0; font-size: 13px; opacity: 0.75; }

/* ---------- A quiet note at the top (an unreadable link or file) ---------- */

.top-note {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(720px, calc(100vw - 32px));
  padding: 6px 6px 6px 16px;
  border-radius: 12px;
  background: var(--card);
  color: var(--panel-text);
  border: 1px solid color-mix(in srgb, var(--panel-text) 20%, transparent);
  z-index: 9;
  line-height: 1.4;
}

/* ---------- Tune the drum, opened from a shared link ---------- */

.shared-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(960px, 100%);
  margin-bottom: 18px;
  padding: 16px 20px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--live);
}
.shared-title { margin: 0; font-size: 20px; }
.shared-meta { margin: 4px 0 0; opacity: 0.8; white-space: nowrap; }
.shared-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; white-space: nowrap; }
.check input { width: 18px; height: 18px; accent-color: var(--live); }

/* A slow, thin progress line (no spinner). */
.progress {
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--panel-text) 12%, transparent);
  overflow: hidden;
}
.progress-fill { height: 100%; width: 0; background: var(--panel-text); opacity: 0.6; transition: width 0.8s ease-out; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.restore-counts { margin: 4px 0 12px; padding-left: 20px; line-height: 1.7; }
.restore-settings { border: 0; padding: 0; margin: 8px 0 0; }
.restore-settings legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.dialog p { line-height: 1.5; }

/* ---------- Listen ---------- */

.listen-setup { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.listen-intro { font-size: 17px; margin: 24px 0 8px; }
.listen-select { font-size: 16px; width: min(420px, 100%); }
.listen-start { margin: 28px 0 0 216px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.listen-preparing { width: min(360px, 100%); }
/* Session length: − [20] min + */
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper .step { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; font-size: 22px; opacity: 0.85; border: 1px solid color-mix(in srgb, currentColor 30%, transparent); }
.stepper .step:hover, .stepper .step:focus-visible { opacity: 1; }
.stepper .step[aria-disabled='true'] { opacity: 0.3; cursor: default; }
.stepper .step-value { width: 3.2em; text-align: center; font-size: 17px; }

.listen-playing { position: absolute; inset: 0; display: grid; place-items: center; background: var(--ground); }
.listen-drum { width: min(78vmin, 640px); aspect-ratio: 1; position: relative; opacity: 0.7; }
.listen-drum .label, .listen-drum .keycap, .listen-drum .halo { display: none; }
.listen-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: opacity 0.4s ease-out; /* waking is quick */
}
.listen-line { margin: 0; white-space: nowrap; }
.listen-buttons { display: flex; gap: 8px; }
.listen.idle .listen-controls { opacity: 0; transition-duration: 3s; /* fading away is slow */ }
/* When idle, the pointer disappears everywhere on the screen. */
.listen.idle.is-playing,
.listen.idle.is-playing * { cursor: none !important; }
/* Listen's drum is only to look at: its tongues can't be clicked. */
.listen-drum { pointer-events: none; }
.listen-end {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.listen-end-line { font-size: 18px; margin: 0; }
/* The end screen stays dark until woken, if the sound ended while the controls slept. */
.listen-end { transition: opacity 0.4s ease-out; }
.listen.end-asleep .listen-end { opacity: 0; }
.listen.end-asleep,
.listen.end-asleep * { cursor: none !important; }
@media (max-width: 700px) {
  .listen-start { margin-left: 0; }
}

/* Choices drawn as cards: a name, and a one-line description that may wrap. */
.row.row-wide { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.row.row-wide .row-label { padding-top: 0; }
.row.row-wide .row-control { align-items: stretch; }
.cards { display: grid; gap: 10px; }
.kind-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sound-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card-choice {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  cursor: pointer;
}
.card-choice input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.choice-name { font-weight: 600; white-space: nowrap; display: flex; align-items: baseline; gap: 8px; }
.choice-desc { font-size: 14px; opacity: 0.8; line-height: 1.35; }
.choice-tag { font-size: 12px; font-weight: 400; opacity: 0.8; }
.card-choice:has(input:checked) {
  background: color-mix(in srgb, currentColor 12%, transparent);
  border-color: color-mix(in srgb, currentColor 55%, transparent);
}
.card-choice:has(input:focus-visible) { outline: 2px solid color-mix(in srgb, currentColor 55%, transparent); outline-offset: 2px; }

/* Wash: Adjust, a link that opens its panel in place. */
.wash-adjust-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.wash-adjust { padding-left: 0; }
.wash-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
}
.wash-panel[hidden] { display: none; }
.wash-density, .wash-reset { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.wash-panel-label { font-weight: 600; }
#wash-reset[aria-disabled='true'] { opacity: 0.35; cursor: default; }

/* A wash playing: one soft glow at the drum's centre follows the level, over seconds. */
.listen-glow {
  position: absolute;
  width: min(46vmin, 380px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, #6f93a6 55%, transparent), transparent);
  opacity: 0;
  transition: opacity 1.6s ease-in-out;
  pointer-events: none;
}
.listen-sound { justify-content: center; }
.listen-keys { text-align: center; }
.primary[aria-disabled='true'] { opacity: 0.4; cursor: default; }

/* ---------- Phones and tablets (Phase 2) ---------- */

/* Notches and home indicators: every screen keeps clear of them (zero on laptops). */
.screen {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html, body { overscroll-behavior: none; } /* no pull-to-refresh */

/* A touch screen has no hover, so controls rest at full contrast. */
@media (hover: none) {
  .control, .chip, .plain, .link, .icon-button { opacity: 1; }
}

.more-button { display: none; }
.more-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, 0.5);
  z-index: 20;
}
.more-menu {
  position: fixed;
  z-index: 21;
  width: 260px;
  padding: 8px;
  border-radius: 16px;
  background: var(--card);
  color: var(--panel-text);
  border: 1px solid color-mix(in srgb, var(--panel-text) 20%, transparent);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
}
.more-menu[hidden] { display: none; }
.more-menu > button {
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.more-theme {
  min-height: 52px;
  padding: 0 6px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
}
.more-themes {
  display: flex;
  padding: 3px;
  border-radius: 22px;
  border: 1px solid color-mix(in srgb, var(--panel-text) 22%, transparent);
}
.more-themes button {
  min-height: 38px;
  padding: 0 11px;
  border: 0;
  border-radius: 19px;
  background: none;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  opacity: 0.75;
}
.more-themes button[aria-checked='true'] {
  opacity: 1;
  font-weight: 600;
  background: color-mix(in srgb, var(--panel-text) 14%, transparent);
}

/* Phone-sized screens, either way up: the drum screen becomes a grid, and its
   bars' children take their own places in it. Tablets keep the laptop layout. */
@media (max-width: 599px) and (orientation: portrait), (max-height: 499px) and (orientation: landscape) and (max-width: 999px) {
  .drum-screen { display: grid; }
  .drum-screen .topbar,
  .drum-screen .strip { display: contents; }
  .drum-screen.focus-mode .topbar,
  .drum-screen.focus-mode .strip { display: none; }
  .drum-screen #focus-button,
  .drum-screen .menu-anchor,
  .drum-screen #settings-button { display: none; }
  .drum-screen .more-button { display: inline-flex; }
  .drum-screen .wordmark { grid-area: mark; font-size: 19px; align-self: center; }
  .drum-screen #tuning-chip { grid-area: chip; font-size: 14px; min-height: 44px; padding: 0 14px; align-self: center; justify-self: end; }
  .drum-screen .stage { grid-area: stage; padding: 8px 10px; }
  .drum-screen .actions { grid-area: tabs; }
  .drum-screen .strip-centre,
  .drum-screen .strip-wide { grid-area: strip; min-width: 0; }
  .drum-screen .strip-side { grid-area: side; }
  .drum-screen .strip-held { display: flex !important; visibility: hidden; }
  .drum-screen .strip-side:empty { display: none; }
  /* Strip contents may wrap onto more lines; single labels and buttons never do. */
  .drum-screen .strip-centre {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 4px;
    white-space: normal;
    text-align: center;
    padding: 8px 12px;
  }
  .drum-screen .strip-wide {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 12px;
    padding: 8px 12px;
  }
  .drum-screen .speaker-note { max-width: none; justify-content: center; padding: 0 12px 6px; }
  .drum-screen .strip-right { justify-self: stretch; }
  /* The listening dot stays beside the first word; the words wrap beside it. */
  .drum-screen #strip-idle { flex-wrap: nowrap; align-items: flex-start; }
  .drum-screen #strip-idle .breath { flex: none; margin-top: 0.55em; }
  /* Record's small ring sits in an icon-sized box, so its word lines up with the others. */
  .drum-screen .record-button .rec-mark { margin: 4.5px; }
  /* Tongue labels stay at 19 px or more on a phone-sized drum. */
  .drum-top .label text { font-size: 28px; }
}

/* Portrait: a top row, the drum, the status, and a tab bar in thumb reach. */
@media (max-width: 599px) and (orientation: portrait) {
  .drum-screen {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 56px minmax(0, 1fr) auto auto auto;
    grid-template-areas: 'mark chip' 'stage stage' 'strip strip' 'side side' 'tabs tabs';
  }
  .drum-screen.focus-mode { grid-template-rows: 0 minmax(0, 1fr) 0 0 0; }
  .drum-screen .wordmark { padding-left: 18px; }
  .drum-screen #tuning-chip { margin-right: 12px; }
  .drum-screen .actions {
    justify-self: stretch;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    border-top: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  }
  .drum-screen .actions > .control {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 64px;
    padding: 0;
    font-size: 12px;
  }
}

/* Landscape: the drum at full height between two rails. */
@media (max-height: 499px) and (orientation: landscape) and (max-width: 999px) {
  .drum-screen {
    grid-template-columns: 212px minmax(0, 1fr) 204px;
    /* The left rail holds the status (and the one-time speaker note); the strip's
       recording, loop and play-along rows take a row under the drum only when shown. */
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: 'mark stage tabs' 'chip stage tabs' '. stage tabs' 'side stage tabs' 'status stage tabs' '. strip tabs';
  }
  .drum-screen.focus-mode { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .drum-screen .wordmark { padding: 18px 12px 0 16px; }
  .drum-screen #tuning-chip { margin: 12px 12px 0 16px; justify-self: start; font-size: 13px; }
  .drum-screen #strip-idle {
    grid-area: status;
    align-self: end;
    justify-content: flex-start;
    text-align: left;
    padding: 0 12px 18px 16px;
    font-size: 13px;
  }
  .drum-screen .stage { padding: 8px 4px; }
  .drum-screen .actions {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    padding: 18px 16px 18px 12px;
  }
  .drum-screen .actions > .control { min-height: 48px; justify-content: flex-start; font-size: 14px; }
  .more-menu { right: calc(216px + env(safe-area-inset-right)); bottom: auto; top: 50%; transform: translateY(-50%); }
}

/* Compact sideways: where the two rails would make the drum shorter than the screen
   (main.js decides), one slim rail of icons on the right and a bare 24 px band on the
   left, where touches strike nothing. The wordmark, tuning and status move into More;
   the speaker note and the recording rows sit under the drum only while shown. */
.drum-screen.rails-compact {
  grid-template-columns: calc(24px + env(safe-area-inset-left)) minmax(0, 1fr) calc(56px + env(safe-area-inset-right));
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: '. stage tabs' '. side tabs' '. strip tabs';
}
.drum-screen.rails-compact.focus-mode { grid-template-columns: 0 minmax(0, 1fr) 0; }
.drum-screen.rails-compact .wordmark,
.drum-screen.rails-compact #tuning-chip,
.drum-screen.rails-compact #strip-idle { display: none; }
.drum-screen.rails-compact .stage { padding: 8px 0; }
.drum-screen.rails-compact .actions { padding: 8px 4px; gap: 4px; align-items: center; }
.drum-screen.rails-compact .actions > .control { justify-content: center; min-width: 48px; min-height: 48px; padding: 0; }
/* Icons only; the words stay for screen readers. */
.drum-screen.rails-compact .actions > .control > span:not(.icon-slot):not(.rec-mark) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
#drum-screen.rails-compact .more-menu { right: calc(60px + env(safe-area-inset-right)); }

/* Listen setup on a phone: upright, one scrolling column with Start pinned at the
   bottom, the four kinds 2 × 2 and the sounds as full-width rows; sideways, two
   columns that scroll on their own, Start at the foot of the right one. */
@media (max-width: 599px) {
  .kind-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sound-cards { grid-template-columns: minmax(0, 1fr); }
  .listen-setup .panel-body { padding-bottom: 150px; }
  .listen-start {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    margin: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--ground);
    border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);
  }
  .listen-start .primary { width: 100%; justify-content: center; }
  .wash-density .segmented { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wash-density .segmented span { justify-content: center; }
  .listen-buttons { flex-wrap: wrap; justify-content: center; }
  .listen-line { white-space: normal; text-align: center; padding: 0 16px; }
}
@media (max-height: 499px) and (orientation: landscape) and (max-width: 999px) {
  .listen-setup .panel-body { overflow: hidden; display: flex; flex-direction: column; padding-bottom: 0; }
  .listen-setup .page { max-width: none; width: 100%; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .listen-intro { margin: 8px 0; }
  .listen-columns { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
  .listen-what, .listen-how { overflow-y: auto; min-height: 0; padding-bottom: 16px; }
  .listen-columns .row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .listen-columns .row-label { padding-top: 0; font-weight: 600; }
  .listen-columns .row-control .check { white-space: normal; align-items: flex-start; }
  .listen-columns .row-control .check input { flex: none; margin-top: 2px; }
  .kind-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sound-cards { grid-template-columns: minmax(0, 1fr); }
  .listen-start { margin: 12px 0 0; }
  .listen-controls { bottom: 12px; }
}

/* ---------- Other screens on a phone (Phase 2a-2) ---------- */

.detail-back { display: none; }

@media (max-width: 599px) {
  /* Settings and Listen setup: labels above their controls, one column. */
  .row { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px 0; }
  .row-label { padding-top: 0; font-weight: 600; }
  .panel-bar { padding: 0 8px 0 12px; }
  .panel-body { padding: 8px 16px 48px; }

  /* Tune the drum */
  .tune-main { padding: 8px 12px 16px; }
  .continue { padding: 0 14px; max-width: 100%; }
  .continue.continue-wide { width: 100%; padding: 0 16px; }
  .returning .card { height: auto; min-height: 150px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; }
  .card { height: auto; min-height: 168px; padding: 18px 12px 14px; }
  /* A name that doesn't fit breaks between words, never cut off (the one label allowed to wrap). */
  .card-name { font-size: 16px; white-space: normal; text-wrap: balance; }
  @media (max-width: 380px) {
    .card { padding: 16px 10px 12px; }
    .card-name { font-size: 15px; } /* no smaller than body text */
    .card-meta { font-size: 13px; }
  }
  .keys { flex-direction: column; align-items: flex-start; gap: 8px; width: 100%; }
  .keys-label { float: none; }
  .keys-options { flex-wrap: wrap; }
  .tune-hint { white-space: normal; text-align: center; }
  .touch-only .tune-hint { display: none; } /* it speaks of drum keys */
  .tune-footer { flex-wrap: wrap; row-gap: 0; }

  /* Sentences beside checkboxes may wrap; the box stays at the first line. */
  .row-control .check { white-space: normal; align-items: flex-start; }
  .row-control .check input { flex: none; margin-top: 2px; }

  /* Panel bars: tighter, and Settings' Close shows its cross alone (still named "Close"). */
  .bar-left, .bar-right { gap: 6px; }
  .songbook-heading { font-size: 19px; }
  #settings-close > span:last-child { display: none; }
  .tabs [role='tab'] { padding: 0 9px; }

  /* Songbook: the list, then the chosen song as its own view with a way back. */
  .songbook-drum { display: none; }
  .songbook-body { grid-template-columns: minmax(0, 1fr); }
  .songbook-body:not(.showing-song) .song-detail,
  .songbook-body:not(.showing-song) .song-typed { display: none; }
  .songbook-body.showing-song .song-list { display: none; }
  .song-list { border-right: 0; padding: 8px 8px 32px; }
  .song-detail { padding: 8px 16px 48px; }
  .detail-back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin: 0 0 4px -8px; padding: 0 8px; }
  .tongue-choices { display: grid; grid-template-columns: repeat(var(--half, 5), minmax(44px, 1fr)); }
  .trim-row { grid-template-columns: minmax(0, 1fr); white-space: normal; gap: 4px; }

  /* Dialogs fit the width; Share becomes a full-screen sheet. */
  .dialog-backdrop { padding: 12px; }
  .dialog { padding: 18px 16px 20px; }
  .dialog-backdrop:has(.sheet) { padding: 0; place-items: stretch; }
  .dialog.sheet {
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border: 0;
    padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  }
}

