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

:root {
  --bg:         #08080a;
  --bg-glass:   rgba(8, 8, 10, 0.8);
  --border:     rgba(255,255,255,0.08);
  --border-hi:  rgba(255,255,255,0.18);
  --text:       #f4f4f5;
  --text-muted: #71717a;
  --accent:     #ffffff;
  --danger:     #ef4444;
  --panel:      rgba(18, 18, 22, 0.9);

  font-family: 'Outfit', sans-serif;
  -webkit-font-smoothing: antialiased;
}

html, body { height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }

/* ─── APP SHELL ───────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; position: relative; }

/* ─── HEADER ──────────────────────────────────────────────────────── */
#header {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 28px;
  background: linear-gradient(to bottom, rgba(8,8,10,0.95) 0%, transparent 100%);
  pointer-events: none; z-index: 100;
}
.header-left, .header-right { pointer-events: auto; }
.header-right { display: flex; gap: 12px; }

.logo {
  font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em;
  color: var(--text); opacity: 0.9;
}

.icon-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--text-muted); width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); transition: all 0.2s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--border-hi); color: var(--text); }

/* ─── MAIN LAYOUT ─────────────────────────────────────────────────── */
#main-layout { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ─── SIDEBAR ─────────────────────────────────────────────────────── */
#sidebar {
  position: absolute; right: 20px; top: 72px; bottom: 20px; width: 280px;
  background: var(--panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 16px;
  overflow-y: auto; display: flex; flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
  padding: 16px; z-index: 90;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.04);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#sidebar.closed { transform: translateX(320px); opacity: 0; pointer-events: none; }

.sidebar-section { margin-bottom: 20px; }

.section-title {
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px;
}

/* ─── PLAY BUTTON ─────────────────────────────────────────────────── */
.play-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-bottom: 16px;
  background: var(--text); color: var(--bg); border: none;
  padding: 12px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 0.9rem; font-weight: 700;
  transition: opacity 0.15s, transform 0.15s;
  letter-spacing: 0.02em;
}
.play-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.play-btn:active { transform: translateY(0); }
.play-btn.playing { background: var(--danger); color: white; }

/* ─── FORM CONTROLS ───────────────────────────────────────────────── */
.control-row {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.control-row label { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); }
.control-row input[type=number] {
  background: rgba(0,0,0,0.4); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 8px; width: 68px;
  font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; text-align: right;
}
.control-row input[type=number]:focus { outline: none; border-color: var(--border-hi); }

.control-row input[type=checkbox] {
  width: 14px; height: 14px; accent-color: var(--text); cursor: pointer;
}

input[type=range] {
  -webkit-appearance: none; height: 3px; border-radius: 2px;
  outline: none; cursor: pointer; width: 130px;
  background: rgba(255,255,255,0.08);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px;
  border-radius: 50%; background: var(--text);
  cursor: pointer; transition: transform 0.12s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.25); }
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.1); }

select {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 7px 10px;
  font-family: inherit; font-size: 0.82rem; cursor: pointer;
}
select:focus { outline: none; border-color: var(--border-hi); }

/* ─── SIDEBAR BUTTONS ─────────────────────────────────────────────── */
.sidebar-btn {
  display: block; width: 100%; margin-bottom: 6px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 12px;
  font-family: inherit; font-size: 0.85rem; font-weight: 500; cursor: pointer;
  transition: background 0.15s, border-color 0.15s; text-align: left;
}
.sidebar-btn:hover { background: rgba(255,255,255,0.07); border-color: var(--border-hi); }
.sidebar-btn.highlight { border-color: rgba(255,255,255,0.25); font-weight: 600; }
.sidebar-btn.danger { border-color: rgba(239,68,68,0.3); color: var(--danger); }
.sidebar-btn.danger:hover { background: rgba(239,68,68,0.06); border-color: var(--danger); }

/* ─── LEGEND ──────────────────────────────────────────────────────── */
#legend { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.legend-name { font-size: 0.78rem; color: var(--text-muted); flex: 1; }
.legend-note { font-size: 0.78rem; font-family: 'JetBrains Mono', monospace; color: var(--text); }

/* ─── INSPECTOR ───────────────────────────────────────────────────── */
#cube-inspector {
  padding-top: 14px; border-top: 1px solid var(--border);
  animation: fadeIn 0.25s ease;
}
.inspector-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}
.inspector-label { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); flex-shrink: 0; }
.inspector-row input[type=range] { width: 110px; }
.inspector-row select { flex: 1; }
.inspector-row input[type=number] {
  background: rgba(0,0,0,0.4); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 8px;
  font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; text-align: right;
}

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

