:root {
  color-scheme: dark;
  font-family: Roboto, Arial, sans-serif;
  font-synthesis: none;
  color: #f1f1f1;
  background: #0f0f0f;

  --page: #0f0f0f;
  --surface: #181818;
  --surface-raised: #222;
  --surface-hover: #303030;
  --border: #303030;
  --muted: #aaa;
  --text: #f1f1f1;
  --accent: #ff4562;
  --focus: #8ab4f8;
  --header-height: 64px;
  --sidebar-width: 240px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
}

button,
input {
  font: inherit;
}

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

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
.video-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

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

/* Header */
.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto;
  display: flex;
  height: var(--header-height);
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(15, 15, 15, 0.94);
  backdrop-filter: blur(16px);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 160ms ease;
}

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

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.brand {
  display: flex;
  flex: 0 0 165px;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 26px;
  place-items: center;
  color: #ff0033;
}

.brand-mark svg {
  width: 32px;
  fill: currentColor;
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -1px;
}

.brand-name small {
  position: relative;
  top: -8px;
  margin-left: 2px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0;
}

.search {
  display: flex;
  width: min(640px, 52vw);
  height: 42px;
  margin: 0 auto;
}

.search input {
  min-width: 0;
  flex: 1;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 22px 0 0 22px;
  outline: none;
  background: #121212;
  color: var(--text);
  font-size: 15px;
  transition: border-color 160ms ease;
}

.search input:focus {
  border-color: #5f83b8;
}

.search button {
  display: grid;
  width: 64px;
  flex: 0 0 64px;
  place-items: center;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 22px 22px 0;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  transition: background 160ms ease;
}

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

.search button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.avatar {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  background: #8658d6;
  font-weight: 700;
}

/* Sidebar and page layout */
.sidebar {
  position: fixed;
  z-index: 15;
  top: var(--header-height);
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  padding: 16px 12px;
  overflow-y: auto;
  background: var(--page);
  scrollbar-color: #444 transparent;
  scrollbar-width: thin;
}

.side-link {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 20px;
  padding: 0 12px;
  border-radius: 10px;
  color: #e8e8e8;
  font-size: 14px;
  transition: background 150ms ease;
}

.side-link:hover,
.side-link.selected {
  background: var(--surface-raised);
}

.side-link.selected {
  color: #fff;
  font-weight: 700;
}

.side-icon {
  display: grid;
  width: 24px;
  flex: 0 0 24px;
  place-items: center;
  font-size: 20px;
}

.sidebar hr {
  height: 1px;
  margin: 16px 0;
  border: 0;
  background: var(--border);
}

.side-heading {
  margin: 0 12px 8px;
  font-size: 15px;
  font-weight: 700;
}

.sidebar-note {
  margin: 16px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.main-content {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: calc(var(--header-height) + 12px) 36px 56px;
}

/* Gallery */
.chips {
  position: sticky;
  z-index: 10;
  top: var(--header-height);
  display: flex;
  gap: 10px;
  margin: 0 -4px 8px;
  padding: 10px 4px 18px;
  overflow-x: auto;
  background: linear-gradient(var(--page) 82%, rgba(15, 15, 15, 0));
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  min-height: 36px;
  flex: 0 0 auto;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #272727;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}

.chip:hover {
  background: #3a3a3a;
}

.chip:active {
  transform: scale(0.97);
}

.chip.active {
  background: #f1f1f1;
  color: #151515;
}

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

.video-card {
  min-width: 0;
  cursor: pointer;
}

.thumbnail-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: linear-gradient(145deg, #242424, #151515);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.thumbnail-wrap.is-placeholder {
  display: grid;
  place-items: center;
  color: #a9a9a9;
  font-size: 14px;
}

.thumbnail-wrap.is-placeholder::before {
  position: absolute;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  content: "▶";
  color: #ddd;
  display: grid;
  place-items: center;
  font-size: 19px;
}

.thumbnail-wrap.is-placeholder span {
  position: absolute;
  top: calc(50% + 42px);
}

.thumbnail-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 240ms ease, filter 240ms ease;
}

.video-card:hover .thumbnail-wrap img {
  transform: scale(1.045);
  filter: brightness(1.06);
}

.video-card:hover .thumbnail-wrap {
  border-color: rgba(255, 255, 255, 0.18);
}

.duration {
  position: absolute;
  right: 7px;
  bottom: 7px;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.82);
  color: white;
  font-size: 11px;
  font-weight: 700;
}

.video-info {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 24px;
  gap: 11px;
  padding-top: 12px;
}

.channel-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  background: #292929;
  color: var(--accent);
  font-size: 18px;
}

.video-copy {
  min-width: 0;
}

.video-title {
  display: -webkit-box;
  margin: 0 0 5px;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.video-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.more-button {
  align-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

.empty-state {
  padding: 64px 12px;
  color: var(--muted);
  text-align: center;
}

/* Video player and episode list */
.featured-video {
  max-width: 820px;
  margin: 0 auto 36px;
  scroll-margin-top: 84px;
}

.featured-video video {
  display: block;
  width: 100%;
  max-height: 70vh;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  background: #000;
  object-fit: contain;
}

.featured-video h1 {
  margin: 14px 0 5px;
  font-size: 20px;
}

.featured-video p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.recommendation-heading {
  margin: 0 0 18px;
  font-size: 18px;
}

.watch-layout[hidden],
#galleryView[hidden] {
  display: none;
}

.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.95fr);
  gap: 28px;
  align-items: start;
}

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

