:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --surface-2: #272727;
  --ink: #f1f1f1;
  --muted: #aaa;
  --line: #303030;
  --brand: #ff0033;
  --brand-dark: #cc0029;
  --danger: #d92d20;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  --radius: 8px;
  --sidebar: 248px;
  --topbar: 64px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: var(--topbar) minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  height: var(--topbar);
  padding: 0 20px;
  display: grid;
  grid-template-columns: minmax(190px, var(--sidebar)) minmax(160px, 680px) auto;
  align-items: center;
  gap: 18px;
  background: rgba(15, 15, 15, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand,
.top-actions,
.watch-actions,
.modal-actions,
.side-heading {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logo strong {
  font-size: 22px;
  letter-spacing: 0;
  white-space: nowrap;
}

.logo-mark {
  width: 36px;
  height: 25px;
  border-radius: 7px;
  background: var(--brand);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.logo-mark span {
  width: 0;
  height: 0;
  border-left: 10px solid #fff;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  margin-left: 2px;
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 18px;
  font-weight: 700;
}

.icon-button,
.mini-button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  background: transparent;
}

.icon-button:hover,
.mini-button:hover {
  background: var(--surface-2);
}

.mini-button {
  width: 32px;
  height: 32px;
  font-size: 20px;
  font-weight: 700;
}

.search {
  height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
}

.search input {
  min-width: 0;
  height: 42px;
  padding: 0 16px;
  border: 1px solid #303030;
  border-right: 0;
  border-radius: 999px 0 0 999px;
  outline: 0;
  background: #121212;
  color: var(--ink);
  font-size: 16px;
}

.search input:focus {
  border-color: #3ea6ff;
  box-shadow: inset 0 0 0 1px #3ea6ff;
}

.search button {
  height: 42px;
  border: 1px solid #303030;
  border-radius: 0 999px 999px 0;
  background: #222;
  color: var(--ink);
}

.search button:hover {
  background: #303030;
}

.top-actions,
.watch-actions {
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.soft-button,
.danger-button {
  min-height: 40px;
  border-radius: 999px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
  text-align: center;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.soft-button {
  background: var(--surface-2);
  color: var(--ink);
}

.soft-button:hover {
  background: #3f3f3f;
}

.danger-button {
  background: #fff0ee;
  color: var(--danger);
}

.danger-button:hover {
  background: #ffe0dc;
}

.file-input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.sidebar {
  grid-column: 1;
  grid-row: 2;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: #0f0f0f;
  overflow: auto;
  position: sticky;
  top: var(--topbar);
  height: calc(100vh - var(--topbar));
}

.nav-list,
.playlist-list {
  display: grid;
  gap: 4px;
}

.nav-item,
.playlist-item {
  width: 100%;
  min-height: 44px;
  border-radius: var(--radius);
  padding: 0 12px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-item:hover,
.playlist-item:hover,
.nav-item.active,
.playlist-item.active {
  background: var(--surface-2);
}

.playlist-item span:nth-child(2) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.count {
  color: var(--muted);
  font-size: 12px;
}

.side-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.side-heading {
  justify-content: space-between;
  padding: 0 4px 8px 12px;
}

.side-heading h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.content {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  padding: 0 28px 28px;
}

.category-rail {
  height: 74px;
  margin: 0 -28px 18px;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  background: rgba(15, 15, 15, 0.96);
  position: sticky;
  top: var(--topbar);
  z-index: 20;
  scrollbar-width: none;
}

.category-rail::-webkit-scrollbar {
  display: none;
}

.category-chip {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  background: #272727;
  font-weight: 700;
  white-space: nowrap;
}

.category-chip:hover {
  background: #3f3f3f;
}

.category-chip.active {
  color: #0f0f0f;
  background: #f1f1f1;
}

.home-panel {
  margin: 0 0 22px;
  display: grid;
  gap: 14px;
}

.home-main {
  min-height: 170px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255, 0, 51, 0.08), transparent 46%),
    linear-gradient(315deg, rgba(47, 111, 235, 0.1), transparent 46%),
    #fff;
  padding: clamp(18px, 3vw, 28px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
}

.home-main h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1;
  letter-spacing: 0;
}

.home-main p {
  margin: 10px 0 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

.home-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.home-stat {
  min-height: 88px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  padding: 14px;
  overflow: hidden;
}

.home-stat b {
  display: block;
  font-size: 27px;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-stat span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.watch {
  margin: 0 0 22px;
  display: grid;
  gap: 14px;
}

.player-shell {
  width: 100%;
  border-radius: var(--radius);
  background: #050505;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.player {
  aspect-ratio: 16 / 9;
  width: 100%;
  min-height: 260px;
  background: #050505;
}

.player video,
.player iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #050505;
}

.processing-player {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 24px;
  color: #fff;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(255, 0, 51, 0.18), transparent 45%),
    linear-gradient(315deg, rgba(47, 111, 235, 0.22), transparent 45%),
    #050505;
}

.processing-player strong {
  font-size: clamp(20px, 3vw, 30px);
}

.processing-player span:not(.loader-ring) {
  color: rgba(255, 255, 255, 0.76);
}

.error-player {
  background:
    linear-gradient(135deg, rgba(217, 45, 32, 0.28), transparent 45%),
    #151515;
}

.error-player .primary-button {
  margin-top: 8px;
}

.watch-info {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.watch-info h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.12;
  letter-spacing: 0;
}

.watch-meta {
  min-height: 28px;
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
}

.chip {
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  color: #3c4043;
  font-size: 13px;
}

.drop-zone {
  min-height: 98px;
  margin-bottom: 22px;
  border: 2px dashed #c6ccd6;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 0, 51, 0.08), transparent 45%),
    linear-gradient(315deg, rgba(47, 111, 235, 0.1), transparent 45%),
    #181818;
  display: none;
  place-items: center;
  text-align: center;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.drop-zone.is-dragging {
  display: grid;
  border-color: var(--brand);
  transform: translateY(-1px);
  background: #fff7f8;
}

.drop-zone strong {
  display: block;
  font-size: 18px;
}

.drop-zone span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.section-head {
  margin-bottom: 16px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-head.is-hidden {
  display: none;
}

.section-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.status {
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 11px;
  display: inline-flex;
  align-items: center;
  color: #15703a;
  background: #e8f7ee;
  font-size: 13px;
  white-space: nowrap;
}

.status.busy {
  color: #92400e;
  background: #fff4d6;
}

.status.error {
  color: #b42318;
  background: #fff0ee;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 34px 18px;
}

.video-card {
  min-width: 0;
  border-radius: var(--radius);
  color: inherit;
  background: transparent;
  text-align: left;
}

.video-card:hover .thumb {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(15, 15, 15, 0.16);
}

.video-card.processing .thumb::after {
  opacity: 0.34;
}

.video-card.failed .thumb {
  background:
    linear-gradient(135deg, rgba(217, 45, 32, 0.9), rgba(39, 39, 39, 0.92)),
    #191b22;
}

.thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 0, 51, 0.95), rgba(255, 181, 71, 0.88)),
    #191b22;
  position: relative;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  position: relative;
  z-index: 1;
}

.thumb.youtube {
  background:
    linear-gradient(135deg, rgba(15, 15, 15, 0.95), rgba(255, 0, 51, 0.76)),
    #191b22;
}

.thumb.local:nth-child(3n + 1) {
  background:
    linear-gradient(135deg, rgba(47, 111, 235, 0.92), rgba(17, 141, 87, 0.86)),
    #191b22;
}

.thumb.local:nth-child(3n + 2) {
  background:
    linear-gradient(135deg, rgba(255, 181, 71, 0.94), rgba(255, 0, 51, 0.84)),
    #191b22;
}

.thumb::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 2;
}

.thumb::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-42%, -50%);
  border-left: 28px solid rgba(255, 255, 255, 0.94);
  border-top: 19px solid transparent;
  border-bottom: 19px solid transparent;
  z-index: 2;
}

