:root {
  --bg: #14161b;
  --panel: #1d2027;
  --panel-2: #262a33;
  --line: #2f3440;
  --text: #e9ebf0;
  --muted: #8d94a3;
  --accent: #5b8cff;
  --accent-text: #fff;
  --danger: #ff5b6b;
  --ok: #3ccf8e;
  --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8; --panel: #fff; --panel-2: #eceef3; --line: #dde0e7;
    --text: #15171c; --muted: #6a7180; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: min(320px, 100%); display: grid; gap: 12px; text-align: center; }
.login .logo { font-size: 48px; color: var(--accent); }
.login h1 { margin: 0 0 8px; }
.err { color: var(--danger); min-height: 1.4em; margin: 0; }

/* layout */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; }
.top h1 { font-size: 22px; margin: 0; }
.top-status { color: var(--muted); font-size: 13px; text-align: right; }
main { flex: 1; overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; padding: 12px 4px; color: var(--muted); position: relative; font-size: 14px; }
.tabs button.on { color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-size: 11px; line-height: 18px; vertical-align: 1px; }
.badge:empty { display: none; }
.badge.dot { min-width: 8px; width: 8px; height: 8px; padding: 0; vertical-align: 3px; }

/* player */
.player { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px 6px; }
.p-info { min-width: 0; }
.p-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-artist { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.2em; }
.seek { padding: 12px 0; cursor: pointer; touch-action: none; outline: none; }
.seek-track { position: relative; height: 6px; border-radius: 3px; background: var(--panel-2); }
.seek-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 3px; background: var(--accent); }
.seek-knob { position: absolute; top: 50%; left: 0; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--text); box-shadow: 0 1px 4px #0006; }
.seek:focus-visible .seek-track { outline: 2px solid var(--accent); outline-offset: 4px; }
.p-row { display: flex; align-items: center; justify-content: space-between; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; width: 44px; }
.time:last-child { text-align: right; }
.p-buttons { display: flex; gap: 18px; align-items: center; }
.icon { background: none; border: 0; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.icon svg { width: 26px; height: 26px; fill: currentColor; }
.icon.big { width: 54px; height: 54px; background: var(--accent); color: var(--accent-text); }
.icon.big svg { width: 30px; height: 30px; }
.icon:active { transform: scale(.94); }

/* common */
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; }
.row > .field { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }

/* sorting panel */
.sorter { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0 10px; }
.sorter .now { font-size: 13px; color: var(--muted); margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sorter .now b { color: var(--text); }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.folder-grid .btn { text-align: left; padding: 12px; position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-grid .btn kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px/1 ui-monospace, monospace; color: var(--muted); }
.sorter .actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-top: 8px; }
.sorter .actions .btn { padding: 12px; }
@media (hover: none) { .folder-grid kbd, .kbd-hint { display: none; } }

/* track list */
.list { list-style: none; margin: 0; padding: 0; }
.track { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; cursor: pointer; }
.track:hover { background: var(--panel); }
.track.cur { background: var(--panel-2); }
.track.cur .t-title { color: var(--accent); }
.track .t-main { flex: 1; min-width: 0; }
.track .t-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .t-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .t-dur { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.track .t-act { background: none; border: 0; color: var(--muted); padding: 6px 8px; border-radius: 8px; }
.track .t-act:hover { background: var(--panel-2); color: var(--text); }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 16px 0 4px; }
.group-head { flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
.group-head .g-name { background: none; border: 0; padding: 4px 0; font-weight: 600; text-align: left; flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-head .g-act { display: flex; gap: 6px; }

/* folders */
.folder-item { display: flex; align-items: center; gap: 10px; padding: 12px; }
.folder-item .f-name { flex: 1; font-weight: 600; cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.folder-item .f-n { color: var(--muted); font-size: 13px; }
.back { background: none; border: 0; color: var(--accent); padding: 4px 0 10px; }

/* downloads */
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress div { height: 100%; background: var(--accent); }
.job { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.job:first-child { border-top: 0; }
.job .j-main { flex: 1; min-width: 0; }
.job .j-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); }
.tag.err { color: var(--danger); }
.tag.run { color: var(--accent); }
.drop { border-style: dashed; border-width: 2px; }
.disk { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.disk div { height: 100%; background: var(--ok); }

/* menu sheet */
.sheet-bg { position: fixed; inset: 0; background: #0008; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); width: min(480px, 100%); border-radius: 16px 16px 0 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto; }
.sheet .s-title { padding: 6px 8px 10px; color: var(--muted); font-size: 13px; }
.sheet button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 10px; border-radius: 10px; }
.sheet button:hover { background: var(--panel-2); }
.sheet button.danger { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 200px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; z-index: 20; display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; }
