:root {
  --bg: #121212;
  --bg-2: #181818;
  --bg-3: #242424;
  --text: #f5f5f5;
  --muted: #a7a7a7;
  --accent: #1db954;
  --accent-dark: #169c46;
  --danger: #f15e6c;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1e3a2f 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(18, 18, 18, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #222;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }

.user-area { display: flex; align-items: center; gap: 12px; }

.scope-warning {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: #3a2d12;
  border-bottom: 1px solid #55451c;
  color: #ffd479;
  font-size: 14px;
  text-align: center;
}
.btn-small { padding: 5px 14px; font-size: 12px; }

.user-info { display: flex; align-items: center; gap: 10px; }
.user-info img {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--accent);
}

/* ---------- buttons ---------- */

.btn {
  border: 0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  padding: 8px 18px;
  transition: transform 0.12s ease, background 0.12s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: wait; }

.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: #1ed760; }

.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid #444;
}
.btn-ghost:hover { border-color: #888; background: var(--bg-3); }

.btn-playlist {
  position: absolute;
  right: 10px; bottom: 10px;
  background: var(--accent);
  color: #000;
  padding: 8px 14px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.card:hover .btn-playlist, .track-row:hover .btn-playlist { opacity: 1; transform: translateY(0); }
.btn-playlist:hover { background: #1ed760; }

.btn-tiny { padding: 4px 10px; font-size: 14px; }

/* ---------- main / search ---------- */

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 80px; }

.search-section { display: flex; align-items: center; gap: 14px; }

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid #333;
  border-radius: 999px;
  padding: 0 18px;
  height: 52px;
  color: var(--muted);
  transition: border-color 0.15s ease;
}
.search-box:focus-within { border-color: var(--accent); color: var(--text); }

.search-box input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--muted); }

.clear-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 15px;
}
.clear-btn:hover { color: var(--text); }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- welcome ---------- */

.welcome { text-align: center; padding: 70px 0 40px; }
.welcome h2 { font-size: 34px; margin: 0 0 12px; letter-spacing: -0.03em; }
.welcome p { color: var(--muted); max-width: 520px; margin: 0 auto; line-height: 1.6; }
.welcome em { color: var(--text); font-style: normal; background: var(--bg-3); padding: 1px 6px; border-radius: 6px; }

/* ---------- results ---------- */

.section { margin-bottom: 36px; }
.section h2 {
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 16px;
}

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

.card {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 14px;
  transition: background 0.15s ease, transform 0.15s ease;
}
.card:hover { background: var(--bg-3); transform: translateY(-2px); }
.album-card, .track-row { cursor: pointer; }

.cover {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #2a2a2a;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  margin-bottom: 12px;
}
.cover.round { border-radius: 50%; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .no-cover {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #555;
}

.meta .name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* track rows */

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-2);
  border-radius: 10px;
  padding: 8px 14px;
  margin-bottom: 8px;
  transition: background 0.15s ease;
}
.row:hover { background: var(--bg-3); }

.track-row .cover {
  width: 48px; height: 48px;
  flex-shrink: 0;
  margin: 0;
  border-radius: 6px;
}
.track-row .btn-playlist { right: 6px; bottom: 6px; }

.grow { flex: 1; min-width: 0; }
.dur { color: var(--muted); font-size: 13px; flex-shrink: 0; }

/* ---------- error / toast ---------- */

.error {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 16px;
}

.login-prompt {
  text-align: center;
  padding: 70px 0;
}
.login-prompt p {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2e2e2e;
  border: 1px solid #444;
  border-left: 4px solid var(--accent);
  color: var(--text);
  padding: 14px 20px;
  border-radius: 10px;
  max-width: min(560px, 90vw);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  z-index: 100;
}
.toast.error { border-left-color: var(--danger); }
.toast a { color: var(--accent); font-weight: 600; }

/* ---------- album modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(3px);
}
.modal-card {
  position: relative;
  width: min(720px, 94vw);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: #1c1c1c;
  border: 1px solid #2c2c2c;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.15); }

#modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.modal-loading { padding: 80px 0; text-align: center; color: var(--muted); }

.modal-head {
  display: flex;
  gap: 22px;
  padding: 28px 28px 22px;
  background: linear-gradient(180deg, rgba(30, 80, 60, 0.35), transparent);
  flex-shrink: 0;
}
.modal-cover {
  width: 160px;
  height: 160px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  background: #2a2a2a;
}
.modal-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-cover .no-cover {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 52px; color: #555;
}

.modal-info { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.modal-kicker { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.modal-title { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; }
.modal-sub { color: var(--muted); font-size: 14px; }
.btn-modal-playlist { margin-top: 12px; align-self: flex-start; }

.track-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-track {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.modal-track:hover { background: var(--bg-3); }
.modal-track.unplayable { opacity: 0.45; }
.track-num {
  width: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
}
.track-play {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #000;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.track-play:hover { background: #1ed760; }
.track-play.playing { background: #fff; }
.track-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.explicit {
  font-size: 9px;
  font-weight: 700;
  background: #555;
  color: #fff;
  border-radius: 3px;
  padding: 1px 4px;
  vertical-align: 1px;
}
.track-dur { color: var(--muted); font-size: 13px; flex-shrink: 0; }

.modal-footer { padding: 12px 28px 20px; text-align: right; flex-shrink: 0; }
.modal-footer .btn { text-decoration: none; display: inline-block; }

@media (max-width: 600px) {
  .modal-head { flex-direction: column; align-items: center; text-align: center; padding: 20px 16px 14px; }
  .modal-cover { width: 110px; height: 110px; }
  .modal-title { font-size: 22px; }
  .btn-modal-playlist { align-self: center; font-size: 13px; }
  .modal-footer { text-align: center; }
}

@media (max-width: 600px) {
  main { padding: 20px 14px 60px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
