:root {
  --bg: #0f0f0f;
  --bg-elevated: #1a1a1a;
  --bg-card: #212121;
  --bg-hover: #3f3f3f;
  --bg-input: #121212;
  --text: #f1f1f1;
  --text-secondary: #aaa;
  --text-muted: #717171;
  --accent: #ff0000;
  --accent-soft: rgba(255, 0, 0, 0.15);
  --blue: #3ea6ff;
  --border: #303030;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.18s ease;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.4;
  overflow-x: hidden;
}

/* One clean scrollbar — dark, thin, no nested white tracks */
html {
  scrollbar-width: thin;
  scrollbar-color: #3f3f3f transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #3f3f3f;
  border: 2px solid var(--bg);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #555;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  padding: 0 16px;
  background: rgba(15, 15, 15, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}

.menu-btn:hover {
  background: var(--bg-hover);
}

.logo {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: max-content;
  font-size: 1.1rem;
  font-weight: 700;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  letter-spacing: -0.02em;
}

.search-form {
  flex: 1;
  display: flex;
  max-width: 640px;
  margin: 0 auto;
  height: 40px;
}

.search-form input {
  flex: 1;
  min-width: 0;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 40px 0 0 40px;
  background: var(--bg-input);
  color: var(--text);
}

.search-form input:focus {
  outline: none;
  border-color: #1c62b9;
}

.search-form button {
  width: 64px;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 40px 40px 0;
  background: #222;
  color: var(--text-secondary);
}

.search-form button:hover {
  background: var(--bg-hover);
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  position: sticky;
  top: var(--header-height);
  align-self: start;
  padding: 12px;
  border-right: 1px solid var(--border);
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  width: 100%;
  font-size: 0.95rem;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.9;
}

.nav-item.active,
.nav-item:hover {
  background: var(--bg-hover);
}

.nav-divider {
  height: 1px;
  margin: 8px 12px;
  background: var(--border);
}

.sidebar-label {
  padding: 8px 12px 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.main {
  padding: 20px 24px 48px;
  max-width: 1800px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  --watch-pad: 24px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 24px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1a1a1a 0%, #2a1515 55%, #1a1a1a 100%);
  border: 1px solid var(--border);
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(1.4rem, 2vw, 1.8rem);
}

.hero p {
  margin: 0;
  color: var(--text-secondary);
}

.hero-stats {
  display: flex;
  gap: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.hero-stats strong {
  display: block;
  color: var(--text);
  font-size: 1.2rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.chip:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: #0f0f0f;
  font-weight: 500;
}

.select-wrap select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.view-toggle button {
  padding: 8px 12px;
  border: 0;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.view-toggle button.active {
  background: var(--text);
  color: #0f0f0f;
}

.section-block {
  margin-bottom: 32px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.section-heading a {
  color: var(--blue);
  font-size: 0.85rem;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px 16px;
}

.video-grid.list-view {
  grid-template-columns: 1fr;
  gap: 12px;
}

.video-grid.list-view .video-card {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid transparent;
}

.video-grid.list-view .video-card:hover {
  border-color: var(--border);
  background: var(--bg-card);
}

.video-grid.list-view .card-body {
  margin-top: 0;
}

.video-grid.list-view .card-title {
  font-size: 1.05rem;
  -webkit-line-clamp: 3;
}

.video-card {
  position: relative;
  transition: transform var(--transition);
}

.video-card:hover {
  transform: translateY(-2px);
}

.video-card:hover .thumb-overlay {
  opacity: 1;
}

.video-card:hover .thumb-wrap img {
  transform: scale(1.03);
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: #1a1a1a;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.play-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(15, 15, 15, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.thumb-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.thumb-wrap img.broken ~ .thumb-fallback {
  display: flex;
}

.fav-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #ff4e6a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.card-body {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff4e50, #f9d423);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.card-actions {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
}

.fav-toggle {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}

.video-card:hover .fav-toggle,
.fav-toggle.is-fav {
  opacity: 1;
}

.fav-toggle.is-fav {
  color: #ff4e6a;
}

.fav-toggle:hover {
  background: rgba(0, 0, 0, 0.85);
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px 16px;
}

.skeleton-card .sk-thumb {
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #1a1a1a 25%, #262626 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

.skeleton-card .sk-line {
  height: 14px;
  margin-top: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #1a1a1a 25%, #262626 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

.skeleton-card .sk-line.short {
  width: 60%;
  margin-top: 8px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

body[data-page="watch"] .main.watch-main {
  width: 100%;
  max-width: 1920px;
  margin-left: auto;
  margin-right: auto;
  padding: 16px 24px 48px;
}

.watch-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  width: 100%;
}

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

.watch-primary {
  min-width: 0;
}

.watch-sidebar {
  width: 402px;
  flex-shrink: 0;
  position: -webkit-sticky;
  position: sticky;
  top: calc(var(--header-height) + 12px);
  overflow: visible;
}

.watch-sidebar .section-heading {
  margin-bottom: 12px;
}

.player-stage {
  min-width: 0;
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

/* Theater: player full width on top row */
body.theater-mode .watch-main {
  max-width: none;
  padding-top: 0;
  padding-left: 16px;
  padding-right: 16px;
}

body.theater-mode .watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 402px;
  grid-template-areas:
    "player player"
    "primary sidebar";
  gap: 16px 24px;
  max-width: 1920px;
  margin-left: auto;
  margin-right: auto;
}

body.theater-mode .watch-column {
  display: contents;
}

body.theater-mode .player-stage {
  grid-area: player;
  border-radius: 0;
}

body.theater-mode .watch-primary {
  grid-area: primary;
}

body.theater-mode .watch-sidebar {
  grid-area: sidebar;
  position: static;
  width: auto;
}

body.theater-mode .player-shell {
  width: 100%;
  border-radius: 0;
  box-shadow: none;
}

body.theater-mode .btn.theater-active {
  background: var(--text);
  color: #0f0f0f;
}

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

@supports (aspect-ratio: 16 / 9) {
  .player-shell {
    aspect-ratio: 16 / 9;
    height: auto;
  }
}

@supports not (aspect-ratio: 16 / 9) {
  .player-shell {
    height: 0;
    padding-bottom: 56.25%;
  }

  .player-shell iframe {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.player-shell iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.watch-header {
  margin-top: 0;
}

.watch-title {
  margin: 0 0 10px;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  line-height: 1.3;
}

.watch-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.watch-meta {
  color: var(--text-secondary);
  font-size: 0.92rem;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 0;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
  transition: background var(--transition);
}

.btn:hover {
  background: var(--bg-hover);
}

.btn.primary {
  background: var(--text);
  color: #0f0f0f;
  font-weight: 500;
}

.btn.primary:hover {
  background: #ddd;
}

.btn.fav-active {
  background: var(--accent-soft);
  color: #ff6b81;
}

.watch-description {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.watch-description h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.watch-description p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stream-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.stream-picker button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.stream-picker button.active {
  border-color: var(--blue);
  color: var(--blue);
}

.nav-arrows {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.related-card {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 8px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.related-card:hover {
  background: var(--bg-elevated);
}

.related-card .thumb-wrap {
  border-radius: var(--radius-sm);
}

.related-card .card-title {
  font-size: 0.9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.related-card .card-meta {
  margin-top: 4px;
  font-size: 0.78rem;
}

.empty-state,
.loading-state {
  padding: 64px 16px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  z-index: 100;
  padding: 12px 20px;
  border-radius: 999px;
  background: #323232;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}

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

.back-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}

.back-top.show {
  opacity: 1;
  pointer-events: auto;
}

.back-top:hover {
  transform: translateY(-2px);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.55);
}

.hidden {
  display: none !important;
}

.kbd-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 1100px) {
  .menu-btn {
    display: inline-flex;
  }

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

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    z-index: 46;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    background: var(--bg);
    box-shadow: var(--shadow);
  }

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

  .sidebar-backdrop.show {
    display: block;
  }

  .watch-layout {
    flex-direction: column;
    gap: 16px;
  }

  .watch-column {
    width: 100%;
  }

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

  .watch-sidebar {
    width: 100%;
    position: static;
    overflow: visible;
  }

  body.theater-mode .watch-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  body.theater-mode .watch-column {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  body.theater-mode .watch-main {
    padding-left: 12px;
    padding-right: 12px;
  }

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

@media (max-width: 640px) {
  .main {
    padding: 16px 12px 40px;
    --watch-pad: 12px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 18px;
  }

  .hero-stats {
    width: 100%;
    justify-content: space-between;
  }

  .video-grid,
  .skeleton-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .related-card {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .search-form {
    max-width: none;
  }

  .logo span:last-child {
    display: none;
  }
}

/* Help page */
.help-page {
  max-width: 820px;
}

.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.help-toc a {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.help-toc a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.help-section {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.help-section:last-child {
  border-bottom: 0;
}

.help-section h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
}

.help-section p,
.help-section li {
  color: var(--text-secondary);
  line-height: 1.6;
}

.help-section ul,
.help-steps {
  padding-left: 1.25rem;
}

.help-section code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--blue);
  font-size: 0.9em;
}

.help-code {
  margin: 12px 0;
  padding: 16px;
  border-radius: var(--radius);
  background: #0a0a0a;
  border: 1px solid var(--border);
  overflow-x: auto;
}

.help-code code {
  padding: 0;
  background: none;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre;
}

.help-dl dt {
  margin-top: 16px;
  font-weight: 500;
  color: var(--text);
}

.help-dl dd {
  margin: 6px 0 0;
  color: var(--text-secondary);
  line-height: 1.55;
}

.help-section kbd {
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85em;
}
