:root {
  --bg: #2a2a2a;
  --surface: #303030;
  --text: #ececec;
  --muted: #9c9c9c;
  --teal: #1fd6b0;
  --pulse: var(--teal);
  --out: 6px 6px 12px #171717, -4px -4px 10px #3a3a3a;
  --out-sm: 3px 3px 7px #171717, -2px -2px 6px #3a3a3a;
  --in: inset 4px 4px 9px #151515, inset -3px -3px 7px #383838;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { overflow-x: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
/* Els textos s'omplen amb JS: reserva la línia perquè no hi hagi salts de maquetació */
[data-i18n]:empty::before { content: "\200b"; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

.app {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.views { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.view { min-height: 100%; display: flex; flex-direction: column; padding: 14px 18px 10px; }
.view[hidden], .panel[hidden], .field[hidden] { display: none; }
.load-title { display: none; margin: 0 0 12px; font-size: 18px; }
.view-title { font-size: 22px; margin: 8px 0 16px; }

/* ---- Botons neumòrfics ---- */
.btn {
  border: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #2c2c2c, #232323);
  box-shadow: var(--out);
  transition: box-shadow .08s, transform .08s;
}
.btn:active, .btn.pressed { box-shadow: var(--in); transform: scale(.98); }
.btn.round { width: 68px; height: 68px; font-weight: 600; font-size: 15px; display: grid; place-items: center; padding: 0; }

/* ---- Pestanyes ---- */
.tabs {
  display: flex;
  width: min(300px, 80%);
  margin: 0 auto;
  padding: 4px;
  border-radius: 16px;
  background: #1f1f1f;
  box-shadow: var(--in);
}
.tabs button {
  flex: 1; padding: 9px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--out-sm); }

.panel { flex: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; padding-top: 18px; }

/* ---- Llums ---- */
.lights {
  --light-h: 80px; /* alçada mínima: les llums creixen fins a ocupar l'espai que sobra */
  flex: 1 1 auto; min-height: calc(var(--light-h) + 8px); /* reserva l'espai abans que el JS dibuixi les llums (sense CLS) */
  max-height: 280px; align-items: stretch;
  display: flex; justify-content: center; gap: clamp(8px, 3vw, 18px);
  border: 0; background: transparent; padding: 4px; border-radius: 14px;
}
.light {
  --tray: inset 0 0 0 1px #2b2b2b, inset 0 3px 8px rgba(0, 0, 0, .55); /* sombra simètrica, sense llum a la dreta */
  flex: 1; max-width: 110px; min-width: 0;
  min-height: var(--light-h);
  display: flex; flex-direction: column; gap: 6px;
  padding: 6px; border-radius: 10px; background: #181818; box-shadow: var(--tray);
  transition: box-shadow .03s;
}
/* Els 3 espais sempre són visibles.
   - muts (sense .has): plans i apagats, es fonen amb el fons de la secció
   - configurats (.has): amb marc ben marcat; s'il·luminen amb la secció */
.light i {
  display: block; flex: 1; min-height: 0; border-radius: 4px;
  background: #2a2a2a; border: 1px solid transparent;
  transition: background .03s, box-shadow .03s;
}
.light i.has { background: #0a0a0a; border-color: #6a6a6a; }
.light.on { box-shadow: var(--tray), 0 0 0 1px color-mix(in srgb, var(--pulse) 55%, #3b3b3b); }
.light.lit { box-shadow: var(--tray), 0 0 0 2px var(--pulse), 0 0 16px color-mix(in srgb, var(--pulse) 70%, transparent); }
.light.lit i.has { background: var(--pulse); border-color: var(--pulse); box-shadow: 0 0 12px var(--pulse); }
body[data-pulse="none"] .light.lit { box-shadow: var(--tray), 0 0 0 2px #5a5a5a; }
body[data-pulse="none"] .light.lit i.has { background: #4a4a4a; border-color: #5a5a5a; box-shadow: none; }

.timer { color: var(--teal); font-size: 14px; font-weight: 600; min-height: 18px; margin-top: -4px; font-variant-numeric: tabular-nums; }

/* ---- Fila de controls ---- */
.ctrl-row { display: flex; justify-content: center; gap: 20px; }
.ctrl { width: 66px; height: 58px; font-size: 18px; font-weight: 600; display: grid; place-items: center; color: var(--text); }
#btn-sound { color: var(--teal); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; line-height: 1; }

/* ---- BPM ---- */
.readout { display: flex; align-items: center; justify-content: center; gap: 14px; }
.readout-center { text-align: center; min-width: 120px; }
.tempo-name { color: var(--muted); font-size: 16px; }
.bpm-value {
  border: 0; background: none; padding: 0 8px; font-size: clamp(40px, 7dvh, 54px);
  font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums;
}
.bpm-label { color: var(--muted); font-size: 14px; letter-spacing: .08em; }
.arrow { border: 0; background: none; color: #5d5d5d; padding: 10px; border-radius: 12px; }
.arrow:active { color: var(--teal); }

/* ---- Roda ---- */
.dial-zone { position: relative; display: grid; place-items: center; min-height: 0; padding: 8px 0 4px; }
.dial {
  position: relative;
  width: min(46vw, 210px, 27dvh); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #262626, #191919);
  box-shadow: var(--out); touch-action: none; user-select: none; cursor: grab;
}
.dial:active { cursor: grabbing; }
.dial-spin { position: absolute; inset: 0; border-radius: 50%; }
.dial-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: repeating-conic-gradient(#474747 0 .9deg, transparent .9deg 6deg);
  -webkit-mask: radial-gradient(circle, transparent 70%, #000 71%, #000 96%, transparent 97%);
  mask: radial-gradient(circle, transparent 70%, #000 71%, #000 96%, transparent 97%);
}
.dial-notch {
  position: absolute; top: 6%; left: 50%; width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%; background: var(--teal); box-shadow: 0 0 8px var(--teal);
}
.play, .tap { position: absolute; bottom: 4px; }
.play { left: 0; color: var(--teal); }
.tap { right: 0; }
.play svg { display: block; grid-area: 1 / 1; }
.play .i-pause, .play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: block; }

/* ---- Navegació inferior ---- */
.bottom-nav {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: #232323; border-top: 1px solid #1a1a1a;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px; border: 0; background: none; color: var(--muted); font-size: 12px;
}
.bottom-nav button[aria-current="page"] { color: var(--teal); }

/* ---- Configuració ---- */
.field { margin-bottom: 22px; display: flex; flex-direction: column; gap: 10px; }
.field label, .field-label { color: var(--muted); font-size: 14px; }
input[type="range"] { width: 100%; accent-color: var(--teal); height: 32px; }

/* ---- Fulls inferiors ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  width: 100%; max-width: 520px; max-height: 80dvh; overflow-y: auto;
  background: #222; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 14px; font-size: 18px; text-align: center; }
.options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.opt {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 6px; min-height: 64px; border: 2px solid transparent; border-radius: 16px;
  background: #2a2a2a; color: var(--text); font-size: 13px;
}
.opt[aria-pressed="true"] { border-color: var(--teal); }
.opt .glyph { font-size: 24px; line-height: 1; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--sw, #555); background: color-mix(in srgb, var(--sw, #555) 18%, #1d1d1d); }
.swatch.none { --sw: #666; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-done, .sheet-cancel { flex: 1; padding: 14px; border: 0; border-radius: 14px; background: #2d2d2d; font-weight: 600; }
.sheet-done.danger { background: #7a2a2a; }
.sheet-msg { margin: 0; color: var(--muted); text-align: center; line-height: 1.4; }
.sheet input {
  width: 100%; font-size: 36px; text-align: center; padding: 10px; border-radius: 14px;
  border: 1px solid #444; background: #181818; color: var(--text);
}

/* ---- Barra de cançó (Anterior / Següent) ---- */
.song-bar { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.song-bar[hidden] { display: none; }
.song-btn {
  min-width: 84px;
  border: 0; border-radius: 12px; padding: 9px 10px; font-size: 13px; font-weight: 600; white-space: nowrap;
  background: linear-gradient(145deg, #2c2c2c, #232323); box-shadow: var(--out-sm);
}
.song-btn:active:not(:disabled) { box-shadow: var(--in); }
.song-btn:disabled { opacity: .35; box-shadow: none; }
.song-info { flex: 1; min-width: 0; text-align: center; }
.song-title, .song-setlist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-title { font-weight: 700; font-size: 15px; }
.song-setlist { color: var(--muted); font-size: 12px; }

/* ---- Biblioteca ---- */
.panel.load { justify-content: flex-start; }
.muted { color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.pill {
  border: 0; border-radius: 14px; padding: 11px 14px; font-size: 14px; font-weight: 600;
  background: linear-gradient(145deg, #2c2c2c, #232323); box-shadow: var(--out-sm);
}
.pill.primary { background: var(--teal); color: #062019; box-shadow: none; }
.pill.danger { color: #ff8a8a; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 2px solid transparent; border-radius: 16px; padding: 13px 14px; background: #2d2d2d; color: var(--text);
}
.row .grow { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.row-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row.current, .song-row.current { border-color: var(--teal); }
.row:disabled { opacity: .45; cursor: default; }
.list.nested { margin: 8px 0 4px 14px; gap: 8px; padding-left: 10px; border-left: 2px solid #3a3a3a; }
.list.nested .row { padding: 10px 12px; }
.song-row { display: flex; align-items: center; gap: 2px; border: 2px solid transparent; border-radius: 16px; background: #2d2d2d; padding-right: 4px; }
.song-row .row { background: none; border: 0; flex: 1; min-width: 0; }
.icon-btn { border: 0; background: none; width: 36px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; flex: none; }
.icon-btn:disabled { opacity: .25; cursor: default; }
.icon-btn:active:not(:disabled) { color: var(--teal); }
.icon { display: grid; place-items: center; }
.detail-head { display: flex; align-items: center; gap: 2px; margin: 4px 0 14px; }
.detail-head h1 { flex: 0 1 auto; min-width: 0; margin: 0 2px 0 4px; font-size: 22px; overflow-wrap: anywhere; }
.detail-head .danger { margin-left: auto; }
.icon-btn.danger { color: #ff8a8a; }
.pill:disabled { opacity: .4; cursor: default; box-shadow: none; }
.section-title { font-size: 14px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }

.lights-menu .section-title { margin: 4px 0 10px; }
.lights-menu .section-title:not(:first-child) { margin-top: 18px; }
.lights-menu .acc-row { justify-content: flex-start; }
.muted.small { font-size: 13px; margin: 12px 0 0; }

/* ---- Comandament / pedal ---- */
.remote-box { margin-top: 8px; padding-top: 20px; border-top: 1px solid #3a3a3a; }
.section-heading { margin: 0 0 8px; font-size: 18px; }
.remote-box .section-title { margin: 18px 0 8px; }
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; }
.check-row input { width: 22px; height: 22px; flex: none; margin: 1px 0 0; accent-color: var(--teal); }
.check-row-text { display: flex; flex-direction: column; gap: 3px; }
.remote-test { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 16px; background: #232323; box-shadow: var(--in); }
.remote-status { display: flex; flex-direction: column; gap: 2px; min-height: 40px; justify-content: center; }
.remote-status.ok strong { color: var(--teal); font-size: 18px; }
.remote-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.remote-log li { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 10px; background: #2a2a2a; }
.remote-log .log-key { font-weight: 600; }
.remote-log .log-detail { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.remote-test .pill { align-self: flex-start; }
.map-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 12px 0; border-bottom: 1px solid #333; }
.map-label { flex: 1 1 100%; font-weight: 600; }
.key-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.key-chip { display: inline-flex; align-items: center; gap: 2px; padding: 4px 4px 4px 12px; border-radius: 999px; border: 1px solid #484848; background: #262626; font-size: 13px; }
.key-chip-x { display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
.learning { display: flex; align-items: center; gap: 10px; color: var(--teal); font-weight: 600; flex: 1 1 100%; }
.notice {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top)); z-index: 30;
  max-width: calc(100% - 24px); padding: 10px 16px; border-radius: 14px; background: #1a1a1a;
  border: 1px solid var(--teal); font-size: 14px; text-align: center;
}

/* ---- Grups: filtre d'una línia, gestor en línia i selector ---- */
.chips-wrap { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; }
.chips {
  display: flex; flex-wrap: nowrap; gap: 8px; flex: 1; min-width: 0; padding: 2px 0;
  overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; white-space: nowrap; padding: 8px 14px; border-radius: 999px;
  border: 1px solid #484848; background: #262626; color: var(--text); font-size: 14px;
}
.chip[aria-checked="true"] { background: var(--teal); border-color: var(--teal); color: #062019; font-weight: 700; }
.chip-create { border-style: dashed; color: var(--muted); }
.chip-edit { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid #484848; background: #262626; color: var(--muted); }
.group-manager, .group-picker { display: flex; flex-direction: column; gap: 8px; }
.group-add { display: flex; gap: 8px; }
.sheet .group-add input, .sheet .group-picker input { flex: 1; min-width: 0; font-size: 16px; text-align: left; padding: 11px 13px; border-radius: 12px; }
.field-error { margin: 0; color: #ff8a8a; font-size: 13px; }
.group-row { display: flex; align-items: center; gap: 4px; padding: 3px 4px 3px 8px; border-radius: 14px; background: #2a2a2a; }
.sheet .g-input { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; text-align: left; padding: 9px 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text); }
.sheet .g-input:focus { border-color: var(--teal); background: #1d1d1d; outline: none; }
.group-row .g-count { color: var(--muted); font-size: 13px; margin-right: 2px; font-variant-numeric: tabular-nums; }
.group-row.confirm { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
.group-row.confirm .g-ask { flex: 1 1 100%; font-size: 14px; }
.group-row.confirm .g-actions { display: flex; gap: 8px; margin-left: auto; }
.pill.danger-fill { background: #7a2a2a; color: #fff; box-shadow: none; }
.check[role="radio"] .box { border-radius: 50%; }
.check[role="radio"][aria-checked="true"] .box::after { width: 8px; height: 8px; margin: 0; border: 0; border-radius: 50%; background: #062019; transform: none; }
.check.create .box { border-style: dashed; border-color: var(--teal); }
.check.create .check-label { color: var(--teal); font-weight: 600; }

/* ---- Subapartats i llistes de selecció ---- */
.tabs.sub { margin: 4px auto 16px; }
.row-sub { font-style: italic; }
.checklist { display: flex; flex-direction: column; gap: 8px; max-height: 50dvh; overflow-y: auto; }
.check {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 14px; border: 0;
  border-radius: 14px; background: #2a2a2a; color: var(--text); text-align: left; font-size: 15px;
}
.check .box { width: 22px; height: 22px; flex: none; border-radius: 6px; border: 2px solid #666; display: grid; place-items: center; }
.check[aria-checked="true"] .box { background: var(--teal); border-color: var(--teal); }
.check[aria-checked="true"] .box::after { content: ''; width: 5px; height: 10px; margin-top: -2px; border: solid #062019; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
.check-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.setlist-picker { display: flex; flex-direction: column; gap: 12px; }
.setlist-picker .pill { align-self: flex-start; }

/* ---- Editor de cançó ---- */
.editor {
  position: fixed; inset: 0; z-index: 5; max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column; background: #1d1d1d; padding-top: env(safe-area-inset-top);
}
.editor-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 8px; }
.editor-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.editor-body { flex: 1; overflow-y: auto; }
.ed-field { display: block; padding: 12px 18px; background: #262626; border-bottom: 1px solid #1d1d1d; }
.ed-field .lbl { display: block; color: var(--muted); font-size: 13px; }
.ed-field input {
  width: 100%; padding: 6px 0; border: 0; border-bottom: 1px solid #4a4a4a; outline: none;
  background: transparent; color: var(--text); font-size: 20px;
}
.ed-field input:focus { border-bottom-color: var(--teal); }
.ed-field input[aria-invalid="true"] { border-bottom-color: #ff8a8a; }
.ed-row {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 16px 18px; border: 0; border-bottom: 1px solid #1d1d1d; background: #262626; color: var(--text);
  font-size: 16px; text-align: left;
}
.ed-row .val { font-weight: 600; font-size: 18px; min-width: 0; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 12px; }
.ed-row.stack { flex-direction: column; align-items: flex-start; gap: 12px; }
.acc-row { display: flex; flex-wrap: wrap; gap: 8px; }
.acc {
  width: 38px; height: 46px; display: flex; flex-direction: column; gap: 3px; padding: 5px;
  border: 0; border-radius: 8px; background: #1b1b1b; box-shadow: var(--in);
}
.acc i { flex: 1; display: block; border-radius: 2px; background: #0b0b0b; border: 1px solid #3b3b3b; }
.acc i.lit { background: #e9e9e9; border-color: #e9e9e9; }
.acc.on { outline: 2px solid var(--teal); outline-offset: 1px; }
.editor-foot { display: flex; align-items: center; gap: 14px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); background: #262626; }
.editor-foot .pill { flex: none; }
.editor-foot .load-btn { margin-left: auto; }
.editor-foot .sum { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-foot .btn.round { width: 52px; height: 52px; flex: none; color: var(--teal); }
.preview svg { display: block; grid-area: 1 / 1; }
.preview .i-pause, .preview[aria-pressed="true"] .i-play { display: none; }
.preview[aria-pressed="true"] .i-pause { display: block; }

/* ---- Avís d'actualització ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px;
  background: #1a1a1a; border: 1px solid var(--teal); border-radius: 14px; z-index: 20; font-size: 14px;
}
.toast[hidden] { display: none; }
.toast { max-width: calc(100% - 24px); }
.toast span { flex: 1; min-width: 0; }
.toast-btn { white-space: nowrap; }
.toast-btn.ghost { background: transparent; color: var(--muted); border: 1px solid #444; }
.toast-btn { border: 0; border-radius: 10px; padding: 8px 12px; background: var(--teal); color: #062019; font-weight: 700; }

/* Pantalles baixes (p. ex. 320×568): tot ha de cabre sense desplaçar */
@media (max-height: 700px) {
  .view { padding-top: 8px; }
  .panel { gap: 4px; padding-top: 10px; }
  .tabs button { padding: 6px; }
  .lights { --light-h: 56px; }
  .light { gap: 4px; padding: 5px; }
  .song-bar { min-height: 34px; }
  .song-btn { padding: 7px 8px; }
  .song-setlist { display: none; }
  .ctrl { height: 46px; width: 56px; }
  #btn-sound { gap: 1px; font-size: 11px; }
  #btn-sound svg { width: 16px; height: 16px; }
  .bpm-value { font-size: 36px; }
  .tempo-name, .bpm-label { font-size: 13px; }
  .dial { width: min(46vw, 26dvh); }
  .btn.round { width: 56px; height: 56px; }
  .bottom-nav button { padding: 6px 0 5px; }
}
@media (max-width: 340px) {
  .bottom-nav button { font-size: 10px; }
}

/* ---- Tauleta (≥ 600 px): més gran, encara una columna ---- */
@media (min-width: 600px) {
  .app { max-width: 680px; }
  .light { max-width: 150px; }
  .dial { width: min(300px, 30dvh); }
  .bpm-value { font-size: clamp(48px, 8dvh, 72px); }
  .btn.round { width: 76px; height: 76px; }
  .ctrl { width: 76px; height: 64px; }
  .view-title { font-size: 26px; }
}

/* ---- Escriptori / tauleta horitzontal (≥ 900 px): metrònom + càrrega en dues columnes ---- */
@media (min-width: 900px) and (min-height: 560px) {
  .app { max-width: 1180px; }
  #view-metronome {
    display: grid; grid-template-columns: minmax(380px, 560px) minmax(300px, 1fr);
    column-gap: 40px; padding: 18px 32px 12px; align-items: stretch;
  }
  #view-metronome[hidden] { display: none; } /* el display:grid de arriba anulaba hidden */
  #view-metronome > .tabs { display: none; }
  #view-metronome > .panel { padding-top: 6px; }
  #view-metronome #panel-load[hidden] { display: flex; }
  #panel-load {
    justify-content: flex-start; overflow-y: auto; min-height: 0; max-height: calc(100dvh - 120px);
    padding: 18px; border-radius: 22px; background: #232323; box-shadow: var(--in);
  }
  .load-title { display: block; }
  .lights { --light-h: 90px; }
  .light { max-width: 130px; }
  .dial { width: min(280px, 28dvh); }
  .view:not(#view-metronome) { width: 100%; max-width: 760px; margin: 0 auto; padding-top: 22px; }
}

/* Escriptori amb finestra poc alta: compacta el metrònom */
@media (min-width: 900px) and (min-height: 560px) and (max-height: 760px) {
  #view-metronome { padding-top: 8px; padding-bottom: 6px; }
  #view-metronome > .panel { gap: 6px; }
  .lights { --light-h: 72px; }
  .ctrl { height: 52px; }
  .bpm-value { font-size: 48px; }
  .dial { width: min(260px, 26dvh); }
  .btn.round { width: 64px; height: 64px; }
  #panel-load { max-height: calc(100dvh - 90px); }
}

/* ---- Mòbil en horitzontal: dues columnes sense desplaçament ---- */
@media (orientation: landscape) and (max-height: 560px) and (min-width: 560px) {
  .app { max-width: none; }
  #panel-compose {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto auto;
    column-gap: 28px; row-gap: 6px; align-items: center; padding-top: 6px;
  }
  #panel-compose[hidden] { display: none; } /* idem: no ha de ganar a hidden */
  #panel-compose > .song-bar { grid-column: 1; grid-row: 1; }
  #panel-compose > .lights { grid-column: 1; grid-row: 2; }
  #panel-compose > .timer { grid-column: 1; grid-row: 3; margin: 0; }
  #panel-compose > .ctrl-row { grid-column: 1; grid-row: 4; }
  #panel-compose > .readout { grid-column: 2; grid-row: 1; }
  #panel-compose > .dial-zone { grid-column: 2; grid-row: 2 / span 3; }
  .view { padding-top: 6px; }
  .tabs button { padding: 5px; }
  .lights { --light-h: 64px; }
  .light { max-width: 80px; }
  .dial { width: min(34dvh, 125px); }
  .bpm-value { font-size: 40px; }
  .btn.round { width: 52px; height: 52px; }
  .song-setlist { display: none; }
}

@media (max-width: 400px) {
  .editor-foot .sum { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
