/* Loops · the loop maker (app/features/loops, js/widgets/beat_looper.js). Registered once through the registry (its
   parent panel sits on the dashboard), so every rule is scoped under the .lp* classes. Tokens only: no hex here.

   Workshop: the instrument is a steel plate with a 1px seam. Each sound's name is a strip of black label tape, and the
   tape is its sound picker. A set square is machinist blue (it is pressed); a loud one adds a center dot in the blue's
   ink. Beat lines are 2px seams between squares, alternate beats sit on brushed steel so a bar can be counted at a
   glance, and the playhead is a thin Shop Ink bar under the playing square plus a 2px rule on its top edge: a shape,
   never a fill.
   Studio ([data-world="studio"], at the end): the same plate in card stock with an ink edge and the taped-card lift,
   names on kraft tags with a punched hole, beat lines in studio ink, squares in the studio's deeper blue (its token).
   Same layout in both worlds. Yellow, marigold and red never appear in the grid: they mean done, lumens and fight.

   Layout (set by the widget): names sit beside the squares once the looper is 900px wide (data-inline="1"), above
   them below that; a row wraps at a beat (--cols) when its squares would be narrower than about 30px, or 44px on a
   touch screen (a 16-step row is 4 lines of 4 at 320px). Squares, melody squares too, are 44px tall on touch screens.
   Motion: the 150ms state change on squares; the opt-in bounce is a 1.06 scale; under
   reduced motion neither runs. Nothing is tied to the beat but the thin playhead. */

/* ------------------------------------------------------------------ the page */
.lp-page { min-width: 0; }
.lp-head p { color: var(--ink-2); max-width: 60ch; }
.lp { display: grid; gap: 10px; min-width: 0; }
.lp-mount { min-width: 0; }
.lp-wait { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.lp-skel-bar { height: 56px; max-width: 520px; }
.lp-skel-grid { height: 200px; }

/* ------------------------------------------------------------------ the instrument plate */
.lp-w { display: block; min-width: 0; }
.lp-w [hidden] { display: none !important; }
.lp-panel {
  display: grid; gap: 14px; min-width: 0; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
}
@media (max-width: 520px) { .lp-panel { padding: 12px; } }

.lp-transport { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.lp-play { min-width: 132px; }
.lp-tempo { flex: 1 1 220px; min-width: min(100%, 210px); max-width: 360px; }
.lp-volume { flex: 1 1 180px; min-width: min(100%, 180px); max-width: 300px; }
.lp-field { display: grid; gap: 4px; min-width: 0; }
.lp-label { font-weight: 700; font-size: .95rem; }
.lp-tipped { display: inline-flex; align-items: center; gap: 2px; }

/* segmented controls: the meter, the bars, which bar shows */
.lp-seg { display: inline-flex; max-width: 100%; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.lp-seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 40px; padding: 0 10px;
  border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--ink); font: 500 .9rem/1 var(--font-mono);
  cursor: pointer; transition: background-color .15s ease;
}
.lp-seg-btn:first-child { border-left: 0; }
.lp-seg-btn:hover:not(:disabled):not([aria-pressed="true"]) { background: var(--surface-2); }
.lp-seg-btn[aria-pressed="true"] { background: var(--blue); color: var(--blue-ink); }
.lp-seg-btn:focus-visible { outline-offset: -3px; }
.lp-seg-btn:disabled { cursor: default; }
.lp-seg-btn:disabled:not([aria-pressed="true"]) { color: var(--ink-3); }
.lp-show .lp-seg-btn { font-family: var(--font-body); font-weight: 700; }
/* the bar that's playing while the other one shows: a small dot (it changes once a bar, at most 1.5 times a second) */
.lp-bar-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0; }
.lp-seg-btn.is-playing .lp-bar-dot { opacity: 1; }
@media (pointer: coarse) { .lp-seg-btn { min-height: 44px; } }
@media (max-width: 420px) {
  .lp-meter, .lp-meter .lp-seg { width: 100%; }
  .lp-meter .lp-seg-btn { flex: 1 1 0; min-width: 0; padding: 0 2px; }
}

