:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --card: rgba(255, 255, 255, 0.9);
  --text: #1f2633;
  --primary: #4a90e2;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 10px 30px rgba(31, 38, 51, 0.12);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

/* .theme-option removed in favor of icon button */

.app-header {
  padding: 1.5rem clamp(1.5rem, 5vw, 4rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: linear-gradient(120deg, rgba(74, 144, 226, 0.92), rgba(88, 86, 214, 0.85));
  color: #fff;
  box-shadow: var(--shadow);
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: 0.05em;
}

.subtitle {
  margin: 0.3rem 0 0;
  opacity: 0.85;
}

main {
  width: min(960px, 92vw);
  margin: 2rem auto;
  display: grid;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: 1rem;
  padding: clamp(1rem, 4vw, 1.5rem);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.section-actions select {
  min-width: 12rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  font: inherit;
  color: inherit;
}

button {
  font: inherit;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(74, 144, 226, 0.4);
}

button.ghost {
  background: transparent;
  color: inherit;
  border: 1px solid var(--border);
  box-shadow: none;
}

button.ghost:not(:disabled):hover {
  box-shadow: 0 2px 8px rgba(31, 38, 51, 0.15);
}

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.4rem;
  border-radius: 0.9rem;
  background: rgba(74, 144, 226, 0.12);
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.file-input input {
  display: none;
}

.hint {
  margin-top: 0.8rem;
  font-size: 0.9rem;
  color: rgba(31, 38, 51, 0.65);
}

#playlist {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.75rem;
}

/* Resultados de búsqueda */
#searchResults {
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.search-result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(74, 144, 226, 0.15);
  background: rgba(255, 255, 255, 0.75);
  cursor: pointer;
}

.search-result:hover {
  box-shadow: 0 4px 10px rgba(74, 144, 226, 0.18);
}

.result-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.result-info strong {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta {
  font-size: 0.82rem;
  color: rgba(31, 38, 51, 0.6);
}

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

.track {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.8rem 1rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(74, 144, 226, 0.15);
  background: rgba(255, 255, 255, 0.85);
  transition: border 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.track.is-playing {
  border-color: var(--primary);
  box-shadow: 0 10px 24px rgba(74, 144, 226, 0.25);
  transform: translateY(-2px);
}

.track.is-remote:not(.is-playing) {
  border-color: rgba(74, 144, 226, 0.32);
  background: rgba(74, 144, 226, 0.12);
}

.track.is-highlighted {
  border-color: var(--primary);
  box-shadow: 0 10px 24px rgba(74, 144, 226, 0.25);
}

.track.dragging {
  opacity: 0.5;
}

.track.drag-over {
  border-style: dashed;
  background: rgba(74, 144, 226, 0.12);
}

.track-handle {
  font-size: 1.1rem;
  opacity: 0.7;
  cursor: grab;
}

.track-handle.is-disabled {
  opacity: 0.3;
  cursor: default;
}

.track-title {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.track-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  margin-top: 0.1rem;
}

.track-rating .star-button {
  width: 1.25rem;
  height: 1.25rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: #f5b301;
  cursor: pointer;
  padding: 0;
  font-size: 1.05rem;
}

.track-rating .star-button[aria-pressed="true"] {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
}

.track-thumb {
  width: 48px;
  height: 48px;
  border-radius: 0.5rem;
  object-fit: cover;
  border: 1px solid rgba(74, 144, 226, 0.2);
  background: rgba(74, 144, 226, 0.08);
  box-shadow: 0 3px 8px rgba(74, 144, 226, 0.12);
}

.track-title strong {
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-title span {
  font-size: 0.85rem;
  color: rgba(31, 38, 51, 0.6);
}

.track-meta {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  max-width: 100%;
  white-space: normal;
}

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

.icon-button {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.35rem;
  font-size: 1.1rem;
  justify-content: center;
  align-items: center;
  display: inline-flex;
}

.icon-button:disabled {
  opacity: 0.45;
}

.icon-button.is-active {
  background: rgba(74, 144, 226, 0.12);
  border-color: rgba(74, 144, 226, 0.45);
}

.favorite-button[aria-pressed="true"],
.favorite-button.is-favorite {
  color: #e53977;
}

.favorite-button {
  font-size: 1.15rem;
  line-height: 1;
}

.favorite-indicator {
  display: inline-flex;
  align-items: center;
  margin-left: 0.35rem;
  font-size: 1rem;
}

.track-title .favorite-indicator {
  font-size: 1.1rem;
}

.now-playing-row .favorite-indicator {
  font-size: 1.2rem;
}

/* Indicadores de estado de pista */
.track-flags {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.track-flag {
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.8;
}

.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1rem 0 0.5rem;
}

.pager {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-end;
  font-size: 0.9rem;
}

.pager #pagerInfo {
  opacity: 0.8;
}

.now-playing-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.9rem;
  align-items: center;
}

.time-row {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.15rem;
}

.time-display {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
}

/* time-option label replaced by icon button */

.icon-button.small {
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
}

.cover-art {
  width: 72px;
  height: 72px;
  border-radius: 0.6rem;
  object-fit: cover;
  border: 1px solid rgba(74, 144, 226, 0.25);
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
  background: rgba(74, 144, 226, 0.08);
  transition: width 0.25s ease, height 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  cursor: zoom-in;
}

/* Dar protagonismo a la carátula cuando existe */
#nowPlayingSection.has-cover .cover-art {
  width: 140px;
  height: 140px;
  box-shadow: 0 16px 40px rgba(74, 144, 226, 0.35);
}

