:root {
  --bg: #111114;
  --bg-2: #18181d;
  --card: #1d1d23;
  --card-hi: #26262e;
  --line: rgba(255,255,255,.08);
  --text: #f4f4f6;
  --muted: #a3a3ae;
  --faint: #6e6e7a;
  --accent: #ff4f81;
  --accent-2: #ff8a5c;
  --on-accent: #1a0710;
  --radius: 14px;
  --nav-h: 62px;
  --mini-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
input, select, textarea { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.ic { width: 22px; height: 22px; flex: none; display: block; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#main {
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  max-width: 1100px;
  margin: 0 auto;
}
body.has-mini #main { padding-bottom: calc(var(--nav-h) + var(--mini-h) + var(--safe-b) + 28px); }
.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.top { display: flex; align-items: flex-end; justify-content: space-between; padding: 14px 0 10px; }
.top.slim { align-items: center; padding: 6px 0; }
.eyebrow { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: .08em; }
h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: .01em; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-grid; place-items: center; color: var(--text);
  transition: background .15s, transform .1s;
}
.icon-btn:active { background: rgba(255,255,255,.1); transform: scale(.94); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px;
  background: var(--card-hi); color: var(--text); font-weight: 650;
  transition: transform .1s, filter .15s;
  white-space: nowrap;
}
.btn .ic { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); }
.btn.big { height: 46px; padding: 0 20px; font-size: 15px; }
.btn.primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: var(--on-accent); }
.btn.danger { background: #3a1820; color: #ff8fa6; }
.btn.block { width: 100%; }

.hero { display: flex; gap: 10px; margin: 4px 0 14px; }
.hero .btn { flex: 1; }

.toolbar { display: flex; gap: 8px; margin-bottom: 6px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; border-radius: 10px; background: var(--card); color: var(--muted);
}
.search .ic { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: inherit; }
.search input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
select {
  height: 40px; padding: 0 10px; border-radius: 10px; border: 0;
  background: var(--card); color: var(--text); font: inherit; outline: 0;
}
.groups { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.groups::-webkit-scrollbar { display: none; }
.gchip { flex: none; height: 34px; padding: 0 14px; border-radius: 999px; background: var(--card-hi); font-size: 14px; font-weight: 600; white-space: nowrap; }
.gchip.on { background: var(--text); color: #111; }
.count { margin: 8px 2px 10px; color: var(--faint); font-size: 13px; }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1040px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.card {
  position: relative; padding: 10px; border-radius: var(--radius);
  background: var(--card); cursor: pointer;
  transition: background .15s, transform .12s;
  content-visibility: auto; contain-intrinsic-size: 220px;
}
.card:active { transform: scale(.98); background: var(--card-hi); }
@media (hover: hover) { .card:hover { background: var(--card-hi); } .card:hover .play-fab { opacity: 1; transform: none; } }
.cover-wrap { position: relative; }
.cover, .row-art, .mini-art, .np-art, .pl-cover {
  aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #2a2a33;
  display: grid; place-items: center; position: relative;
}
.cover img, .row-art img, .mini-art img, .np-art img, .pl-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gen span { font-size: 42px; font-weight: 800; color: rgba(255,255,255,.88); text-shadow: 0 2px 16px rgba(0,0,0,.25); }
.gen::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 75% 20%, rgba(255,255,255,.28), transparent 45%);
}
.play-fab {
  position: absolute; right: 8px; bottom: 8px; width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(6px); transition: opacity .15s, transform .15s;
}
.play-fab .ic { width: 18px; height: 18px; }
.card.playing .play-fab { opacity: 1; transform: none; }
.card .meta { padding: 10px 26px 2px 2px; min-width: 0; }
.t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.playing .t { color: var(--accent); }
.card .more { position: absolute; right: 2px; bottom: 10px; width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; }
.card .more .ic { width: 18px; height: 18px; }
.card .more:active { background: rgba(255,255,255,.1); }

/* equalizer */
.eq { display: none; gap: 3px; align-items: flex-end; height: 16px; }
.card .eq { position: absolute; left: 10px; bottom: 10px; padding: 5px 6px; border-radius: 6px; background: rgba(0,0,0,.55); height: 26px; }
.playing .eq { display: inline-flex; }
.eq i { width: 3px; height: 100%; background: var(--accent); border-radius: 2px; transform-origin: bottom; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.35s; }
.eq i:nth-child(3) { animation-delay: -.7s; }
body.paused .eq i { animation-play-state: paused; transform: scaleY(.35); }
@keyframes eq { 0%,100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

/* playlists */
.pl-cover { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 0; }
.pl-cover.one { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.pl-cover > * { width: 100%; height: 100%; border-radius: 0; aspect-ratio: auto; }
.pl-cover .gen span { font-size: 22px; }
.pl-cover.one .gen span { font-size: 42px; }
.pl-cover.empty-cover { background: linear-gradient(135deg, #33333d, #22222a); color: var(--faint); }
.pl-cover.empty-cover .ic { width: 44px; height: 44px; }

.pl-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 4px 0 10px; }
.pl-hero .pl-cover { width: min(62vw, 240px); box-shadow: 0 18px 50px rgba(0,0,0,.5); border-radius: 12px; }
.pl-hero h2 { margin: 16px 0 2px; font-size: 24px; font-weight: 800; word-break: break-word; }
.pl-hero .s { white-space: normal; }
.pl-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 14px 0 8px; }

/* rows */
.rows { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 8px 4px 8px 8px; border-radius: 10px; cursor: pointer;
}
.row:active { background: var(--card); }
.row-art { width: 50px; flex: none; border-radius: 6px; }
.row-art .gen span, .row-art.gen span { font-size: 20px; }
.row .meta { flex: 1; min-width: 0; }
.row.playing .t { color: var(--accent); }
.row .eq { margin-right: 4px; }
.row .more { width: 38px; height: 38px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; flex: none; }
.row .more:active { background: rgba(255,255,255,.1); }
.row .num { width: 22px; text-align: center; color: var(--faint); font-size: 13px; flex: none; }
.row.playing .num { display: none; }

/* empty states */
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty-art { width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 26px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); }
.empty-art .ic { width: 44px; height: 44px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0 0 22px; font-size: 14px; }

/* ---------- mini player ---------- */
#mini {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--nav-h) + var(--safe-b) + 6px); z-index: 20;
  height: var(--mini-h); border-radius: 12px; overflow: hidden;
  background: #2a2230; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: 1084px; margin: 0 auto;
  transition: background .4s;
}
.mini-progress { position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; background: rgba(255,255,255,.15); border-radius: 2px; overflow: hidden; }
.mini-progress i { display: block; height: 100%; width: 0; background: #fff; }
.mini-body { display: flex; align-items: center; gap: 10px; height: 100%; padding: 0 4px 0 8px; cursor: pointer; }
.mini-art { width: 46px; border-radius: 7px; flex: none; }
.mini-art .gen span, .mini-art.gen span { font-size: 18px; }
.mini-meta { flex: 1; min-width: 0; }
.mini-meta .s { color: rgba(255,255,255,.7); }

/* ---------- tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: space-around;
  background: linear-gradient(to top, rgba(10,10,12,.98) 55%, rgba(10,10,12,.82));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabs button { flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 11.5px; font-weight: 600; }
#tabs button.on { color: var(--text); }
#tabs button:active { transform: scale(.94); }

/* ---------- full player ---------- */
#player {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 8px) 24px calc(var(--safe-b) + 18px);
  background: var(--bg);
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
}
body.player-open #player { transform: none; }
.np-bg { position: absolute; inset: 0; z-index: -1; transition: background .6s; }
.np-top { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px; }
.np-src { text-align: center; min-width: 0; flex: 1; padding: 0 6px; }
.np-src span { display: block; font-size: 11px; letter-spacing: .12em; color: rgba(255,255,255,.7); }
.np-src b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-art-wrap { flex: 1; display: grid; place-items: center; min-height: 0; padding: 18px 0; }
.np-art { width: min(100%, 46vh, 420px); border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.55); }
.np-art .gen span, .np-art.gen span { font-size: 120px; }
.np-meta { margin-bottom: 14px; }
.np-meta .t { font-size: 22px; font-weight: 800; }
.np-meta .s { font-size: 15px; color: rgba(255,255,255,.72); }
.np-seek .times { display: flex; justify-content: space-between; font-size: 12px; color: rgba(255,255,255,.7); margin-top: 4px; font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: none; margin: 0; cursor: pointer;
  --p: 0%;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, #fff var(--p), rgba(255,255,255,.25) var(--p)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, #fff var(--p), rgba(255,255,255,.25) var(--p)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; border: 0; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }

.np-controls { display: flex; align-items: center; justify-content: space-between; margin: 10px -8px 6px; }
.icon-btn.lg .ic { width: 34px; height: 34px; }
.icon-btn.lg { width: 56px; height: 56px; }
.icon-btn.mode { position: relative; color: rgba(255,255,255,.75); }
.icon-btn.mode.on { color: var(--accent); }
.icon-btn.mode.on::after { content: ""; position: absolute; bottom: 3px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.icon-btn.mode em { position: absolute; top: 7px; right: 6px; font-style: normal; font-size: 9px; font-weight: 800; display: none; }
.icon-btn.mode.one em { display: block; }
.play-big { width: 70px; height: 70px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; transition: transform .1s; }
.play-big .ic { width: 32px; height: 32px; }
.play-big:active { transform: scale(.94); }
.np-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: rgba(255,255,255,.7); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px; background: rgba(255,255,255,.12); font-size: 13px; font-weight: 600; }
.chip .ic { width: 16px; height: 16px; }

/* ---------- sheet / overlay ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.sheet-open #overlay { opacity: 1; pointer-events: auto; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 560px; margin: 0 auto; max-height: 86vh; overflow: auto; overscroll-behavior: contain;
  background: #202027; border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(var(--safe-b) + 16px);
  transform: translateY(105%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
}
body.sheet-open #sheet { transform: none; }
.grab { width: 38px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.22); margin: 2px auto 12px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 4px 4px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.sheet-head .row-art { width: 52px; }
.sheet-head .meta { min-width: 0; flex: 1; }
#sheet h3 { margin: 4px 4px 14px; font-size: 18px; }
.menu-item { width: 100%; display: flex; align-items: center; gap: 14px; padding: 13px 8px; border-radius: 10px; text-align: left; font-size: 15px; }
.menu-item:active { background: rgba(255,255,255,.07); }
.menu-item .ic { width: 20px; height: 20px; color: var(--muted); }
.menu-item.danger { color: #ff7d97; }
.menu-item.danger .ic { color: #ff7d97; }
.menu-item .grow { flex: 1; min-width: 0; }
.menu-item .tick { color: var(--accent); }
.field {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #15151a; color: var(--text); font: inherit; outline: 0; margin-bottom: 12px;
}
.field:focus { border-color: var(--accent); }
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 0 4px 6px; }
.row-btns { display: flex; gap: 10px; margin-top: 6px; }
.row-btns .btn { flex: 1; height: 46px; }
.sheet-note { color: var(--muted); font-size: 13px; margin: 0 4px 14px; }
.pick-list { display: flex; flex-direction: column; margin: 6px 0 12px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 7px 6px; border-radius: 10px; cursor: pointer; }
.pick:active { background: rgba(255,255,255,.06); }
.pick .row-art { width: 42px; }
.pick .meta { flex: 1; min-width: 0; }
.pick .box { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--faint); display: grid; place-items: center; color: transparent; flex: none; }
.pick .box .ic { width: 16px; height: 16px; }
.pick.on .box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pick.disabled { opacity: .45; }
.sticky-foot { position: sticky; bottom: calc(-16px - var(--safe-b)); background: #202027; padding: 10px 0 4px; margin-bottom: calc(-4px); }
.stat { display: flex; justify-content: space-between; padding: 12px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.stat span:last-child { color: var(--muted); }
.q-row.cur .t { color: var(--accent); }
.q-label { font-size: 12px; color: var(--muted); letter-spacing: .08em; margin: 14px 6px 4px; }

/* ---------- toast / drop ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--mini-h) + var(--safe-b) + 22px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #f4f4f6; color: #111; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
