:root {
  --bg: #f9f9f9;
  --bg-2: #f3f3f3;
  --ink: #0f0f0f;
  --muted: #606060;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --line: #e5e5e5;
  --brand: #ff0033;
  --brand-2: #d90026;
  --ok: #00a958;
  --warn: #f5a623;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  --r1: 8px;
  --r2: 10px;
  --r3: 12px;
}

body.theme-dark {
  --bg: #0f0f0f;
  --bg-2: #161616;
  --ink: #f1f1f1;
  --muted: #aaaaaa;
  --surface: #1f1f1f;
  --surface-2: #242424;
  --line: #303030;
  --brand: #ff355e;
  --brand-2: #e11d48;
  --ok: #32d27a;
  --warn: #ffbf47;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  font-family: "Roboto", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.noise { display: none; }

.commandbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  height: 56px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-cube {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
}

.brand-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: -1px;
}

.cmd-actions { display: flex; gap: 8px; }

.btn,
select {
  height: 36px;
  border-radius: var(--r1);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  padding: 0 10px;
}

.btn { cursor: pointer; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-flat { background: transparent; }

.btn-strong {
  border: 0;
  color: #fff;
  font-weight: 500;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}

.status-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
}

.rail-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--warn);
}

.dot.online { background: var(--ok); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: 12px;
  padding: 0 12px 12px;
  min-height: 0;
  align-items: start;
}

.library-column,
.player-column {
  min-width: 0;
}

.controls-panel,
.player-shell,
.stats,
.card,
.stat,
.control,
.switcher {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r2);
}

.controls-panel {
  padding: 8px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: end;
}

.control { padding: 8px; }

.control label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.control select { width: 100%; }

.switcher {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.card {
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.card.active {
  border-color: color-mix(in srgb, var(--brand), transparent 20%);
}

.thumb,
.thumb-fallback {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
}

.thumb {
  object-fit: cover;
  background: #222;
}

.thumb-fallback {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  background: linear-gradient(145deg, #454545, #2d2d2d);
}

.card-body { padding: 8px; }

.title {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  font-weight: 500;
}

.sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.row {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  color: var(--muted);
  background: var(--surface-2);
}

.progress {
  margin-top: 7px;
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--line), transparent 20%);
}

.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}

.player-shell {
  padding: 10px;
  box-shadow: var(--shadow);
}

.video-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--r1);
  overflow: hidden;
  background: #000;
}

#player { width: 100%; height: 100%; }

.action-row {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.stats {
  margin-top: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
  overflow-x: auto;
}

.stat { padding: 8px; }

.stat .k {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

.stat .v {
  margin-top: 3px;
  font-size: 14px;
  font-weight: 500;
}

.empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: var(--r1);
  background: var(--surface);
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1220px) {
  .layout { grid-template-columns: 1fr; }
  .player-column { order: -1; }
  .controls-panel { grid-template-columns: 1fr 1fr; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .layout {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 56px);
  }

  .player-column {
    order: -1;
    width: 100%;
  }

  .library-column {
    width: 100%;
  }

  .video-wrap {
    width: 100%;
    max-height: none;
  }

  .controls-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 780px) {
  .commandbar {
    height: auto;
    padding: 10px;
  }

  .cmd-actions { justify-content: flex-end; }

  .status-rail,
  .layout {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand-sub { display: none; }

  .controls-panel { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
}