#nowPlayingSection.has-cover #nowPlaying {
  font-size: 1.25rem;
  font-weight: 700;
}

@media (max-width: 720px) {
  #nowPlayingSection.has-cover .cover-art {
    width: 104px;
    height: 104px;
  }
}

/* Valoración en "Reproducción" */
.now-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin: 0.4rem 0 0.2rem 0.1rem;
}

.now-rating .star-button {
  width: 1.6rem;
  height: 1.6rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: #f5b301;
  cursor: pointer;
  padding: 0;
  font-size: 1.35rem;
}

.now-rating .star-button[aria-pressed="true"] {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

/* Lightbox para carátula ampliada */
.lightbox[hidden] { display: none; }
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}
.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 0.8rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.fade-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.fade-control input[type="range"] {
  flex: 1;
}

.loop-control {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.loop-control input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.loop-indicator {
  width: 2.6rem;
  height: 1.4rem;
  border-radius: 999px;
  background: rgba(31, 38, 51, 0.28);
  position: relative;
  transition: background 0.2s ease;
}

.loop-indicator::after {
  content: '';
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  top: 50%;
  left: 0.2rem;
  transform: translate(0, -50%);
  background: #fff;
  box-shadow: 0 2px 6px rgba(31, 38, 51, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.loop-control input[type="checkbox"]:checked + .loop-indicator {
  background: var(--primary);
}

.loop-control input[type="checkbox"]:checked + .loop-indicator::after {
  transform: translate(1.2rem, -50%);
}

.eq-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.eq-label {
  font-weight: 600;
  margin-right: 0.25rem;
}

.eq-button {
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

.eq-button.is-active,
.eq-button[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.eq-button.is-active:disabled,
.eq-button[aria-pressed="true"]:disabled {
  opacity: 0.75;
}

.loop-control.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.loop-control input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.loop-control input[type="checkbox"]:disabled + .loop-indicator {
  opacity: 0.5;
}

.loop-control span:first-child {
  flex: 1;
}

.waveform {
  position: relative;
  margin-top: 1.25rem;
  border-radius: 0.9rem;
  background: rgba(74, 144, 226, 0.08);
  border: 1px solid rgba(74, 144, 226, 0.18);
  overflow: hidden;
  min-height: 160px;
}

.waveform canvas {
  width: 100%;
  height: 160px;
  display: block;
  cursor: pointer;
}

#waveformMessage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.9rem;
  color: rgba(31, 38, 51, 0.65);
  padding: 0 1rem;
  pointer-events: none;
}

.waveform.is-loading #waveformMessage {
  color: rgba(31, 38, 51, 0.85);
}

.waveform.has-data #waveformMessage {
  opacity: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(74, 144, 226, 0.14);
  color: var(--primary);
}

.badge.is-error {
  background: rgba(232, 93, 117, 0.2);
  color: #b91c1c;
}

.cloud-sync {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 0.9rem;
  background: rgba(74, 144, 226, 0.08);
  border: 1px solid rgba(74, 144, 226, 0.2);
  display: grid;
  gap: 0.65rem;
}

/* Barra de progreso Dropbox */
.progress { 
  height: 6px; 
  border-radius: 999px; 
  background: rgba(74, 144, 226, 0.18);
  overflow: hidden;
  margin: 0.35rem 0 0.6rem 0;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(74, 144, 226, 0.9), rgba(88, 86, 214, 0.85));
  transition: width 0.25s ease;
}

.cloud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.cloud-header h3 {
  margin: 0;
  font-size: 1rem;
}

.cloud-hint {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(31, 38, 51, 0.7);
}

.cloud-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cloud-actions button {
  flex: none;
}

.cloud-sync button + button {
  margin-left: 0;
}

.cloud-actions button.ghost {
  border-color: rgba(74, 144, 226, 0.35);
}

/* Alinear estilo del botón de borrar copias locales con el resto de botones cloud */
#clearLocalCopies.ghost {
  border-color: rgba(74, 144, 226, 0.35);
}

