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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --border: #2e2e42;
  --accent: #7c5cfc;
  --accent-dim: #4a3799;
  --text: #e4e4f0;
  --text-muted: #888899;
  --radius: 8px;
  --gap: 16px;
  --danger: #e05c5c;
  --success: #5ce08c;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 32px var(--gap);
}

/* ---- Search ---- */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 32px;
  position: relative;
}

.search-bar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus { border-color: var(--accent); }

.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 50;
  max-height: 280px;
  overflow-y: auto;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.autocomplete-item:hover, .autocomplete-item.active { background: var(--accent-dim); }

.autocomplete-item img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
}

.autocomplete-item .name { font-weight: 600; font-size: 0.95rem; }
.autocomplete-item .tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: auto;
}

/* ---- Columns ---- */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 400px;
}

.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-header .count {
  background: var(--accent-dim);
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75rem;
}

.panel-body { padding: 14px 18px; flex: 1; overflow-y: auto; }

/* ---- Albums list ---- */
.album-list { display: flex; flex-direction: column; gap: 8px; }

.album-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
  border: 1px solid transparent;
}

.album-item:hover { background: var(--surface2); }
.album-item.active { border-color: var(--accent); background: var(--surface2); cursor: default; }

.album-item img {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}

.album-item .album-name { font-size: 0.9rem; font-weight: 600; }
.album-item .album-year { font-size: 0.75rem; color: var(--text-muted); }

/* ---- Inline track list (inside album card) ---- */
.track-list-inline {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.no-preview-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
}

/* ---- Tracks list ---- */
.track-list { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }

.track-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 0.88rem;
}

.track-item:hover { background: var(--surface2); }
.track-item.active { background: var(--accent-dim); }
.track-item.no-preview { opacity: 0.4; cursor: not-allowed; }

.track-item .track-num { width: 22px; color: var(--text-muted); font-size: 0.8rem; text-align: right; }
.track-item .track-name { flex: 1; }
.track-item .preview-badge {
  font-size: 0.7rem;
  background: var(--success);
  color: #000;
  padding: 1px 6px;
  border-radius: 4px;
  opacity: 0.8;
}

/* ---- Gallery columns (inside photos panel) ---- */
.gallery-list { display: flex; flex-direction: column; gap: 6px; }

.gallery-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.1s;
}

.gallery-item:hover { background: var(--surface2); }
.gallery-item.active { background: var(--accent-dim); }

/* ---- Photo grid (selection) ---- */
.photo-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.photo-select-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.photo-select-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-select-cell.selected { border-color: var(--accent); }

.photo-select-cell .select-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* ---- Selection tray ---- */
#selection-tray {
  margin-top: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tray-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tray-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  flex: 1;
}

.tray-body {
  padding: 14px 18px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 100px;
  align-items: flex-start;
}

.tray-slot {
  width: 80px;
  height: 80px;
  border-radius: 6px;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  position: relative;
  transition: border-color 0.15s;
  cursor: grab;
}

.tray-slot.filled { border-style: solid; border-color: var(--accent); cursor: grab; }
.tray-slot.filled:active { cursor: grabbing; }
.tray-slot.drag-over { border-color: var(--accent); background: rgba(124,92,252,0.15); }

.tray-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.tray-slot .slot-num {
  position: absolute;
  bottom: 2px;
  left: 2px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
}

.tray-slot .remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  border-radius: 50%;
  border: none;
  color: #fff;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.tray-slot.filled:hover .remove-btn { opacity: 1; }

/* ---- Build button ---- */
.build-row {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
}

.selected-track-label {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.selected-track-label span { color: var(--text); font-weight: 600; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover  { background: #9070ff; }
button:active { background: var(--accent-dim); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:hover { background: var(--accent); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.btn-ghost:hover { border-color: var(--accent); color: var(--text); background: transparent; }

/* ---- Slideshow overlay ---- */
#slideshow {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.slide-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.6s ease-in-out;
}

.slide-img.visible { opacity: 1; }

.slide-controls {
  position: absolute;
  bottom: 32px;
  left: 32px;
  right: 32px;
  display: flex;
  gap: 12px;
  z-index: 10;
  align-items: center;
}

#btn-pause { margin-left: auto; }

.slide-info {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 10;
}

/* ---- Progress bar ---- */
#cache-progress {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* ---- Share row (inside slideshow overlay) ---- */
.share-row {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 10;
  background: rgba(0,0,0,0.75);
  padding: 10px 14px;
  border-radius: 10px;
  min-width: 360px;
}

.share-row input {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  outline: none;
}

/* ---- Utility ---- */
.hidden { display: none !important; }
.status {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 24px 0;
  text-align: center;
}