.watch-main video {
  display: block;
  width: 100%;
  max-height: 76vh;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: #000;
  object-fit: contain;
}

.watch-main h1 {
  margin: 16px 0 8px;
  font-size: 20px;
  line-height: 1.4;
}

.watch-main p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.back-button {
  margin: 0 0 14px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  transition: background 150ms ease;
}

.back-button:hover {
  background: var(--surface-hover);
}

.watch-next {
  min-width: 0;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}

.watch-next h2 {
  margin: 0 0 16px;
  font-size: 17px;
}

.next-video-list {
  display: grid;
  gap: 12px;
  max-height: min(72vh, 760px);
  overflow-y: auto;
  scrollbar-color: #444 transparent;
  scrollbar-width: thin;
}

.next-video-item {
  display: grid;
  grid-template-columns: minmax(90px, 36%) minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.next-video-item:hover {
  border-color: rgba(255, 255, 255, 0.07);
  background: var(--surface-raised);
}

.next-video-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 7px;
  background: #252525;
  object-fit: cover;
}

.next-video-item span {
  overflow: hidden;
  padding-top: 2px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

.next-video-item small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.next-video-card {
  display: grid;
  grid-template-columns: minmax(90px, 35%) minmax(0, 1fr);
  gap: 9px;
  align-items: start;
}

.next-video-card .thumbnail-wrap {
  border-radius: 8px;
}

.next-video-card .video-info {
  display: block;
  padding: 0;
}

.next-video-card .channel-avatar {
  display: none;
}

.next-video-card .video-title {
  font-size: 13px;
}

.next-video-card .video-meta {
  font-size: 12px;
}

/* Dialog player */
.player-dialog {
  width: min(960px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--text);
}

.player-dialog::backdrop {
  background: rgba(0, 0, 0, 0.84);
  backdrop-filter: blur(5px);
}

.player-shell {
  position: relative;
  padding: 16px;
  border: 1px solid #383838;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.55);
}

.player-shell video {
  display: block;
  width: 100%;
  max-height: calc(100dvh - 120px);
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  background: #000;
  object-fit: contain;
}

.player-shell h2 {
  margin: 14px 48px 4px 0;
  font-size: 18px;
}

.player-close {
  position: absolute;
  z-index: 1;
  top: 22px;
  right: 22px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: white;
  font-size: 28px;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 1100px) {
  .main-content {
    padding-right: 24px;
    padding-left: 24px;
  }

  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 175px), 1fr));
  }

  .watch-layout {
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.9fr);
    gap: 18px;
  }
}

@media (max-width: 760px) {
  :root {
    --header-height: 56px;
  }

  .topbar {
    gap: 10px;
    padding: 0 12px;
  }

  .menu-button {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .brand {
    flex-basis: auto;
    gap: 3px;
  }

  .brand-name {
    font-size: 17px;
  }

  .brand-mark,
  .brand-mark svg {
    width: 27px;
  }

  .search {
    width: auto;
    flex: 1;
    margin-left: auto;
  }

  .search input {
    padding-left: 12px;
    font-size: 14px;
  }

  .search button {
    width: 44px;
    flex-basis: 44px;
  }

  .avatar {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .sidebar {
    transform: translateX(-105%);
    transition: transform 200ms ease;
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.35);
  }

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

  .main-content {
    margin-left: 0;
    padding: calc(var(--header-height) + 8px) 16px 36px;
  }

  .chips {
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 16px;
  }

  .video-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px 12px;
  }

  .thumbnail-wrap {
    border-radius: 11px;
  }

  .video-info {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 9px;
    padding-top: 9px;
  }

  .channel-avatar {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .video-title {
    font-size: 13px;
  }

  .video-meta {
    font-size: 11px;
  }

  .more-button {
    display: none;
  }

  .watch-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .watch-main video {
    border-radius: 10px;
  }

  .watch-next {
    padding: 14px;
  }

  .next-video-list {
    max-height: none;
    overflow: visible;
  }

  .featured-video {
    margin-bottom: 28px;
    scroll-margin-top: 68px;
  }

  .featured-video video {
    border-radius: 10px;
  }

  .featured-video h1 {
    font-size: 17px;
  }
}

@media (max-width: 390px) {
  .topbar {
    gap: 7px;
    padding: 0 8px;
  }

  .brand-name {
    font-size: 15px;
  }

  .brand-mark,
  .brand-mark svg {
    width: 24px;
  }

  .search button {
    width: 38px;
    flex-basis: 38px;
  }

  .main-content {
    padding-right: 12px;
    padding-left: 12px;
  }

  .video-grid {
    gap: 20px 9px;
  }

  .video-info {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }

  .channel-avatar {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
