/* ROUND — minimal pegboard (iPhone 13 mini baseline ~375×812) */

:root {
  --bg: #f4f0e8;
  --bg-sheet: #ebe6dc;
  --charcoal: #2a2a28;
  --charcoal-soft: #3d3d3a;
  --muted: #8a8680;
  --muted-2: #b0aaa2;
  --accent: #d4784a;
  --accent-soft: rgba(212, 120, 74, 0.22);
  --peg-shadow: 0 1px 4px rgba(42, 42, 40, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --cols: 6;
  --rows: 6;
  --board-gap: clamp(4px, 1.4vmin, 10px);
  --transport-h: 36px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--charcoal);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.3;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(4px + var(--safe-top))
    calc(6px + var(--safe-right))
    calc(4px + var(--safe-bottom))
    calc(6px + var(--safe-left));
  overflow: hidden;
}

/* —— Micro transport (single row) —— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
  height: var(--transport-h);
  margin-bottom: 4px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.28em;
  font-size: 10px;
  color: var(--charcoal);
  text-transform: uppercase;
  opacity: 0.55;
  flex-shrink: 0;
}

.transport {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
  min-width: 0;
}

.btn {
  appearance: none;
  border: none;
  background: var(--charcoal);
  color: var(--bg);
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0;
  min-width: 36px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:active { transform: scale(0.94); }

.btn--ghost {
  background: transparent;
  color: var(--charcoal);
  border: 1.5px solid rgba(42, 42, 40, 0.18);
}

.btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn--sm {
  min-width: 32px;
  height: 30px;
  padding: 0 10px;
  font-size: 10px;
}

.btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.btn-icon {
  min-width: 32px;
  width: 32px;
  padding: 0;
  font-size: 14px;
  letter-spacing: 0;
  line-height: 1;
}

.bpm-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(42, 42, 40, 0.05);
  border-radius: 999px;
  padding: 0 6px 0 8px;
  height: 30px;
}

.bpm-wrap label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.bpm-wrap input {
  width: 34px;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  color: var(--charcoal);
  text-align: center;
  -moz-appearance: textfield;
}

.bpm-wrap input::-webkit-outer-spin-button,
.bpm-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.rec-cluster {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}

.btn-rec {
  min-width: 0;
  padding: 0 8px;
  letter-spacing: 0.02em;
}

.btn-rec.is-recording {
  background: #c44;
  color: #fff;
  border-color: transparent;
  animation: rec-pulse 1.1s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

.rec-timer {
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #c44;
  letter-spacing: 0.02em;
  min-width: 28px;
  padding: 0 2px;
}

#btn-take.is-playing-take {
  background: var(--charcoal);
  color: var(--bg);
  border-color: transparent;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

.status-dot.is-live {
  opacity: 1;
  background: #5a9a6a;
  box-shadow: 0 0 5px rgba(90, 154, 106, 0.55);
}

/* —— Ableton Link micro control —— */
.btn-link {
  min-width: 0;
  padding: 0 8px;
  letter-spacing: 0.06em;
  font-size: 9px;
  opacity: 0.55;
  border-color: rgba(42, 42, 40, 0.14);
}

.btn-link.is-on {
  opacity: 1;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 0 1px rgba(212, 120, 74, 0.35);
}

.btn-link.is-connecting {
  opacity: 0.85;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-link.is-error {
  opacity: 0.7;
  border-color: rgba(196, 68, 68, 0.45);
  color: #a44;
}

.btn-link .link-peers {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-left: 3px;
  opacity: 0.9;
}

@media (max-width: 360px) {
  .btn-link .link-peers { display: none; }
}

/* —— Pegboard fills remaining viewport —— */
.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  container-type: size;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--peg));
  grid-template-rows: repeat(var(--rows), var(--peg));
  gap: var(--board-gap);
  place-content: center;
  /* Peg = min of width/cols and height/rows so board fits mini without scroll */
  --peg: min(
    calc((100cqi - (var(--cols) - 1) * var(--board-gap)) / var(--cols)),
    calc((100cqb - (var(--rows) - 1) * var(--board-gap)) / var(--rows))
  );
}

