* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0b0b0f;
  --bg-2: #15151c;
  --bg-3: #1d1d27;
  --bg-4: #292935;
  --fg: #f4f4f8;
  --muted: #8a8a99;
  --accent: #1db954;
  --accent-2: #1ed760;
  --danger: #e91429;
  --radius: 12px;
}
html, body {
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
#app { height: 100%; width: 100%; }
.hidden { display: none !important; }
/* Rendered but invisible: iOS Safari refuses to open the picker when .click()
   is called on a display:none file input, so keep it in the layout instead. */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
  opacity: 0;
}
.view { height: 100%; width: 100%; display: flex; flex-direction: column; }
button { cursor: pointer; border: none; background: none; color: inherit; font-family: inherit; }
input, select { font-family: inherit; outline: none; }

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

/* Login */
#loginView { align-items: center; justify-content: center; background: linear-gradient(135deg, #0b0b0f 0%, #15151c 100%); }
.login-card { background: var(--bg-2); padding: 40px; border-radius: 16px; width: 90%; max-width: 400px; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 24px; }
.logo img { width: 48px; height: 48px; }
.logo h1 { color: var(--accent); font-size: 32px; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; background: var(--bg-3); padding: 4px; border-radius: 8px; }
.tab-btn { flex: 1; padding: 10px; border-radius: 6px; color: var(--muted); font-weight: 600; transition: background 0.2s, color 0.2s; }
.tab-btn.active { background: var(--bg); color: var(--fg); }
.form-section { display: flex; flex-direction: column; gap: 12px; }
.login-card p { color: var(--muted); margin-bottom: 20px; font-size: 14px; }
.login-card input { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid var(--bg-3); background: var(--bg); color: var(--fg); margin-bottom: 12px; font-size: 15px; }
.login-card input:focus { border-color: var(--accent); }
.btn-primary { width: 100%; padding: 14px; border-radius: 8px; background: var(--accent); color: #000; font-weight: 700; font-size: 16px; }
.btn-primary:hover { background: var(--accent-2); }

/* Login Instructions Box */
.hint-box {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg-3);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  line-height: 1.6;
  max-height: 240px;
  overflow-y: auto;
}
.hint-box strong { color: var(--fg); }
.hint-box code { background: var(--bg); padding: 2px 4px; border-radius: 4px; font-size: 11px; }

.hint { color: var(--muted); font-size: 12px; margin-top: 12px; line-height: 1.5; }
.hint code { background: var(--bg-3); padding: 2px 6px; border-radius: 4px; font-size: 11px; }

