:root {
  --bg: #050608;
  --bg-elevated: #111318;
  --bg-soft: #181b21;
  --accent: #1db954;
  --accent-soft: rgba(29, 185, 84, 0.2);
  --accent-strong: #1ed760;
  --text: #f5f7fb;
  --text-soft: #9da3b4;
  --border-subtle: #23252e;
  --danger: #ff4b5c;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 18px 60px rgba(0, 0, 0, 0.6);

  --spacing-xs: 6px;
  --spacing-sm: 10px;
  --spacing-md: 14px;
  --spacing-lg: 18px;
  --spacing-xl: 22px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at top, #141620 0, #050608 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  position: relative;
  width: 100%;
  height: 100vh;
  max-width: 480px;
  background: transparent;
  overflow: hidden;
}

/* TOP BAR */

.top-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-lg);
  gap: var(--spacing-md);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 20%, #56ff91, var(--accent));
  box-shadow: 0 0 0 2px rgba(8, 11, 16, 0.9), 0 12px 24px rgba(0, 0, 0, 0.7);
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.05em;
  font-size: 0.86rem;
  text-transform: uppercase;
  color: var(--text-soft);
}

.icon-button {
  border: none;
  background: rgba(9, 12, 18, 0.92);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.65);
}

.icon-button:active {
  transform: translateY(1px) scale(0.98);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: linear-gradient(135deg, #242735, #40465e);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ICONS */

.icon {
  position: relative;
  display: inline-block;
}

.icon-search {
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-soft);
  border-radius: 999px;
}

.icon-search::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 2px;
  border-radius: 999px;
  background: var(--text-soft);
  transform: rotate(45deg);
  right: -3px;
  bottom: -1px;
}

.icon-play,
.icon-pause {
  width: 0;
  height: 0;
}

.icon-play {
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent #050608;
  margin-left: 2px;
}

.icon-pause {
  width: 12px;
  height: 12px;
  box-shadow: inset 0 0 0 3px #050608;
  border-radius: 3px;
}

.icon-prev,
.icon-next {
  width: 14px;
  height: 12px;
}

.icon-prev::before,
.icon-prev::after,
.icon-next::before,
.icon-next::after {
  content: "";
  position: absolute;
  border-style: solid;
  border-width: 6px 0 6px 9px;
  border-color: transparent transparent transparent var(--text-soft);
}

.icon-prev::before {
  left: -6px;
}

.icon-prev::after {
  right: -2px;
}

.icon-next::before {
  right: -2px;
}

.icon-next::after {
  left: -6px;
}

.icon-close {
  width: 10px;
  height: 10px;
}

.icon-close::before,
.icon-close::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 2px;
  border-radius: 999px;
  background: var(--text-soft);
}

.icon-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}
.icon-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* MAIN */

.main {
  position: absolute;
  inset: 56px 0 72px 0;
  padding: 0 var(--spacing-lg) var(--spacing-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.section-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: var(--spacing-lg);
}

.section-title {
  display: none;
}

.section-subtitle {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-soft);
}

/* SEARCH BAR */

