:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --side: #131318;
  --dim: #8e8e98;
  --muted: #b4b4be;
  --line: rgba(255, 255, 255, 0.08);
  --red: #e53935;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: #fff; }
button, input, select { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
#app { height: 100%; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.card {
  width: min(420px, 100%);
  background: var(--side);
  border-radius: 18px;
  padding: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--red);
  display: grid; place-items: center;
}
.brand h1 { margin: 0; font-size: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { color: var(--dim); font-size: 13px; }
.field input, .field select, .src input, .src select {
  background: #0b0b0f;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
}
.field input:focus, .src input:focus, .src select:focus { border-color: #fff; }
.primary, .ghost {
  border: 0; border-radius: 10px; padding: 12px 16px; font-weight: 650;
}
.primary { background: #fff; color: #111; }
.ghost { background: transparent; color: var(--muted); }
.error { color: #ff8a80; font-size: 14px; min-height: 1.2em; }

.shell { height: 100%; display: flex; min-height: 0; }
.side {
  width: 240px; flex: none; background: var(--side);
  display: flex; flex-direction: column; padding: 22px 12px 12px;
  min-height: 0; overflow: hidden;
}
.side nav {
  overflow: auto; flex: 1; min-height: 0; padding-right: 2px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.side-btn, .foot button {
  width: 100%; height: 38px; border: 0; background: transparent; border-radius: 10px;
  display: flex; align-items: center; gap: 10px; padding: 0 10px; color: var(--muted);
  text-align: left; margin-bottom: 3px;
}
.side-btn .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.side-btn .count, .side-btn .chev { color: var(--dim); font-size: 12px; }
.side-btn.selected { background: rgba(255, 255, 255, 0.12); color: #fff; font-weight: 650; }
.side-btn.focused { background: #fff; color: #111; font-weight: 650; }
.side-btn.focused .count, .side-btn.focused .chev { color: rgba(0, 0, 0, 0.55); }
.side-btn.depth-1 { padding-left: 22px; }
.side-btn.depth-2 { padding-left: 40px; }
.foot { display: flex; gap: 6px; padding-top: 8px; }
.foot button { justify-content: center; background: rgba(255, 255, 255, 0.06); }
.foot button.on { background: #fff; color: #111; }

.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.library { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.head {
  display: flex; align-items: flex-end; gap: 12px;
  padding: 22px 28px 8px;
}
.head h2 { margin: 0; font-size: 24px; }
.head .meta { color: var(--dim); font-size: 13px; padding-bottom: 3px; }
.head .spacer { flex: 1; }
.filter {
  background: #131318; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; width: min(280px, 40vw);
}
.status {
  flex: 1; display: grid; place-items: center; color: var(--dim); text-align: center; padding: 24px;
}
.status[hidden], .grid[hidden], .fail[hidden], .playlist[hidden], .dock[hidden], .ratio-menu[hidden], #ratio-wrap[hidden], .ibtn[hidden], .pbtn[hidden], .play[hidden], .library[hidden], .settings-page[hidden] { display: none !important; }
.grid {
  flex: 1; overflow: auto; position: relative; padding: 8px 16px 28px;
}
.grid-inner { position: relative; }
.tile {
  position: absolute; padding: 6px; background: transparent; border: 0; text-align: center;
}
.art {
  height: 104px; border-radius: 10px; display: grid; place-items: center;
  overflow: hidden; position: relative; background: #f4f4f6;
}
.art img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.art.fallback { color: #fff; font-weight: 800; letter-spacing: 1px; font-size: 22px; }
.tile.focused .art { outline: 2px solid #fff; outline-offset: 2px; transform: scale(1.04); }
.tile .name {
  margin-top: 8px; color: #a0a0aa; font-size: 12px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile.focused .name { color: #fff; }
.star {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.8); color: #666; display: grid; place-items: center;
}
.star.on { color: #ffc107; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: rgba(26, 26, 30, 0.94); border-radius: 20px; padding: 8px 16px; z-index: 30;
}

.player { position: fixed; inset: 0; background: #000; z-index: 20; display: none; }
.player.open { display: flex; flex-direction: column; overflow: hidden; }
.stage { position: relative; flex: 1; min-height: 0; min-width: 0; background: #000; display: grid; container-type: size; }
.stage > video { grid-area: 1 / 1; width: 100%; height: 100%; background: #000; object-fit: contain; }
.stage.ratio-fill > video { object-fit: cover; }
.stage.ratio-stretch > video { object-fit: fill; }
.stage.ratio-16 > video, .stage.ratio-43 > video { justify-self: center; align-self: center; object-fit: contain; }
.stage.ratio-16 > video { width: min(100%, calc(100cqh * 16 / 9)); height: min(100%, calc(100cqw * 9 / 16)); }
.stage.ratio-43 > video { width: min(100%, calc(100cqh * 4 / 3)); height: min(100%, calc(100cqw * 3 / 4)); }
.chrome-btn, .pbtn {
  border: 0; background: rgba(0, 0, 0, 0.55); color: #fff; border-radius: 10px; padding: 10px 14px;
}
.chrome-btn { position: absolute; top: max(18px, env(safe-area-inset-top)); z-index: 5; display: grid; place-items: center; min-height: 42px; }
#player-back { left: max(18px, env(safe-area-inset-left)); }
#player-close { right: max(18px, env(safe-area-inset-right)); width: 42px; height: 42px; padding: 0; }
.bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 28px 32px max(22px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
}
.bar h3 { margin: 0 0 4px; font-size: 22px; }
.bar .sub { color: rgba(255, 255, 255, 0.65); font-size: 13px; margin-bottom: 12px; }
.times { display: flex; align-items: center; gap: 10px; color: rgba(255, 255, 255, 0.75); font-size: 13px; font-variant-numeric: tabular-nums; }
.times input { flex: 1; accent-color: #fff; }
.controls { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.controls .play {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: #fff; color: #111; font-size: 18px;
}
.zap, .view, .vol {
  display: flex; align-items: center; gap: 6px;
  padding: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 16px;
}
.ratio-wrap { position: relative; }
.ratio-menu {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  z-index: 6; min-width: 132px; padding: 6px;
  background: rgba(19, 19, 24, 0.98); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.ratio-menu button {
  display: block; width: 100%; min-height: 44px; border: 0; border-radius: 8px;
  background: transparent; color: #fff; text-align: left; padding: 8px 12px;
}
.ratio-menu button.on, .ratio-menu button:hover { background: rgba(229, 57, 53, 0.28); }
.ibtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-width: 88px; height: 62px; padding: 6px 10px;
  border: 0; border-radius: 12px; background: transparent; color: #fff;
  font-size: 11px; font-weight: 650; letter-spacing: 0.2px;
}
.ibtn svg { display: block; }
.ibtn:hover { background: rgba(255, 255, 255, 0.12); }
.ibtn.on { background: #fff; color: #111; }
.ibtn.icon-only { min-width: 44px; width: 44px; height: 44px; padding: 0; border-radius: 12px; }
.vol { padding-right: 14px; }
.vol input { width: 108px; accent-color: #fff; }
.hint { text-align: center; color: rgba(255, 255, 255, 0.5); font-size: 12px; margin-top: 10px; }
.mini-ui { display: none; }
.player.theater { background: #0b0b0f; }
.player.theater .stage { flex: 2; }
.dock {
  display: none; flex: 1; min-height: 132px; min-width: 0;
  flex-direction: column; background: #101014; border-top: 1px solid var(--line);
}
.player.theater .dock { display: flex; }
.dock-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 14px 0; }
.dock-head strong { font-size: 14px; }
.dock-head span { color: var(--dim); font-size: 12px; }
.dock-list { position: relative; flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden; }
.dock-inner { position: relative; height: 100%; }
.dock-card {
  position: absolute; top: 8px; width: 144px; height: calc(100% - 16px); max-height: 128px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; background: transparent; color: #fff; padding: 6px;
}
.dock-card.on { background: rgba(229, 57, 53, 0.28); }
.dock-card:hover { background: rgba(255, 255, 255, 0.08); }
.dock-art {
  width: 72px; height: 40px; border-radius: 8px; overflow: hidden; flex: none;
  display: grid; place-items: center; background: #0b0b0f;
  font-size: 11px; font-weight: 750;
}
.dock-art img { width: 100%; height: 100%; object-fit: contain; }
.dock-name { width: 100%; font-size: 12px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player.mini {
  inset: auto; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 24;
  width: min(560px, calc(100vw - 28px)); aspect-ratio: 16 / 9; height: auto;
  border-radius: 16px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}
.player.mini .stage { position: absolute; inset: 0; flex: none; }
.player.mini .chrome-btn,
.player.mini .bar,
.player.mini .playlist,
.player.mini .dock { display: none !important; }
.player.mini .mini-ui { display: block; position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.player.mini .mini-top,
.player.mini .mini-bottom {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 8px;
}
.player.mini .mini-top { top: 0; padding-left: 46px; background: linear-gradient(rgba(0, 0, 0, 0.72), transparent); }
.mini-resize {
  position: absolute; top: 0; left: 0; z-index: 6; width: 44px; height: 44px;
  border: 0; padding: 0; background: transparent; color: #fff;
  pointer-events: auto; cursor: nwse-resize; touch-action: none;
}
.mini-resize::before {
  content: ''; position: absolute; top: 8px; left: 8px; width: 14px; height: 14px;
  border-top: 2px solid #fff; border-left: 2px solid #fff; border-radius: 2px 0 0 0;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.8));
}
.player.mini .mini-bottom { bottom: 0; background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)); }
.mini-title {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 2px #000;
}
.mbtn {
  width: 36px; height: 36px; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 9px; padding: 0;
  background: rgba(12, 12, 16, 0.86); color: #fff; display: grid; place-items: center;
  pointer-events: auto; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.mbtn:hover { background: rgba(255, 255, 255, 0.22); }
.player.mini .fail { font-size: 13px; padding: 42px 12px 48px; }
.player.mini .fail .actions { display: none; }
.chrome-btn:focus-visible, .ibtn:focus-visible, .mbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.fail { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; text-align: center; padding: 72px 24px 160px; }
.fail .actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.playlist {
  position: absolute; top: 72px; left: 18px; bottom: 150px; z-index: 4;
  width: min(340px, calc(100% - 36px));
  display: flex; flex-direction: column;
  background: rgba(19, 19, 24, 0.96);
  border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.playlist-head { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.playlist-head strong { display: block; font-size: 15px; }
.playlist-head span { color: var(--dim); font-size: 12px; }
.playlist-list { position: relative; flex: 1; overflow: auto; }
.playlist-inner { position: relative; }
.plist {
  position: absolute; left: 8px; right: 8px; height: 44px;
  display: flex; align-items: center; gap: 10px;
  border: 0; border-radius: 10px; background: transparent; color: #fff;
  text-align: left; padding: 0 8px;
}
.plist.on { background: rgba(229, 57, 53, 0.28); }
.plist:hover { background: rgba(255, 255, 255, 0.08); }
.plist.on:hover { background: rgba(229, 57, 53, 0.4); }
.plist-art {
  width: 36px; height: 28px; border-radius: 6px; flex: none; overflow: hidden;
  display: grid; place-items: center; background: #0b0b0f;
  font-size: 9px; font-weight: 700; letter-spacing: 0.3px;
}
.plist-art img { width: 100%; height: 100%; object-fit: contain; }
.plist-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }

.settings-page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.settings-back {
  border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.08);
  padding: 8px 14px; margin: 0 4px 2px 0;
}
.settings-scroll {
  overflow: auto; padding: 4px 28px 36px;
  display: flex; flex-direction: column; gap: 16px;
}
.set-card {
  width: min(880px, 100%); background: var(--side); border-radius: 16px; padding: 20px 20px 16px;
}
.set-card h3 { margin: 0 0 6px; font-size: 18px; }
.set-card p.lead { margin: 0 0 14px; color: var(--dim); font-size: 14px; line-height: 1.45; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; border-bottom: 1px solid var(--line);
}
.user-name { font-weight: 650; }
.you {
  font-size: 12px; font-weight: 700; color: #111; background: #fff;
  border-radius: 999px; padding: 2px 8px;
}
.user-row .ghost { margin-left: auto; width: auto; }
.add-user {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; margin-top: 14px;
}
.add-user .field, .account .field { margin: 0; }
.add-user .primary { height: 46px; }
.src {
  display: grid; grid-template-columns: minmax(140px, 180px) 210px minmax(0, 1fr) auto; gap: 8px; margin-bottom: 8px;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.row-actions .ghost { width: auto; }
.account { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#account-form .primary, #settings-form .primary { margin-top: 4px; }
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .side { width: 100%; max-height: 38vh; padding: 12px 10px 8px; }
  .side.menu-open { max-height: 62vh; }
  .side-btn, .foot button { height: 44px; }
  .head { padding: 14px 14px 8px; flex-wrap: wrap; }
  .head h2 { font-size: 20px; }
  .filter { width: 100%; }
  .settings-scroll { padding: 4px 14px 28px; }
  .set-card { padding: 16px 14px 14px; }
  .src, .account, .add-user { grid-template-columns: 1fr; }
  .add-user .primary, .user-row .ghost, .row-actions .ghost { width: 100%; }
  .bar { padding: 16px 12px max(10px, env(safe-area-inset-bottom)); }
  .bar h3 { font-size: 16px; }
  .bar .sub { margin-bottom: 6px; }
  .hint { display: none; }
  .controls { gap: 8px; margin-top: 8px; }
  .zap, .view, .vol { gap: 2px; padding: 4px; }
  .ibtn { min-width: 44px; width: 44px; height: 44px; padding: 0; }
  .ibtn span { display: none; }
  .vol { padding-right: 8px; }
  .vol input { width: 76px; }
  .fail { padding: 64px 16px 110px; }
  .playlist { top: 64px; left: 10px; bottom: 110px; width: min(300px, calc(100% - 20px)); }
  .player.mini { width: min(560px, calc(100vw - 16px)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); }
  .player.theater .dock { min-height: 112px; }
  .ratio-menu { left: auto; right: 0; transform: none; }
}