.peg {
  position: relative;
  border: none;
  border-radius: 50%;
  background: #e8e2d6;
  box-shadow: var(--peg-shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.2s ease, opacity 0.18s ease, filter 0.18s ease;
  width: 100%;
  height: 100%;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}

.peg::after {
  content: "";
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.peg:active { transform: scale(0.93); }

.peg.is-on {
  box-shadow: var(--peg-shadow), 0 0 0 2px var(--accent-soft);
}

.peg.is-on::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.peg[data-role="kick"] { background: #3a3a38; }
.peg[data-role="kick"].is-on { background: #2a2a28; }
.peg[data-role="snare"] { background: #9a7a76; }
.peg[data-role="snare"].is-on { background: #856560; }
.peg[data-role="hat"] { background: #c4b89a; }
.peg[data-role="hat"].is-on { background: #b8a878; }
.peg[data-role="rim"] { background: #b0a090; }
.peg[data-role="rim"].is-on { background: #9a8878; }
.peg[data-role="bass"] { background: #5c6b7a; }
.peg[data-role="bass"].is-on { background: #4a5a6a; }
.peg[data-role="growl"] { background: #5a4a55; }
.peg[data-role="growl"].is-on { background: #483840; }
.peg[data-role="click"] { background: #a8b0b8; }
.peg[data-role="click"].is-on { background: #909aa4; }
.peg[data-role="glitch"] { background: #8a9a6a; }
.peg[data-role="glitch"].is-on { background: #728054; }
.peg[data-role="metal"] { background: #7a8a9a; }
.peg[data-role="metal"].is-on { background: #627282; }
.peg[data-role="bell"] { background: #c4a878; }
.peg[data-role="bell"].is-on { background: #b09060; }
.peg[data-role="chirp"] { background: #7a9a9a; }
.peg[data-role="chirp"].is-on { background: #628282; }
.peg[data-role="lead"] { background: #c4896a; }
.peg[data-role="lead"].is-on { background: var(--accent); }

.peg.is-pulse {
  transform: scale(1.07);
  box-shadow: var(--peg-shadow), 0 0 0 3px var(--accent-soft), 0 0 12px rgba(212, 120, 74, 0.32);
}

/* Labels hidden — color encodes role */
.peg-label { display: none; }

/* —— Bottom sheet (all edit complexity) —— */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 42, 40, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 40;
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88dvh, 720px);
  background: var(--bg-sheet);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(42, 42, 40, 0.18);
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  overscroll-behavior: contain;
}

.sheet.is-open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--muted-2);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 18px 10px;
  flex-shrink: 0;
}

.sheet-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px 24px;
  flex: 1;
}

.section { margin-bottom: 18px; }

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg--roles {
  gap: 5px;
}

.seg--roles .seg-btn {
  font-size: 11px;
  padding: 7px 10px;
}

.seg-btn {
  appearance: none;
  border: 1.5px solid rgba(42, 42, 40, 0.15);
  background: transparent;
  color: var(--charcoal-soft);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}

.seg-btn.is-active {
  background: var(--charcoal);
  color: var(--bg);
  border-color: var(--charcoal);
}

.steps {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 4px;
  margin: 10px 0;
}

.step {
  aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: rgba(42, 42, 40, 0.12);
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s, transform 0.1s;
}

.step.is-on { background: var(--accent); }
.step.is-now { box-shadow: 0 0 0 2px var(--charcoal); }
.step:active { transform: scale(0.9); }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.row label {
  flex: 0 0 72px;
  font-size: 12px;
  font-weight: 600;
  color: var(--charcoal-soft);
}

.row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 28px;
}

.row .val {
  flex: 0 0 40px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.regen-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}



/* —— Ghost muted pegs (tap-off), stopped or playing —— */
.peg:not(.is-on),
.peg.is-ghost {
  background: #d8d2c6 !important;
  opacity: 0.55;
  filter: none;
  box-shadow: inset 0 0 0 1.5px rgba(42, 42, 40, 0.16);
}

.peg:not(.is-on)::after,
.peg:not(.is-on)::before,
.peg.is-ghost::after,
.peg.is-ghost::before {
  opacity: 0;
  content: none;
}

.peg.is-on {
  opacity: 1;
  filter: none;
}

/* —— Play-mode visuals: radial sequence dots + greyed inactive —— */
body.is-playing .peg:not(.is-on),
.board.is-playing .peg:not(.is-on) {
  background: #d0cac0 !important;
  opacity: 0.48;
  filter: none;
  box-shadow: inset 0 0 0 1.5px rgba(42, 42, 40, 0.14);
}

body.is-playing .peg:not(.is-on)::after,
body.is-playing .peg:not(.is-on)::before,
.board.is-playing .peg:not(.is-on)::after,
.board.is-playing .peg:not(.is-on)::before {
  opacity: 0;
}

/* Active pegs: soft role tint base; dots carry the pattern */
body.is-playing .peg.is-on,
.board.is-playing .peg.is-on {
  box-shadow: var(--peg-shadow), 0 0 0 1.5px rgba(42, 42, 40, 0.08);
}

body.is-playing .peg.is-on[data-role="kick"],
.board.is-playing .peg.is-on[data-role="kick"] { background: #4a4a46; }
body.is-playing .peg.is-on[data-role="snare"],
.board.is-playing .peg.is-on[data-role="snare"] { background: #a88884; }
body.is-playing .peg.is-on[data-role="hat"],
.board.is-playing .peg.is-on[data-role="hat"] { background: #d0c6ae; }
body.is-playing .peg.is-on[data-role="rim"],
.board.is-playing .peg.is-on[data-role="rim"] { background: #c0b0a0; }
body.is-playing .peg.is-on[data-role="bass"],
.board.is-playing .peg.is-on[data-role="bass"] { background: #6a7886; }
body.is-playing .peg.is-on[data-role="growl"],
.board.is-playing .peg.is-on[data-role="growl"] { background: #6a5864; }
body.is-playing .peg.is-on[data-role="click"],
.board.is-playing .peg.is-on[data-role="click"] { background: #b8c0c8; }
body.is-playing .peg.is-on[data-role="glitch"],
.board.is-playing .peg.is-on[data-role="glitch"] { background: #9aaa7c; }
body.is-playing .peg.is-on[data-role="metal"],
.board.is-playing .peg.is-on[data-role="metal"] { background: #8a9aaa; }
body.is-playing .peg.is-on[data-role="bell"],
.board.is-playing .peg.is-on[data-role="bell"] { background: #d4b888; }
body.is-playing .peg.is-on[data-role="chirp"],
.board.is-playing .peg.is-on[data-role="chirp"] { background: #8aaaaa; }
body.is-playing .peg.is-on[data-role="lead"],
.board.is-playing .peg.is-on[data-role="lead"] { background: #d49a78; }

body.is-playing .peg.is-on::after,
.board.is-playing .peg.is-on::after {
  inset: 28%;
  background: rgba(244, 240, 232, 0.35);
}

.radial {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
}

body.is-playing .peg.is-on .radial,
.board.is-playing .peg.is-on .radial {
  opacity: 1;
  visibility: visible;
}

.radial-spoke {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-transform: rotate(calc(var(--i) * 360deg / var(--n)));
  transform: rotate(calc(var(--i) * 360deg / var(--n)));
}

.radial-dot {
  position: absolute;
  left: 50%;
  top: 14%;
  width: 11%;
  height: 11%;
  min-width: 3px;
  min-height: 3px;
  max-width: 6px;
  max-height: 6px;
  border-radius: 50%;
  background: rgba(42, 42, 40, 0.18);
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  pointer-events: none;
  transition: background 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
  opacity: 0.55;
}

.radial-dot.is-hit {
  background: rgba(42, 42, 40, 0.88);
  opacity: 1;
}

/* Light dots on dark roles (kick / bass / growl / snare) */
body.is-playing .peg.is-on[data-role="kick"] .radial-dot,
body.is-playing .peg.is-on[data-role="bass"] .radial-dot,
body.is-playing .peg.is-on[data-role="growl"] .radial-dot,
body.is-playing .peg.is-on[data-role="snare"] .radial-dot,
.board.is-playing .peg.is-on[data-role="kick"] .radial-dot,
.board.is-playing .peg.is-on[data-role="bass"] .radial-dot,
.board.is-playing .peg.is-on[data-role="growl"] .radial-dot,
.board.is-playing .peg.is-on[data-role="snare"] .radial-dot {
  background: rgba(244, 240, 232, 0.22);
}
body.is-playing .peg.is-on[data-role="kick"] .radial-dot.is-hit,
body.is-playing .peg.is-on[data-role="bass"] .radial-dot.is-hit,
body.is-playing .peg.is-on[data-role="growl"] .radial-dot.is-hit,
body.is-playing .peg.is-on[data-role="snare"] .radial-dot.is-hit,
.board.is-playing .peg.is-on[data-role="kick"] .radial-dot.is-hit,
.board.is-playing .peg.is-on[data-role="bass"] .radial-dot.is-hit,
.board.is-playing .peg.is-on[data-role="growl"] .radial-dot.is-hit,
.board.is-playing .peg.is-on[data-role="snare"] .radial-dot.is-hit {
  background: rgba(244, 240, 232, 0.95);
}

.radial-dot.is-now {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(212, 120, 74, 0.35), 0 0 8px rgba(212, 120, 74, 0.45);
  -webkit-transform: translateX(-50%) scale(1.45);
  transform: translateX(-50%) scale(1.45);
}

body.is-playing .peg.is-on[data-role="kick"] .radial-dot.is-now,
body.is-playing .peg.is-on[data-role="bass"] .radial-dot.is-now,
body.is-playing .peg.is-on[data-role="growl"] .radial-dot.is-now,
body.is-playing .peg.is-on[data-role="snare"] .radial-dot.is-now,
.board.is-playing .peg.is-on[data-role="kick"] .radial-dot.is-now,
.board.is-playing .peg.is-on[data-role="bass"] .radial-dot.is-now,
.board.is-playing .peg.is-on[data-role="growl"] .radial-dot.is-now,
.board.is-playing .peg.is-on[data-role="snare"] .radial-dot.is-now {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35), 0 0 8px rgba(212, 120, 74, 0.5);
}

/* Keep hit pulse subtle so dots stay readable */
body.is-playing .peg.is-pulse,
.board.is-playing .peg.is-pulse {
  transform: scale(1.04);
}


/* —— Preset list (bottom sheet) —— */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-row {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1.5px solid rgba(42, 42, 40, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--charcoal);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.12s, background 0.12s;
}

.preset-row:active {
  transform: scale(0.99);
}

.preset-row.is-active {
  border-color: var(--charcoal);
  background: rgba(42, 42, 40, 0.06);
}

.preset-row.is-active .preset-name::after {
  content: ' ✓';
  font-weight: 700;
}

.preset-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.preset-blurb {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--muted);
}


/* —— Song mode —— */
.song-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--muted);
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
  line-height: 1.2;
}

.btn-song[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.preset-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.preset-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(42, 42, 40, 0.1);
  color: var(--charcoal);
  flex-shrink: 0;
}

.preset-row.is-active .preset-badge {
  background: var(--charcoal);
  color: var(--bg);
}

.preset-hint {
  margin: 14px 2px 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--muted);
}
