:root {
  --bg: #0f1115;
  --bg-elev: #1a1d24;
  --bg-elev-2: #242831;
  --fg: #e8ebf0;
  --fg-dim: #9aa3b2;
  --accent: #e04f68;
  --accent-hover: #ef6b82;
  --border: #2a2f3a;
  --success: #4ade80;
  --error: #f87171;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

a {
  color: var(--accent);
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header h1 {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 1.3rem;
}

.site-header .logo {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.site-header small {
  color: var(--fg-dim);
  font-weight: 400;
  font-size: 0.85rem;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--fg-dim);
}

.breadcrumb .crumb.active {
  color: var(--fg);
  font-weight: 600;
}

.breadcrumb .sep {
  opacity: 0.4;
}

/* Container & steps */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}

.step {
  display: none;
  animation: fade-in 0.25s ease;
}

.step.active {
  display: block;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.search-bar input {
  flex: 1;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

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

.search-bar button,
.back-btn {
  padding: 0.85rem 1.2rem;
  font-size: 0.95rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

.search-bar button:hover,
.back-btn:hover {
  background: var(--accent-hover);
}

.back-btn {
  background: var(--bg-elev);
  color: var(--fg);
  margin-bottom: 1rem;
}

.back-btn:hover {
  background: var(--bg-elev-2);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1.2rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card .thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg-elev-2);
  display: block;
}

.card .thumb-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #2a2f3a, #1a1d24);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  font-size: 2rem;
}

.card .meta {
  padding: 0.7rem 0.8rem 0.9rem;
}

.card .meta .title {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 0.2rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .meta .sub {
  color: var(--fg-dim);
  font-size: 0.8rem;
  margin: 0;
}

/* Album header */
.album-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.2rem;
}

.album-header img {
  width: 110px;
  height: 110px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--bg-elev-2);
}

.album-header h2 {
  margin: 0 0 0.3rem;
}

.muted {
  color: var(--fg-dim);
  margin: 0;
}

/* Track list */
.track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.track-list li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}

.track-list li:last-child {
  border-bottom: none;
}

.track-list li:hover {
  background: var(--bg-elev-2);
}

.track-number {
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  width: 2rem;
  text-align: right;
}

.track-title {
  flex: 1;
  font-weight: 500;
}

.track-duration {
  color: var(--fg-dim);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.track-actions {
  display: flex;
  gap: 0.4rem;
}

.download-btn {
  padding: 0.5rem 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s;
  min-width: 90px;
  text-align: center;
}

.download-btn.audio {
  background: #4a7fd6;
}

.download-btn.audio:hover:not(:disabled) {
  background: #6a99e3;
}

.download-btn.video {
  background: var(--accent);
}

.download-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.download-btn:disabled {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  cursor: not-allowed;
}

.download-btn.done {
  background: var(--success);
  color: #0f1115;
}

.download-btn.error {
  background: var(--error);
}

/* Full album download button */
.album-header-meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
}

.album-download-btn {
  margin-top: 0.3rem;
  padding: 0.55rem 1rem;
  background: #4a7fd6;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.album-download-btn:hover:not(:disabled) {
  background: #6a99e3;
}

.album-download-btn:disabled {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  cursor: not-allowed;
}

.album-download-btn.done {
  background: var(--success);
  color: #0f1115;
}

