:root {
  --bg: #0b0b10;
  --bg-2: #12121a;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --surface-3: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.10);
  --text: #f5f5f8;
  --muted: #a2a2b4;
  --accent: #7c5cff;
  --accent-2: #ff7a59;
  --glow-a: #241b4d;
  --glow-b: #3d1f2c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mini-h: 0px;
  --tab-h: 62px;
  --radius: 16px;
}

/* Themes */
html[data-theme="dim"] { --bg: #15151d; --bg-2: #1b1b25; --text: #e9e9ef; }
html[data-theme="black"] { --bg: #000; --bg-2: #050506; }

* { box-sizing: border-box; }

/* display rules below would otherwise defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--mini-h) + var(--tab-h) + var(--safe-bottom) + 10px);
  overscroll-behavior-y: contain;
  min-height: 100vh;
}

/* Ambient tint from artwork */
.glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(110% 70% at 18% -5%, var(--glow-a) 0%, transparent 62%),
    radial-gradient(110% 70% at 92% 6%, var(--glow-b) 0%, transparent 58%),
    var(--bg);
  transition: background 800ms ease;
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 20px) 20px 8px;
  max-width: var(--col, 640px);
  margin: 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  background: linear-gradient(100deg, #fff 15%, #cbbcff 55%, #ffc3b1 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.top-actions { display: flex; gap: 8px; }

main {
  max-width: var(--col, 640px);
  margin: 0 auto;
  padding: 0 20px;
}

.panel { display: none; }
.panel.active { display: block; animation: fade 220ms ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- buttons ---------- */

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 15px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  min-height: 42px;
  cursor: pointer;
  transition: background 140ms ease, transform 110ms ease, border-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  color: #fff;
}
.icon-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- search ---------- */

.search { display: flex; gap: 8px; margin: 10px 0 8px; }

.search input {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search input::placeholder { color: var(--muted); }
.search input:focus {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
  background: var(--surface-2);
}

.search-btn {
  min-width: 64px;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 140ms ease, transform 110ms ease;
}
.search-btn:hover { filter: brightness(1.08); }
.search-btn:active { transform: scale(0.97); }

.search-scope { display: flex; gap: 6px; margin-bottom: 14px; }

.scope {
  flex: 1;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.scope.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
}

.hint { margin: 4px 2px 14px; color: var(--muted); font-size: 0.85rem; }

/* ---------- shelves ---------- */

.shelf { margin: 4px 0 16px; }

.shelf-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(120deg, var(--surface-2), var(--surface));
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease, transform 110ms ease;
}
.shelf-card:hover { background: var(--surface-3); }
.shelf-card:active { transform: scale(0.99); }

.shelf-card img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex: 0 0 64px; background: var(--bg-2); }
.shelf-meta { flex: 1; min-width: 0; }
.shelf-title { margin: 0 0 2px; font-weight: 650; font-size: 0.96rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf-sub { margin: 0; color: var(--muted); font-size: 0.8rem; }
.shelf-play {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ---------- lists ---------- */

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

.result {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.result:hover { background: var(--surface-2); }
.result[aria-current="true"] {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.result img {
  width: 64px;
  height: 48px;
  flex: 0 0 64px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--bg-2);
}

.result .info { min-width: 0; flex: 1; }

.result .name {
  margin: 0 0 2px;
  font-size: 0.94rem;
  font-weight: 620;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result .sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row.small { justify-content: center; margin-top: 10px; gap: 8px; }
.row.small .icon-btn { min-height: 38px; padding: 7px 13px; font-size: 0.8rem; }
.row > .icon-btn { padding: 7px 12px; min-height: 38px; font-size: 0.78rem; }

.empty { color: var(--muted); text-align: center; padding: 26px 0; font-size: 0.9rem; }

/* ---------- section headings ---------- */

.h2 {
  margin: 22px 0 10px;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
}
.h3 { margin: 14px 0 8px; font-size: 0.82rem; font-weight: 650; color: var(--text); }

/* ---------- segmented ---------- */

.seg { display: flex; gap: 5px; margin: 4px 0 12px; flex-wrap: wrap; }

.seg-btn {
  flex: 1 1 auto;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 620;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.seg-btn:hover { background: var(--surface-2); }
.seg-btn.active { background: var(--surface-3); color: var(--text); border-color: var(--line); }

.playlist-new { display: flex; gap: 8px; margin-top: 16px; }

.playlist-new input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}

/* ---------- video grid ---------- */

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.vcard {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
  transition: transform 140ms ease, background 140ms ease;
}
.vcard:hover { transform: translateY(-2px); background: var(--surface-2); }

.vcard .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-2);
}
.vcard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vcard .dur {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.78);
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.vcard .vmeta { padding: 8px 10px 11px; }
.vcard .vtitle {
  margin: 0 0 3px;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vcard .vsub { margin: 0; color: var(--muted); font-size: 0.74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- settings ---------- */

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  margin-bottom: 7px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.set-row.danger { border-color: color-mix(in srgb, #ff5a5a 35%, transparent); }
.set-row.danger .set-label span { color: #ff8a8a; }

.set-label { min-width: 0; }
.set-label span { display: block; font-size: 0.92rem; font-weight: 600; }
.set-label small { display: block; color: var(--muted); font-size: 0.76rem; margin-top: 1px; }

.chips { display: flex; gap: 4px; flex: 0 0 auto; }

.chips button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease;
}

.chips button:hover { background: var(--surface-2); }
.chips button.active {
  background: color-mix(in srgb, var(--accent) 32%, transparent);
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  color: #fff;
}

.switch {
  min-width: 58px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}

.switch[aria-checked="true"] {
  background: color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  color: #fff;
}

/* ---------- stats ---------- */

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.card {
  padding: 14px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
}
.card span { display: block; font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.card small { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; }

.rank { margin: 0; padding-left: 20px; display: grid; gap: 5px; }
.rank li { font-size: 0.88rem; }
.rank small { color: var(--muted); }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 76px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.chart i {
  flex: 1;
  min-width: 2px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  opacity: 0.9;
}

/* ---------- tabs (bottom nav) ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.66rem;
  font-weight: 620;
  cursor: pointer;
  transition: color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; fill: currentColor; opacity: 0.75; transition: opacity 150ms ease, transform 150ms ease; }
.tab.active { color: var(--text); }
.tab.active svg { opacity: 1; transform: translateY(-1px); }

/* ---------- mini player ---------- */

.mini {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 6px);
  z-index: 31;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 8px 0 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  animation: rise 240ms ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.mini img { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; flex: 0 0 44px; background: var(--surface); }
.mini-meta { flex: 1; min-width: 0; display: block; }
.mini-title { display: block; font-size: 0.85rem; font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-artist { display: block; font-size: 0.73rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mini-btn {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
}
.mini-btn svg { width: 19px; height: 19px; fill: var(--text); }

.mini-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
}
.mini-progress i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 400ms linear;
}

/* ---------- full player ---------- */

.full {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 14px) 22px calc(var(--safe-bottom) + 18px);
  background: linear-gradient(180deg, var(--bg-2), var(--bg) 70%);
  overflow-y: auto;
  animation: sheetUp 260ms cubic-bezier(0.22, 0.8, 0.28, 1);
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}

.full-top { display: flex; justify-content: space-between; gap: 10px; flex: 0 0 auto; }

.full-art {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  margin: 18px auto 6px;
  width: min(74vw, 340px);
}
.full-art img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 22px;
  object-fit: cover;
  background: var(--bg-2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.full-meta { text-align: center; margin: 10px auto 2px; width: 100%; max-width: 520px; }
.full-title { margin: 0 0 3px; font-size: 1.16rem; font-weight: 720; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.full-artist { margin: 0; color: var(--muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.scrub {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 540px;
  margin: 14px auto 2px;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.scrub span { flex: 0 0 40px; text-align: center; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 24px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
}
input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px auto 2px;
  width: 100%;
  max-width: 560px;
}

.icon-btn.big { min-width: 54px; font-variant-numeric: tabular-nums; }

.play {
  width: 66px;
  height: 66px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.4);
  transition: transform 110ms ease, box-shadow 150ms ease;
}
.play:hover { box-shadow: 0 12px 36px rgba(124, 92, 255, 0.55); }
.play:active { transform: scale(0.94); }
.play svg { width: 30px; height: 30px; fill: currentColor; }

.vol {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 330px;
  margin: 12px auto 0;
}

.keys {
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.71rem;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}
html[data-keys="off"] .keys { display: none; }

.status {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

/* lyrics pane */
.lyrics {
  position: absolute;
  inset: auto 0 0 0;
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  background: color-mix(in srgb, var(--bg-2) 97%, transparent);
  backdrop-filter: blur(20px);
  animation: rise 220ms ease;
}
.lyrics-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.lyrics-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--muted);
}
.lyrics-body .line { transition: color 200ms ease, transform 200ms ease; padding: 3px 0; }
.lyrics-body .line.on { color: var(--text); font-weight: 650; transform: scale(1.01); }

/* ---------- dialog ---------- */

dialog#sheet {
  width: min(560px, 93vw);
  max-height: 76vh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-2);
  color: var(--text);
  overflow: auto;
}
dialog#sheet::backdrop { background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(3px); }
dialog#sheet h2 { margin: 0 0 12px; font-size: 1.02rem; }
dialog#sheet #sheet-body { margin-bottom: 14px; }
dialog#sheet #sheet-body .row { margin-bottom: 12px; }

.sheet-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.87rem;
}
.sheet-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-item button { flex: 0 0 auto; }

.sheet-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* ---------- video element ---------- */

#video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  background: #000;
  object-fit: contain;
}

/* ---------- desktop ---------- */

@media (min-width: 760px) {
  :root { --col: 820px; --tab-h: 66px; }

  main, .topbar { max-width: var(--col); }
  .topbar { padding-top: 26px; }
  .topbar h1 { font-size: 1.8rem; }

  .mini {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(760px, calc(100vw - 40px));
    bottom: calc(var(--tab-h) + var(--safe-bottom) + 8px);
  }

  .tabbar { border-radius: 0; }

  .full { padding-top: 20px; }
  .full-art { width: min(38vh, 320px); margin-top: 8px; }
  .full-title { font-size: 1.35rem; }

  .video-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
  .result img { width: 84px; height: 56px; flex-basis: 84px; }
  .result:hover { background: var(--surface-2); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
