/* Looper (looper.html): a loop pedal. Always dark, like a stage. Each track has its own colour
   in --c; its pedal's light (--led) shows what it's doing: red recording, orange overdub,
   green playing. Works with a mouse, a touch screen and the keyboard. */

.lp-body { background: radial-gradient(1200px 600px at 50% -10%, #1d1a2b 0%, var(--surface-1) 60%); }
.lp-main { max-width: 1180px; padding-top: 24px; }
.lp-crumbs { font-size: .85rem; color: var(--text-muted); }
.lp-crumbs a { color: var(--text-muted); }
.lp-main .section-title { margin-top: 6px; font-size: 2.4rem; letter-spacing: .01em; }
.lp-main .section-sub { max-width: 780px; margin-bottom: 18px; }
.lp-h2 { margin: 0; font-family: var(--font-display); font-weight: 400; text-transform: uppercase; font-size: 1.25rem; letter-spacing: .02em; }
.lp-note { margin: 4px 0 10px; color: var(--text-muted); font-size: .85rem; }

/* ---- panels and small controls ---- */
.lp-panel {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  margin: 12px 0; padding: 12px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
}
.lp-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: .9rem; color: var(--text-dim); }
.lp-field input[type="range"] { accent-color: var(--accent-pink); width: 130px; }
.lp-field output { min-width: 2.2em; font-variant-numeric: tabular-nums; color: var(--text); }
.lp-field small { color: var(--text-muted); font-weight: 600; }
.lp-bpm input[type="range"] { width: 170px; }
.lp-select {
  font: inherit; font-weight: 700; color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.lp-select:disabled, .lp-field input:disabled { opacity: .5; }
.lp-tempo-only.off { opacity: .35; pointer-events: none; }
.lp-lock { font-size: .8rem; color: var(--text-muted); font-style: italic; }
.lp-tip { font-size: .82rem; color: var(--text-muted); }
.lp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.lp-seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 999px; }
.lp-seg button {
  font: inherit; font-weight: 700; font-size: .88rem; color: var(--text-dim); background: transparent;
  border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer; touch-action: manipulation;
}
.lp-seg button[aria-pressed="true"] { background: var(--accent-pink); color: #fff; }
.lp-seg button:disabled { cursor: not-allowed; opacity: .55; }
.lp-seg button:disabled[aria-pressed="true"] { opacity: .8; }

.lp-chip, .lp-btn {
  font: inherit; font-weight: 700; font-size: .88rem; color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px; touch-action: manipulation;
  transition: background .12s, border-color .12s, transform .08s;
}
.lp-chip:hover:not(:disabled), .lp-btn:hover:not(:disabled) { border-color: var(--text-muted); text-decoration: none; }
.lp-chip:active:not(:disabled), .lp-btn:active:not(:disabled) { transform: scale(.97); }
.lp-chip:disabled, .lp-btn:disabled { opacity: .4; cursor: not-allowed; }
.lp-chip[aria-pressed="true"] { background: color-mix(in srgb, var(--accent-green) 22%, var(--surface-3)); border-color: var(--accent-green); }
.lp-micbtn[aria-pressed="true"] { background: color-mix(in srgb, var(--accent-pink) 25%, var(--surface-3)); border-color: var(--accent-pink); }
.lp-btn-go { background: var(--accent-pink); border-color: var(--accent-pink); color: #fff; }
.lp-btn-x:hover:not(:disabled) { border-color: var(--danger); color: #ff8a80; }
.lp-btn-hi { background: var(--accent-purple); border-color: var(--accent-purple); color: #fff; }
:focus-visible { outline: 3px solid var(--accent-amber); outline-offset: 2px; }

.lp-meter { position: relative; width: 120px; height: 10px; border-radius: 5px; background: var(--surface-3); overflow: hidden; border: 1px solid var(--border); }
.lp-meter i { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, var(--accent-green) 0 70%, var(--accent-amber) 70% 90%, #ff3b3b 90%); }
.lp-meter i.hot { filter: brightness(1.3); }

.lp-saved {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 12px; padding: 10px 14px;
  border: 1px solid var(--accent-green); border-radius: 12px; background: color-mix(in srgb, var(--accent-green) 12%, var(--surface-2));
  font-weight: 600;
}
.lp-saved[hidden] { display: none; }
.lp-sync p, .lp-sync ol { margin: 0; flex-basis: 100%; color: var(--text-dim); font-size: .9rem; }
.lp-sync ol { padding-left: 1.3em; }
.lp-calmsg { font-size: .88rem; color: var(--text-dim); }
.lp-syncman input[type="range"] { width: 200px; }
.lp-panel[hidden] { display: none; }

/* ---- the pedalboard ---- */
.lp-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.lp-track {
  --led: transparent; --pk: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 12px 12px; min-width: 0;
  background: linear-gradient(180deg, #23222c, #18171f);
  border: 1px solid var(--border); border-top: 3px solid var(--c); border-radius: 16px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04);
}
.lp-track.sel { border-color: color-mix(in srgb, var(--c) 55%, var(--border)); border-top-color: var(--c); }
.lp-ringwrap { position: relative; width: 100%; max-width: 230px; aspect-ratio: 1; }
.lp-ring { position: absolute; inset: 0; width: 100%; height: 100%; }
.lp-pedal {
  position: absolute; left: 50%; top: 50%; width: 58%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #f4f4f6; font: inherit;
  background: radial-gradient(circle at 35% 30%, #5b5a66, #2b2a33 55%, #1c1b22);
  box-shadow:
    0 0 0 4px #121117,
    0 0 0 7px var(--led),
    0 0 calc(10px + 26px * var(--pk)) calc(2px + 6px * var(--pk)) var(--led),
    0 8px 16px rgba(0,0,0,.6),
    inset 0 2px 2px rgba(255,255,255,.18), inset 0 -4px 8px rgba(0,0,0,.5);
  touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  transition: box-shadow .12s, transform .06s;
}
.lp-pedal.down { transform: translate(-50%, -50%) scale(.94); }
.lp-pedal:focus-visible { outline: 3px solid var(--accent-amber); outline-offset: 10px; }
.lp-num { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.6rem, 3.4vw, 2.4rem); line-height: 1; }
.lp-st { font-size: .74rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #c3c3cf; }
.lp-track[data-state="count"] .lp-num { display: none; }
.lp-track[data-state="count"] .lp-st { font-family: var(--font-display); font-weight: 400; font-size: clamp(2rem, 4.6vw, 3.2rem); letter-spacing: 0; color: #ff6b6b; }
.lp-track[data-state="count"] .lp-pedal,
.lp-track[data-state="armed"] .lp-pedal { animation: lpBlink .5s steps(1) infinite; }
.lp-track[data-state="rec"] .lp-st, .lp-track[data-state="armed"] .lp-st { color: #ff6b6b; }
.lp-track[data-state="dub"] .lp-st { color: #ffb84d; }
.lp-track[data-state="play"] .lp-st { color: #5fe39b; }
.lp-track[data-state="muted"] .lp-pedal, .lp-track[data-state="stopped"] .lp-pedal { filter: saturate(.6); }
@keyframes lpBlink { 50% { box-shadow: 0 0 0 4px #121117, 0 0 0 7px transparent, 0 8px 16px rgba(0,0,0,.6), inset 0 2px 2px rgba(255,255,255,.18), inset 0 -4px 8px rgba(0,0,0,.5); } }
.lp-hint { min-height: 1.2em; font-size: .8rem; color: var(--text-muted); text-align: center; }

.lp-tbtns { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.lp-tb {
  font: inherit; font-weight: 700; font-size: .85rem; color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 8px; min-width: 40px; height: 36px; padding: 0 10px; cursor: pointer; touch-action: manipulation;
}
.lp-tb:disabled { opacity: .35; cursor: not-allowed; }
.lp-ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.lp-tb .lp-ic { display: block; margin: 0 auto; }
.lp-tb.on { background: var(--c); border-color: var(--c); color: #111; }
.lp-vol { display: flex; align-items: center; gap: 8px; width: 100%; font-size: .75rem; color: var(--text-muted); font-weight: 700; }
.lp-vol input { flex: 1; min-width: 0; accent-color: var(--c); }

/* ---- transport ---- */
.lp-transport { gap: 10px 14px; }
.lp-play {
  font: inherit; font-weight: 800; font-size: 1.05rem; color: #fff; min-width: 120px; height: 48px; padding: 0 20px;
  background: var(--accent-green); border: 0; border-radius: 999px; cursor: pointer; touch-action: manipulation;
}
.lp-play[aria-pressed="true"] { background: #3a3946; }
.lp-play:disabled { opacity: .4; cursor: not-allowed; }
.lp-posbox { display: flex; flex-direction: column; gap: 4px; min-width: 190px; }
.lp-pos { font-weight: 800; font-variant-numeric: tabular-nums; }
.lp-savestate { color: var(--text-muted); font-size: .75rem; min-height: 1em; }
.lp-beats { display: flex; gap: 6px; }
.lp-beats b { width: 14px; height: 14px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--border); transition: background .05s; }
.lp-beats b:first-child { border-color: var(--text-muted); }
.lp-beats b.on { background: var(--accent-amber); border-color: var(--accent-amber); box-shadow: 0 0 10px var(--accent-amber); }
.lp-beats b:first-child.on { background: #ff3b3b; border-color: #ff3b3b; box-shadow: 0 0 10px #ff3b3b; }
.lp-outs { margin-left: auto; }
.lp-recdot { width: 10px; height: 10px; border-radius: 50%; background: #ff3b3b; }
.lp-take.on { background: #ff3b3b; border-color: #ff3b3b; color: #fff; }
.lp-take.on .lp-recdot { background: #fff; animation: lpBlink2 1s steps(1) infinite; }
@keyframes lpBlink2 { 50% { opacity: 0; } }

/* ---- takes ---- */
.lp-takes { display: block; }
.lp-takerow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.lp-takename { display: flex; flex-direction: column; min-width: 70px; }
.lp-takename small { color: var(--text-muted); }
.lp-takerow audio { height: 36px; flex: 1 1 240px; min-width: 0; }

/* ---- the sound pads ---- */
.lp-pads { display: block; }
.lp-padshead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 12px; }
#lp-keywrap.off { opacity: .35; pointer-events: none; }
.lp-padgrid { --pc: var(--accent-pink); display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; }
.lp-padgrid[data-bank="bass"] { --pc: var(--accent-blue); }
.lp-padgrid[data-bank="chords"] { --pc: var(--accent-green); }
.lp-pad {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  aspect-ratio: 1; min-height: 72px; padding: 6px; cursor: pointer;
  font: inherit; color: var(--text); text-align: center;
  background: linear-gradient(180deg, color-mix(in srgb, var(--pc) 22%, #24232d), color-mix(in srgb, var(--pc) 10%, #17161d));
  border: 1px solid color-mix(in srgb, var(--pc) 45%, var(--border)); border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 4px 10px rgba(0,0,0,.3);
  touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.lp-pad:active { transform: scale(.96); }
.lp-pad.hit { animation: lpHit .22s ease-out; }
@keyframes lpHit { 0% { background: var(--pc); box-shadow: 0 0 22px var(--pc); } 100% { } }
.lp-padname { font-weight: 800; font-size: 1.05rem; line-height: 1.1; }
.lp-pad small { font-size: .7rem; color: var(--text-muted); }
.lp-pad kbd { position: absolute; top: 5px; right: 6px; font: 700 .65rem/1 var(--font); color: var(--text-muted); padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; }

/* ---- help ---- */
.lp-help { display: block; }
.lp-help summary { cursor: pointer; font-weight: 800; font-size: 1rem; }
.lp-help ol { margin: 12px 0; padding-left: 1.4em; color: var(--text-dim); line-height: 1.55; }
.lp-help li { margin-bottom: 6px; }
.lp-help h3 { margin: 16px 0 8px; font-size: .95rem; }
.lp-keys { border-collapse: collapse; font-size: .88rem; color: var(--text-dim); }
.lp-keys td { padding: 5px 14px 5px 0; vertical-align: top; }
.lp-keys td:first-child { white-space: nowrap; }
kbd { font: 700 .78rem/1 var(--font); padding: 2px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-3); color: var(--text); }

/* ---- toast ---- */
.lp-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); opacity: 0; z-index: 50;
  width: max-content; max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 12px;
  background: #f4f4f6; color: #111; font-weight: 700; font-size: .92rem; box-shadow: 0 12px 30px rgba(0,0,0,.45);
  transition: opacity .2s, transform .2s;
}
.lp-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- smaller screens: phones and tablets ---- */
@media (max-width: 900px) {
  .lp-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lp-padgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lp-outs { margin-left: 0; }
}
@media (max-width: 560px) {
  .lp-main { padding: 16px 16px 80px; }
  .lp-main .section-title { font-size: 2rem; }
  .lp-panel { padding: 10px 12px; gap: 8px 12px; }
  .lp-board { gap: 10px; }
  .lp-track { padding: 10px 8px; gap: 6px; }
  .lp-tbtns { gap: 4px; flex-wrap: nowrap; }
  .lp-tb { min-width: 32px; height: 34px; padding: 0 7px; font-size: .78rem; }
  .lp-tredo { display: none; }     /* Redo stays in the transport bar */
  .lp-hint { font-size: .72rem; }
  .lp-st { font-size: .62rem; }
  .lp-field input[type="range"], .lp-bpm input[type="range"] { width: 110px; }
  .lp-posbox { min-width: 0; flex: 1 1 140px; }
  .lp-tip { flex-basis: 100%; }
  .lp-padgrid { gap: 8px; }
  .lp-padname { font-size: .95rem; }
}
@media (hover: none) { .lp-pad kbd { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .lp-track[data-state="count"] .lp-pedal, .lp-track[data-state="armed"] .lp-pedal, .lp-take.on .lp-recdot, .lp-pad.hit { animation: none; }
}
