:root {
  color-scheme: dark;
  --bg: #0a0c12;
  --panel: rgba(16, 20, 30, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f2f4f8;
  --muted: #a8b2c1;
  --accent: #37f0d4;
  --accent-2: #ffcf7a;
  --danger: #ff6b6b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --body-bg: radial-gradient(circle at top, #1b2332 0%, #0a0c12 55%, #06070b 100%);
  --grid-line: rgba(255, 255, 255, 0.05);
  --surface-1: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.08);
  --surface-4: rgba(255, 255, 255, 0.12);
  --toast-bg: rgba(16, 18, 24, 0.95);
  --overlay: rgba(6, 8, 12, 0.7);
  --episode-bg: rgba(0, 0, 0, 0.3);
  --avatar-bg: linear-gradient(120deg, #334155, #111827);
  --danger-bg: rgba(255, 107, 107, 0.12);
  --danger-border: rgba(255, 107, 107, 0.3);
  --bg-accent-1: rgba(55, 240, 212, 0.18);
  --bg-accent-2: rgba(255, 207, 122, 0.16);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.95);
  --panel-border: rgba(15, 23, 42, 0.12);
  --text: #101827;
  --muted: #5b6473;
  --accent: #0ea5a3;
  --accent-2: #f5b042;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  --body-bg: radial-gradient(circle at top, #f2f5fb 0%, #e8edf6 60%, #dfe6f1 100%);
  --grid-line: rgba(15, 23, 42, 0.08);
  --surface-1: rgba(15, 23, 42, 0.04);
  --surface-2: rgba(15, 23, 42, 0.06);
  --surface-3: rgba(15, 23, 42, 0.08);
  --surface-4: rgba(15, 23, 42, 0.12);
  --toast-bg: rgba(255, 255, 255, 0.95);
  --overlay: rgba(15, 23, 42, 0.45);
  --episode-bg: rgba(15, 23, 42, 0.06);
  --avatar-bg: linear-gradient(120deg, #e2e8f0, #cbd5f5);
  --danger-bg: rgba(220, 38, 38, 0.12);
  --danger-border: rgba(220, 38, 38, 0.25);
  --bg-accent-1: rgba(14, 165, 163, 0.18);
  --bg-accent-2: rgba(245, 176, 66, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Archivo", "Noto Sans SC", system-ui, sans-serif;
  background: var(--body-bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 10% 10%, var(--bg-accent-1), transparent 50%),
    radial-gradient(circle at 90% 15%, var(--bg-accent-2), transparent 55%);
  z-index: 0;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 140px 140px;
  mask-image: radial-gradient(circle at 40% 20%, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.1));
  pointer-events: none;
  z-index: 0;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 36px 8vw 12px;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(120deg, rgba(55, 240, 212, 0.9), rgba(255, 207, 122, 0.8));
  color: #04101a;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-title {
  font-size: 18px;
  font-weight: 600;
}


.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--surface-2);
  backdrop-filter: blur(12px);
  min-width: 200px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--avatar-bg);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 600;
}

.username {
  font-weight: 600;
}

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

.layout {
  position: relative;
  z-index: 1;
  padding: 0 8vw 80px;
  display: grid;
  gap: 32px;
}

.query-bar {
  display: grid;
  gap: 16px;
}

.hero-text h1 {
  margin: 0;
}

.search-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--panel-border);
  display: grid;
  gap: 12px;
}

.search-card.compact {
  padding: 14px 16px;
}

.field {
  display: grid;
  gap: 8px;
}

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

.field input,
.field select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-3);
  color: var(--text);
  outline: none;
  font-size: 14px;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field select:focus {
  border-color: rgba(55, 240, 212, 0.6);
  box-shadow: 0 0 0 3px rgba(55, 240, 212, 0.2);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.actions-inline {
  align-self: end;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.inline {
  display: flex;
  gap: 8px;
}

.inline input {
  flex: 1;
}

.primary,
.ghost {
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.primary:disabled,
.ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: linear-gradient(120deg, var(--accent), #6ee7b7);
  color: #04101a;
  box-shadow: 0 12px 24px rgba(55, 240, 212, 0.25);
}

.primary:hover {
  transform: translateY(-1px);
}

.ghost {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--panel-border);
}

.ghost:hover {
  transform: translateY(-1px);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.content {
  display: grid;
  gap: 28px;
}

.search-results {
  display: grid;
  gap: 16px;
}

.results-list {
  display: grid;
  gap: 12px;
}

.search-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-1);
  border: 1px solid transparent;
}

.search-item:hover {
  border-color: var(--panel-border);
}

.search-thumb {
  width: 64px;
  height: 96px;
  border-radius: 10px;
  background: linear-gradient(150deg, rgba(55, 240, 212, 0.2), rgba(255, 207, 122, 0.2));
  background-size: cover;
  background-position: center;
}

.search-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.search-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.search-meta span {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-1);
  line-height: 1;
}
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-header h3 {
  margin: 0;
  font-size: 18px;
}

.card-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

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

.table {
  display: grid;
  gap: 10px;
}

.row {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-1);
  border: 1px solid transparent;
  transition: border 0.2s ease, transform 0.2s ease;
}

.row:hover {
  border-color: var(--panel-border);
  transform: translateY(-1px);
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.row-title strong {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.select-box input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.row-meta > span {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-1);
  line-height: 1;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-4);
  border: 1px solid var(--panel-border);
  font-size: 11px;
  line-height: 1;
}

.tree {
  display: grid;
  gap: 16px;
}

.video-card {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
}

.poster {
  width: 140px;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(55, 240, 212, 0.2), rgba(255, 207, 122, 0.2));
  background-size: cover;
  background-position: center;
}

.video-info h4 {
  margin: 0 0 8px;
  font-size: 20px;
}

.video-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 16px;
  margin-bottom: 10px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  align-items: baseline;
}

.info-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

.info-value {
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}

.copy-chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-4);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.copy-chip:hover {
  border-color: rgba(55, 240, 212, 0.6);
}

.genre-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.video-desc {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-desc.expanded {
  -webkit-line-clamp: initial;
  display: block;
}

.desc-toggle {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 10px;
}

.link-row {
  margin-bottom: 8px;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  background: var(--surface-2);
}

.ghost-link:hover {
  border-color: rgba(55, 240, 212, 0.6);
}

.tree-section {
  display: grid;
  gap: 12px;
}

.episode-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.episode {
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--episode-bg);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.episode-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.episode:hover {
  border-color: rgba(55, 240, 212, 0.4);
}

.episode.active {
  border-color: rgba(255, 207, 122, 0.7);
  background: rgba(255, 207, 122, 0.15);
}

.episode.selected {
  border-color: rgba(55, 240, 212, 0.6);
  background: rgba(55, 240, 212, 0.12);
}

.episode-count {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-3);
  font-size: 11px;
  flex-shrink: 0;
}

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

.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--toast-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.is-hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(520px, 92vw);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

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

  .poster {
    width: 100%;
  }

  .actions-inline {
    justify-self: start;
  }

  .search-item {
    grid-template-columns: 1fr;
  }

  .search-thumb {
    width: 100%;
    height: 180px;
  }
}