/* ------------------------------------------------------------------ the grid */
.lp-grid { display: grid; gap: 14px; min-width: 0; --lp-head: 18rem; }
.lp-track { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.lp-w[data-inline="1"] .lp-track { grid-template-columns: var(--lp-head) minmax(0, 1fr); align-items: center; gap: 12px; }
.lp-ruler { gap: 0; }
.lp-w[data-inline="0"] .lp-ruler-head { display: none; }
.lp-ruler-head { gap: 6px; color: var(--ink-3); font-size: .78rem; font-weight: 700; }
.lp-col-sound { width: 8.75rem; }
/* beside the squares the column is headed once, so each row drops its "steps" word and the names line up */
.lp-w[data-inline="1"] .lp-steps-w { display: none; }
.lp-w[data-inline="1"] .lp-voice { width: 8.75rem; }
.lp-beat { color: var(--ink-3); font-size: .78rem; line-height: 1; padding-left: 2px; }

.lp-cells {
  --lp-gap: 4px;
  display: grid; grid-template-columns: repeat(var(--cols, 16), minmax(0, 1fr)); gap: 10px var(--lp-gap); min-width: 0;
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.lp-cell {
  position: relative; display: block; min-width: 0; height: 34px; margin: 0; padding: 0;
  border: 1px solid var(--field-line); border-radius: var(--r-sm); background: var(--surface); color: inherit;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
@media (pointer: coarse) { .lp-cell { height: 44px; } }
.lp-cell.is-alt:not(.is-on) { background: var(--surface-2); }
@media (hover: hover) { button.lp-cell:hover:not(.is-on) { border-color: var(--blue); } }
.lp-cell.is-on { background: var(--blue); border-color: var(--blue); }
.lp-cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; z-index: 1; }
.lp-dot { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; translate: -50% -50%; border-radius: 50%; background: var(--blue-ink); opacity: 0; pointer-events: none; }
.lp-cell.is-loud .lp-dot { opacity: 1; }
/* beat lines: a 2px seam in the gap before a square that starts a beat; 6/8's eighths get a 1px one */
.lp-cell.is-beat::before, .lp-cell.is-sub::before {
  content: ""; position: absolute; top: -3px; bottom: -3px; left: -3px; width: 2px; border-radius: 1px; background: var(--field-line); pointer-events: none;
}
.lp-cell.is-sub::before { left: -2px; width: 1px; background: var(--line); }
/* the playhead: a 2px rule on the playing square's top edge and a 3px bar under it */
.lp-cell.is-now { box-shadow: inset 0 2px 0 var(--ink); }
.lp-cell.is-on.is-now { box-shadow: inset 0 2px 0 var(--blue-ink); }
.lp-cell.is-now::after { content: ""; position: absolute; left: 1px; right: 1px; bottom: -7px; height: 3px; border-radius: 2px; background: var(--ink); pointer-events: none; }
.lp-cell.is-hit { transform: scale(1.06); }
.lp-track.is-muted .lp-cells { opacity: .45; }
.lp-w[data-mode="play"] .lp-cell { cursor: default; }

/* a sound's name and controls: label tape (its sound picker), steps, mute, take it out */
.lp-thead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.lp-w[data-inline="1"] .lp-thead { flex-wrap: nowrap; }
.lp-thead-end { display: inline-flex; gap: 2px; margin-left: auto; }
.lp-w[data-inline="0"] .lp-thead-end { margin-left: 0; }
.lp-voice-wrap, .lp-steps-wrap { position: relative; display: inline-flex; flex: none; min-width: 0; }
.lp-voice { min-width: 8.75rem; } /* the longest name ("Wood block") fits beside its chevron */
.lp-voice, .lp-tag {
  appearance: none; -webkit-appearance: none; width: auto; max-width: 100%; min-height: 36px; margin: 0; padding: 5px 28px 6px 10px;
  border: 0; border-radius: var(--r-sm); background: var(--label-tape); color: var(--label-ink);
  font: 500 .8rem/1.4 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; cursor: pointer;
}
.lp-tag { position: relative; display: inline-flex; align-items: center; padding-right: 10px; cursor: default; }
.lp-voice option { color: var(--ink); background: var(--surface); text-transform: none; letter-spacing: normal; font-family: var(--font-body); }
.lp-voice:focus-visible, .lp-steps-sel:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.lp-voice-chev, .lp-steps-chev { position: absolute; right: 7px; top: 50%; translate: 0 -50%; width: 14px; height: 14px; pointer-events: none; }
.lp-voice-chev { color: var(--label-ink); }
.lp-steps-chev { color: var(--ink-3); }
.lp-steps { display: inline-flex; align-items: center; gap: 6px; }
.lp-steps-sel {
  appearance: none; -webkit-appearance: none; width: auto; min-width: 58px; min-height: 36px; margin: 0; padding: 4px 26px 4px 10px;
  border: 1px solid var(--field-line); border-radius: var(--r); background: var(--surface); color: var(--ink);
  font: 500 .9rem/1.2 var(--font-mono); cursor: pointer;
}
.lp-steps-w, .lp-steps-ro, .lp-muted-note { color: var(--ink-3); font-size: .85rem; font-weight: 700; }
.lp-mini {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--ink-2); cursor: pointer; transition: background-color .15s ease, color .15s ease;
}
.lp-mini .icon { width: 18px; height: 18px; }
.lp-mini:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.lp-mini:disabled { opacity: .4; cursor: not-allowed; }
.lp-mute[aria-pressed="true"] { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
@media (pointer: coarse) {
  .lp-voice, .lp-tag, .lp-steps-sel { min-height: 44px; }
  .lp-mini { width: 44px; height: 44px; }
}

/* ------------------------------------------------------------------ the melody */
.lp-melody { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); min-width: 0; }
.lp-mhead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.lp-mnote { color: var(--ink-2); font-size: .9rem; }
.lp-mrows { display: grid; gap: 6px; min-width: 0; }
.lp-note-row, .lp-w[data-inline="1"] .lp-note-row { grid-template-columns: 2.75rem minmax(0, 1fr); align-items: center; gap: 8px; }
.lp-w[data-inline="1"] .lp-note-row { grid-template-columns: var(--lp-head) minmax(0, 1fr); gap: 12px; }
.lp-note-row .lp-thead { justify-content: flex-end; }
.lp-note-name { color: var(--ink-2); font-size: .82rem; }
.lp-note-row .lp-cells { row-gap: 6px; }
.lp-note-row .lp-cell { height: 26px; }
@media (pointer: coarse) { .lp-note-row .lp-cell { height: 44px; } }
.lp-wave { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-height: 36px; }
.lp-wave-read { color: var(--ink); font-size: .9rem; }
.lp-wave-svg { width: 160px; height: 32px; flex: none; overflow: visible; }
.lp-wave-path { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ tools, hint, view options, messages */
.lp-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.lp-start { width: auto; max-width: 100%; min-height: 36px; padding: 6px 10px; font-size: .9rem; }
@media (pointer: coarse) { .lp-start { min-height: 44px; } }
.lp-hint { color: var(--ink-2); font-size: .92rem; max-width: 65ch; }
.lp-options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; }
.lp-options .check { font-size: .95rem; min-height: 44px; }
.lp-keys > summary { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; font-weight: 700; color: var(--ink-2); list-style: none; }
.lp-keys > summary::-webkit-details-marker { display: none; }
.lp-keys > summary .icon { width: 1em; height: 1em; transition: rotate .2s cubic-bezier(.16, 1, .3, 1); }
.lp-keys[open] > summary .icon { rotate: 180deg; }
.lp-keys dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; margin: 4px 0 0; }
.lp-keys dt { font: 500 .85rem/1.5 var(--font-mono); color: var(--ink); }
.lp-keys dd { margin: 0; color: var(--ink-2); }
.lp-ask { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }

