/* =====================
   RESET & VARIABLES
   ===================== */
:root {
  --bg:         #121212;
  --surface:    #181818;
  --surface2:   #282828;
  --surface3:   #3e3e3e;
  --text:       #ffffff;
  --muted:      #b3b3b3;
  --dim:        #6a6a6a;
  --accent:     #1db954;
  --accent-h:   #1ed760;
  --border:     rgba(255,255,255,0.08);
  --radius:     8px;
  --radius-lg:  12px;
  --player-h:   90px;
  --seek-h:     20px;
  --tab-h:      44px;
  --header-h:   64px;
}

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

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.4;
  overflow: hidden;
  height: 100dvh;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input  { border: none; outline: none; background: none; color: inherit; font: inherit; }
img    { display: block; }
a      { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }

/* =====================
   LOGIN SCREEN
   ===================== */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}

.login-card {
  text-align: center;
  padding: 48px 40px;
  max-width: 380px;
  width: 100%;
}

.login-logo {
  color: var(--accent);
  margin-bottom: 20px;
}
.login-logo svg { margin: auto; }

.login-card h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.6;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  font-size: 14px;
  border-radius: 100px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.97); }

.hint {
  margin-top: 20px;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.8;
}
.hint code {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: monospace;
  word-break: break-all;
}

/* =====================
   MAIN APP LAYOUT
   ===================== */
#app {
  display: grid;
  grid-template-rows: var(--header-h) var(--tab-h) 1fr var(--player-h);
  height: 100dvh;
}

.hidden { display: none !important; }

/* =====================
   HEADER
   ===================== */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 10;
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: 100px;
  padding: 0 16px;
  height: 40px;
  transition: background 0.15s;
}
.search-wrap:focus-within { background: var(--surface3); }

.search-icon { color: var(--muted); flex-shrink: 0; }

#search-input {
  flex: 1;
  font-size: 14px;
  height: 100%;
}
#search-input::placeholder { color: var(--dim); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.header-pill:hover {
  color: var(--text);
  border-color: var(--surface3);
  background: var(--surface2);
}
.header-pill svg { color: var(--accent); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 13px;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* =====================
   TABS
   ===================== */
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 5;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 4px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--text);
  color: #000;
}

/* =====================
   MAIN / RESULTS
   ===================== */
.main {
  overflow-y: auto;
  padding: 20px;
}

#results { min-height: 100%; }

.result-section { margin-bottom: 32px; }

.section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title .count {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

/* Cards grid */
.artists-grid,
.albums-grid,
.playlists-grid,
.audiobooks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.card {
  cursor: pointer;
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  transition: background 0.15s, transform 0.15s;
}
.card:hover { background: var(--surface2); transform: translateY(-2px); }

.card-img {
  width: 100%;
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
  background-color: var(--surface2);
  border-radius: 4px;
  margin-bottom: 12px;
}
.card-img.circle { border-radius: 50%; }

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

/* Tracks list */
.tracks-grid { display: flex; flex-direction: column; gap: 2px; }

.track-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
}
.track-item:hover { background: var(--surface2); }
.track-item:hover .track-num { visibility: hidden; }