.cloud-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.9rem;
  user-select: none;
}

.cloud-sync.is-syncing {
  border-style: dashed;
}

.cloud-sync.is-error {
  border-color: #e85d75;
  background: rgba(232, 93, 117, 0.1);
}

.storage-stats {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: rgba(31, 38, 51, 0.8);
}

footer {
  margin: auto 0 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: rgba(31, 38, 51, 0.6);
  padding: 0 1rem;
}

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

  .track {
    grid-template-columns: 1.5rem auto 1fr;
    grid-template-rows: auto auto;
  }

  .track-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: rgba(15, 23, 42, 0.85);
    --text: #f8fafc;
    --border: rgba(148, 163, 184, 0.4);
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.6);
  }

  .card {
    background: rgba(15, 23, 42, 0.85);
  }

  .hint {
    color: rgba(248, 250, 252, 0.7);
  }

  .track {
    background: rgba(30, 41, 59, 0.8);
  }

  .track.is-remote:not(.is-playing) {
    background: rgba(74, 144, 226, 0.16);
    border-color: rgba(148, 163, 184, 0.35);
  }

  .search-result {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(148, 163, 184, 0.35);
  }

  .result-meta {
    color: rgba(226, 232, 240, 0.7);
  }

  .loop-indicator {
    background: rgba(148, 163, 184, 0.35);
  }

  .loop-control input[type="checkbox"]:checked + .loop-indicator {
    background: rgba(74, 144, 226, 0.75);
  }

  .cloud-sync {
    background: rgba(37, 54, 92, 0.55);
    border-color: rgba(148, 163, 184, 0.35);
  }

  .waveform {
    background: rgba(37, 54, 92, 0.55);
    border-color: rgba(148, 163, 184, 0.35);
  }

  #waveformMessage {
    color: rgba(226, 232, 240, 0.65);
  }

  .time-display { color: var(--text); }

  .cloud-hint {
    color: rgba(226, 232, 240, 0.7);
  }

  .badge {
    background: rgba(74, 144, 226, 0.2);
    color: #dbeafe;
  }

  .badge.is-error {
    background: rgba(248, 113, 113, 0.25);
    color: #fecaca;
  }

  footer {
    color: rgba(248, 250, 252, 0.6);
  }
}