/* ------------------------------------------------------------------ the save bar */
.lp-savebar { display: grid; gap: 10px; min-width: 0; }
.lp-save-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.lp-name { flex: 1 1 240px; max-width: 420px; }
.lp-save-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.lp-dirty { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: .9rem; font-weight: 700; }
.lp-dirty::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--ink-2); }
.lp-dirty[hidden] { display: none; }
.lp-proof-done { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--good); font-weight: 700; text-decoration: none; }
.lp-proof-done:hover { text-decoration: underline; }
.lp-free { display: flex; gap: 8px; align-items: flex-start; color: var(--ink-2); font-size: .92rem; max-width: 65ch; }
.lp-free .icon { color: var(--ink-3); margin-top: 2px; }

/* ------------------------------------------------------------------ the shelf (and a parent's lists) */
/* under a dimension line, |———|, headed by its own label tape */
.lp-shelf { position: relative; display: grid; gap: 12px; padding-top: 20px; min-width: 0; }
.lp-shelf::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 9px;
  background: linear-gradient(var(--line), var(--line)) 0 50% / 100% 1px no-repeat;
  border-inline: 1px solid var(--line);
}
.lp-shelf-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.lp-shelf-label {
  display: inline-flex; padding: 4px 10px 5px; border-radius: var(--r-sm); background: var(--label-tape); color: var(--label-ink);
  font: 500 .85rem/1.35 var(--font-mono); letter-spacing: .1em; text-transform: uppercase;
}
.lp-shelf-count { color: var(--ink-2); font-size: .9rem; font-weight: 700; }
.lp-shelf-count .num { font-family: var(--font-mono); font-weight: 500; }
.lp-rows { display: grid; margin: 0; padding: 0; list-style: none; }
.lp-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.lp-row:first-child { border-top: 0; }
.lp-row-main { display: grid; gap: 2px; min-width: 0; }
.lp-row-title { justify-self: start; font-weight: 700; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.lp-row-title:hover { color: var(--blue); text-decoration: underline; }
.lp-row.is-current .lp-row-title { color: var(--blue); }
.lp-row-meta { color: var(--ink-2); font-size: .88rem; }
.lp-row-meta .mono, .lp-facts .mono { font-size: .85rem; }
.lp-row-proof { display: inline-flex; align-items: center; gap: 6px; color: var(--good); font-size: .85rem; font-weight: 700; }
.lp-row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.lp-row-open { align-self: center; padding: 0 10px; color: var(--blue); font-size: .88rem; font-weight: 700; }
.lp-del:hover { color: var(--bad); }
@media (max-width: 560px) {
  .lp-row { grid-template-columns: minmax(0, 1fr); }
  .lp-row-actions { justify-content: flex-start; }
}
.lp-kid .panel-head h3 { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ the read-only player */
.lp-back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; justify-self: start; font-weight: 700; }
.lp-facts { color: var(--ink-2); }
.lp-text > summary { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; cursor: pointer; font-weight: 700; color: var(--ink-2); list-style: none; }
.lp-text > summary::-webkit-details-marker { display: none; }
.lp-text > summary .icon { width: 1em; height: 1em; transition: rotate .2s cubic-bezier(.16, 1, .3, 1); }
.lp-text[open] > summary .icon { rotate: 180deg; }
.lp-notation { margin: 6px 0 0; padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); color: var(--ink); font: 500 .85rem/1.6 var(--font-mono); white-space: pre; overflow-x: auto; }

