/* ══════════════════════════════════════════════════════
   La-Ti-Do — Instrument Styles
   ══════════════════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: #eee8e0;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Instrument Body ── */
.instrument {
  --body-w: 214;
  --body-h: 124.25;
  position: relative;
  width: min(92vw, calc(82vh * 214 / 124.25), 960px);
  aspect-ratio: 214 / 124.25;
  background: linear-gradient(160deg, #e2d7cb 0%, #d9cec2 40%, #d4c8bc 100%);
  border-radius: calc(10 / 214 * 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.45) inset,
    0 -1px 2px rgba(0,0,0,0.04) inset,
    0 4px 12px rgba(80,60,40,0.10),
    0 12px 40px rgba(80,60,40,0.08);
}

/* Subtle surface texture */
.instrument::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: repeating-conic-gradient(rgba(0,0,0,0.012) 0% 25%, transparent 0% 50%) 0 0 / 3px 3px;
  pointer-events: none;
  z-index: 50;
}

/* ── Circles (shared: disc recess + knobs) ── */
.circle {
  position: absolute;
  width: 21.1%;          /* 45.16 / 214 */
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  top: 22.54%;
  z-index: 10;
}

.circle-c1 { left: 13.67%; }
.circle-c2 { left: 37.89%; }
.circle-c3 { left: 62.11%; }
.circle-c4 { left: 86.33%; }

/* ── Knob Recess (outer ring) ── */
.knob-recess {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #bfb3a5 0%, #c8bdb0 50%, #bab0a3 100%);
  box-shadow:
    0 2px 4px rgba(0,0,0,0.08) inset,
    0 -1px 2px rgba(255,255,255,0.15) inset,
    0 1px 3px rgba(0,0,0,0.06);
}

/* ── Knob Cap (inner colored disc) ── */
.knob-cap {
  position: absolute;
  inset: 5.8%;
  border-radius: 50%;
  cursor: grab;
  transition: box-shadow 0.15s ease;
  z-index: 2;
}

.knob-cap:active { cursor: grabbing; }

