/* ==========================================================================
   Beat Lab — BL-707 Rhythm Composer
   Matte-black hardware aesthetic: silkscreen labels, LED pads, orange playhead.
   No external fonts or images — system stacks + CSS/canvas texture only.
   ========================================================================== */

:root {
  --bg: #08080a;
  --chassis: #141417;
  --chassis-edge: #1f1f24;
  --panel: #101013;
  --inset: #0b0b0d;
  --line: #26262c;
  --line-soft: #1c1c21;

  --silk: #cfcabd;          /* silkscreen ink */
  --silk-dim: #85817a;
  --silk-faint: #57544f;

  --orange: #ff6a2b;        /* playhead + transport */
  --orange-hot: #ffa25e;
  --led: #ffb15e;           /* armed pad LED */
  --led-deep: #ff7a2e;
  --red: #ff4d4d;           /* accent row LED */
  --red-deep: #d92e2e;

  --radius: 8px;
  --radius-sm: 6px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 700px at 50% -10%, #131318 0%, var(--bg) 60%),
    var(--bg);
  color: var(--silk);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 14px;
  overflow-x: hidden;
}

/* ---------- Atmosphere overlays ---------- */

.grain {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background-repeat: repeat; /* image painted by app.js from a canvas */
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 39;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(0, 0, 0, 0.5) 100%);
}

/* ---------- Chassis ---------- */

.unit {
  position: relative;
  width: 100%;
  max-width: 1060px;
  background: linear-gradient(178deg, var(--chassis-edge) 0%, var(--chassis) 8%, #101014 100%);
  border: 1px solid #2c2c33;
  border-radius: 16px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 30px 80px rgba(0, 0, 0, 0.65),
    0 4px 16px rgba(0, 0, 0, 0.5);
  padding: 26px 28px 22px;
}

.screw {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a4a52, #17171b 70%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.8), 0 0 0 1px #0a0a0c inset;
}
.screw::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 5px;
  height: 1.5px;
  background: #0c0c0f;
  transform: rotate(38deg);
}
.screw-tl { top: 10px; left: 10px; }
.screw-tr { top: 10px; right: 10px; }
.screw-bl { bottom: 10px; left: 10px; }
.screw-br { bottom: 10px; right: 10px; transform: rotate(72deg); }

/* ---------- Silkscreen type ---------- */

.silk {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--silk-dim);
  user-select: none;
}

/* ---------- Top panel ---------- */

.panel-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px 28px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-name {
  font-size: clamp(30px, 5vw, 44px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: #eae6db;
}
.brand-accent { color: var(--orange); }

.brand-sub {
  margin-top: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--silk-faint);
}

/* Transport cluster */