/* ------------------------------------------------------------------ reduced motion: squares change in place */
@media (prefers-reduced-motion: reduce) {
  .lp-cell, .lp-seg-btn, .lp-mini { transition: none; }
  .lp-cell.is-hit { transform: none; }
}

/* ------------------------------------------------------------------ studio: card stock, kraft tags, ink beat lines */
[data-world="studio"] .lp-panel { background: var(--card); border-color: var(--card-edge); border-radius: var(--r-sm); box-shadow: var(--shadow-hung); }
[data-world="studio"] .lp-wait { background: var(--card); border-color: var(--card-edge); border-radius: var(--r-sm); }
[data-world="studio"] :is(.lp-transport, .lp-melody, .lp-tools) { border-color: var(--line); }
[data-world="studio"] .lp-seg { background: var(--card); border-color: var(--field-line); }
[data-world="studio"] .lp-seg-btn { border-left-color: var(--field-line); }
/* a sound's name on a kraft tag with a punched hole (still its sound picker) */
[data-world="studio"] :is(.lp-voice, .lp-tag, .lp-shelf-label) {
  background: var(--kraft); color: var(--ink); font: 700 .85rem/1.4 var(--font-body); letter-spacing: normal; text-transform: none;
  padding-left: 22px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--card-edge) 35%, transparent);
}
[data-world="studio"] .lp-shelf-label { position: relative; font-size: .95rem; }
[data-world="studio"] :is(.lp-voice-wrap, .lp-tag, .lp-shelf-label)::before {
  content: ""; position: absolute; left: 8px; top: 50%; translate: 0 -50%; z-index: 1; width: 7px; height: 7px; border-radius: 50%;
  background: var(--card); box-shadow: inset 0 0 0 1px var(--card-edge); pointer-events: none;
}
[data-world="studio"] .lp-voice-chev { color: var(--ink); }
[data-world="studio"] .lp-cell { background: var(--card); }
[data-world="studio"] .lp-cell.is-alt:not(.is-on) { background: var(--surface-2); }
[data-world="studio"] .lp-cell.is-on { background: var(--blue); border-color: var(--blue); }
[data-world="studio"] :is(.lp-cell.is-beat, .lp-cell.is-sub)::before { background: var(--ink); }
[data-world="studio"] .lp-cell.is-sub::before { opacity: .45; }
[data-world="studio"] .lp-steps-sel { background: var(--card); }
[data-world="studio"] .lp-notation { background: var(--surface-2); }