/* Per-knob colors */
.knob-key .knob-cap {
  background: linear-gradient(145deg, #6fa0cc 0%, #5b8fbf 40%, #4f80b0 100%);
  box-shadow: 0 2px 6px rgba(50,80,120,0.25), 0 1px 0 rgba(255,255,255,0.25) inset;
}

.knob-track .knob-cap {
  background: linear-gradient(145deg, #dfa08e 0%, #d4897c 40%, #c87d70 100%);
  box-shadow: 0 2px 6px rgba(150,80,60,0.25), 0 1px 0 rgba(255,255,255,0.25) inset;
}

.knob-voice .knob-cap {
  background: linear-gradient(145deg, #ddb855 0%, #d4a545 40%, #c89a3a 100%);
  box-shadow: 0 2px 6px rgba(160,120,30,0.25), 0 1px 0 rgba(255,255,255,0.25) inset;
}

/* Knob indicator notch */
.knob-indicator {
  position: absolute;
  top: 10%;
  left: 50%;
  width: 3px;
  height: 18%;
  background: rgba(255,255,255,0.55);
  border-radius: 2px;
  transform: translateX(-50%);
  pointer-events: none;
  box-shadow: 0 0 2px rgba(0,0,0,0.1);
}

/* ── Disc Recess ── */
.disc-recess-inner {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #a29588 0%, #ab9f93 60%, #a69a8e 100%);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.15) inset,
    0 -1px 2px rgba(255,255,255,0.08) inset,
    0 1px 3px rgba(0,0,0,0.06);
}

/* LED Ring */
.led-dot {
  position: absolute;
  width: 5.5%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #9e9488;
  transform: translate(-50%, -50%);
  z-index: 3;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.led-dot.active {
  background: #e8a840;
  box-shadow: 0 0 6px 2px rgba(232,168,64,0.5);
}

.led-dot.ambient {
  animation: ambientPulse 3.5s ease-in-out infinite;
}

@keyframes ambientPulse {
  0%, 100% { background: #c4a060; box-shadow: 0 0 3px 1px rgba(200,160,60,0.15); }
  50% { background: #e0b050; box-shadow: 0 0 5px 2px rgba(232,168,64,0.3); }
}

/* Stagger ambient animation per dot */
.led-dot.ambient:nth-child(1)  { animation-delay: 0s; }
.led-dot.ambient:nth-child(2)  { animation-delay: 0.29s; }
.led-dot.ambient:nth-child(3)  { animation-delay: 0.58s; }
.led-dot.ambient:nth-child(4)  { animation-delay: 0.87s; }
.led-dot.ambient:nth-child(5)  { animation-delay: 1.16s; }
.led-dot.ambient:nth-child(6)  { animation-delay: 1.45s; }
.led-dot.ambient:nth-child(7)  { animation-delay: 1.74s; }
.led-dot.ambient:nth-child(8)  { animation-delay: 2.03s; }
.led-dot.ambient:nth-child(9)  { animation-delay: 2.32s; }
.led-dot.ambient:nth-child(10) { animation-delay: 2.61s; }
.led-dot.ambient:nth-child(11) { animation-delay: 2.9s; }
.led-dot.ambient:nth-child(12) { animation-delay: 3.19s; }

/* ── Pads ── */
.pad-row {
  position: absolute;
  left: 2.34%;
  right: 2.34%;
  top: 50.5%;
  bottom: 7.2%;
  display: flex;
  gap: 1.87%;
  z-index: 10;
}

.pad {
  flex: 1;
  border-radius: 999px;
  background: linear-gradient(180deg, #c9bcae 0%, #bfb2a4 50%, #b9ab9d 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.3) inset,
    0 -1px 2px rgba(0,0,0,0.04) inset,
    0 2px 4px rgba(80,60,40,0.06);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease;
  position: relative;
  overflow: hidden;
}

.pad::before {
  content: '';
  position: absolute;
  top: 0; left: 10%; right: 10%;
  height: 40%;
  background: radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.15), transparent 70%);
  border-radius: 999px;
  pointer-events: none;
}

.pad.pressed {
  transform: scale(0.96);
  background: linear-gradient(180deg, #b8ab9d 0%, #aea193 50%, #a89a8c 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1) inset, 0 0px 1px rgba(0,0,0,0.05);
}

.pad.pressed::before { opacity: 0; }

/* Pad tray background */
.pad-tray {
  position: absolute;
  left: 1.4%;
  right: 1.4%;
  top: 49%;
  bottom: 5.5%;
  border-radius: calc(6 / 214 * 100%);
  background: linear-gradient(180deg, #b8ab9d 0%, #c0b4a7 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.06) inset;
  z-index: 5;
}

/* ── Pogo Pins ── */
.pogo-pin {
  position: absolute;
  bottom: 1.8%;
  width: 1.6%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(145deg, #d0c5b8, #bab0a3);
  box-shadow: 0 0.5px 0 rgba(255,255,255,0.3) inset, 0 1px 2px rgba(0,0,0,0.08);
  transform: translateX(-50%);
  z-index: 12;
}

/* Pogo pins are children 7-11 of .instrument
   (after pad-tray, disc-recess, 3 knobs, pad-row) */
.pogo-pin:nth-child(7)  { left: 30%; }
.pogo-pin:nth-child(8)  { left: 40%; }
.pogo-pin:nth-child(9)  { left: 50%; }
.pogo-pin:nth-child(10) { left: 60%; }
.pogo-pin:nth-child(11) { left: 70%; }

/* ── Status Label ── */
.status-label {
  position: absolute;
  padding: 4px 12px;
  background: rgba(58,53,48,0.82);
  color: #f0ebe5;
  font-size: clamp(9px, 1.4vw, 13px);
  font-weight: 400;
  letter-spacing: 0.5px;
  border-radius: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.status-label.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ── Branding ── */
.brand {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: #b0a698;
  pointer-events: none;
}

/* ── Audio Init Overlay ── */
.audio-init-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(238,232,224,0.6);
  z-index: 1000;
  cursor: pointer;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity 0.4s ease;
}

.audio-init-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.audio-init-label {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: clamp(14px, 2.5vw, 20px);
  font-weight: 300;
  letter-spacing: 1.5px;
  color: #8a7e72;
  text-transform: uppercase;
  animation: initPulse 2s ease-in-out infinite;
}

@keyframes initPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ── Mobile Adjustments ── */
@media (max-height: 500px) and (orientation: landscape) {
  /* Cap at 78vh height equivalent so the instrument doesn't bleed off-screen.
     78vh * aspect = ~134vw — clamped by the vw term. Leaves ~22vh breathing room. */
  .instrument { width: min(92vw, calc(78vh * 214 / 124.25)); }
  .brand { display: none; }
}

@media (max-width: 480px) and (orientation: portrait) {
  body { align-items: flex-start; padding-top: 15vh; }
  .instrument { width: 96vw; }
}


/* ══════════════════════════════════════════════════════
   Debug Panel Styles
   ══════════════════════════════════════════════════════ */

#debug-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 420px;
  max-width: 100vw;
  height: 100vh;
  background: rgba(18, 18, 22, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #c8c8cc;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.5;
  z-index: 10000;
  transition: right 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}

#debug-panel.visible {
  right: 0;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(30, 30, 36, 0.9);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.debug-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #e8a840;
}

.debug-actions {
  display: flex;
  gap: 8px;
}

.debug-actions button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: #aaa;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.debug-actions button:hover {
  background: rgba(255,255,255,0.15);
  color: #ddd;
}

.debug-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.debug-content::-webkit-scrollbar { width: 6px; }
.debug-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.debug-section { margin-bottom: 4px; }

.debug-section-label {
  color: #666;
  font-size: 10px;
  letter-spacing: 1px;
  margin: 10px 0 4px;
  text-transform: uppercase;
}

.debug-line {
  padding: 1px 0;
  word-break: break-all;
}

.debug-line.ok, .debug-line .ok {
  color: #5fba5f;
}

.debug-line.fail, .debug-line .fail {
  color: #e85050;
}

.debug-line.warn {
  color: #e8a840;
}

.debug-line.selftest {
  color: #6fa0cc;
}

.debug-ts {
  color: #555;
  margin-right: 6px;
}

.debug-log {
  margin-top: 4px;
}

/* ══════════════════════════════════════════════════════
   Phase 2: Disc, Drum, Mode Styles
   ══════════════════════════════════════════════════════ */

/* ── Disc Loaded State ── */
.disc-recess-inner.disc-loaded {
  /* Fallback for browsers without color-mix */
  background: linear-gradient(180deg, #a29588 0%, #ab9f93 60%, #a69a8e 100%);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.15) inset,
    0 -1px 2px rgba(255,255,255,0.08) inset;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}

/* Modern browsers: blend disc series color into the recess */
@supports (background: color-mix(in srgb, red 50%, blue)) {
  .disc-recess-inner.disc-loaded {
    background: linear-gradient(
      180deg,
      color-mix(in srgb, var(--disc-bg, #888) 30%, #a29588) 0%,
      color-mix(in srgb, var(--disc-bg, #888) 50%, #ab9f93) 60%,
      color-mix(in srgb, var(--disc-bg, #888) 35%, #a69a8e) 100%
    );
    box-shadow:
      0 3px 8px rgba(0,0,0,0.15) inset,
      0 -1px 2px rgba(255,255,255,0.08) inset,
      0 0 12px color-mix(in srgb, var(--disc-bg, #888) 30%, transparent);
  }
}

/* Disc name label inside recess */
.disc-name {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: clamp(5px, 0.9vw, 9px);
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  letter-spacing: 0.3px;
}

/* ── LED Disc Color Animation ── */
.led-dot.disc-color {
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.led-dot.disc-ambient {
  animation: discPulse 3.5s ease-in-out infinite;
}

@keyframes discPulse {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* ── Beat Pulse ── */
.led-dot.beat-pulse {
  transition: box-shadow 0.06s ease;
}

/* ── Drum Hit Visual Feedback on Knob Cap ── */
.knob-cap.drum-hit {
  transform: scale(0.94) !important;
  transition: transform 0.06s ease !important;
}

/* ── Mode Toggle Controls ── */
.mode-controls {
  position: fixed;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 100;
}

.mode-btn {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.5px;
  padding: 5px 10px;
  border: 1px solid rgba(160,150,140,0.3);
  border-radius: 12px;
  background: rgba(226,215,203,0.7);
  color: #7a7068;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
}

.mode-btn:hover {
  background: rgba(210,200,188,0.9);
  color: #5a5248;
}

.mode-btn:active {
  transform: scale(0.96);
}

/* ── Disc Shelf ── */
.disc-shelf {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 10px 16px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.disc-thumb {
  width: clamp(44px, 8vw, 60px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 35%,
    color-mix(in srgb, var(--disc-color, #888) 60%, white) 0%,
    var(--disc-color, #888) 50%,
    color-mix(in srgb, var(--disc-color, #888) 70%, black) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow:
    0 2px 6px rgba(0,0,0,0.12),
    0 0 0 2px rgba(255,255,255,0.15) inset;
  position: relative;
}

/* Fallback for no color-mix support */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .disc-thumb {
    background: var(--disc-color, #888);
  }
}

.disc-thumb:hover {
  transform: scale(1.08);
  box-shadow:
    0 4px 12px rgba(0,0,0,0.18),
    0 0 0 2px rgba(255,255,255,0.2) inset;
}

.disc-thumb:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.disc-thumb.dragging {
  opacity: 0.3;
  transform: scale(0.9);
}

.disc-thumb.active {
  box-shadow:
    0 0 0 2.5px rgba(255,255,255,0.6),
    0 2px 8px rgba(0,0,0,0.2);
  transform: scale(0.92);
  opacity: 0.6;
}

/* Eject / Free Play disc in shelf */
.disc-thumb.disc-eject {
  background: none;
  border: 2px dashed rgba(176,166,152,0.5);
  box-shadow: none;
}

.disc-thumb.disc-eject:hover {
  border-color: rgba(176,166,152,0.8);
  background: rgba(176,166,152,0.1);
}

.disc-thumb.disc-eject .disc-thumb-label {
  color: rgba(176,166,152,0.8);
  text-shadow: none;
}

.disc-thumb-label {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: clamp(5px, 1vw, 8px);
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  line-height: 1.15;
  padding: 2px;
  pointer-events: none;
  letter-spacing: 0.2px;
}

/* ── Disc Ghost (follows pointer during drag) ── */
.disc-ghost {
  position: fixed;
  width: clamp(44px, 8vw, 60px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 35%,
    color-mix(in srgb, var(--disc-color, #888) 60%, white) 0%,
    var(--disc-color, #888) 50%,
    color-mix(in srgb, var(--disc-color, #888) 70%, black) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5000;
  transform: translate(-50%, -50%) scale(1.15);
  opacity: 0;
  transition: opacity 0.12s ease;
  box-shadow:
    0 8px 24px rgba(0,0,0,0.25),
    0 0 0 2px rgba(255,255,255,0.2) inset;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: clamp(5px, 1vw, 8px);
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .disc-ghost {
    background: var(--disc-color, #888);
  }
}

.disc-ghost.visible {
  opacity: 0.9;
}

/* ── Disc Recess Drop Target States ── */
.circle-c1.drop-target .disc-recess-inner {
  box-shadow:
    0 3px 8px rgba(0,0,0,0.15) inset,
    0 -1px 2px rgba(255,255,255,0.08) inset,
    0 0 12px rgba(232,168,64,0.3);
  transition: box-shadow 0.2s ease;
}

.circle-c1.drop-hover .disc-recess-inner {
  box-shadow:
    0 3px 8px rgba(0,0,0,0.15) inset,
    0 -1px 2px rgba(255,255,255,0.08) inset,
    0 0 20px rgba(232,168,64,0.5);
  transform: scale(1.04);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.mode-btn.mode-discovery {
  border-color: rgba(221,184,85,0.4);
  color: #b09030;
}

.mode-btn.mode-player {
  border-color: rgba(91,143,191,0.4);
  color: #5b8fbf;
}

/* Mobile: bottom panel instead of side panel */
@media (max-width: 600px) {
  #debug-panel {
    top: auto;
    bottom: -55vh;
    right: 0;
    left: 0;
    width: 100vw;
    height: 55vh;
    transition: bottom 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }

  #debug-panel.visible {
    bottom: 0;
  }
}
