:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-2: #24242c;
  --border: #2a2a33;
  --text: #f2f2f5;
  --muted: #9a9aa8;
  --accent: #ff3b5c;
  --ok: #34c77b;
  --warn: #f5a524;
  --radius: 14px;
  --mini-player-height: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

body.has-player main {
  padding-bottom: calc(var(--mini-player-height) + 24px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }
.muted { color: var(--muted); margin: 0; }
.small-text { font-size: .85rem; font-weight: 400; }

/* Controls */

label { font-weight: 600; }

textarea, input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }
input[type="text"], input[type="password"], input[type="search"] { min-height: 48px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

button:disabled { opacity: .45; cursor: default; }

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}

.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }

.icon { width: 24px; height: 24px; fill: currentColor; flex: none; }
.icon.big { width: 36px; height: 36px; }

.icon-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  background: transparent;
  color: var(--text);
  border-radius: 50%;
}

.icon-btn.toggle { color: var(--muted); }
.icon-btn.toggle[aria-pressed="true"] { color: var(--accent); }

/* Layout */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
}
.topbar h1 { flex: 1; }

.banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--warn);
  font-size: .9rem;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--surface);
}

.tabs [role="tab"] {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
}
.tabs [role="tab"][aria-selected="true"] { background: var(--surface-2); color: var(--text); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.empty { text-align: center; padding: 32px 0; }

/* Library */

.library-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  margin: 10px 0;
  font-size: .85rem;
}

.tracks { list-style: none; margin: 0; padding: 0; }

.track {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.track-main {
  flex: 1;
  min-width: 0;
  min-height: 64px;
  padding: 8px 4px 8px 0;
  gap: 12px;
  justify-content: flex-start;
  background: transparent;
  color: var(--text);
  font-weight: 400;
  text-align: left;
  border-radius: 0;
}

.track-main img, .mini-info img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

.track-text { display: grid; min-width: 0; flex: 1; }
.track-title, .track-artist { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-title { font-weight: 600; }
.track-artist, .track-duration { color: var(--muted); font-size: .85rem; }

.track.current .track-title { color: var(--accent); }
.track.unavailable { opacity: .45; }

.offline-btn { color: var(--muted); }
.offline-btn.saved { color: var(--ok); }
.progress-text { font-size: .75rem; font-variant-numeric: tabular-nums; }

/* Downloads */

form { display: grid; gap: 10px; margin-bottom: 24px; }

.feedback { min-height: 1.4em; margin: 0; font-size: .9rem; color: var(--muted); }
.feedback.error { color: var(--accent); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.jobs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.job {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.job-title {
  font-weight: 600;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.job-meta { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }

.badge { padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--border); }
.badge.downloading { background: var(--warn); color: #000; }
.badge.done { background: var(--ok); color: #000; }
.badge.failed { background: var(--accent); color: #fff; }

.bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--warn); transition: width .3s; }

.error-text { color: var(--accent); font-size: .85rem; margin: 0; overflow-wrap: anywhere; }

.job-actions { display: flex; gap: 8px; }
.job-actions > * { flex: 1; min-height: 44px; }

/* Mini player */

.mini-player {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  max-width: 624px;
  margin: 0 auto;
  height: var(--mini-player-height);
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 8px 24px rgb(0 0 0 / .5);
  overflow: hidden;
}

.mini-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--border); }
.mini-progress > span { display: block; height: 100%; width: 0; background: var(--accent); }

.mini-info {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 0;
  gap: 10px;
  justify-content: flex-start;
  background: transparent;
  color: var(--text);
  font-weight: 400;
  text-align: left;
}
.mini-info img { width: 44px; height: 44px; }

/* Full player */

.full-player {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  border: 0;
  background: linear-gradient(var(--surface-2), var(--bg) 60%);
  color: var(--text);
}

.full-player[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.full-player::backdrop { background: var(--bg); }

#full-close { align-self: flex-start; }

.full-cover {
  width: min(100%, 360px, 45vh);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 16px 40px rgb(0 0 0 / .5);
  margin-top: auto;
}

.full-text { width: 100%; max-width: 400px; text-align: center; }
.full-text h2 { font-size: 1.3rem; overflow-wrap: anywhere; }

#seek { width: 100%; max-width: 400px; accent-color: var(--accent); }

.times {
  width: 100%;
  max-width: 400px;
  display: flex;
  justify-content: space-between;
  margin-top: -12px;
  color: var(--muted);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.controls {
  width: 100%;
  max-width: 400px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: auto;
}
.controls .icon-btn { min-width: 52px; min-height: 52px; }

.play-btn { width: 72px; height: 72px; padding: 0; border-radius: 50%; }

/* Login */

.login { padding-top: max(15vh, env(safe-area-inset-top)); }
.login h1 { margin-bottom: 24px; }

/* Toast */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--mini-player-height) + 20px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  text-align: center;
  z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  .bar > span { transition: none; }
}