.album-download-btn.error {
  background: var(--error);
}

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.7);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.loader.hidden {
  display: none;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Toasts */
.toasts {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}

.toast {
  padding: 0.75rem 1rem;
  background: var(--bg-elev-2);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  box-shadow: var(--shadow);
  min-width: 220px;
  max-width: 340px;
  font-size: 0.9rem;
  animation: slide-in 0.2s ease;
}

.toast.success {
  border-left-color: var(--success);
}

.toast.error {
  border-left-color: var(--error);
}

@keyframes slide-in {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.empty {
  color: var(--fg-dim);
  text-align: center;
  padding: 2rem;
}

.hidden {
  display: none !important;
}

/* Header actions */
.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.header-btn {
  padding: 0.55rem 0.9rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}

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

/* Cancel button */
.cancel-btn {
  padding: 0.5rem 0.8rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  min-width: 80px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cancel-btn:hover {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.download-btn.cancelled {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
}

.album-download-btn.cancelled {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
}

/* Downloads browser */
.downloads-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.downloads-header h2 {
  margin: 0;
}

.downloads-tools {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.downloads-tools .search-bar {
  flex: 1;
  min-width: 300px;
  margin: 0;
}

.file-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  border: 1px solid var(--border);
}

.file-badge.audio {
  color: #a9c6ff;
  border-color: #3b4e7a;
}

.file-badge.video {
  color: #ffb3bf;
  border-color: #6a3340;
}

.file-size {
  color: var(--fg-dim);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
}

.file-open-btn {
  padding: 0.5rem 0.8rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s, border-color 0.15s;
}

.file-open-btn:hover {
  background: var(--border);
  border-color: var(--accent);
}

.delete-btn {
  padding: 0.5rem 0.8rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.delete-btn:hover:not(:disabled) {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.delete-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Album grouping view */
.albums-view {
  display: block;
}

.albums-view.hidden {
  display: none;
}

.album-section {
  margin-bottom: 2rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.album-name {
  margin: 0;
  padding: 0.8rem 1rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
}

.album-info {
  padding: 0.4rem 1rem;
  color: var(--fg-dim);
  font-size: 0.85rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
}

.album-tracks {
  list-style: none;
  margin: 0;
  padding: 0;
}

.album-tracks li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}

.album-tracks li:last-child {
  border-bottom: none;
}

.album-tracks li:hover {
  background: var(--bg-elev-2);
}

/* Duplicate warning */
.warning {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.15), rgba(124, 45, 18, 0.1));
  border: 1px solid rgba(180, 83, 9, 0.3);
  border-radius: var(--radius);
  color: #fed7aa;
}

.warning p {
  margin: 0 0 0.8rem;
  font-weight: 500;
}

.warning ul {
  margin: 0;
  padding-left: 1.5rem;
}

.warning li {
  margin: 0.3rem 0;
  font-size: 0.9rem;
}

.warning code {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.85rem;
}

/* Library stats */
.library-stats {
  font-size: 0.85rem;
  margin: 0.1rem 0 0.2rem;
}

/* "In library" state for track-row download buttons */
.download-btn.in-library,
.download-btn.in-library:disabled {
  background: var(--success);
  color: #0f1115;
  cursor: default;
  opacity: 1;
}

.download-btn.in-library:hover {
  background: var(--success);
}

/* Library track rows */
.album-section-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.8rem 1rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
}

.album-section-header .album-name {
  background: transparent;
  padding: 0;
  border: none;
}

.album-section-header .album-info {
  padding: 0;
  background: transparent;
  border: none;
}

.library-track {
  display: flex !important;
  flex-direction: column;
  align-items: stretch !important;
  gap: 0.5rem !important;
  padding: 0.8rem 1rem !important;
}

.library-track-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.library-track-main .track-title {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}

.format-badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.mirror-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.4);
}

.library-track-formats {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.format-row {
  display: grid;
  grid-template-columns: 0 80px 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  transition: grid-template-columns 0.15s;
}

.format-row.missing {
  grid-template-columns: 80px 1fr;
  color: var(--fg-dim);
  background: transparent;
  border-style: dashed;
}

/* Hide the checkbox cell by default; the body.select-mode class reveals it. */
.select-cell {
  display: none;
  align-items: center;
  justify-content: center;
}

.select-cell input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

body.select-mode .format-row:not(.missing) {
  grid-template-columns: 28px 80px 1fr auto auto;
}

body.select-mode .format-row:not(.missing) .select-cell {
  display: flex;
}

/* Highlight rows whose checkbox is checked for clearer feedback. */
body.select-mode .format-row:has(.select-checkbox:checked) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Danger-styled header buttons for destructive actions. */
.header-btn.danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.4);
}

