:root {
  --bg: #0e0f13;
  --bg2: #16181f;
  --bg3: #1e212b;
  --fg: #f2f4f8;
  --muted: #8a90a2;
  --accent: #ff6b3d;
  --accent2: #4d7cff;
  --line: #262a36;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Ensure the [hidden] attribute always wins over class display rules
   (e.g. .sheet-backdrop { display:flex }). */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; }

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: rgba(14,15,19,.9);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
#title {
  flex: 1; font-size: 18px; font-weight: 700; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: none; border: none; color: var(--fg);
  font-size: 22px; line-height: 1; padding: 6px 10px;
  border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--bg3); }
#backBtn { font-size: 30px; padding: 0 8px; }

/* Search */
#searchBar { padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
#searchInput {
  width: 100%; padding: 12px 14px; font-size: 16px;
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}

/* Main scroll area */
#view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: 160px;
}
.loading, .empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.section-title {
  padding: 18px 16px 6px; font-size: 13px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}

/* Rows */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:active { background: var(--bg2); }
.row .lead {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg3); font-size: 17px;
}
.row .body { flex: 1; min-width: 0; }
.row .name {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .sub {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .meta { font-size: 12px; color: var(--muted); flex: 0 0 auto; text-align: right; }
.row.playing .name { color: var(--accent); }
.row.folder .lead { background: #2a2410; color: #ffd479; }
.row.playlist .lead { background: #10243a; color: #79b8ff; }
.chev { color: var(--muted); font-size: 20px; }
.badge {
  font-size: 11px; color: var(--muted);
  background: var(--bg3); padding: 2px 8px; border-radius: 20px;
}

/* Player */
#player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(20,22,29,.96);
  backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(var(--safe-bot) + 10px);
}
#pAddBtn {
  position: absolute; top: 8px; right: 10px; z-index: 1;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg3); color: var(--accent); font-size: 24px;
  display: flex; align-items: center; justify-content: center;
}
#pAddBtn:active { background: #2a2f3d; }
#playerInfo { text-align: center; margin-bottom: 6px; padding: 0 44px; }
#pTitle { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pArtist { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#seek { width: 100%; margin: 2px 0 4px; accent-color: var(--accent); }
#playerRow { display: flex; align-items: center; gap: 12px; }
.time { font-size: 11px; color: var(--muted); width: 40px; text-align: center; font-variant-numeric: tabular-nums; }
.controls { flex: 1; display: flex; align-items: center; justify-content: center; gap: 20px; }
.icon-btn.big {
  font-size: 24px; width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.icon-btn.big:active { filter: brightness(.9); }

/* Add-to-playlist button on track rows */
.row .add-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg3); color: var(--accent); border: none;
  font-size: 20px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.row .add-btn:active { background: #2a2f3d; }
.row .del-btn { color: #ff5b5b; }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5); display: flex; align-items: flex-end;
}
.sheet {
  width: 100%; background: var(--bg2);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(var(--safe-bot) + 16px);
  max-height: 75vh; overflow-y: auto;
  border-top: 1px solid var(--line);
}
.sheet-title { font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; text-align: center; }
.sheet-list .sheet-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 8px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 16px;
}
.sheet-list .sheet-item:active { background: var(--bg3); }
.sheet-item .cnt { margin-left: auto; color: var(--muted); font-size: 13px; }
.sheet-new { display: flex; gap: 8px; margin-top: 12px; }
.sheet-new input {
  flex: 1; padding: 12px 14px; font-size: 16px; background: var(--bg3);
  color: var(--fg); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.sheet-new button, .sheet-cancel {
  border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.sheet-new button { background: var(--accent); color: #fff; padding: 0 18px; }
.sheet-cancel { width: 100%; margin-top: 12px; padding: 14px; background: var(--bg3); color: var(--fg); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bot) + 120px);
  transform: translateX(-50%); z-index: 60;
  background: #2a2f3d; color: var(--fg); padding: 10px 18px; border-radius: 22px;
  font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 80%; text-align: center;
}

input[type="range"] { -webkit-appearance: none; height: 4px; background: var(--line); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); margin-top: 0;
}