.track-num {
  font-size: 13px;
  color: var(--muted);
  min-width: 20px;
  text-align: right;
  flex-shrink: 0;
}
.track-art {
  width: 40px; height: 40px;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--surface2);
}
.track-info { flex: 1; min-width: 0; }
.track-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-artist {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.track-duration {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: 8px;
}

/* Empty / loading / error states */
.btn-more {
  display: block;
  margin: 24px auto 8px;
  padding: 10px 32px;
  border-radius: 100px;
  border: 1px solid var(--surface3);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-more:hover:not(:disabled) { color: var(--text); border-color: var(--muted); background: var(--surface2); }
.btn-more:disabled { opacity: 0.5; cursor: default; }

.empty-state, .loading-state, .error-state {
  text-align: center;
  color: var(--muted);
  padding: 64px 20px;
  font-size: 15px;
}
.empty-state h3 { font-size: 22px; color: var(--text); margin-bottom: 8px; }
.error-state   { color: #ff5c5c; }

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

/* =====================
   DETAIL PANEL
   ===================== */
.detail-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.detail-inner {
  position: relative;
  width: min(460px, 100%);
  background: #1a1a1a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -8px 0 32px rgba(0,0,0,0.5);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.detail-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 48px;
}
.detail-topbar .icon-btn { font-size: 14px; font-weight: 500; width: auto; padding: 0 8px; border-radius: 4px; }

.detail-content {
  overflow-y: auto;
  flex: 1;
}

/* Detail header layouts */
.detail-hero {
  position: relative;
  height: 220px;
  background-size: cover;
  background-position: center top;
  flex-shrink: 0;
}
.detail-hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.1) 0%, rgba(26,26,26,1) 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px;
}
.detail-hero-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.detail-hero-meta { font-size: 13px; color: var(--muted); }

.detail-row-header {
  display: flex;
  gap: 20px;
  padding: 20px 20px 16px;
  align-items: flex-start;
  flex-shrink: 0;
}
.detail-cover {
  width: 110px; height: 110px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface2);
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.detail-cover.circle { border-radius: 50%; }

.detail-meta-block { flex: 1; min-width: 0; }
.detail-type-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 6px;
}
.detail-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
}
.detail-meta { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 12px; }

.btn-play-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  font-size: 13px;
  border-radius: 100px;
  transition: background 0.15s, transform 0.1s;
}
.btn-play-all:hover  { background: var(--accent-h); }
.btn-play-all:active { transform: scale(0.96); }

.detail-section {
  padding: 0 16px 16px;
}
.detail-section h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 16px 0 8px;
}

.detail-description {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
  padding: 0 16px 16px;
}

/* nested albums grid inside detail */
.detail-albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.detail-albums-grid .card { padding: 8px; }

/* =====================
   PLAYER BAR
   ===================== */
.player {
  border-top: 1px solid var(--border);
  background: #0d0d0d;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 16px env(safe-area-inset-bottom) 16px;
  gap: 0;
}

.seek-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
}

.time-label {
  font-size: 11px;
  color: var(--dim);
  min-width: 32px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
#time-total { text-align: right; }

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.player-art {
  width: 44px; height: 44px;
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--surface2);
}

.player-info { min-width: 0; }
.player-track {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-artist {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--muted);
  transition: color 0.15s, background 0.15s;
}
.ctrl-btn:hover { color: var(--text); }
.ctrl-btn.dim   { color: var(--dim); }
.ctrl-btn.dim:hover { color: var(--muted); }

.ctrl-btn.active { color: var(--accent) !important; }

.play-btn {
  width: 40px; height: 40px;
  background: var(--text);
  color: #000;
  border-radius: 50%;
  transition: background 0.15s, transform 0.1s;
}
.play-btn:hover  { background: var(--muted); transform: scale(1.05); }
.play-btn:active { transform: scale(0.95); }

.volume-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 130px;
}
.vol-icon { color: var(--muted); flex-shrink: 0; }

/* =====================
   RANGE INPUTS (seek + volume)
   ===================== */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface3);
  cursor: pointer;
  position: relative;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0;
  transition: opacity 0.15s;
  cursor: grab;
}

input[type=range]:hover::-webkit-slider-thumb,
input[type=range]:active::-webkit-slider-thumb { opacity: 1; }
input[type=range]:active::-webkit-slider-thumb { cursor: grabbing; }

input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--text);
  opacity: 0;
  cursor: grab;
}

/* Filled track via CSS background — updated via JS */
#seek-bar   { background: linear-gradient(to right, var(--accent) 0%, var(--surface3) 0%); }
#volume-slider { background: linear-gradient(to right, var(--text) 80%, var(--surface3) 80%); }

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  bottom: calc(var(--player-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  pointer-events: none;
  animation: fadeUp 0.2s ease;
  white-space: nowrap;
}
.toast.error { background: #c0392b; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =====================
   RESPONSIVE
   ===================== */
@media (max-width: 600px) {
  .detail-inner { width: 100%; }
  .artists-grid, .albums-grid, .playlists-grid, .audiobooks-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .volume-wrap { display: none; }
  .controls { gap: 2px; }
  .now-playing { flex: none; max-width: 45%; }
}