.header-btn.danger:hover:not(:disabled) {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.header-btn.danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.format-row .format-label {
  font-weight: 600;
  color: var(--fg-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.format-row .format-filename {
  color: var(--fg-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  white-space: nowrap;
  justify-self: start;
  cursor: default;
}

.library-track.mirrored {
  background: linear-gradient(
    90deg,
    rgba(74, 222, 128, 0.06),
    transparent 60%
  );
}

@media (max-width: 640px) {
  .format-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "label size"
      "name  name"
      "actions actions";
  }
  .format-row .format-label {
    grid-area: label;
  }
  .format-row .file-size {
    grid-area: size;
    text-align: right;
  }
  .format-row .format-filename {
    grid-area: name;
  }
  .format-row .track-actions {
    grid-area: actions;
    justify-content: flex-end;
  }
  .format-row .select-cell {
    display: none;
  }
  body.select-mode .format-row:not(.missing) {
    grid-template-columns: 28px 1fr auto;
    grid-template-areas:
      "sel label size"
      "sel name  name"
      "sel actions actions";
  }
  body.select-mode .format-row:not(.missing) .select-cell {
    display: flex;
    grid-area: sel;
  }
}

/* =========================================================================
   User chip, logout, config tab
   ========================================================================= */

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--bg-elev-2);
  color: var(--fg);
}

.user-chip-admin {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.logout-form {
  display: inline;
  margin: 0;
}

.config-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1rem 0;
}

.config-section h3 {
  margin: 0 0 0.6rem 0;
  font-size: 1rem;
  color: var(--fg);
}

.config-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}

.config-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
}

.config-form label.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--fg);
}

.config-form input[type="text"],
.config-form input[type="password"],
.config-form select {
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  min-width: 180px;
  outline: none;
}

.config-form input:focus,
.config-form select:focus {
  border-color: var(--accent);
}

.config-form button {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

.config-form button:hover {
  background: var(--accent-hover);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.users-table th,
.users-table td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.users-table th {
  font-size: 0.75rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.users-table .actions-col {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

/* =========================================================================
   Login page
   ========================================================================= */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 500px at 30% -10%, rgba(224, 79, 104, 0.15), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(78, 110, 220, 0.1), transparent 60%),
    var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 420px;
  padding: 2rem 1.5rem;
}

.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-logo {
  margin: 0 0 0.25rem 0;
  font-size: 2rem;
  text-align: center;
}

.login-sub {
  text-align: center;
  color: var(--fg-dim);
  margin: 0 0 1.5rem 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
}

.login-form input {
  padding: 0.75rem 0.9rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-form button {
  margin-top: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
}

.login-form button:hover {
  background: var(--accent-hover);
}

.login-error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--error);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.login-hint {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.8rem;
}

/* =========================================================================
   Persistent audio player bar (works with Media Session on lock screen)
   ========================================================================= */

body.has-player .container {
  padding-bottom: 7rem;
}

.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr) auto;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
}

.player-bar.hidden {
  display: none;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.player-art {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-elev-2);
}

.player-text {
  min-width: 0;
}

