/* ============================================================
   Tydal — Dark Theme, Mobile-First, Push 3-Inspired
   ============================================================ */

:root {
  --bg-body: #0a0a0a;
  --bg-surface: #1a1a1a;
  --bg-surface-hover: #2a2a2a;
  --accent: #2A9D8F;
  --accent-glow: rgba(42, 157, 143, 0.4);
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --header-height: 40px;
  --toolbar-height: 44px;
  --sheet-height: 55vh;

  --step-empty: #111;
  --step-inactive: #1a1a1a;
  --step-active: var(--accent);
  --step-selected-bg: rgba(42, 157, 143, 0.12);
  --step-playhead: rgba(255, 255, 255, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-body);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* -------------------------
   Header
   ------------------------- */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  padding: 0 16px;
}

.app-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-primary);
  margin: 0;
  user-select: none;
}

/* -------------------------
   Main Layout
   ------------------------- */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 6px;
}

.instrument-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
}

/* -------------------------
   Push Grid — 8×8 split layout
   ------------------------- */
.push-grid {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 700px;
  gap: 0;
  touch-action: none;
}

@media (min-width: 768px) {
  .push-grid {
    max-width: 560px;
  }
}

/* Step zone — top 4 rows × 8 cols */
.step-zone {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 3px;
  flex: 2;
  min-height: 0;
}

/* Zone divider — page controls */
.zone-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 3px 0;
  flex-shrink: 0;
}

.page-label {
  font-size: 0.6rem;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  user-select: none;
}

.page-toggle-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.55rem;
  width: 20px;
  height: 16px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* Note zone — bottom 4 rows × 8 cols */
.note-zone {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 4px;
  flex: 3;
  min-height: 0;
}

/* -------------------------
   Grid Cells — shared base
   ------------------------- */
