:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e9ecf2;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #7aa8ff;
  --ok: #3ecf8e;
  --warn: #f5b84b;
  --bad: #ff6b6b;
  --radius: 14px;
  --gutter: max(16px, env(safe-area-inset-left));
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
svg text { fill: currentColor; stroke: none; font: 700 7px -apple-system, system-ui, sans-serif; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: rgba(15, 17, 21, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #4f8cff, #8b5cf6); position: relative; }
.logo::after { content: ""; position: absolute; left: 11px; top: 8px; border-left: 9px solid #fff; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 12px; padding: 0 12px; max-width: 560px; margin-left: auto; }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: inherit; padding: 11px 0; -webkit-user-select: text; user-select: text; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--panel-2); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 6px; padding: 4px var(--gutter) 12px; overflow-x: auto; position: sticky; top: calc(env(safe-area-inset-top) + 64px); z-index: 9; background: rgba(15, 17, 21, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.tabs button { padding: 9px 16px; border-radius: 999px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; line-height: 20px; margin-left: 4px; }
.tabs button[aria-selected="true"] .count { background: var(--bg); color: var(--text); }

.status { margin: 0 var(--gutter) 12px; padding: 12px 14px; border-radius: 12px; background: var(--panel); color: var(--muted); font-size: 14px; display: flex; gap: 12px; align-items: center; }
.status.bad { color: #ffd4d4; background: #3a1e22; }
.status button { margin-left: auto; color: var(--accent-2); font-weight: 600; }

main { padding: 0 var(--gutter) 40px; outline: none; }
h2 { font-size: 20px; margin: 18px 0 12px; display: flex; align-items: baseline; gap: 10px; }
h2 small { font-size: 14px; color: var(--muted); font-weight: 500; }

/* ---- cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px 16px; }
.row-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 280px); gap: 16px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.row-scroll > * { scroll-snap-align: start; }
.card { position: relative; content-visibility: auto; contain-intrinsic-size: 240px 220px; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, #1f2430, #262b38); display: grid; place-items: center; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.thumb img.loaded { opacity: 1; }
.thumb .ext { font-weight: 800; letter-spacing: .08em; color: #5b6475; font-size: 22px; }
.chip { position: absolute; padding: 2px 7px; border-radius: 7px; font-size: 12px; font-weight: 600; background: rgba(0, 0, 0, .72); color: #fff; }
.chip.dur { right: 8px; bottom: 8px; }
.chip.badge { left: 8px; top: 8px; }
.chip.badge.ok { background: rgba(30, 120, 80, .92); }
.chip.badge.warn { background: rgba(140, 95, 20, .92); }
.resume { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.card-body { display: flex; gap: 6px; padding: 8px 2px 0; }
.card-text { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-more { width: 40px; height: 40px; margin: -4px -6px 0 0; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.card-more:active { background: var(--panel-2); }
.card .play-hit { position: absolute; inset: 0; z-index: 1; border-radius: var(--radius); }
.card .card-more { position: relative; z-index: 2; }
.dlbar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 6px; }
.dlbar > div { height: 100%; background: var(--accent); transition: width .3s; }

.acct-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* ---- folders ---- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0 14px; color: var(--muted); }
.crumbs button { padding: 6px 10px; border-radius: 8px; color: var(--accent-2); font-weight: 600; }
.crumbs button:last-child { color: var(--text); }
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 22px; }
.folder { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; background: var(--panel); text-align: left; min-width: 0; }
.folder:active { background: var(--panel-2); }
.folder svg { color: var(--accent-2); flex: none; }
.folder .f-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder .f-count { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; }
.seg { display: inline-flex; background: var(--panel); border-radius: 10px; padding: 3px; }
.seg button { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--text); }
.more { display: block; margin: 24px auto 0; padding: 12px 22px; border-radius: 12px; background: var(--panel); font-weight: 600; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 22px; margin: 0 0 8px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 20px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; }
.btn.secondary { background: var(--panel-2); color: var(--text); }
.btn.danger { background: #3a1e22; color: #ffb3b3; }
.btn:active { filter: brightness(.9); }

/* ---- downloads ---- */
.storage { padding: 14px; border-radius: 12px; background: var(--panel); margin: 6px 0 18px; }
.storage .meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 8px 0 6px; }
.storage .meter > div { height: 100%; background: var(--accent); }
.storage small { color: var(--muted); }
.dl-row { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 12px; background: var(--panel); margin-bottom: 8px; }
.dl-row .dl-text { flex: 1; min-width: 0; }
.dl-row .dl-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-row .dl-state { color: var(--muted); font-size: 13px; }
.dl-row .dl-state.bad { color: var(--bad); }

/* ---- sheet ---- */
.sheet { border: 0; padding: 0; border-radius: 18px; background: var(--panel); color: var(--text); width: min(520px, calc(100vw - 32px)); max-height: 85vh; }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
#sheet-body { padding: 20px; }
.sheet h3 { margin: 0 0 14px; font-size: 20px; }
.sheet .acct { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sheet .acct .a-text { flex: 1; min-width: 0; }
.sheet .acct .a-mail { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.sheet .acct .a-state { font-size: 12px; color: var(--muted); }
.sheet .acct .a-state.bad { color: var(--bad); }
.sheet .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.menu-item { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 6px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 600; }
.menu-item:last-child { border-bottom: 0; }
.menu-item.danger { color: var(--bad); }
.menu-note { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2b303b; color: var(--text); padding: 12px 18px; border-radius: 12px; z-index: 60; max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .4); }

/* ---- player ---- */
.player { position: fixed; inset: 0; z-index: 50; background: #000; }
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player video::cue { font-size: 1.15em; background: rgba(0, 0, 0, .6); }
.p-ui { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; transition: opacity .25s; color: #fff;
  background: linear-gradient(rgba(0,0,0,.65), transparent 22%, transparent 70%, rgba(0,0,0,.75)); }
.player.idle .p-ui { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
.p-top { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 12px) max(18px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
.p-title { flex: 1; min-width: 0; }
#p-name { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-subline { font-size: 13px; color: #c5ccd8; }
.p-btn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.p-btn:active { background: rgba(255, 255, 255, .15); }
.p-btn.big { width: 72px; height: 72px; }
.p-btn.big svg { width: 40px; height: 40px; }
.p-btn.huge { width: 96px; height: 96px; background: rgba(255, 255, 255, .14); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.p-btn.huge svg { width: 48px; height: 48px; }
.p-btn .i-pause { display: none; }
.player.playing .p-btn .i-pause { display: block; }
.player.playing .p-btn .i-play { display: none; }
.p-btn.on { color: var(--accent-2); }
.p-center { display: flex; justify-content: center; align-items: center; gap: 48px; }
.p-bottom { padding: 0 max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 14px) max(20px, env(safe-area-inset-left)); }
.p-scrub { display: flex; align-items: center; gap: 14px; font-variant-numeric: tabular-nums; font-size: 14px; }
.scrub { position: relative; flex: 1; height: 36px; touch-action: none; }
.scrub::before, .scrub-buf, .scrub-fill { content: ""; position: absolute; left: 0; top: 16px; height: 5px; border-radius: 3px; }
.scrub::before { right: 0; background: rgba(255, 255, 255, .25); }
.scrub-buf { background: rgba(255, 255, 255, .45); width: 0; }
.scrub-fill { background: var(--accent); width: 0; }
.scrub-knob { position: absolute; top: 9px; width: 19px; height: 19px; margin-left: -9px; border-radius: 50%; background: #fff; left: 0; box-shadow: 0 1px 6px rgba(0,0,0,.5); }
.scrub.dragging .scrub-knob { transform: scale(1.3); }
.p-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.p-row .spacer { flex: 1; }
.p-pill { padding: 8px 14px; border-radius: 999px; background: rgba(255, 255, 255, .14); font-weight: 600; font-size: 14px; color: #fff; min-width: 54px; }
.p-pill.on { background: #fff; color: #000; }
.p-cues { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 130px); width: min(90%, 1100px);
  display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; transition: bottom .25s; z-index: 1; }
.player.idle .p-cues { bottom: calc(env(safe-area-inset-bottom) + 36px); }
.p-cues span { background: rgba(0, 0, 0, .72); color: #fff; font-size: clamp(18px, 2.4vw, 30px); line-height: 1.3; padding: 2px 10px; border-radius: 6px; text-align: center; white-space: pre-line; }
.player.has-message .p-center, .player.has-message .p-scrub, .player.has-message .p-row > :not(.spacer) { visibility: hidden; }
.p-loading, .p-message { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; text-align: center; color: #fff; }
.p-loading { display: flex; flex-direction: column; align-items: center; gap: 14px; pointer-events: none; }
.spinner { width: 44px; height: 44px; border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; }
.p-message { background: rgba(23, 26, 33, .96); padding: 24px; border-radius: 18px; width: min(460px, calc(100vw - 40px)); }
.p-message h3 { margin: 0 0 8px; }
.p-message p { color: #c5ccd8; margin: 0 0 16px; }
.p-message .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 700px) {
  .brand { font-size: 0; gap: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px 10px; }
  .p-center { gap: 24px; }
}
