:root {
  --bg: #121016;
  --surface: #1c1922;
  --surface-2: #26222e;
  --line: #34303d;
  --text: #f1eef6;
  --muted: #a49eb0;
  --accent: #b69cff;
  --accent-ink: #1a1326;
  --warn: #ffd27a;
  --bad: #ff8a8a;
  --good: #8fe3b0;
  --radius: 14px;
  --nav-h: 62px;
  --player-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f5fa; --surface: #ffffff; --surface-2: #efebf5; --line: #ddd7e6;
    --text: #1b1722; --muted: #6b6478; --accent: #6b47d6; --accent-ink: #ffffff;
    --warn: #9a6700; --bad: #c62828; --good: #1b7a45; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f7f5fa; --surface: #ffffff; --surface-2: #efebf5; --line: #ddd7e6;
  --text: #1b1722; --muted: #6b6478; --accent: #6b47d6; --accent-ink: #ffffff;
  --warn: #9a6700; --bad: #c62828; --good: #1b7a45; color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
img { display: block; }
#app { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--player-h) + var(--safe-b) + 8px); }
#topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); }
#topbar h1 { font-size: 20px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-actions { display: flex; gap: 6px; }
#view { padding: 4px 16px 24px; max-width: 980px; margin: 0 auto; outline: none; }
.icon-btn { background: none; border: 0; padding: 6px 8px; border-radius: 10px; font-size: 20px; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
#nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--line); }
#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11.5px; position: relative; }
#nav a .ic { font-size: 21px; line-height: 1; }
#nav a.on { color: var(--accent); }
#nav .dot { position: absolute; top: 8px; right: calc(50% - 18px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--warn); color: #000; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

/* blocks */
.section { margin: 18px 0 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 60px; }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; cursor: pointer; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.thumb.round { border-radius: 50%; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.tile { cursor: pointer; min-width: 0; }
.tile img, .tile .ph { width: 100%; aspect-ratio: 1; border-radius: 12px; object-fit: cover; background: var(--surface-2); }
.tile .t { font-weight: 600; margin-top: 6px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .s { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shelf { display: grid; grid-auto-flow: column; grid-auto-columns: 140px; gap: 12px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.shelf .tile { scroll-snap-align: start; }
.hero { display: flex; gap: 16px; align-items: flex-end; margin: 8px 0 14px; }
.hero img { width: 140px; height: 140px; border-radius: 14px; object-fit: cover; background: var(--surface-2); flex: none; }
.hero h2 { margin: 0 0 4px; font-size: 22px; line-height: 1.2; }
@media (max-width: 420px) { .hero { flex-direction: column; align-items: flex-start; } .hero img { width: 100%; height: auto; aspect-ratio: 1; max-width: 260px; } }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); padding: 9px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.chip { text-decoration: none; color: var(--text); border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; white-space: nowrap; font-size: 13.5px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-weight: 600; margin-bottom: 5px; font-size: 14px; }
label.field small { display: block; color: var(--muted); margin-top: 4px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch input { width: 44px; height: 26px; appearance: none; background: var(--line); border-radius: 13px; position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.lib { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 22%, transparent); color: var(--bad); }
.badge.acc { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.err { color: var(--bad); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.searchbar { display: flex; gap: 8px; position: sticky; top: 56px; z-index: 4; background: var(--bg); padding: 6px 0; }
.searchbar input { flex: 1; }
.check { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

/* banner */
#banner { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--player-h) + var(--safe-b) + 10px); z-index: 7; background: var(--warn); color: #241a00; border-radius: 12px; padding: 10px 14px; font-weight: 600; cursor: pointer; max-width: 760px; margin: 0 auto; box-shadow: 0 6px 24px rgba(0,0,0,.3); }

/* player */
#player { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 6; background: var(--surface-2); border-top: 1px solid var(--line); }
#player .mini { display: flex; align-items: center; gap: 10px; padding: 8px 12px; height: 64px; }
#player .mini .main { flex: 1; min-width: 0; cursor: pointer; }
#player .prog { height: 3px; background: var(--line); }
#player .prog i { display: block; height: 100%; background: var(--accent); width: 0; }
.np { padding: 8px 4px 20px; text-align: center; }
.np img { width: min(320px, 80vw); aspect-ratio: 1; border-radius: 16px; margin: 6px auto 14px; object-fit: cover; background: var(--surface-2); }
.np .seek { width: 100%; accent-color: var(--accent); }
.np .ctrls { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 10px 0; }
.np .ctrls button { font-size: 26px; }
.np .ctrls .play { font-size: 30px; width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); border: 0; cursor: pointer; }
.lyrics { text-align: left; max-height: 46vh; overflow-y: auto; padding: 8px 4px; font-size: 18px; line-height: 1.6; }
.lyrics p { margin: 6px 0; color: var(--muted); transition: color .2s; cursor: pointer; }
.lyrics p.on { color: var(--text); font-weight: 700; }

/* sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--surface); border-radius: 18px 18px 0 0; max-height: 88dvh; overflow-y: auto; padding: 10px 16px calc(var(--safe-b) + 20px); max-width: 760px; margin: 0 auto; box-shadow: 0 -10px 40px rgba(0,0,0,.35); }
#sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 10px; }
#sheet .menu button { display: flex; width: 100%; gap: 12px; align-items: center; background: none; border: 0; padding: 13px 4px; text-align: left; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 15.5px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--player-h) + var(--safe-b) + 16px); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; }
.vnc { width: 100%; height: 70dvh; border: 1px solid var(--line); border-radius: 12px; background: #000; }
.login { max-width: 380px; margin: 10vh auto 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
pre.log { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 10px; max-height: 50vh; overflow: auto; }
@media (min-width: 900px) {
  #nav { left: 50%; transform: translateX(-50%); max-width: 640px; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