.grid-cell {
  border-radius: 6px;
  user-select: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* -------------------------
   Step Cells (sequencer)
   ------------------------- */
.step-cell {
  background: var(--step-inactive);
  border: 1px solid var(--border-subtle);
  transition: background-color 60ms ease;
}

.step-cell.step-empty {
  background: var(--step-empty);
  border-color: transparent;
  cursor: default;
}

/* Selected note's lane — subtle highlight */
.step-cell.step-selected-lane {
  background: var(--step-selected-bg);
  border-color: rgba(42, 157, 143, 0.2);
}

/* Step has note active */
.step-cell.step-active {
  background: var(--step-active);
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

/* Playhead column */
.step-cell.step-playhead {
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 8px var(--step-playhead);
}

.step-cell.step-active.step-playhead {
  background: #3fc7b7;
  box-shadow: 0 0 10px var(--accent-glow), inset 0 0 8px rgba(255, 255, 255, 0.15);
}

/* Lane label (first cell in each lane row) */
.lane-label {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.45rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.02em;
  pointer-events: none;
}

.step-selected-lane .lane-label {
  color: var(--accent);
}

/* -------------------------
   Note Cells (pads)
   ------------------------- */
.note-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  flex-direction: column;
  transition: background-color 60ms ease, box-shadow 60ms ease, border-color 60ms ease;
  touch-action: manipulation;
}

@media (hover: hover) {
  .note-cell:hover {
    background: var(--bg-surface-hover);
  }
}

.note-cell.active {
  background-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  border-color: transparent;
}

.note-cell.selected {
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.note-cell.active .cell-note {
  color: rgba(255, 255, 255, 0.9);
}

.note-cell.expressing {
  border-color: var(--accent);
  box-shadow: inset 0 0 8px rgba(42, 157, 143, 0.3);
  transition: border-color 100ms ease;
}

.cell-note {
  font-size: 0.55rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  line-height: 1;
  pointer-events: none;
}

/* -------------------------
   Visualizer (overlay on grid)
   ------------------------- */
#visualizer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.visualizer-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* -------------------------
   Toolbar
   ------------------------- */
.toolbar {
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
  padding: 0 6px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-body);
  z-index: 20;
  position: relative;
}

.toolbar-panels {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.toolbar-btn {
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 80ms ease, color 80ms ease, border-color 80ms ease;
}

.toolbar-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

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

/* Play button */
.toolbar-btn--play {
  font-size: 0.8rem;
  padding: 5px 12px;
  min-width: 36px;
}

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

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

/* -------------------------
   Octave Control
   ------------------------- */
.octave-control {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.octave-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}

.octave-display {
  font-size: 0.65rem;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
  min-width: 30px;
  text-align: center;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 1 70px;
  min-width: 40px;
}

/* -------------------------
   Scale Control
   ------------------------- */
.scale-control {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.scale-control select {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

/* -------------------------
   Gyro Control
   ------------------------- */
.gyro-control {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

.gyro-btn {
  font-size: 0.6rem;
  font-weight: 600;
  white-space: nowrap;
  width: auto;
  padding: 0 5px;
  border-radius: 12px;
  letter-spacing: 0.03em;
}

.gyro-btn--active {
  color: var(--accent);
  border-color: var(--accent);
}

.gyro-btn--unavailable {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -------------------------
   Note Repeat Control
   ------------------------- */
.note-repeat-control {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.note-repeat-rate {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.gyro-denied-msg {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.65rem;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}

.control-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
}

/* Range input */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px var(--accent-glow);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
}

/* -------------------------
   Bottom Sheet System
   ------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

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

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--sheet-height);
  background: #111;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  z-index: 40;
  transform: translateY(100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.sheet-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px 0 4px;
  flex-shrink: 0;
}

.sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}

/* -------------------------
   Panel Controls (inside sheets)
   ------------------------- */
.panel-section {
  background: transparent;
  border-radius: 0;
  border: none;
  margin-bottom: 0;
  overflow: visible;
}

.bottom-sheet .panel-header {
  display: none;
}

.bottom-sheet .panel-body {
  display: block;
  padding: 0;
}

.panel-heading {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 12px 0 6px 0;
}

.panel-heading:first-child {
  margin-top: 4px;
}

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

.panel-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  min-width: 60px;
  flex-shrink: 0;
  user-select: none;
}

.panel-body input[type="range"] {
  flex: 1;
}

.panel-select {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  flex: 1;
  cursor: pointer;
  outline: none;
}

.panel-btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.panel-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-btn--small {
  padding: 3px 7px;
  font-size: 0.65rem;
  flex-shrink: 0;
}

.panel-patch-controls {
  display: flex;
  flex: 1;
  gap: 6px;
  align-items: center;
}

.panel-patch-controls .panel-select {
  flex: 1;
  min-width: 0;
}

.panel-patch-actions {
  display: flex;
  flex: 1;
  gap: 6px;
  align-items: center;
}

/* -------------------------
   Help
   ------------------------- */
.help-wrapper {
  position: relative;
  flex-shrink: 0;
}

.help-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.help-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: #1e1e1e;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  padding: 16px;
  min-width: 260px;
  z-index: 50;
}

.help-panel[hidden] { display: none; }

.help-panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin: 0 0 12px 0;
}

.help-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-row {
  display: grid;
  grid-template-columns: 80px 80px 1fr;
  align-items: center;
  gap: 8px;
}

.help-row-label { font-size: 0.7rem; color: var(--text-secondary); }
.help-keys { font-size: 0.8rem; font-weight: 700; color: var(--text-primary); font-family: monospace; }
.help-notes { font-size: 0.7rem; color: var(--accent); font-family: monospace; }

.help-tip {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin: 12px 0 0 0;
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

/* -------------------------
   Audio Overlay
   ------------------------- */
#audio-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 10, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#audio-overlay[hidden] { display: none; }

.overlay-inner { text-align: center; pointer-events: none; }

.overlay-text {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: 0.04em;
}

.overlay-text::after {
  content: '';
  display: block;
  width: 40px;
  height: 2px;
  background: var(--accent);
  margin: 12px auto 0;
  border-radius: 1px;
}

/* -------------------------
   Sequencer (drum grid in sheet)
   ------------------------- */
.sequencer-section {
  padding: 0;
  background: transparent;
  flex-shrink: 0;
}

.sequencer-transport {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.seq-btn {
  padding: 0.4rem 1rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: #eee;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.seq-btn:active { background: rgba(255,255,255,0.15); }

.bpm-control { display: flex; align-items: center; gap: 0.5rem; }
.bpm-control label { color: #aaa; font-size: 0.75rem; }
#bpm-slider { width: 80px; flex: none; }
#bpm-display { color: #eee; font-size: 0.8rem; min-width: 2.5rem; text-align: center; }

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

.seq-row { display: flex; align-items: center; gap: 2px; }

.seq-row-label {
  width: 40px;
  font-size: 0.7rem;
  color: #aaa;
  text-transform: capitalize;
  flex-shrink: 0;
}

.seq-cell {
  width: 100%;
  max-width: 32px;
  aspect-ratio: 1;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.08s;
  flex: 1;
}

.seq-cell.beat-start { border-left: 2px solid rgba(255,255,255,0.2); }
.seq-cell.active { background: var(--accent); border-color: var(--accent); }
.seq-cell.playing { box-shadow: 0 0 8px rgba(255,255,255,0.4); border-color: rgba(255,255,255,0.6); }
.seq-cell.active.playing { background: #3fc7b7; box-shadow: 0 0 12px rgba(42,157,143,0.6); }

.seq-btn.recording { background: rgba(220,50,50,0.6); border-color: rgba(220,50,50,0.8); }
#overdub-count { color: #aaa; font-size: 0.7rem; margin-left: 0.25rem; }
#quantize-select { background: rgba(255,255,255,0.08); color: #eee; border: 1px solid rgba(255,255,255,0.2); border-radius: 4px; padding: 0.25rem 0.4rem; font-size: 0.75rem; }

/* -------------------------
   Randomize panel controls
   ------------------------- */

/* Full-width randomize button */
.panel-btn--randomize {
  flex: 1;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Variation slots row */
.panel-row--variations {
  gap: 6px;
  justify-content: flex-start;
}

/* Individual variation slot button — compact square */
.variation-slot-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-family: monospace;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.5;
  transition: border-color 0.15s, color 0.15s, background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

/* Filled slot — has a saved variation */
.variation-slot-btn.filled {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}

/* Currently active/loaded slot */
.variation-slot-btn.active-slot {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  opacity: 1;
}

.variation-slot-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}

/* -------------------------
   Preset Browser
   ------------------------- */
.preset-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-primary);
  user-select: none;
  transition: background 120ms ease;
}

.preset-item:hover {
  background: var(--bg-surface-hover);
}

.preset-item.previewing {
  background: rgba(42, 157, 143, 0.15);
  border-left: 3px solid var(--accent);
  padding-left: 9px; /* compensate for the 3px border */
}

.preset-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  padding: 8px 0 4px;
  margin: 0;
  font-weight: 600;
}

.preset-browser-actions {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  justify-content: flex-end;
  border-top: 1px solid var(--border-subtle);
  margin-top: 8px;
}

.preset-empty {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 8px 0;
  margin: 0;
}

.panel-btn--browse {
  font-size: 0.65rem;
  padding: 3px 8px;
}