/* Explicit theme overrides via attribute */
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --card: rgba(255, 255, 255, 0.9);
  --text: #1f2633;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 10px 30px rgba(31, 38, 51, 0.12);
}

html[data-theme="light"] .card { background: var(--card); }
html[data-theme="light"] .hint { color: rgba(31, 38, 51, 0.7); }
html[data-theme="light"] .track { background: rgba(255, 255, 255, 0.85); }
html[data-theme="light"] .track.is-remote:not(.is-playing) {
  background: rgba(74, 144, 226, 0.12);
  border-color: rgba(74, 144, 226, 0.15);
}
html[data-theme="light"] .loop-indicator { background: rgba(31, 38, 51, 0.28); }
html[data-theme="light"] .loop-control input[type="checkbox"]:checked + .loop-indicator { background: var(--primary); }
html[data-theme="light"] .cloud-sync { background: rgba(74, 144, 226, 0.08); border-color: rgba(74, 144, 226, 0.2); }
html[data-theme="light"] .waveform { background: rgba(74, 144, 226, 0.08); border-color: rgba(74, 144, 226, 0.18); }
html[data-theme="light"] #waveformMessage { color: rgba(31, 38, 51, 0.65); }
html[data-theme="light"] .cloud-hint { color: rgba(31, 38, 51, 0.7); }
html[data-theme="light"] .badge { background: rgba(74, 144, 226, 0.14); color: var(--primary); }
html[data-theme="light"] .badge.is-error { background: rgba(232, 93, 117, 0.2); color: #b91c1c; }
html[data-theme="light"] footer { color: rgba(31, 38, 51, 0.6); }

:root[data-theme="dark"] {
  --bg: #0f172a;
  --card: rgba(15, 23, 42, 0.85);
  --text: #f8fafc;
  --border: rgba(148, 163, 184, 0.4);
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.6);
}

html[data-theme="dark"] .card { background: rgba(15, 23, 42, 0.85); }
html[data-theme="dark"] .hint { color: rgba(248, 250, 252, 0.7); }
html[data-theme="dark"] .track { background: rgba(30, 41, 59, 0.8); }
html[data-theme="dark"] .track.is-remote:not(.is-playing) {
  background: rgba(74, 144, 226, 0.16);
  border-color: rgba(148, 163, 184, 0.35);
}

html[data-theme="dark"] .search-result {
  background: rgba(30, 41, 59, 0.7);
  border-color: rgba(148, 163, 184, 0.35);
}

html[data-theme="dark"] .result-meta {
  color: rgba(226, 232, 240, 0.7);
}
html[data-theme="dark"] .track-title span {
  color: rgba(226, 232, 240, 0.7);
}
html[data-theme="dark"] .track-meta {
  color: rgba(226, 232, 240, 0.7);
}
html[data-theme="dark"] .loop-indicator { background: rgba(148, 163, 184, 0.35); }
html[data-theme="dark"] .loop-control input[type="checkbox"]:checked + .loop-indicator { background: rgba(74, 144, 226, 0.75); }
html[data-theme="dark"] .cloud-sync { background: rgba(37, 54, 92, 0.55); border-color: rgba(148, 163, 184, 0.35); }
html[data-theme="dark"] .waveform { background: rgba(37, 54, 92, 0.55); border-color: rgba(148, 163, 184, 0.35); }
html[data-theme="dark"] #waveformMessage { color: rgba(226, 232, 240, 0.65); }
html[data-theme="dark"] .cloud-hint { color: rgba(226, 232, 240, 0.7); }
html[data-theme="dark"] .badge { background: rgba(74, 144, 226, 0.2); color: #dbeafe; }
html[data-theme="dark"] .badge.is-error { background: rgba(248, 113, 113, 0.25); color: #fecaca; }
html[data-theme="dark"] footer { color: rgba(248, 250, 252, 0.6); }