.action-row { display: flex; gap: 6px; margin-top: 14px; }
.action-btn {
  flex: 1; background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  color: var(--text); border-radius: 7px; padding: 9px;
  font-family: inherit; font-size: 0.8rem; font-weight: 500; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.action-btn:hover { background: rgba(255,255,255,0.07); border-color: var(--border-hi); }
.action-btn.danger { border-color: rgba(239,68,68,0.3); color: var(--danger); }
.action-btn.danger:hover { background: rgba(239,68,68,0.06); border-color: var(--danger); }

/* ─── RHYTHM MODULE ───────────────────────────────────────────────── */

#step-sequencer {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; margin-top: 4px;
}
.step-btn {
  aspect-ratio: 1; border-radius: 4px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s, border-color 0.1s;
  padding: 0;
}
.step-btn.step-bombo  { background: rgba(239,80,60,0.75);  border-color: rgba(239,80,60,0.9); }
.step-btn.step-caja   { background: rgba(210,210,210,0.7); border-color: rgba(230,230,230,0.85); }
.step-btn.step-hihat  { background: rgba(255,200,0,0.65);  border-color: rgba(255,200,0,0.85); }
.step-btn.step-current {
  outline: 2px solid rgba(255,255,255,0.9);
  outline-offset: 1px;
}

/* ─── MOSAIC CANVAS ───────────────────────────────────────────────── */
#mosaic-wrap {
  position: absolute; inset: 0;
  overflow: hidden; cursor: grab;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 28px 28px;
}
#mosaic-wrap:active { cursor: grabbing; }

#mosaic {
  position: absolute; top: 50%; left: 50%;
  width: 0; height: 0; transform-origin: 0 0;
}

/* ─── CUBE CARD ───────────────────────────────────────────────────── */
.cube-card {
  position: absolute;
  cursor: pointer;
  transition: filter 0.2s, transform 0.2s;
  user-select: none;
  border-radius: 10px;
}
.cube-card:hover {
  transform: scale(1.015);
  z-index: 10;
  filter: brightness(1.08);
}
.cube-card.selected::after {
  content: '';
  position: absolute; inset: -3px;
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  pointer-events: none;
}
.cube-card.playing {
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.05));
}
.cube-card.solved {
  filter: drop-shadow(0 0 20px rgba(255,255,255,0.2)) brightness(1.1);
}

.cube-net { display: block; border-radius: 8px; }

/* ─── EMPTY STATE ─────────────────────────────────────────────────── */
#empty-state {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.empty-icon { font-size: 3rem; opacity: 0.1; }

/* ─── ZOOM CONTROLS ───────────────────────────────────────────────── */
#zoom-controls {
  position: absolute; bottom: 28px; left: 28px;
  display: flex; flex-direction: column; gap: 8px; z-index: 80;
}
#zoom-controls button {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 1.4rem; cursor: pointer;
  backdrop-filter: blur(8px); transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
#zoom-controls button:hover { border-color: var(--border-hi); color: var(--text); }

/* ─── HELP MODAL ──────────────────────────────────────────────────── */
#help-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
#help-modal-overlay.hidden { display: none; }
#help-modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px; max-width: 480px; width: 90%;
  position: relative; box-shadow: 0 16px 48px rgba(0,0,0,0.7);
}
#help-modal h2 { margin-bottom: 16px; font-size: 1.4rem; font-weight: 600; }
#help-modal p  { color: var(--text-muted); line-height: 1.65; margin-bottom: 14px; font-size: 0.9rem; }
#help-modal ul { padding-left: 18px; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 14px; }
#help-modal li { margin-bottom: 8px; line-height: 1.55; }
#btn-close-help {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--text-muted); width: 32px; height: 32px; border-radius: 50%;
  font-size: 0.85rem; cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#btn-close-help:hover { color: var(--text); background: rgba(255,255,255,0.08); border-color: var(--border-hi); }

