:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15171c;
  --muted: #5f6672;
  --border: #e1e4e9;
  --accent: #e5484d;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgb(16 18 24 / 6%), 0 4px 16px rgb(16 18 24 / 6%);
  --radius: 12px;
  --gutter: 16px;
  --topbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #20242d; --text: #eceef2; --muted: #9aa1ad;
    --border: #2a2f3a; --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #20242d; --text: #eceef2; --muted: #9aa1ad;
  --border: #2a2f3a; --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; height: var(--topbar-h);
  padding: 0 var(--gutter); display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 14px;
}
.brand-text { font-size: 18px; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-weight: 500; margin-left: 4px; }
.search {
  flex: 1; max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; /* >=16px để iOS không zoom */
}
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* Layout */
.layout {
  max-width: 1440px; margin: 0 auto; padding: 0 var(--gutter);
  display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px;
}
.sidebar {
  position: sticky; top: calc(var(--topbar-h) + 16px); align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 32px); overflow: auto; padding: 16px 0;
}
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 10px 8px; }
.channel-list { display: flex; flex-direction: column; gap: 2px; }
.channel-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 8px; border: 0; background: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.channel-item:hover { background: var(--surface-2); }
.channel-item[aria-current="true"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.side-section + .side-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
a.channel-item { text-decoration: none; }
.tool-item { justify-content: flex-start; }
.tool-icon {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 8px;
  background: var(--accent); color: var(--accent-text);
}
.tool-icon svg { width: 16px; height: 16px; }
.channel-item.tool-item .name { white-space: normal; line-height: 1.35; }
.tool-item .ext { margin-left: auto; color: var(--muted); font-size: 13px; }
.channel-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.content { min-width: 0; padding: 16px 0 48px; }
.toolbar { margin-bottom: 16px; }
.chips { display: none; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.summary { margin: 0; color: var(--muted); }
.sort select {
  height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; padding: 0;
  font: inherit; color: inherit; transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play {
  position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .15s;
  background: rgb(0 0 0 / 25%);
}
.thumb .play span {
  width: 56px; height: 56px; border-radius: 999px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 20px;
}
.card:hover .play { opacity: 1; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.card-title {
  margin: 0; font-size: 15px; font-weight: 600; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 13px; color: var(--muted); }
.card-meta .ch { color: var(--text); opacity: .85; }

.skeleton .thumb, .skeleton .line {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 20px;
  border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-ghost { background: var(--surface-2); color: var(--text); }
.more { display: flex; justify-content: center; margin-top: 28px; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.banner {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.banner.info { background: var(--surface); border-color: var(--border); color: var(--muted); }

/* Player */
.player {
  width: min(1000px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 40%);
}
.player::backdrop { background: rgb(0 0 0 / 70%); }
.player-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 14px 16px; }
.player-meta { min-width: 0; }
.player-meta h3 { margin: 0; font-size: 17px; line-height: 1.35; }
.player-meta p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.player-frame { aspect-ratio: 16 / 9; background: #000; }
.player-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-foot { padding: 12px 16px; display: flex; justify-content: flex-end; }

/* Tablet */
@media (max-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .chips {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 calc(-1 * var(--gutter)) 12px;
    padding-left: var(--gutter); padding-right: var(--gutter); scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex: none; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
  }
  a.chip { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
  .chip-label {
    flex: none; align-self: center; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  }
  .tool-chips .chip { border-color: var(--accent); color: var(--accent); }
  .tool-chips .chip svg { width: 16px; height: 16px; }
  .chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
}

/* Mobile */
@media (max-width: 640px) {
  .brand-text { display: none; }
  .topbar-inner { gap: 8px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .card { border-radius: 10px; }
  .player { width: 100vw; max-width: 100vw; max-height: 100vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .player-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .player-foot .btn { width: 100%; }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
