:root {
  --bg: #0f1630;
  --bg2: #17204a;
  --card: rgba(255, 255, 255, 0.06);
  --card-hi: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3f5ff;
  --muted: #a7b0d6;
  --accent: #35d0ba;
  --accent2: #6c7bff;
  --danger: #ff6b81;
  --radius: 18px;
  --player-h: 150px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 10% -10%, #2a3a8f 0%, transparent 60%),
              radial-gradient(900px 600px at 110% 10%, #146b6b 0%, transparent 55%),
              var(--bg);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 28px; margin: 12px 0 6px; }
h2 { margin: 0; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }

.screen { min-height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 32px; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.card.narrow { width: min(460px, 100%); text-align: center; }
.logo-big { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.lock-icon { font-size: 56px; }

form { display: grid; gap: 14px; margin-top: 22px; }
input {
  font: inherit; font-size: 22px; letter-spacing: 2px; text-align: center; text-transform: uppercase;
  padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); color: var(--text);
  -webkit-user-select: text; user-select: text;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.msg { min-height: 1.4em; color: var(--danger); margin: 14px 0 0; }
.help { margin-top: 10px; color: var(--muted); text-align: left; font-size: 15px; }
.help summary { cursor: pointer; text-align: center; color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; color: var(--text); background: var(--card-hi);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 20px; min-height: 44px; cursor: pointer;
  transition: transform 0.08s ease, background 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #2aa7d6); border-color: transparent; color: #04201c; }
.btn.big { font-size: 19px; padding: 14px 28px; min-height: 56px; }
.btn.ghost { background: transparent; border-color: transparent; padding-left: 6px; }
.btn:disabled { opacity: 0.55; }
.btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 28px 6px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 22px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.device { color: var(--muted); font-size: 14px; }

main { padding: 10px 28px calc(var(--player-h) + 30px + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; }

.sync-card {
  display: flex; align-items: center; gap: 20px; padding: 20px 24px; margin: 8px 0 26px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.sync-card.attention { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53, 208, 186, 0.15); }
.sync-text { flex: 1; min-width: 0; }
.sync-title { font-weight: 700; font-size: 20px; }
.progress { height: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.1); margin-top: 12px; overflow: hidden; }
.bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.3s; }

.section-title { font-size: 22px; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
.tile {
  position: relative; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0; overflow: hidden; background: var(--card);
  transition: transform 0.1s ease;
}
.tile:active { transform: scale(0.97); }
.tile .cover { aspect-ratio: 1.35; display: flex; align-items: center; justify-content: center; font-size: 54px; }
.tile .info { padding: 12px 14px 14px; }
.tile .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .count { color: var(--muted); font-size: 14px; }
.tile .play-badge {
  position: absolute; right: 12px; top: 12px; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center;
}
.empty { text-align: center; padding: 50px 0; font-size: 18px; }

.list-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.list-title { flex: 1; min-width: 200px; }
.list-title h2 { font-size: 26px; }
.list-actions { display: flex; gap: 10px; }
.tracks { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--card); }
.tracks li { display: flex; align-items: center; gap: 14px; padding: 12px 18px; min-height: 60px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tracks li:last-child { border-bottom: 0; }
.tracks li:active { background: var(--card-hi); }
.tracks li.playing { background: rgba(53, 208, 186, 0.12); }
.tracks li.playing .t-title { color: var(--accent); }
.tracks li.unavailable { opacity: 0.4; cursor: default; }
.tracks .num { width: 28px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.tracks .t-main { flex: 1; min-width: 0; }
.tracks .t-title, .tracks .t-artist { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tracks .t-artist { color: var(--muted); font-size: 14px; }
.tracks .t-flag { font-size: 13px; color: var(--muted); }

.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; grid-template-areas: "now controls ." "seek seek seek";
  align-items: center; gap: 6px 20px; padding: 14px 28px calc(14px + env(safe-area-inset-bottom));
  background: rgba(15, 22, 48, 0.85); border-top: 1px solid var(--line);
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
}
.now { grid-area: now; display: flex; align-items: center; gap: 14px; min-width: 0; }
.art { width: 54px; height: 54px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 26px; background: linear-gradient(135deg, var(--accent2), var(--accent)); }
.now-text { min-width: 0; }
.now-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-artist { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { grid-area: controls; display: flex; align-items: center; gap: 10px; }
.icon-btn { position: relative; width: 52px; height: 52px; border-radius: 50%; border: 0; background: transparent; color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:active { background: var(--card-hi); }
.icon-btn svg { width: 28px; height: 28px; }
.icon-btn.play { width: 66px; height: 66px; background: var(--text); color: var(--bg); }
.icon-btn.play svg { width: 34px; height: 34px; }
.icon-btn.play .i-pause, .icon-btn.play.is-playing .i-play { display: none; }
.icon-btn.play.is-playing .i-pause { display: block; }
#btn-shuffle, #btn-repeat { color: var(--muted); }
#btn-shuffle[aria-pressed="true"], #btn-repeat:not([data-mode="off"]) { color: var(--accent); }
#btn-repeat .one { display: none; position: absolute; font-size: 10px; font-weight: 800; top: 13px; right: 12px; }
#btn-repeat[data-mode="one"] .one { display: block; }
.seek { grid-area: seek; display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seek input { flex: 1; padding: 0; height: 30px; letter-spacing: 0; background: transparent; border: 0; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 30px); transform: translateX(-50%); z-index: 20;
  background: #fff; color: #111; padding: 12px 20px; border-radius: 999px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: 90vw; text-align: center;
}

@media (max-width: 700px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .sync-card { flex-direction: column; align-items: stretch; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .player { grid-template-columns: 1fr; grid-template-areas: "now" "controls" "seek"; justify-items: center; padding-left: 16px; padding-right: 16px; }
  .now { justify-self: stretch; }
  :root { --player-h: 210px; }
}

/* download state on tiles and rows */
.sync-card .btn + .btn { margin-left: -8px; }
.tile .status { font-size: 13px; margin-top: 2px; color: var(--muted); }
.tile .status.done { color: var(--accent); }
.tile .status.partial { color: #ffd479; }
.tile .dl-badge {
  position: absolute; right: 12px; top: 12px; height: 44px; padding: 0 14px; border-radius: 22px;
  background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 15px; color: #fff;
}
.tile .mini-bar { height: 4px; background: rgba(255, 255, 255, 0.12); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.tile .mini-bar div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.tracks li.queued .t-flag { color: #ffd479; }
.tracks li.unavailable.queued { opacity: 0.7; }
