<style>
  :root { color-scheme: light dark; }
  html[data-theme="light"] {
    --bg: #fbfbfe;
    --ink: #0b0e13;
    --card: #fff;
    --line: #e6e8ee;
    --mut: #5b667a;
    --chip: #f4f6fb;
  }
  :root {
    --bg: #0b0e13;
    --ink: #eaeef5;
    --card: #121621;
    --line: #232a36;
    --mut: #9aa4b2;
    --chip: #0d1117;
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial;
  }
  a { color: inherit; text-decoration: none; }

  /* ===== HEADER ===== */
  .cs-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: calc(8px + env(safe-area-inset-top)) 12px 10px 12px;
    backdrop-filter: blur(6px);
  }

  .cs-header__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    max-width: 1300px;
    margin: 0 auto;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 18px;
    padding: 6px 8px;
    border-radius: 8px;
  }

  .brand .logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #4b9cff;
    display: inline-block;
  }

  .actions { display: flex; gap: 8px; align-items: center; }

  /* ===== SEARCH BAR ===== */
  .cs-search {
    max-width: 600px; /* shorter on desktop */
    width: 100%;
    margin: 8px auto 0 auto;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    position: relative;
  }
  .input-wrap { position: relative; width: 100%; }
  .cs-input {
    width: 100%;
    padding: 10px 40px 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--chip);
    color: inherit;
    font: 16px system-ui;
  }
  .cs-input::placeholder { opacity: .7; }

  /* ===== BUTTONS ===== */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--chip);
    color: inherit;
    font-weight: 600;
    text-decoration: none;
  }
  .btn--icon { padding: 10px; width: auto; }
  .icon { width: 18px; height: 18px; fill: currentColor; display: inline-block; }
  .btn-label { display: inline; }

  /* ===== MAIN LAYOUT ===== */
  main {
    max-width: 2200px;   /* wider canvas so each column is larger on desktop */
    margin: 20px auto;
    padding: 0 16px;
  }

  /* ===== RESPONSIVE GRID =====
     Mobile-first: 1 col → 2 (≥640px) → 3 (≥900px) → 4 (≥1200px)
  */
  .grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr; /* full-width cards on phones */
  }
  @media (min-width: 640px)  { .grid { grid-template-columns: repeat(2, 1fr); } }
  @media (min-width: 900px)  { .grid { grid-template-columns: repeat(3, 1fr); } }
  @media (min-width: 1200px) { .grid { grid-template-columns: repeat(4, 1fr); } }

  .card {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease;
  }
  .card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.25); }

  .thumb-wrap { position: relative; aspect-ratio: 16/9; background: #000; }
  .thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }

  /* ===== DURATION BADGE ===== */
  .badge.dur {
    position: absolute;
    right: 6px;
    bottom: 6px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(0,0,0,.75);
    color: #fff;
    border: 1px solid rgba(255,255,255,.15);
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    letter-spacing: .2px;
  }

  .meta { padding: 12px 14px; display: grid; gap: 6px; }

  .title {
    font-weight: 700;
    font-size: 17px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .sub {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
  }

  .channel { display: flex; align-items: center; gap: 8px; }

  /* ===== AVATAR ===== */
  .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #1b2230;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
  }
  .avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
  }

  .muted { color: var(--mut); font-size: 13.5px; }

  .desc {
    color: var(--mut);
    font-size: 14px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.7em;
  }

  nav.pager {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    padding: 16px;
  }

  .empty { opacity: .8; text-align: center; padding: 40px 10px; display: none; }

  /* ===== CLEAR (×) BUTTON ===== */
  .clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: transparent;
    color: var(--mut);
    font-size: 20px;
    line-height: 1;
  }
  .clear-btn:hover { color: #fff; background: #2b3446; }

  /* ===== TOOLBAR ABOVE VIDEOS ===== */
  .video-toolbar,
  #video-toolbar,
  .toolbar,
  .sort-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 20px auto 32px auto; /* spacing above and below */
    padding: 0 12px;
    max-width: 1300px;
  }

  #video-toolbar + .grid,
  .video-toolbar + .grid {
    margin-top: 16px; /* ensures space even if margin-bottom collapses */
  }

  /* ===== RESPONSIVE TWEAKS ===== */
  @media (max-width: 900px) { .cs-search { max-width: 90%; } }
  @media (max-width: 640px) {
    .btn { padding: 10px 10px; }
    .cs-search { max-width: 100%; }
  }
  @media (max-width: 420px) {
    .cs-search {
      grid-template-columns: 1fr 44px;
      gap: 6px;
      max-width: 100%;
    }
    .btn[type="submit"] .btn-label { display: none; }
    .btn[type="submit"] { padding: 10px; }
  }

  /* Views pill */
  .cs-views{
    display:inline-flex;
    align-items:center;
    gap:.4rem;
    padding:.18rem .5rem;
    border-radius:999px;
    font-size:.85rem;
    line-height:1;
    background: var(--chip);
    color: var(--mut);
    border: 1px solid var(--line);
  }
  .cs-views svg{ width:16px; height:16px; fill: currentColor; opacity:.9; }

  /* Right meta cluster (date · duration + views) */
  .meta-right{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
  }