/* Main Layout */
#mainView { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 16px; background: var(--bg); border-bottom: 1px solid var(--bg-3); flex-wrap: wrap; flex-shrink: 0; }
.topbar .search-box { flex: 1; min-width: 200px; }
.topbar .search-box input { width: 100%; padding: 10px 14px; border-radius: 20px; background: var(--bg-2); border: 1px solid var(--bg-3); color: var(--fg); }
.nav { display: flex; gap: 8px; overflow-x: auto; }
.nav button { padding: 8px 16px; border-radius: 20px; color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }
.nav button.active { background: var(--bg-3); color: var(--fg); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions select { padding: 8px; border-radius: 6px; border: 1px solid var(--bg-3); background: var(--bg-2); color: var(--fg); }

.content { flex: 1; overflow-y: auto; padding: 24px 16px 140px 16px; -webkit-overflow-scrolling: touch; }
.content h2 { font-size: 24px; margin-bottom: 24px; }
.content h3 { font-size: 18px; margin-bottom: 16px; color: var(--fg); }

/* Sub Navigation (Search Tabs) */
.sub-nav { 
  display: flex; gap: 16px; margin: -24px -16px 24px -16px; 
  padding: 0 16px; background: var(--bg); 
  border-bottom: 1px solid var(--bg-3); position: -webkit-sticky; position: sticky; top: 0; z-index: 10; 
}
.sub-nav button { 
  background: transparent; color: var(--muted); padding: 16px 8px; 
  border-bottom: 2px solid transparent; font-weight: 600; font-size: 15px; border-radius: 0; 
}
.sub-nav button.active { color: var(--fg); border-bottom-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 24px; padding-bottom: 32px; width: 100%; }
.card { background: var(--bg-2); padding: 16px; border-radius: 8px; cursor: pointer; transition: background 0.2s; }
.card:hover { background: var(--bg-3); }
.card img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 6px; margin-bottom: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.card .title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .subtitle { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-gap { margin-top: 40px; }

.list { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.list-row { display: grid; grid-template-columns: 48px 1fr auto auto auto auto; gap: 12px; padding: 8px; border-radius: 6px; align-items: center; cursor: pointer; }
.list-row:hover { background: var(--bg-2); }
.list-row img { width: 48px; height: 48px; border-radius: 4px; object-fit: cover; }
.list-row .info { overflow: hidden; }
.list-row .info .t { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .info .s { font-size: 13px; color: var(--muted); margin-top: 4px; }
.list-row .dur { color: var(--muted); font-size: 13px; }
.list-row.active { background: var(--bg-3); }
.list-row.active .t { color: var(--accent); }

/* Action Buttons (Fav & Add to PL) */
.action-btn {
    background: transparent;
    border: 1px solid var(--bg-4);
    color: var(--muted);
    width: 28px; height: 28px;
    border-radius: 50%;
    font-size: 14px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.action-btn:hover { color: var(--fg); border-color: var(--fg); }
.fav-btn.active { color: var(--danger); border-color: var(--danger); background: rgba(233, 20, 41, 0.1); }
.add-pl-btn { font-size: 12px; }

/* Standout Colors for Shuffle/Repeat */
.player-controls .btn-icon.active, .np-controls .btn-icon.active { 
    color: var(--accent-2); 
    background: rgba(29, 185, 84, 0.2); 
    border: 1px solid var(--accent); 
}

/* Playlist Modal */
.create-pl { display: flex; gap: 8px; margin-bottom: 16px; }
.create-pl input { flex: 1; padding: 10px; border-radius: 6px; background: var(--bg-3); border: 1px solid var(--bg-4); color: var(--fg); }
.create-pl .btn-primary { width: auto; padding: 10px 16px; font-size: 14px; }
.pl-item { 
    display: block; width: 100%; text-align: left; 
    padding: 12px; margin-bottom: 8px; 
    background: var(--bg-3); color: var(--fg); 
    border-radius: 6px; font-weight: 600; 
}
.pl-item:hover { background: var(--bg-4); }

/* Album/Playlist View */
.album-view { display: flex; flex-direction: column; gap: 32px; width: 100%; }
.album-header { display: flex; gap: 24px; align-items: flex-end; padding: 16px 0; }
.album-header img { width: 200px; height: 200px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); object-fit: cover; flex-shrink: 0; }
.album-meta { min-width: 0; }
.album-meta h1 { font-size: 32px; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-meta p { font-size: 16px; color: var(--muted); }
.album-play-btn { margin-top: 16px; padding: 12px 32px; background: var(--accent); color: #000; border-radius: 24px; font-weight: 700; font-size: 16px; }
.album-play-btn:hover { background: var(--accent-2); }
.playlist-actions { display: flex; gap: 12px; margin-top: 16px; }
.playlist-actions .shuffle-btn { background: var(--bg-3); color: var(--fg); }

/* Player */
.player { 
  background: var(--bg-2); 
  border-top: 1px solid var(--bg-3);
  display: flex; justify-content: space-between; align-items: center; 
  padding: 12px 16px; gap: 16px; height: 80px; flex-shrink: 0; 
}
.player-track { display: flex; gap: 12px; align-items: center; width: 30%; min-width: 150px; cursor: pointer; }
.player-track img { width: 48px; height: 48px; border-radius: 4px; object-fit: cover; }
.player-meta { overflow: hidden; }
.player-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-artist { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.player-center { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; }
.player-controls { display: flex; gap: 16px; align-items: center; }
.btn-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.btn-icon:hover { color: var(--fg); background: var(--bg-3); }
.btn-play { width: 40px; height: 40px; border-radius: 50%; background: var(--fg); color: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.btn-play:hover { transform: scale(1.08); background: var(--accent-2); }
.player-controls .btn-icon.active { color: var(--accent); }
.player-progress { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 500px; }
.time-label { font-size: 11px; color: var(--muted); min-width: 35px; text-align: center; }

.player-extras { display: flex; gap: 8px; align-items: center; justify-content: flex-end; width: 30%; min-width: 150px; }
.player-extras input[type=range] { width: 80px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--bg-4); border-radius: 2px; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 12px; height: 12px; background: var(--fg); border-radius: 50%; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; background: var(--fg); border-radius: 50%; border: none; }

/* Read-only Progress Bar */
.progress-bar-bg {
  flex: 1;
  height: 4px;
  background: var(--bg-4);
  border-radius: 2px;
  overflow: hidden;
  cursor: default;
}
.progress-bar-bg.large { height: 6px; }
.progress-bar-fill {
  height: 100%;
  background: var(--fg);
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s linear;
}
.np-progress { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 8px; }

/* Now Playing Screen */
.now-playing { 
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
  background: var(--bg-2); z-index: 200; display: flex; flex-direction: column; 
  animation: slideUp 0.3s ease; 
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.np-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; color: var(--muted); }
.np-header span { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.np-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 32px; }
.np-body img { width: min(80vw, 350px); height: min(80vw, 350px); object-fit: cover; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.np-meta { text-align: center; width: 100%; }
.np-meta h2 { font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-meta p { font-size: 16px; color: var(--muted); margin-top: 4px; }
.np-time-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.np-controls { display: flex; align-items: center; gap: 24px; }
.np-controls .btn-icon { width: 48px; height: 48px; font-size: 24px; }
.np-controls .btn-play { width: 64px; height: 64px; font-size: 24px; }

/* Now Playing Actions */
.np-actions { display: flex; gap: 24px; margin-top: 16px; }
.np-action-btn {
    background: transparent;
    border: 1px solid var(--bg-4);
    color: var(--muted);
    width: 48px; height: 48px;
    border-radius: 50%;
    font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.np-action-btn:hover { color: var(--fg); border-color: var(--fg); }
.np-action-btn.active { color: var(--danger); border-color: var(--danger); background: rgba(233, 20, 41, 0.1); }

/* Overlays */
#overlayContainer { position: fixed; inset: 0; pointer-events: none; z-index: 150; }
.overlay { position: absolute; bottom: 90px; right: 16px; width: 320px; max-height: 60vh; background: var(--bg-2); border: 1px solid var(--bg-3); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; overflow: hidden; pointer-events: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.overlay-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.overlay-head h3 { font-size: 18px; }
.overlay-body { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.lyrics-body .line { padding: 8px 0; font-size: 16px; color: var(--muted); text-align: center; }
.lyrics-body .line.active { color: var(--accent); font-weight: 700; }
.eq-body select { padding: 8px; border-radius: 6px; background: var(--bg-3); border: 1px solid var(--bg-4); color: var(--fg); }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.sleep-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sleep-presets button { padding: 10px; border-radius: 6px; background: var(--bg-3); color: var(--fg); font-weight: 600; }
.sleep-presets button:hover { background: var(--accent); color: #000; }
.btn-danger { padding: 10px; border-radius: 6px; background: rgba(233, 20, 41, 0.2); color: var(--danger); font-weight: 600; }

/* Mobile Responsive */
@media (max-width: 768px) {
  .topbar { padding: 12px; gap: 12px; }
  .content { padding: 16px 12px 140px 12px; -webkit-overflow-scrolling: touch; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
  
  .player { 
    height: auto; 
    flex-wrap: wrap; 
    justify-content: space-between;
    padding: 8px 12px; 
    padding-bottom: calc(8px + env(safe-area-inset-bottom)); 
    gap: 6px;
  }
  .player-track { width: 60%; }
  .player-track img { width: 44px; height: 44px; }
  .player-center { 
    width: 40%; 
    flex-direction: row; 
    justify-content: flex-end;
    gap: 12px;
  }
  .player-controls { gap: 12px; }
  .player-progress { 
    display: flex; 
    width: 100%; 
    max-width: 100%; 
    order: 3; 
  }
  .btn-icon { width: 32px; height: 32px; font-size: 16px; }
  .btn-play { width: 36px; height: 36px; font-size: 14px; }
  
  .player-extras { display: none; }
  
  .overlay { 
    width: calc(100% - 24px); 
    right: 12px; 
    left: 12px; 
    bottom: calc(100px + env(safe-area-inset-bottom)); 
  }
  .album-header { flex-direction: column; align-items: center; text-align: center; }
}
/* ---------- Batch ZIP downloads & CSV import ---------- */
.playlist-actions .zip-btn,
.playlist-actions .pl-btn { background: var(--bg-3); color: var(--fg); font-size: 14px; }
.playlist-actions .zip-btn:hover,
.playlist-actions .pl-btn:hover { background: var(--bg-2); }
.csv-btn { width: auto; padding: 0 10px; font-size: 11px; font-weight: 700; }
.import-report h4 { margin: 18px 0 8px; font-size: 14px; }
.import-report .report-pl { padding: 8px 0; font-size: 14px; border-bottom: 1px solid var(--bg-3); }
.import-report .report-pl a { color: var(--accent); }
.import-report .report-skip { padding: 6px 0; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--bg-3); line-height: 1.5; }
.import-report .report-skip .r-title { color: var(--fg); }
.import-report .report-skip em { color: var(--muted); }
