:root {
  --bg-dark: #0b0d12;
  --panel-bg: #141821;
  --panel-border: #252b3b;
  --text-main: #f3f5f9;
  --text-muted: #8b95ab;
  --purple-arm: #c084fc;
  --red-rec: #ff2e4c;
  --green-play: #00e676;
  --amber-dub: #ffab00;
  --blue-stop: #38bdf8;
  --idle-ring: #2a3142;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
  touch-action: manipulation;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px 20px;
  gap: 12px;
}

/* Header */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--red-rec);
}

.brand h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
}

.mode-pills {
  display: flex;
  background: #0d1017;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  gap: 4px;
}

.mode-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-pill.active {
  background: #232a3b;
  color: var(--text-main);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.status-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.arm-pill {
  background: #1c2233;
  color: var(--text-muted);
  border: 1px solid #2e3852;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.arm-pill.active {
  background: rgba(192, 132, 252, 0.18);
  color: #e9d5ff;
  border-color: var(--purple-arm);
  box-shadow: 0 0 12px rgba(192, 132, 252, 0.25);
}

.pair-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #0d1017;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
}

.room-code-input {
  width: 60px;
  background: #1a2030;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.08em;
  user-select: text;
  -webkit-user-select: text;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.status-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555e70;
}

.status-dot.online::before {
  background: var(--green-play);
  box-shadow: 0 0 8px var(--green-play);
}

/* Workspace Layout */
.workspace-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.workspace-grid.deck-view {
  grid-template-columns: 1.05fr 1.15fr;
  align-items: start;
}

.deck-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.workspace-grid.deck-view .deck-panel {
  display: flex;
}

.deck-section {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.deck-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1f2536;
  padding-bottom: 8px;
}

.deck-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.deck-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(192, 132, 252, 0.16);
  color: #d8b4fe;
}

/* Quick Slot Selector Bar (Loop 1 .. Loop 4) */
.quick-slot-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.slot-tab {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.slot-tab.has-audio {
  border-color: rgba(0, 230, 118, 0.45);
}

.slot-tab.active {
  background: #1e2638;
  border-color: var(--blue-stop);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.slot-tab-name {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.slot-tab-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Interactive Waveform Cropper */
.waveform-editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#waveformCanvas {
  width: 100%;
  height: 136px;
  background: #090b10;
  border: 1px solid #263044;
  border-radius: 10px;
  cursor: ew-resize;
  touch-action: none;
}

.waveform-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.waveform-legend strong {
  color: var(--text-main);
}

.nudge-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #0d1017;
  border: 1px solid #1e2536;
  border-radius: 10px;
  padding: 8px 10px;
}

.nudge-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nudge-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 2px;
}

.accent-mini-btn {
  background: rgba(56, 189, 248, 0.18) !important;
  border-color: #38bdf8 !important;
  color: #bae6fd !important;
  font-weight: 700;
}

.quantize-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 4px;
}

