:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel-2: #1c2230;
  --line: #262d3d;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #f5a524;
  --accent-ink: #1a1203;
  --danger: #ff6b6b;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
svg { display: block; }

/* ---------------- Library ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: rgba(13, 15, 20, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: .2px;
  flex: none;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center;
}
.brand-mark svg { width: 16px; height: 16px; fill: var(--accent-ink); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; min-width: 0; color: var(--muted); font-size: 14px; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 3px 6px; border-radius: 6px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { background: var(--panel-2); color: var(--text); }
.crumbs a:last-child { color: var(--text); }
.crumbs .sep { opacity: .5; }

.library-main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
.library-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.library-head h1 { margin: 0; font-size: 24px; font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
#filter {
  width: min(280px, 100%); padding: 9px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); outline: none;
}
#filter:focus { border-color: var(--accent); }
.lib-status { color: var(--muted); padding: 32px 0; text-align: center; }
.lib-status.err { color: var(--danger); }

.drives { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.drive {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s;
}
.drive:hover { border-color: var(--accent); transform: translateY(-1px); }
.drive .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--panel-2); display: grid; place-items: center; flex: none; }
.drive .ic svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; }
.drive b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive small { color: var(--muted); text-transform: capitalize; }
.drive > div { min-width: 0; }

.entries { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); overflow: hidden; }
.entries:not(:empty) { border: 1px solid var(--line); }
.entries li + li { border-top: 1px solid var(--line); }
.entry {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--panel); color: var(--text); text-decoration: none; position: relative;
}
.entry:hover { background: var(--panel-2); }
.entry .ic { width: 22px; height: 22px; flex: none; fill: none; stroke-width: 1.8; }
.entry.dir .ic { stroke: var(--muted); }
.entry.file .ic { stroke: var(--accent); }
.entry .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry .meta { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry .progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); opacity: .8; }

/* ---------------- Player ---------------- */
.player { position: fixed; inset: 0; background: #000; }
.stage { position: absolute; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage.idle { cursor: none; }
.stage.idle .chrome { opacity: 0; pointer-events: none; }

.chrome { position: absolute; left: 0; right: 0; transition: opacity .25s; z-index: 3; }
.chrome.top {
  top: 0; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 36px;
  background: linear-gradient(rgba(0,0,0,.7), transparent);
}
.title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 3px #000; }
.chrome.bottom {
  bottom: 0; padding: 40px 16px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}

.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%; cursor: pointer; color: #fff;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn text { fill: currentColor; font-family: system-ui, sans-serif; }

#play .i-pause, .playing #play .i-play { display: none; }
.playing #play .i-pause { display: block; }
#mute .i-mute, .muted #mute .i-vol { display: none; }
.muted #mute .i-mute { display: block; }

.controls { display: flex; align-items: center; gap: 4px; }
.spacer { flex: 1; }
.time { font-size: 13px; font-variant-numeric: tabular-nums; color: #dfe3ec; margin-left: 8px; white-space: nowrap; }
.volume { display: flex; align-items: center; }
#vol { width: 90px; accent-color: var(--accent); }
.pill {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); border-radius: 8px;
  padding: 5px 8px; font-size: 13px; cursor: pointer; max-width: 180px;
}
.pill option { background: var(--panel); }

.seek { position: relative; height: 22px; display: flex; align-items: center; cursor: pointer; touch-action: none; margin-bottom: 4px; }
.seek-track { position: relative; width: 100%; height: 4px; border-radius: 4px; background: rgba(255,255,255,.22); transition: height .12s; }
.seek:hover .seek-track, .seek.dragging .seek-track { height: 6px; }
.seek-buffer, .seek-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: inherit; }
.seek-buffer { background: rgba(255,255,255,.35); }
.seek-fill { background: var(--accent); }
.seek-thumb {
  position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px rgba(245,165,36,.25); transform: scale(0); transition: transform .12s;
}
.seek:hover .seek-thumb, .seek.dragging .seek-thumb { transform: scale(1); }
.seek-tip {
  position: absolute; bottom: 24px; transform: translateX(-50%); padding: 3px 7px; border-radius: 6px;
  background: rgba(0,0,0,.85); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none;
}

.bigplay {
  position: absolute; left: 50%; top: 50%; width: 84px; height: 84px; margin: -42px 0 0 -42px; z-index: 2;
  border-radius: 50%; border: 0; background: rgba(245,165,36,.92); cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.bigplay svg { width: 38px; height: 38px; fill: var(--accent-ink); margin-left: 5px; }

.spinner { position: absolute; left: 50%; top: 50%; margin: -24px 0 0 -24px; z-index: 2; pointer-events: none; }
.spinner div {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute; left: 50%; top: 72px; transform: translateX(-50%); z-index: 4;
  background: rgba(21,25,34,.95); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px 8px 14px; display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap;
}
.toast button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px; padding: 4px 10px; font-weight: 600; cursor: pointer; }
.error {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4; max-width: min(520px, 90vw);
  background: var(--panel); border: 1px solid var(--danger); color: var(--text); border-radius: var(--radius);
  padding: 18px 20px; text-align: center;
}

/* ---------------- Login ---------------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px;
}
.login-card .brand { margin-bottom: 14px; font-size: 20px; }
.login-card label { color: var(--muted); font-size: 14px; }
.login-card input {
  padding: 11px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  margin-top: 6px; padding: 11px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.login-err { margin: 0; color: var(--danger); font-size: 14px; }

.logout { margin-left: auto; flex: none; }
.logout button {
  background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.logout button:hover { color: var(--text); border-color: var(--muted); }

@media (max-width: 600px) {
  .topbar { gap: 12px; }
  .brand { font-size: 0; gap: 0; }
  #vol, .time.hide-sm { display: none; }
  #rew, #fwd { display: none; }
  .pill { max-width: 90px; }
  .entry .meta { display: none; }
}
