:root {
  --bg: #0d0f13;
  --surface: #151820;
  --surface-2: #1c2029;
  --border: #262b36;
  --text: #e8eaef;
  --muted: #8a92a3;
  --accent: #ff6a3d;
  --accent-hover: #ff8259;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #f25f5c;
  --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;
  display: flex;
  flex-direction: column;
}

svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

.muted { color: var(--muted); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand-mark svg { width: 28px; height: 28px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: #fff; }
.brand-name em { font-style: normal; color: var(--muted); font-weight: 500; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill-ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgb(62 207 142 / 20%); }
.pill-bad .dot { background: var(--bad); }
.pill-bad { color: var(--bad); }

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
}

.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Play form */
.play-form { display: flex; gap: 10px; }
.play-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  font: inherit;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.play-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(255 106 61 / 18%); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 550;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3a4150; background: #232835; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 11px 20px; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn.is-saved svg { color: var(--warn); }

/* Player */
.player {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.player video { width: 100%; height: 100%; display: block; background: #000; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #161a22 0%, #07080b 100%);
  text-align: center;
  padding: 24px;
  transition: opacity .25s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay.translucent { background: rgb(0 0 0 / 55%); }
.overlay-title { margin: 12px 0 4px; font-size: 18px; font-weight: 600; }
.overlay-sub { margin: 0; color: var(--muted); max-width: 440px; }
.empty-icon {
  width: 64px; height: 64px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgb(255 106 61 / 12%);
  color: var(--accent);
}
.empty-icon svg { width: 30px; height: 30px; }

.spinner {
  width: 44px; height: 44px; margin: 0 auto;
  border: 3px solid rgb(255 255 255 / 12%);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Now playing */
.now-playing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.np-meta { min-width: 0; }
.np-meta h1 { margin: 0; font-size: 20px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.cast-menu-wrap { position: relative; }
.btn.is-casting { border-color: var(--accent); color: var(--accent); }

.cast-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 10;
  width: 280px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid #343a48;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 45%);
}
.cast-menu[hidden] { display: none; }
.cast-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 6px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.cast-menu ul { list-style: none; margin: 0; padding: 0; }
.cast-menu li > button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.cast-menu li > button:hover { background: #2a303c; }
.cast-menu li > button.active { color: var(--accent); }
.cast-menu .device-sub { display: block; font-size: 12px; color: var(--muted); }
.cast-menu .menu-note { padding: 10px; font-size: 13px; color: var(--muted); }
.cast-menu .menu-label { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); }
.cast-menu .menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.cast-menu .menu-note .spinner { width: 18px; height: 18px; border-width: 2px; display: inline-block; vertical-align: middle; margin: 0 8px 0 0; }
.overlay .btn { margin-top: 16px; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stats > div { background: var(--surface); padding: 12px 16px; }
.stats dt { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint code { color: var(--text); }

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
  max-height: calc(100vh - 110px);
  position: sticky;
  top: 24px;
}
@media (max-width: 1000px) { .sidebar { max-height: none; position: static; } }

.tabs { display: flex; padding: 6px; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 8px;
  font: inherit;
  font-weight: 550;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); }

.panel { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel[hidden] { display: none; }
.panel-note { margin: -4px 16px 8px; font-size: 12px; color: var(--muted); }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box input {
  flex: 1;
  padding: 10px 0;
  font: inherit;
  color: var(--text);
  background: none;
  border: 0;
  outline: none;
}

.list { list-style: none; margin: 0; padding: 0 6px 8px; overflow-y: auto; flex: 1; }
.list-empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 14px; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.item:hover { background: var(--surface-2); }
.item.playing { background: rgb(255 106 61 / 10%); }
.item.playing .item-name { color: var(--accent); }

.item-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
}
.item-icon img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.item-body { flex: 1; min-width: 0; }
.item-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.item:hover .item-actions, .item:focus-within .item-actions { opacity: 1; }
@media (hover: none) { .item-actions { opacity: 1; } }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: #2a303c; color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }
.icon-btn.fav { color: var(--warn); }
.icon-btn svg { width: 16px; height: 16px; }
.item .fav-static { color: var(--warn); }

/* Dialog */
dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / 60%); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 550; }
dialog input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
dialog input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Login */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.login-card label { font-size: 13px; font-weight: 550; }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { justify-content: center; }
.login-error { margin: -8px 0 0; min-height: 1em; font-size: 13px; color: var(--bad); }

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  background: #262b36;
  border: 1px solid #343a48;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--bad); }