.thumb.has-image::after {
  display: none;
}

.badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-height: 24px;
  border-radius: 5px;
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.74);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  z-index: 3;
}

.loader-ring {
  position: absolute;
  left: 12px;
  bottom: 10px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.38);
  border-top-color: #fff;
  animation: spin 900ms linear infinite;
  z-index: 3;
}

.loader-ring.large {
  position: static;
  width: 48px;
  height: 48px;
  border-width: 4px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.card-body {
  padding: 10px 2px 0;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2d2d2d;
  color: #fff;
  font-weight: 800;
}

.video-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.28;
  letter-spacing: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.empty-state {
  min-height: 280px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #181818;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 20px;
}

.empty-state.compact {
  min-height: 72px;
  padding: 12px;
}

.empty-state.compact strong {
  font-size: 14px;
}

.empty-state.compact span {
  font-size: 12px;
}

.modal {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
}

.modal.wide,
.modal-card.wide {
  width: min(560px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(15, 15, 15, 0.42);
}

.modal-card {
  width: 100%;
  border-radius: var(--radius);
  padding: 18px;
  background: #181818;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field span,
.check span {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #3f3f3f;
  border-radius: var(--radius);
  padding: 0 12px;
  outline: 0;
}

.field input:focus,
.field select:focus {
  border-color: #3ea6ff;
  box-shadow: 0 0 0 3px rgba(62, 166, 255, 0.16);
}

.check {
  margin: 4px 0 14px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
}

.check input {
  margin-top: 2px;
}

.modal-actions {
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions.split {
  justify-content: space-between;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 90;
  max-width: calc(100vw - 28px);
  min-height: 42px;
  border-radius: 999px;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 90px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1040px) {
  .app {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: minmax(160px, 220px) minmax(140px, 1fr) auto;
  }

  .sidebar {
    padding: 8px;
  }

  .nav-item,
  .playlist-item {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 3px;
    padding: 8px 4px;
    font-size: 11px;
    text-align: center;
  }

  .nav-item .count,
  .playlist-item .count,
  .side-heading h2 {
    display: none;
  }

  .side-heading {
    justify-content: center;
    padding: 8px 0;
  }

  .home-main {
    grid-template-columns: 1fr;
  }

  .home-actions {
    justify-content: flex-start;
  }

  .home-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --topbar: auto;
  }

  .app {
    display: block;
  }

  .topbar {
    position: sticky;
    min-height: 64px;
    grid-template-columns: 1fr auto;
    padding: 10px 12px;
  }

  .search {
    grid-column: 1 / -1;
    order: 3;
  }

  .top-actions {
    gap: 6px;
  }

  .top-actions .soft-button {
    width: 42px;
    padding: 0;
    overflow: hidden;
  }

  .primary-button,
  .soft-button,
  .danger-button {
    padding: 0 12px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    height: 100vh;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .nav-item,
  .playlist-item {
    grid-template-columns: 24px minmax(0, 1fr) auto;
    justify-items: stretch;
    gap: 12px;
    padding: 0 12px;
    font-size: 14px;
    text-align: left;
  }

  .nav-item .count,
  .playlist-item .count,
  .side-heading h2 {
    display: block;
  }

  .side-heading {
    justify-content: space-between;
    padding: 0 4px 8px 12px;
  }

  .content {
    padding: 14px;
  }

  .home-main {
    min-height: 0;
  }

  .home-main p {
    font-size: 15px;
  }

  .watch-info {
    grid-template-columns: 1fr;
  }

  .watch-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .logo strong {
    font-size: 18px;
  }

  .top-actions .primary-button {
    width: 42px;
    padding: 0;
    overflow: hidden;
  }

  .watch-info h1 {
    font-size: 22px;
  }

  .player {
    min-height: 210px;
  }

  .home-stats {
    grid-template-columns: 1fr;
  }

  .modal-actions.split {
    display: grid;
    grid-template-columns: 1fr;
  }
}
