:root {
  --bg: #0b0b10;
  --surface: #14141d;
  --surface-alt: #1c1c28;
  --border: #2a2a3c;
  --text: #f0f0f5;
  --muted: #8a8a9e;
  --deck-a: #ff3b5c;
  --deck-b: #00d2ff;
  --accent: #ff0055;
  --cue: #ffcc00;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

/* Portrait blocker overlay */
#rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text);
  text-align: center;
  padding: 24px;
}

.rotate-icon {
  font-size: 48px;
  animation: spin 2s infinite ease-in-out;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

@media (orientation: portrait) {
  #rotate-overlay {
    display: flex;
  }
}

/* DJ Main Grid */
.dj {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 140px 1fr;
  grid-template-rows: 1fr auto;
  padding: env(safe-area-inset-top, 8px) env(safe-area-inset-right, 12px) env(safe-area-inset-bottom, 8px) env(safe-area-inset-left, 12px);
  gap: 12px;
  overflow: hidden;
  position: relative;
}

/* Decks */
.deck {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.deck-a { border-top: 3px solid var(--deck-a); }
.deck-b { border-top: 3px solid var(--deck-b); }

.deck-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.deck-tag {
  font-weight: 800;
  font-size: 14px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-alt);
}

.deck-a .deck-tag { color: var(--deck-a); border: 1px solid var(--deck-a); }
.deck-b .deck-tag { color: var(--deck-b); border: 1px solid var(--deck-b); }

.track-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.waveform {
  width: 100%;
  height: 44px;
  background: var(--surface-alt);
  border-radius: 6px;
  display: block;
}

.time-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: monospace;
  color: var(--muted);
  margin-top: -4px;
}

.deck-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

.play-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
}

.play-btn:active { transform: scale(0.92); }
.play-btn.playing { background: #22c55e; color: #fff; }

.cues {
  display: flex;
  gap: 6px;
}

.cue {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.cue:active { transform: scale(0.92); }
.cue.active {
  border-color: var(--cue);
  color: #000;
  background: var(--cue);
  box-shadow: 0 0 8px rgba(255, 204, 0, 0.4);
}

.pitch {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  width: 75px;
}

.pitch span {
  display: flex;
  justify-content: space-between;
}

.pitch input[type="range"] {
  width: 100%;
  accent-color: var(--muted);
}

/* Center Mixer */
.mixer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.eq-wrap {
  display: flex;
  gap: 12px;
  flex: 1;
  width: 100%;
  justify-content: center;
  align-items: center;
}

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

.eq label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
}

.vslider {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 16px;
  height: 60px;
  accent-color: #6366f1;
  cursor: pointer;
}

.deck-a-eq .vslider { accent-color: var(--deck-a); }
.deck-b-eq .vslider { accent-color: var(--deck-b); }

.xfader {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
}

.xfader span:first-child { color: var(--deck-a); }
.xfader span:last-child { color: var(--deck-b); }

#crossfader {
  flex: 1;
  accent-color: #f43f5e;
  cursor: pointer;
}

/* Collapsible Crate / Drawer */
.crate {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  display: flex;
  flex-direction: column;
  position: absolute;
  left: env(safe-area-inset-left, 12px);
  right: env(safe-area-inset-right, 12px);
  bottom: 0;
  max-height: 40px;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
}

.crate.open {
  max-height: 75vh;
}

.crate-toggle {
  height: 38px;
  min-height: 38px;
  background: var(--surface-alt);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.crate-toggle span {
  background: var(--border);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
}

.crate-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(75vh - 40px);
}

.crate-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crate-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
}

.crate-search-wrap svg {
  color: var(--muted);
  flex-shrink: 0;
}

.crate-search-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12px;
}

.crate-btn-clear {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 0 4px;
}

.crate-btn-clear.hidden {
  display: none;
}

.crate-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.crate-tab {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.crate-tab.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.crate-add {
  display: flex;
  gap: 8px;
}

.crate-add input {
  flex: 1;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
}

.crate-add button {
  background: #22c55e;
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.crate-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crate-view.hidden {
  display: none !important;
}

/* Feed Picker Grid */
.crate-feeds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.crate-feed-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s, background 0.15s;
  user-select: none;
}

.crate-feed-card:active {
  transform: scale(0.97);
}

.crate-feed-card:hover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

.crate-feed-art {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: #1c1c24;
  margin-bottom: 6px;
}

.crate-feed-title {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.crate-feed-meta {
  font-size: 9px;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Feed Detail View */
.crate-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 8px 2px;
  border-bottom: 1px solid var(--border);
}

.crate-btn-back {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.crate-btn-back:hover {
  background: #2b2b3a;
  border-color: #4b4b60;
}

.crate-detail-art {
  width: 38px;
  height: 38px;
  border-radius: 4px;
  object-fit: cover;
  background: #1c1c24;
  flex-shrink: 0;
}

.crate-detail-info {
  flex: 1;
  min-width: 0;
}

.crate-detail-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crate-detail-ep-count {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

/* Matching Podcasts in Search */
.crate-search-feed-matches {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
}

.crate-search-feed-matches.hidden {
  display: none !important;
}

.crate-search-matches-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.crate-search-feed-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.crate-mini-feed-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.crate-mini-feed-chip:hover {
  border-color: #3b82f6;
}

.crate-mini-feed-chip img {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  object-fit: cover;
}

.crate-mini-feed-chip span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

/* Loading & Spinner */
.crate-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.crate-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: dj-spin 0.7s linear infinite;
}

@keyframes dj-spin {
  to { transform: rotate(360deg); }
}

.crate-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.crate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  gap: 10px;
}

.crate-item-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.crate-item-title {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crate-item-meta {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.crate-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-load {
  border: none;
  padding: 6px 11px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  user-select: none;
}

.btn-load:active { transform: scale(0.92); }

.btn-load-a { background: rgba(255, 59, 92, 0.2); color: var(--deck-a); border: 1px solid var(--deck-a); }
.btn-load-a:hover { background: var(--deck-a); color: #fff; }

.btn-load-b { background: rgba(0, 210, 255, 0.2); color: var(--deck-b); border: 1px solid var(--deck-b); }
.btn-load-b:hover { background: var(--deck-b); color: #000; }

.btn-load.loaded {
  background: #22c55e !important;
  border-color: #22c55e !important;
  color: #fff !important;
}
