:root {
  --bg: #16151a;
  --raise: #211f27;
  --line: #2d2b35;
  --text: #efece6;
  --dim: #9c98a6;
  --accent: #e8b76b;
  --on-accent: #221806;
  --danger: #f08a7a;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f3f6;
    --raise: #ffffff;
    --line: #e2e0e8;
    --text: #1b1a20;
    --dim: #6f6b7a;
    --accent: #a1620f;
    --on-accent: #ffffff;
    --danger: #b83a2a;
    --shadow: 0 10px 40px rgba(40, 30, 60, .16);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
html.locked { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.35 "Instrument Sans", -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; width: 24px; height: 24px; fill: currentColor; }

/* ---------- shared controls ---------- */
.solid { background: var(--accent); color: var(--on-accent); font-weight: 600; padding: 13px 20px; border-radius: 12px; }
.quiet { background: var(--raise); padding: 13px 16px; border-radius: 12px; font-weight: 500; }
.text { color: var(--dim); font-size: 14px; padding: 8px 0; text-decoration: underline; text-underline-offset: 3px; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon:active, .round:active, .playbtn:active { transform: scale(.92); }
input[type=search], input[type=url], input[type=password] {
  width: 100%; font: inherit; color: var(--text); background: var(--raise);
  border: 1px solid transparent; border-radius: 12px; padding: 12px 14px; appearance: none; -webkit-appearance: none;
}
input::placeholder { color: var(--dim); }
input:focus { border-color: var(--accent); outline: none; }

/* ---------- sign in ---------- */
#login {
  min-height: 100dvh; max-width: 340px; margin: 0 auto; padding: 24px;
  display: flex; flex-direction: column; justify-content: center; gap: 12px;
}
#login img { border-radius: 18px; }
#login h1 { font-size: 34px; font-weight: 600; letter-spacing: -.02em; margin-bottom: 16px; }
#login label { color: var(--dim); font-size: 14px; }
#loginErr { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- library ---------- */
#app {
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 110px);
}
header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
header h1 { font-size: 34px; font-weight: 600; letter-spacing: -.025em; flex: 1; }
.round { width: 40px; height: 40px; border-radius: 50%; background: var(--raise); display: grid; place-items: center; }
.pill { font-size: 13px; font-weight: 500; color: var(--accent); background: var(--raise); padding: 8px 12px; border-radius: 999px; }

#chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px -18px 4px; padding: 0 18px 6px; scrollbar-width: none; }
#chips::-webkit-scrollbar { display: none; }
#chips:empty { display: none; }
#chips button { flex: none; font-size: 14px; font-weight: 500; padding: 7px 13px; border-radius: 999px; color: var(--dim); border: 1px solid var(--line); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chips button[aria-pressed=true] { color: var(--bg); background: var(--text); border-color: var(--text); }