.quantize-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.bpm-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bpm-input {
  width: 62px;
  background: #0d1017;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field select,
.field input[type='range'] {
  width: 100%;
  background: #0d1017;
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.83rem;
}

.mini-btn {
  background: #222b3f;
  color: var(--text-main);
  border: 1px solid #364463;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.mini-btn:hover {
  background: #2d3852;
}

.hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.checkbox-field label {
  justify-content: flex-start;
  gap: 8px;
  cursor: pointer;
}

/* Main Pedal Stage */
.pedal-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.init-banner {
  background: rgba(11, 13, 18, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid #2e374f;
  border-radius: 18px;
  padding: 16px;
  text-align: center;
}

.init-banner.hidden {
  display: none;
}

.init-card h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

.init-card p {
  margin: 0 auto 14px;
  max-width: 540px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.banner-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-cta {
  background: linear-gradient(135deg, #ff2e4c, #d91b38);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 46, 76, 0.35);
}

.secondary-cta {
  background: #1f2637;
  color: var(--text-main);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* Stomp Pad */
.stomp-pad {
  flex: 1;
  min-height: 350px;
  background: radial-gradient(circle at center, #1b2130 0%, #11151f 100%);
  border: 3px solid var(--panel-border);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: pointer;
  color: var(--text-main);
  transition: transform 0.06s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.stomp-pad:active,
.stomp-pad.pressed {
  transform: scale(0.988);
}

@keyframes armedPulse {
  0%,
  100% {
    box-shadow: 0 0 24px rgba(192, 132, 252, 0.25), inset 0 0 20px rgba(192, 132, 252, 0.12);
  }
  50% {
    box-shadow: 0 0 46px rgba(192, 132, 252, 0.55), inset 0 0 38px rgba(192, 132, 252, 0.28);
  }
}

.stomp-pad.state-armed {
  border-color: var(--purple-arm);
  animation: armedPulse 1.1s infinite ease-in-out;
}

.stomp-pad.state-recording {
  border-color: var(--red-rec);
  box-shadow: 0 0 36px rgba(255, 46, 76, 0.28), inset 0 0 32px rgba(255, 46, 76, 0.12);
}

.stomp-pad.state-playing {
  border-color: var(--green-play);
  box-shadow: 0 0 36px rgba(0, 230, 118, 0.24), inset 0 0 32px rgba(0, 230, 118, 0.1);
}

.stomp-pad.state-overdubbing {
  border-color: var(--amber-dub);
  box-shadow: 0 0 40px rgba(255, 171, 0, 0.3), inset 0 0 34px rgba(255, 171, 0, 0.14);
}

.stomp-pad.state-stopped {
  border-color: var(--blue-stop);
}

/* Circular LED Ring */
.ring-container {
  position: relative;
  width: 240px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loop-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  stroke: #1f2637;
}

.ring-progress {
  stroke: var(--idle-ring);
  stroke-linecap: round;
  transition: stroke 0.12s ease;
}

.state-armed .ring-progress {
  stroke: var(--purple-arm);
}

.state-recording .ring-progress {
  stroke: var(--red-rec);
}

.state-playing .ring-progress {
  stroke: var(--green-play);
}

.state-overdubbing .ring-progress {
  stroke: var(--amber-dub);
}

.state-stopped .ring-progress {
  stroke: var(--blue-stop);
}

.ring-center-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
}

.state-label {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 999px;
  background: #232b3e;
}

.state-armed .state-label {
  background: rgba(192, 132, 252, 0.24);
  color: #e9d5ff;
}

.state-recording .state-label {
  background: rgba(255, 46, 76, 0.22);
  color: #ff6b81;
}

.state-playing .state-label {
  background: rgba(0, 230, 118, 0.2);
  color: #4ade80;
}

.state-overdubbing .state-label {
  background: rgba(255, 171, 0, 0.22);
  color: #fbbf24;
}

.state-stopped .state-label {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
}

.time-readout {
  font-size: 2.45rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.layer-readout {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.stomp-Callout {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.next-action {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
}

.sub-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  text-align: center;
}

/* Meters */
.meter-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 14px;
}

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

.meter-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  min-width: 105px;
}

.meter-bar-bg {
  position: relative;
  flex: 1;
  height: 12px;
  background: #0b0d12;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid #22293a;
}

.meter-bar-fill {
  height: 100%;
  width: 0%;
  transition: width 0.04s linear;
}

.input-fill {
  background: linear-gradient(90deg, #00e676, #ffab00, #ff2e4c);
}

.loop-fill {
  background: linear-gradient(90deg, #38bdf8, #00e676);
}

.threshold-marker {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 3px;
  background: #ffffff;
  box-shadow: 0 0 6px var(--purple-arm);
  left: 18%;
  pointer-events: none;
  z-index: 2;
}

/* Dedicated Bottom Footswitches */
.aux-switches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.aux-btn {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 16px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.06s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.aux-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.aux-btn:not(:disabled):active {
  transform: scale(0.97);
}

.stop-btn:not(:disabled):hover {
  border-color: var(--blue-stop);
}

.undo-btn:not(:disabled):hover {
  border-color: var(--amber-dub);
}

.clear-btn:not(:disabled):hover {
  border-color: var(--red-rec);
}

.aux-title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.aux-key {
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (max-width: 880px) {
  .workspace-grid.deck-view {
    grid-template-columns: 1fr;
  }
  .meter-strip {
    grid-template-columns: 1fr;
  }
  .ring-container {
    width: 215px;
    height: 215px;
  }
  .stomp-pad {
    min-height: 295px;
  }
}