/* ===== Sidebar layout for sorting (≥1440×810) ===== */
@media (min-width: 1440px) and (min-height: 810px) {
  /* Turn main into a two-column layout */
  main {
    display: grid;
    grid-template-columns: 280px 1fr;
    column-gap: 24px;
    align-items: start;
  }

  /* Left-side vertical toolbar */
  .video-toolbar,
  #video-toolbar,
  .sort-filter-bar,
  .toolbar {
    grid-column: 1;
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;     /* stack vertically */
    align-items: stretch;       /* buttons fill width */
    justify-content: flex-start;
    gap: 10px;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    max-width: 280px;
  }

  /* Ensure all buttons stack vertically and fill the sidebar width */
  .video-toolbar .btn,
  #video-toolbar .btn,
  .sort-filter-bar .btn,
  .toolbar .btn {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
  }

  /* Adjust icon + label spacing for vertical list */
  .video-toolbar .btn .icon,
  #video-toolbar .btn .icon,
  .sort-filter-bar .btn .icon,
  .toolbar .btn .icon {
    margin-right: 8px;
  }

  /* Video grid now occupies the right side */
  #results.grid {
    grid-column: 2;
    margin-top: 0;
  }

  /* Remove top margins between toolbar and grid */
  #video-toolbar + .grid,
  .video-toolbar + .grid,
  .sort-filter-bar + .grid,
  .toolbar + .grid {
    margin-top: 0;
  }
}

/* Sidebar layout + vertical stacking for .cs-toolbar (≥1440×810) */
@media (min-width: 1440px) and (min-height: 810px) {
  /* put toolbar in left column; grid already defined on <main> */
  .cs-toolbar {
    grid-column: 1;
    position: sticky;
    top: 16px;
    display: flex !important;
    flex-direction: column !important;   /* stack buttons */
    align-items: stretch !important;      /* full width */
    gap: 10px !important;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    max-width: 280px;
  }

  /* if your partial wraps buttons in rows/groups, flip those vertical too */
  .cs-toolbar > .btn-row,
  .cs-toolbar > .group,
  .cs-toolbar > .chips,
  .cs-toolbar > .controls {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    width: 100%;
  }

  /* the buttons themselves */
  .cs-toolbar .btn {
    display: block !important;
    width: 100% !important;
    justify-content: flex-start !important;
    text-align: left !important;
  }

  /* make selects full-width as well (optional) */
  .cs-toolbar select { width: 100% !important; }

  /* video results stay on the right column */
  #results.grid { grid-column: 2; margin-top: 0; }

  /* kill any top margin added when toolbar precedes grid */
  .cs-toolbar + .grid { margin-top: 0; }
}
/* Center pager under the video grid area when sidebar is visible */
@media (min-width: 1440px) and (min-height: 810px) {
  #pager-wrap {
    grid-column: 2;             /* stay in the video column */
    display: flex;
    justify-content: center;    /* center within that column */
    align-items: center;
    margin: 24px auto 40px auto;
    width: 100%;
  }

  #pager-wrap nav.pager {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
}
/* ===== TAG FILTER (chips) ===== */
.cs-tagbar{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin:14px auto 10px auto;
  padding:0 12px;
  max-width:1300px;
}

.cs-selected{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin:6px auto 18px auto;
  padding:0 12px;
  max-width:1300px;
}

.chip{
  display:inline-flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:8px 12px;
  border-radius:999px;
  cursor:pointer;
  border:1px solid var(--line);
  background:var(--chip);
  color:inherit;
  font-weight:600;
  font-size:14px;
  user-select:none;
  transition:transform .08s ease, box-shadow .12s ease, outline-color .12s ease;
}

.chip:hover{ transform:translateY(-1px); }
.chip:active{ transform:translateY(0); }

.chip:focus-visible{
  outline:2px solid #4b9cff88;
  outline-offset:2px;
}

.chip .count{
  font-weight:700;
  font-size:12px;
  opacity:.8;
  padding:.1rem .45rem;
  border-radius:999px;
  border:1px solid var(--line);
  background:var(--card);
}

/* Active chip (selected) */
.chip[data-active="1"]{
  outline:2px solid #4b9cff55;
  box-shadow:0 0 0 2px #4b9cff22 inset;
}

/* “Clear tags” style */
.chip--clear{
  border-style:dashed;
  opacity:.9;
}

/* Compact on very small screens */
@media (max-width: 420px){
  .chip{ padding:7px 10px; font-size:13px; }
  .chip .count{ font-size:11px; }
}




/* Tags full-width row on ultra-wide screens */
@media (min-width:1440px){
  .cs-tags-wrap.is-wide-top{
    /* span whole row whether parent is Grid or Flex (or old float layouts) */
    grid-column: 1 / -1 !important;
    flex: 0 1 100% !important;
    width: 100% !important;
    max-width: min(1600px, 95vw) !important;
    margin: 8px auto 18px !important;
    align-self: stretch !important;
    float: none !important;
    min-width: 0 !important;   /* defeat sidebar min-widths */
  }
  .cs-tags-wrap.is-wide-top .cs-tagbar{
    justify-content: center !important;
    gap: 12px !important;
  }
  /* defeat any sidebar style that pins children narrow */
  .sidebar .cs-tags-wrap.is-wide-top{ width:100% !important; max-width:none !important; }
}


</style>