#list { margin: 8px -8px 0; }
#list li {
  display: grid; grid-template-columns: 48px 1fr auto 36px; align-items: center; gap: 12px;
  padding: 7px 0 7px 8px; border-radius: 12px; content-visibility: auto; contain-intrinsic-size: auto 62px;
}
#list li:active { background: var(--raise); }
.cover { position: relative; display: block; width: 48px; height: 48px; border-radius: 8px; overflow: hidden; background: var(--raise); color: var(--dim); flex: none; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover svg { position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; opacity: .6; }
.meta { min-width: 0; display: block; text-align: left; }
.meta b, .meta i { display: block; font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta b { font-weight: 500; }
.meta i { color: var(--dim); font-size: 14px; }
#list time { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
#list .more { width: 36px; height: 44px; display: grid; place-items: center; color: var(--dim); }
#list .more svg { width: 20px; height: 20px; }
#list li.on .meta b { color: var(--accent); }

/* small equaliser over the cover of the song that is playing */
#list li.on .cover::after {
  content: ""; position: absolute; inset: 0; background:
    linear-gradient(var(--accent), var(--accent)) 16px 100% / 3px var(--a, 40%) no-repeat,
    linear-gradient(var(--accent), var(--accent)) 22.5px 100% / 3px var(--b, 70%) no-repeat,
    linear-gradient(var(--accent), var(--accent)) 29px 100% / 3px var(--c, 50%) no-repeat,
    rgba(10, 9, 14, .62);
  background-origin: content-box; padding: 15px 0; animation: eq 1.1s ease-in-out infinite alternate;
}
@property --a { syntax: "<percentage>"; inherits: false; initial-value: 40%; }
@property --b { syntax: "<percentage>"; inherits: false; initial-value: 70%; }
@property --c { syntax: "<percentage>"; inherits: false; initial-value: 50%; }
@keyframes eq {
  0% { --a: 30%; --b: 90%; --c: 45%; }
  50% { --a: 85%; --b: 40%; --c: 100%; }
  100% { --a: 50%; --b: 75%; --c: 30%; }
}
body.paused #list li.on .cover::after { animation-play-state: paused; }

#empty { text-align: center; padding: 64px 12px; color: var(--dim); }
#empty p { margin-bottom: 18px; }
footer { display: flex; gap: 16px; align-items: center; color: var(--dim); font-size: 14px; margin-top: 24px; flex-wrap: wrap; }
footer #count { flex: 1; font-variant-numeric: tabular-nums; }

/* ---------- mini player ---------- */
#dock {
  position: fixed; z-index: 5; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 8px);
  max-width: 624px; margin: 0 auto; display: flex; align-items: center; gap: 2px;
  padding: 8px 6px 8px 8px; border-radius: 16px; overflow: hidden;
  background: color-mix(in srgb, var(--raise) 86%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(1.4); backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
#dockOpen { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
#dock .cover { width: 44px; height: 44px; }
#dockBar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; }
#dockBar span { display: block; height: 100%; width: 0; background: var(--accent); }

/* ---------- full player ---------- */
#player {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 8px) 28px calc(env(safe-area-inset-bottom) + 28px);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 16px;
  transform: translateY(100%); visibility: hidden;
  transition: transform .42s var(--ease), visibility 0s .42s;
}
#player.open { transform: none; visibility: visible; transition: transform .42s var(--ease); }
#playerClose { align-self: flex-start; margin-left: -10px; color: var(--dim); }
#art {
  width: min(100%, 46dvh, 420px); aspect-ratio: 1; border-radius: 18px; overflow: hidden;
  background: var(--raise); color: var(--dim); box-shadow: var(--shadow); position: relative;
  transition: transform .5s var(--ease);
}
body.paused #art { transform: scale(.86); }
#art img { width: 100%; height: 100%; object-fit: cover; display: block; }
#art svg { position: absolute; inset: 0; margin: auto; width: 64px; height: 64px; opacity: .5; }
.titles { width: 100%; max-width: 420px; }
.titles h2 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.titles p { color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scrub { width: 100%; max-width: 420px; }
.times { display: flex; justify-content: space-between; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 2px; }
#seek {
  --p: 0%; width: 100%; height: 28px; margin: 0; background: none; appearance: none; -webkit-appearance: none; touch-action: none;
}
#seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--text) var(--p), var(--line) var(--p)); }
#seek::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--text) var(--p), var(--line) var(--p)); }
#seek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--text); margin-top: -5px; }
#seek::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--text); }
.transport { width: 100%; max-width: 420px; display: flex; align-items: center; justify-content: space-between; }
.icon.big svg { width: 34px; height: 34px; }
.icon.big { width: 56px; height: 56px; }
.playbtn { width: 76px; height: 76px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; transition: transform .15s; }
.playbtn svg { width: 34px; height: 34px; }
.toggle { color: var(--dim); position: relative; }
.toggle[aria-pressed=true] { color: var(--accent); }
.toggle[data-one]::after { content: "1"; position: absolute; top: 4px; right: 4px; font-size: 11px; font-weight: 600; }

/* ---------- sheets ---------- */
#scrim { position: fixed; inset: 0; z-index: 20; background: rgba(8, 7, 12, .5); }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding: 24px 20px calc(env(safe-area-inset-bottom) + 24px); max-height: 82dvh; overflow-y: auto;
  transform: translateY(105%); visibility: hidden; transition: transform .34s var(--ease), visibility 0s .34s;
}
.sheet.open { transform: none; visibility: visible; transition: transform .34s var(--ease); }
.sheet h2 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.sheet .hint { color: var(--dim); font-size: 14px; margin: 4px 0 16px; }
#addForm { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
#addForm input { grid-column: 1 / -1; }
#addForm .solid { grid-column: 3; }
#addForm .quiet { grid-column: 2; }
#jobs { margin-top: 18px; }
#jobs li { display: grid; grid-template-columns: 1fr 36px; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
#jobs b { display: block; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#jobs i { display: block; font-style: normal; font-size: 14px; color: var(--dim); }
#jobs li.error i { color: var(--danger); }
#jobs button { width: 36px; height: 36px; display: grid; place-items: center; color: var(--dim); }
#jobs button svg { width: 18px; height: 18px; }
.action { display: block; width: 100%; text-align: left; padding: 15px 0; border-top: 1px solid var(--line); font-weight: 500; }
.action.danger { color: var(--danger); }

#toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translate(-50%, 12px);
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; padding: 10px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