.player-title {
  font-weight: 600;
  color: var(--fg);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-sub {
  font-size: 0.75rem;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.player-ctrl {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.player-ctrl:hover {
  background: var(--bg-elev-2);
}

.player-play {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 42px;
  height: 42px;
  font-size: 0.95rem;
}

.player-play:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.player-seek {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.player-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--fg-dim);
  min-width: 90px;
  white-space: nowrap;
}

.player-progress {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 4px;
}

.player-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.player-close:hover {
  background: var(--bg-elev-2);
  color: var(--fg);
}

/* Play button inside library format rows */
.format-row .play-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.format-row .play-btn:hover {
  background: var(--accent-hover);
}

.format-row .file-open-btn {
  background: var(--bg-elev-2);
  color: var(--fg);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.format-row .file-open-btn:hover {
  background: var(--bg);
}

@media (max-width: 700px) {
  .player-bar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "info controls"
      "seek seek";
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
  }
  .player-info {
    grid-area: info;
  }
  .player-controls {
    grid-area: controls;
  }
  .player-seek {
    grid-area: seek;
  }
  .player-close {
    position: absolute;
    top: -14px;
    right: 8px;
    background: var(--bg-elev);
  }
  body.has-player .container {
    padding-bottom: 9rem;
  }
}

/* -----------------------------------------------------------------------
 * Library: album grid view (default) + album cover on list header
 * ----------------------------------------------------------------------- */

.albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.album-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.album-tile-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  background: transparent;
  color: inherit;
  border: none;
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
}

.album-tile-header:hover .album-tile-meta,
.album-tile-header:focus-visible .album-tile-meta {
  background: var(--bg-elev-2);
}

.album-cover-art {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-elev-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.album-cover-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-cover-art--fallback {
  font-size: 3rem;
  font-weight: 700;
  color: var(--fg-dim);
  background: linear-gradient(135deg, var(--bg-elev-2), var(--bg-elev));
}

.album-tile-meta {
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-top: 1px solid var(--border);
  transition: background 0.15s ease;
}

.album-tile-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.album-tile-info {
  font-size: 0.8rem;
  color: var(--fg-dim);
}

.album-tile-body {
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.album-tile-body.hidden {
  display: none;
}

.album-tile-body .album-tracks {
  list-style: none;
  margin: 0;
  padding: 0;
}

.album-tile-body .album-tracks li {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.album-tile-body .album-tracks li:last-child {
  border-bottom: none;
}

/* Cover thumbnail shown next to album name in list view */
.album-section-header {
  flex-direction: row !important;
  align-items: center;
  gap: 0.8rem !important;
}

.album-section-cover {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  flex: 0 0 auto;
}

.album-section-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

/* Player bar artwork: fall back cleanly when there's no cover */
#player-art:not([src]),
#player-art[src=""] {
  display: none;
}

@media (max-width: 480px) {
  .albums-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.6rem;
  }
  .album-tile-name {
    font-size: 0.85rem;
  }
}

/* -----------------------------------------------------------------------
 * Search mode tabs (step 1: Artists vs Videos)
 * ----------------------------------------------------------------------- */

.search-mode-tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.8rem;
}

.search-mode-tab {
  padding: 0.4rem 0.9rem;
  background: transparent;
  color: var(--fg-dim);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
}

.search-mode-tab:hover {
  color: var(--fg);
}

.search-mode-tab.active {
  background: var(--accent);
  color: #fff;
}

/* -----------------------------------------------------------------------
 * Video quality picker (shared between album tracks and video search)
 * ----------------------------------------------------------------------- */

.quality-select {
  padding: 0.45rem 0.4rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 70px;
}

.quality-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* -----------------------------------------------------------------------
 * Direct video search results
 * ----------------------------------------------------------------------- */

.video-result {
  display: flex !important;
  align-items: center;
  gap: 0.8rem;
}

.video-thumb {
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  flex: 0 0 auto;
  background: var(--bg-elev-2);
}

.video-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  font-size: 1.4rem;
}

.video-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.video-title {
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.video-sub {
  color: var(--fg-dim);
  font-size: 0.8rem;
}

@media (max-width: 600px) {
  .video-result {
    flex-wrap: wrap;
  }
  .video-thumb {
    width: 72px;
    height: 40px;
  }
  .track-list li .track-actions {
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
  }
  .quality-select {
    min-width: 64px;
  }
}

/* -------------------------------------------------------------------------
 * Video modal player
 * ------------------------------------------------------------------------- */
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-modal.hidden {
  display: none;
}
.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
}
.video-modal-content {
  position: relative;
  z-index: 1;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.video-modal-close {
  position: absolute;
  top: -36px;
  right: 0;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.video-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}
.video-modal-title {
  color: #fff;
  font-size: 14px;
  text-align: center;
  max-width: 90vw;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-modal-video {
  max-width: 95vw;
  max-height: 85vh;
  background: #000;
  border-radius: 6px;
  outline: none;
}
body.has-video-modal {
  overflow: hidden;
}
@media (max-width: 640px) {
  .video-modal-close {
    top: -32px;
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .video-modal-title {
    font-size: 12px;
  }
}