.transport {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font: 700 13px/1 var(--font);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #111;
  background: linear-gradient(180deg, var(--orange-hot), var(--orange));
  border: 1px solid #b4441a;
  border-radius: var(--radius);
  padding: 13px 20px;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 4px 14px rgba(255, 106, 43, 0.35);
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn-play:hover { filter: brightness(1.07); }
.btn-play:active { transform: translateY(1px); }
.btn-play[aria-pressed="true"] {
  background: linear-gradient(180deg, #2c2c31, #202024);
  color: var(--orange-hot);
  border-color: #3a3a41;
  box-shadow: 0 0 0 1px rgba(255, 122, 46, 0.35), 0 0 18px rgba(255, 106, 43, 0.25);
}
.play-icon { font-size: 11px; line-height: 1; }

.knob {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 118px;
}

.knob-val {
  font: 600 12px/1 var(--mono);
  color: var(--orange-hot);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 7px;
  align-self: flex-start;
  min-width: 46px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6) inset;
}

/* Range inputs — machined slider look */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 118px;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(180deg, #0a0a0c, #17171b);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 3px rgba(0, 0, 0, 0.7) inset;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fdc79a, var(--orange) 62%);
  border: 1px solid #96370f;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}
input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: #101014;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.7) inset;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fdc79a, var(--orange) 62%);
  border: 1px solid #96370f;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}

/* Pattern bar */

.pattern-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg-btn {
  font: 700 12px/1 var(--font);
  color: var(--silk-dim);
  background: transparent;
  border: 0;
  padding: 9px 15px;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { color: var(--silk); }
.seg-btn.is-on {
  color: #111;
  background: linear-gradient(180deg, var(--orange-hot), var(--orange));
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-small {
  font: 600 11px/1 var(--font);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--silk);
  background: linear-gradient(180deg, #232328, #1a1a1e);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, transform 0.08s ease;
}
.btn-small:hover { border-color: #3d3d45; color: #fff; }
.btn-small:active { transform: translateY(1px); }
.btn-danger:hover { border-color: var(--red-deep); color: var(--red); }

.btn-help {
  font: 700 13px/1 var(--mono);
  color: var(--silk-dim);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.btn-help:hover, .btn-help[aria-expanded="true"] { color: var(--orange-hot); border-color: #4a3527; }

/* ---------- Sequencer ---------- */

.panel-seq { padding: 20px 0 6px; }

.seq-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
  /* soft edge fade hints that the grid scrolls on small screens */
  scrollbar-color: #33333b var(--inset);
}

.seq { min-width: 640px; }

.led-row, .row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row { margin-top: 7px; }

.cells {
  flex: 1;
  display: flex;
  gap: 5px;
}

/* group breathing room after every 4 steps */
.cells > :nth-child(4n + 1):not(:first-child) { margin-left: 9px; }

/* Track strip (left column) */

.strip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 190px;
  flex: none;
}
.strip-spacer { height: 1px; }

.trig {
  width: 34px;
  height: 34px;
  flex: none;
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.05em;
  color: var(--silk-dim);
  background: linear-gradient(180deg, #202025, #17171b);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}
.trig:hover { color: var(--silk); border-color: #3d3d45; }
.trig.hit {
  color: #111;
  background: linear-gradient(180deg, var(--orange-hot), var(--led-deep));
  box-shadow: 0 0 12px rgba(255, 138, 58, 0.6);
}

.track-name {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--silk-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.mute {
  width: 24px;
  height: 24px;
  flex: none;
  font: 700 10px/1 var(--font);
  color: var(--silk-faint);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  transition: color 0.1s ease, background 0.1s ease, box-shadow 0.1s ease;
}
.mute:hover { color: var(--silk); }
.mute[aria-pressed="true"] {
  color: #111;
  background: linear-gradient(180deg, #ffd08a, #f0a03c);
  box-shadow: 0 0 9px rgba(240, 160, 60, 0.5);
}

.vol { width: 62px; flex: none; }
.vol::-webkit-slider-thumb { width: 12px; height: 12px; margin-top: -4px; }
.vol::-moz-range-thumb { width: 11px; height: 11px; }

/* Pads */

.pad {
  flex: 1;
  height: 36px;
  min-width: 22px;
  border: 1px solid #2c2c32;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #232327, #1a1a1e);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 2px 3px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  padding: 0;
  transition: box-shadow 0.1s ease, background 0.1s ease, filter 0.1s ease;
}
.pad:hover { border-color: #43434c; }

.pad.on {
  background: radial-gradient(circle at 50% 32%, #ffd2a1, var(--led) 42%, var(--led-deep) 100%);
  border-color: #b4581e;
  box-shadow:
    0 0 12px rgba(255, 138, 58, 0.5),
    0 0 3px rgba(255, 177, 94, 0.8),
    0 1px 0 rgba(255, 255, 255, 0.35) inset;
}

/* Orange playhead sweep */
.pad.play { box-shadow: inset 0 0 0 2px var(--orange), 0 2px 3px rgba(0, 0, 0, 0.45); }
.pad.on.play {
  filter: brightness(1.3);
  box-shadow:
    inset 0 0 0 2px #fff3e6,
    0 0 18px rgba(255, 138, 58, 0.85),
    0 0 4px rgba(255, 200, 140, 0.9);
}

/* Muted rows dim their armed LEDs */
.row.muted .pad.on { filter: saturate(0.15) brightness(0.55); }
.row.muted .track-name { color: var(--silk-faint); }

/* Accent row — red LEDs, slimmer pads */

.row-accent { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-soft); }
.row-accent .pad { height: 22px; border-radius: 5px; }
.row-accent .pad.on {
  background: radial-gradient(circle at 50% 32%, #ffb3b3, var(--red) 45%, var(--red-deep) 100%);
  border-color: #a32222;
  box-shadow: 0 0 11px rgba(255, 77, 77, 0.5), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
}
.row-accent .pad.on.play {
  filter: brightness(1.25);
  box-shadow: inset 0 0 0 2px #ffe9e9, 0 0 16px rgba(255, 77, 77, 0.8);
}
.accent-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--red);
  opacity: 0.85;
  user-select: none;
}

/* Step LEDs + beat numbers */

.sled {
  flex: 1;
  min-width: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-bottom: 4px;
}
.sled .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--inset);
  border: 1px solid var(--line);
  transition: background 0.08s ease, box-shadow 0.08s ease;
}
.sled.play .dot {
  background: var(--orange);
  border-color: var(--orange-hot);
  box-shadow: 0 0 9px rgba(255, 106, 43, 0.9);
}
.sled .num {
  font: 600 9px/1 var(--mono);
  color: var(--silk-faint);
  height: 9px;
}

/* ---------- Library panel ---------- */

.panel-lib {
  margin-top: 14px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.lib-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lib-divider { width: 1px; height: 22px; background: var(--line); }

#pat-name, #pat-select {
  font: 500 13px/1.2 var(--font);
  color: var(--silk);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-width: 0;
}
#pat-name { width: 150px; }
#pat-name::placeholder { color: var(--silk-faint); }
#pat-name.err { border-color: var(--red-deep); animation: shake 0.25s ease; }
#pat-select { width: 190px; cursor: pointer; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
}

.lib-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.lib-status {
  font-size: 11.5px;
  color: var(--orange-hot);
  min-height: 1em;
  transition: opacity 0.4s ease;
}
.lib-status.off { opacity: 0; }
.hints {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--silk-faint);
}

/* ---------- Help overlay ---------- */

.help[hidden] { display: none; }

.help {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 5, 7, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.help-card {
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #1b1b20, #141417);
  border: 1px solid #303038;
  border-radius: 12px;
  padding: 26px 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
}
.help-card h2 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #eae6db;
  margin-bottom: 14px;
}
.help-card ul { list-style: none; }
.help-card li {
  font-size: 13.5px;
  line-height: 1.55;
  color: #b9b4a9;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}
.help-card li:last-of-type { border-bottom: 0; }
.help-card b { color: var(--silk); font-weight: 600; }
.help-card kbd {
  font: 600 11px/1 var(--mono);
  color: var(--orange-hot);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
}
.help-card .btn-small { margin-top: 16px; }

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 70;
  text-align: center;
  padding: 14px;
  background: var(--red-deep);
  color: #fff;
  font-weight: 600;
}

/* ---------- Focus + motion ---------- */

:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .unit { padding: 20px 18px 18px; }
  .panel-top { align-items: flex-start; }
}

@media (max-width: 640px) {
  body { padding: 14px 8px; }
  .unit { padding: 18px 14px 16px; border-radius: 12px; }
  .strip { width: 150px; }
  .track-name { font-size: 10px; }
  .vol { width: 46px; }
  .pad { height: 32px; }
  .knob { min-width: 100px; }
  input[type="range"] { width: 100px; }
  #pat-name { width: 120px; }
  #pat-select { width: 140px; }
}

@media (max-width: 420px) {
  .brand-name { font-size: 28px; }
  .transport { gap: 12px; }
  .btn-play { padding: 12px 16px; }
}