/* ─── SCROLLBAR ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* ─── STICKER ANIMATIONS ──────────────────────────────────────────── */
.sticker { transition: fill 0.14s ease; }
.face-flash { animation: faceFlash 0.2s ease; }
@keyframes faceFlash {
  0%   { opacity: 1; }
  35%  { opacity: 0.5; filter: brightness(2); }
  100% { opacity: 1; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── MIXER PANEL ─────────────────────────────────────────────────── */
#mixer-panel {
  position: absolute; left: 20px; top: 72px;
  width: 230px;
  background: var(--panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 16px;
  max-height: calc(100vh - 100px); overflow-y: auto;
  z-index: 90; padding: 14px 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
  transform: translateX(-260px); opacity: 0; pointer-events: none;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#mixer-panel.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
#btn-mixer.mixer-active { background: rgba(255,255,255,0.12); border-color: var(--border-hi); color: var(--text); }

.mixer-panel-title {
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px;
}
.mixer-channel {
  display: flex; flex-direction: column; gap: 5px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
}
.mixer-channel:last-child { border-bottom: none; padding-bottom: 0; }
.mixer-rhythm-sep { margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,0.12); }
.mixer-ch-top { display: flex; align-items: center; gap: 6px; }
.mixer-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  cursor: pointer; transition: transform 0.15s;
}
.mixer-dot:hover { transform: scale(1.4); }
.mixer-name {
  flex: 1; font-size: 0.76rem; font-weight: 500; color: var(--text-muted);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color 0.15s;
}
.mixer-name:hover { color: var(--text); }
.mixer-btn {
  width: 22px; height: 22px; border-radius: 4px; flex-shrink: 0;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.6rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.mixer-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); border-color: var(--border-hi); }
.mixer-btn.mute.active { background: rgba(239,68,68,0.18); color: var(--danger); border-color: rgba(239,68,68,0.4); }
.mixer-btn.solo.active { background: rgba(255,200,0,0.18); color: rgba(255,200,0,1); border-color: rgba(255,200,0,0.45); }
.mixer-vol {
  width: 100%; height: 3px; border-radius: 2px;
  -webkit-appearance: none; outline: none; cursor: pointer;
  background: rgba(255,255,255,0.08);
}
.mixer-vol::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px;
  border-radius: 50%; background: var(--text); cursor: pointer;
}
.mixer-channel.mixer-ch-pulse {
  background: rgba(255,255,255,0.07);
  border-radius: 6px;
  outline: 1px solid rgba(255,255,255,0.18);
  outline-offset: 1px;
  transition: background 0.15s, outline 0.15s;
}
.cube-card.mixer-focus {
  filter: drop-shadow(0 0 22px rgba(255,255,255,0.55)) brightness(1.25) !important;
  transform: scale(1.06) !important;
  z-index: 20;
}

/* ─── SIDEBAR OVERLAY (mobile tap-to-close) ───────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 89;
}
#sidebar-overlay.active { display: block; }

/* ─── MOBILE ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #header { height: 52px; padding: 0 16px; }
  .logo { font-size: 1rem; }
  .icon-btn { width: 40px; height: 40px; font-size: 0.95rem; }

  /* Sidebar as bottom sheet */
  #sidebar {
    right: 0; left: 0;
    top: auto; bottom: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    transform: translateY(0);
    opacity: 1;
    padding: 10px 16px env(safe-area-inset-bottom, 20px);
  }
  /* Drag handle visual hint */
  #sidebar::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 0 auto 12px;
    flex-shrink: 0;
  }
  #sidebar.closed {
    transform: translateY(100%);
    opacity: 1;
  }

  /* Bigger touch targets */
  .play-btn { padding: 14px; font-size: 1rem; }
  .sidebar-btn { padding: 13px; font-size: 0.9rem; }
  .sidebar-section { margin-bottom: 16px; }
  .control-row { margin-bottom: 12px; }
  .control-row label { font-size: 0.88rem; }
  input[type=range] { width: 100%; max-width: 170px; height: 5px; }
  input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; }
  select { font-size: 0.88rem; padding: 9px 12px; }
  .control-row input[type=number] { width: 72px; padding: 7px 8px; font-size: 0.9rem; }

  /* Step sequencer — taller buttons on mobile */
  .step-btn { min-height: 36px; border-radius: 5px; }

  /* Inspector rows more spacious */
  .inspector-row { margin-bottom: 12px; }
  .inspector-row input[type=range] { width: 130px; }
  .action-btn { padding: 13px; font-size: 0.88rem; }

  /* Mixer panel — bottom sheet on mobile */
  #mixer-panel {
    left: 0; right: 0; top: auto; bottom: 0;
    width: 100%; max-height: 55vh;
    border-radius: 16px 16px 0 0; border-bottom: none;
    transform: translateY(110%); opacity: 1; pointer-events: none;
  }
  #mixer-panel.open { transform: translateY(0); opacity: 1; pointer-events: auto; }

  /* Zoom controls — left side, below header, away from sidebar toggle */
  #zoom-controls {
    bottom: auto; right: auto;
    top: 60px; left: 14px;
    gap: 6px;
  }
  #zoom-controls button { width: 42px; height: 42px; font-size: 1.2rem; }

  /* Help modal full width */
  #help-modal {
    padding: 28px 20px 32px;
    border-radius: 16px 16px 0 0;
    max-width: 100%;
    width: 100%;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    border-bottom: none;
  }
}