.search-bar {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.search-field {
  flex: 1;
}

.search-field input,
.search-field select {
  width: 100%;
  font: inherit;
  font-size: 0.8rem;
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(4, 7, 11, 0.96);
  color: var(--text);
  appearance: none;
}

/* ALBUM GRID */

.albums {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--spacing-md);
  padding-bottom: 64px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 12px;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.empty-title {
  font-size: 0.96rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.empty-subtitle {
  font-size: 0.78rem;
  opacity: 0.9;
}

.album-card {
  background: radial-gradient(circle at top, #262a36 0, #141620 40%, #0a0c10 100%);
  border-radius: var(--radius-lg);
  padding: var(--spacing-sm);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  position: relative;
  overflow: hidden;
}

.album-cover {
  width: 100%;
  border-radius: var(--radius-md);
  aspect-ratio: 1 / 1;
  background: linear-gradient(145deg, #33384b, #171924);
  position: relative;
  overflow: hidden;
}

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

.album-meta {
  padding: var(--spacing-sm) var(--spacing-xs) var(--spacing-xs);
}

.album-title {
  font-size: 0.94rem;
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-artist {
  font-size: 0.76rem;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-chip {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(5, 7, 11, 0.96);
  color: var(--accent-strong);
  font-size: 0.7rem;
}

.album-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.album-spotify-badge {
  margin-top: 4px;
  margin-left: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #1db954;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.album-spotify-badge:hover {
  background: #1ed760;
  transform: scale(1.05);
}

/* FAB */

.fab {
  position: absolute;
  right: 18px;
  bottom: 84px;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: radial-gradient(circle at 30% 20%, #56ff91, var(--accent));
  color: #050608;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: translateY(1px) scale(0.98);
}

.fab-icon {
  font-size: 1.7rem;
  font-weight: 400;
}

/* PLAYER */

.player {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 62px;
  background: linear-gradient(135deg, #111318, #181b21 60%, #14151b 100%);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.02);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.8);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.player-cover {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: linear-gradient(135deg, #262a36, #111318);
  overflow: hidden;
}

.player-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.player-title {
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-meta {
  font-size: 0.72rem;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.play-button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

/* SHEET (ALBUM DETAIL) */

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 88%;
  max-height: 88%;
  background: radial-gradient(circle at top, #202331 0, #07090d 55%);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.85);
  padding: 6px 16px 84px;
  display: flex;
  flex-direction: column;
  transition: transform 260ms cubic-bezier(0.22, 0.61, 0.36, 1);
  transform: translateY(100%);
  z-index: 20;
}

.sheet[aria-hidden="false"] {
  transform: translateY(0);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  align-self: center;
  margin: 4px 0 10px;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet-cover {
  width: 70px;
  height: 70px;
  border-radius: 16px;
  background: linear-gradient(135deg, #33384b, #171924);
  overflow: hidden;
}

.sheet-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sheet-text {
  flex: 1;
  min-width: 0;
}

.sheet-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-body {
  flex: 1;
  overflow: auto;
  padding: 6px 0 0;
}

/* TRACK LIST */

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

.track-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 12px;
}

.track-item + .track-item {
  margin-top: 4px;
}

.track-item.active {
  background: rgba(29, 185, 84, 0.12);
}

.track-index {
  width: 18px;
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.track-main {
  flex: 1;
  min-width: 0;
}

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

.track-meta {
  font-size: 0.7rem;
  color: var(--text-soft);
}

.track-play {
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.track-play:hover {
  background: var(--accent);
  transform: scale(1.1);
}

.track-item.active .track-play {
  background: var(--accent);
}

.track-action-btn {
  background: transparent;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.5;
  line-height: 1;
}

.track-action-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.15);
}

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

.track-like {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* MODAL */

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease-out;
  z-index: 15;
}

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

#confirmModal[aria-hidden="true"],
#confirmBackdrop:not(.visible),
#playlistModal[aria-hidden="true"],
#playlistBackdrop:not(.visible),
#selectPlaylistModal[aria-hidden="true"],
#selectPlaylistBackdrop:not(.visible),
#confirmDeleteModal[aria-hidden="true"],
#confirmDeleteBackdrop:not(.visible),
#shareModal[aria-hidden="true"],
#shareBackdrop:not(.visible),
#infoModal[aria-hidden="true"],
#infoBackdrop:not(.visible) {
  display: none;
}

/* Share backdrop encima del sheet pero debajo del modal */
#shareBackdrop {
  z-index: 25;
  background: rgba(0, 0, 0, 0.88);
}

#shareModal {
  z-index: 30;
}

/* Todos los backdrops secundarios deben estar por encima del sheet (z-index: 20) */
#confirmBackdrop,
#playlistBackdrop,
#selectPlaylistBackdrop,
#confirmDeleteBackdrop,
#infoBackdrop {
  z-index: 25;
  background: rgba(0, 0, 0, 0.88);
}

#confirmModal,
#playlistModal,
#selectPlaylistModal,
#confirmDeleteModal,
#infoModal {
  z-index: 30;
}

.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  pointer-events: none;
  z-index: 30;
}

.modal[aria-hidden="false"] {
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: linear-gradient(145deg, #10131a, #161925);
  border-radius: 18px;
  padding: 14px 16px 10px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.9);
  transform: translateY(16px);
  opacity: 0;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

.modal[aria-hidden="false"] .modal-card {
  opacity: 1;
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.02rem;
}

.modal-form {
  margin: 0;
}

.field-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-small {
  max-width: 96px;
}

label {
  font-size: 0.74rem;
  color: var(--text-soft);
}

input[type="text"],
input[type="number"],
input[type="file"] {
  font: inherit;
  font-size: 0.86rem;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: rgba(4, 7, 11, 0.96);
  color: var(--text);
}

input[type="file"] {
  padding: 6px 6px;
  font-size: 0.78rem;
}

.field-help {
  margin-top: 2px;
  font-size: 0.7rem;
  color: var(--text-soft);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

#backToAlbumsBtn {
  background: rgba(255,255,255,0.07);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 9px 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  letter-spacing: 0.01em;
}

#backToAlbumsBtn:hover {
  background: rgba(255,255,255,0.13);
  border-color: rgba(255,255,255,0.25);
  transform: translateX(-2px);
}

.button {
  font: inherit;
  font-size: 0.84rem;
  border-radius: 999px;
  padding: 7px 14px;
  border: none;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  color: #050608;
}

.button.ghost {
  background: transparent;
  color: var(--text-soft);
}

.spotify-button {
  padding: 6px 12px;
  font-size: 0.76rem;
  white-space: nowrap;
  background: #1db954;
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.spotify-button:hover {
  background: #1ed760;
  transform: scale(1.05);
}

/* FAVORITOS */

.favorite-album-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.favorite-album-card .album-cover {
  display: none;
}

.favorite-album-info h3 {
  font-size: 1.2rem;
  margin-bottom: 6px;
  font-weight: 600;
}

.favorite-album-info p {
  font-size: 0.9rem;
  color: var(--text-soft);
  margin-bottom: 16px;
}

.favorite-tracks-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.favorite-track-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.favorite-track-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.favorite-track-item span:first-child {
  font-size: 0.75rem;
  opacity: 0.5;
  width: 20px;
  text-align: center;
}

.favorite-track-item span:nth-child(2) {
  flex: 1;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* RESPONSIVE */

@media (min-width: 420px) {
  .albums {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
