:root {
  --bg: #ffffff;
  --bg-2: #f4f5f4;
  --surface: #ffffff;
  --text: #141414;
  --muted: #6a6f6b;
  --line: #e4e6e4;
  --accent: #16a34a;
  --accent-2: #15803d;
  --accent-soft: #e5f6eb;
  --danger: #dc2626;
  --warn: #b45309;
  --badge: rgba(0, 0, 0, .78);
  --radius: 6px;
}
:root[data-theme="dark"] {
  --bg: #101211; --bg-2: #181b19; --surface: #1b1e1c; --text: #eef0ee; --muted: #9aa29c;
  --line: #2a2f2c; --accent: #22c55e; --accent-2: #16a34a; --accent-soft: #14301f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101211; --bg-2: #181b19; --surface: #1b1e1c; --text: #eef0ee; --muted: #9aa29c;
    --line: #2a2f2c; --accent: #22c55e; --accent-2: #16a34a; --accent-soft: #14301f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif; font-size: 14px; line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, video { display: block; max-width: 100%; }
.muted { color: var(--muted); }
.container { max-width: 1720px; margin: 0 auto; padding: 18px clamp(10px, 3vw, 40px) 40px; min-height: 60vh; outline: none; }

/* ---------- header ---------- */
.hdr { background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.hdr-top { display: flex; align-items: center; gap: 18px; padding: 10px clamp(10px, 3vw, 40px); max-width: 1720px; margin: 0 auto; }
.logo { flex: none; display: block; line-height: 0; }
.logo img { height: 64px; width: auto; }
.search { flex: 1; max-width: 640px; display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--surface); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; padding: 10px 12px; background: transparent; outline: none; font-size: 15px; }
.search button { border: 0; background: var(--bg-2); padding: 0 16px; cursor: pointer; }
.auth { display: flex; align-items: center; gap: 10px; margin-left: auto; white-space: nowrap; }
.auth > a:not(.btn) { color: var(--muted); }
.auth > a:not(.btn):hover { color: var(--text); }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 20px; padding: 4px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.15); min-width: 190px; padding: 6px; display: flex; flex-direction: column; z-index: 40;
}
.menu-list a, .menu-list button { text-align: left; padding: 8px 10px; border-radius: 6px; border: 0; background: none; cursor: pointer; }
.menu-list a:hover, .menu-list button:hover { background: var(--bg-2); }

.nav { display: flex; justify-content: center; gap: clamp(8px, 3vw, 44px); padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { display: flex; align-items: center; gap: 7px; padding: 11px 4px; font-weight: 700; font-size: 15px; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a i { font-style: normal; color: var(--muted); font-weight: 400; }
.nav a:hover, .nav a.active { border-bottom-color: var(--accent); }
.nav a.nav-up { color: var(--accent); }

/* ---------- buttons, forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 8px 14px; border-radius: 4px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.dark { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.danger { color: var(--danger); }
.btn.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form label small { font-weight: 400; color: var(--muted); }
.form input, .form textarea, .form select, .input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 4px; padding: 10px 12px; outline: none;
}
.form input:focus, .form textarea:focus, .form select:focus, .input:focus { border-color: var(--accent); }
.form textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.err { color: var(--danger); min-height: 1em; margin: 0; }

/* ---------- list page ---------- */
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.list-head h1 { margin: 0; font-size: 22px; }
.list-head h1 small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 4px; background: var(--bg-2); font-weight: 600; font-size: 13px; }
.tabs a.active { background: var(--text); color: var(--bg); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; scrollbar-width: thin; }
.chips a { flex: none; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
.chips a.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 22px 8px; }
.card { min-width: 0; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: #1a1d1b; overflow: hidden; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.thumb .ph { width: 100%; height: 100%; display: grid; place-items: center; color: rgba(255,255,255,.9); font-weight: 800; font-size: 18px; }
.card:hover .thumb img, .card:hover .thumb video { filter: brightness(1.08); }
.q { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 3px; }
.st { position: absolute; top: 6px; left: 6px; color: #fff; font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 3px; background: var(--warn); }
.st.rejected { background: var(--danger); }
.card .t {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  text-align: center; font-size: 16px; line-height: 1.3; margin: 8px 4px 4px; min-height: 2.6em;
}
.card .t:hover { color: var(--accent); }
.card .m { text-align: center; color: var(--muted); font-size: 14px; }
.card .m a { text-decoration: underline; text-underline-offset: 2px; }
.card .m a:hover { color: var(--accent); }
.dur { display: inline-block; background: var(--badge); color: #fff; padding: 0 5px; border-radius: 3px; font-size: 13px; font-variant-numeric: tabular-nums; }
.grid.small { grid-template-columns: 1fr; gap: 12px; }
.grid.small .card { display: grid; grid-template-columns: 168px 1fr; gap: 10px; align-items: start; }
.grid.small .card .t { text-align: left; margin: 0 0 4px; font-size: 14px; min-height: 0; }
.grid.small .card .m { text-align: left; font-size: 12px; }

.pager { display: flex; justify-content: center; gap: 4px; margin: 30px 0 0; flex-wrap: wrap; }
.pager a, .pager span { min-width: 38px; text-align: center; padding: 7px 10px; border-radius: 4px; background: var(--bg-2); font-weight: 600; }
.pager .active { background: var(--accent); color: #fff; }
.empty { text-align: center; padding: 60px 10px; color: var(--muted); }
.loading { text-align: center; padding: 60px; color: var(--muted); }

/* ---------- watch page ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; }
.player { background: #000; aspect-ratio: 16 / 9; }
.player video { width: 100%; height: 100%; background: #000; }
.w-title { font-size: 21px; margin: 14px 0 8px; line-height: 1.3; }
.w-bar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.w-meta { color: var(--muted); }
.w-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.rating { height: 4px; background: var(--danger); border-radius: 2px; overflow: hidden; margin-top: 4px; width: 150px; }
.rating i { display: block; height: 100%; background: var(--accent); }
.w-channel { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.w-channel .name { font-weight: 700; font-size: 15px; }
.w-channel .sub { margin-left: auto; }
.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px;
}
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.lg { width: 84px; height: 84px; font-size: 34px; }
.w-desc { background: var(--bg-2); border-radius: 8px; padding: 12px 14px; white-space: pre-line; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; white-space: normal; }
.tags a { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.tags a:hover { border-color: var(--accent); color: var(--accent); }
.notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-weight: 600; background: #fef3c7; color: #78350f; }
.notice.rejected { background: #fee2e2; color: #7f1d1d; }
.comments h3 { margin: 24px 0 12px; }
.c-form { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; }
.c-form textarea { flex: 1; }
.c-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.c-list li { display: flex; gap: 10px; }
.c-list .who { font-weight: 700; }
.c-list time { color: var(--muted); font-size: 12px; margin-left: 6px; }
.c-list p { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.side h3 { margin: 0 0 12px; font-size: 16px; }

/* ---------- upload ---------- */
.narrow { max-width: 760px; margin: 0 auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: clamp(16px, 3vw, 28px); }
.panel h1 { margin: 0 0 6px; font-size: 22px; }
.drop {
  border: 2px dashed var(--line); border-radius: 10px; padding: 36px 16px; text-align: center; cursor: pointer; color: var(--muted);
  transition: border-color .15s, background .15s; display: block;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop b { color: var(--text); display: block; font-size: 16px; margin-bottom: 4px; }
.file-ok { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.file-ok video { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 6px; }
.thumb-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb-pick button { padding: 0; border: 3px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: none; }
.thumb-pick button.sel { border-color: var(--accent); }
.thumb-pick img { aspect-ratio: 16/9; object-fit: cover; width: 100%; }
.progress { height: 10px; background: var(--bg-2); border-radius: 5px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.ok { color: var(--accent); font-weight: 600; }

/* ---------- channels / categories ---------- */
.ch-head { display: flex; align-items: center; gap: 18px; padding: 20px; background: var(--bg-2); border-radius: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.ch-head h1 { margin: 0; font-size: 26px; }
.ch-head .stats { color: var(--muted); }
.ch-head .act { margin-left: auto; display: flex; gap: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; background: #222; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.tile .lbl { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 12px; color: #fff;
  background: linear-gradient(transparent 30%, rgba(0,0,0,.8)); }
.tile .lbl b { font-size: 18px; }
.tile:hover img { opacity: .9; }
.ch-card { display: flex; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 10px; }
.ch-card:hover { border-color: var(--accent); }
.ch-card b { display: block; font-size: 15px; }
.ch-card small { color: var(--muted); }

/* ---------- tables (me/admin) ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.tbl .tt { display: flex; gap: 10px; align-items: center; min-width: 260px; }
.tbl .tt .thumb { width: 120px; flex: none; border-radius: 4px; }
.tbl .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.published { background: var(--accent-soft); color: var(--accent); }
.pill.pending { background: #fef3c7; color: #92400e; }
.pill.rejected { background: #fee2e2; color: #991b1b; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--bg-2); border-radius: 8px; padding: 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.scroll-x { overflow-x: auto; }

/* ---------- dialog & toast ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg { padding: 22px; }
.dlg h2 { margin: 0 0 14px; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer { border-top: 1px solid var(--line); padding: 22px 16px; text-align: center; font-size: 13px; }
.footer p { margin: 4px 0; }
.footer a { text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .watch { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .hdr-top { flex-wrap: wrap; gap: 10px; }
  .logo img { height: 48px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .auth .hide-m { display: none; }
  .nav { justify-content: flex-start; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 6px; }
  .card .t { font-size: 13px; }
  .card .m { font-size: 12px; }
  .grid.small .card { grid-template-columns: 140px 1fr; }
  .row2, .file-ok { grid-template-columns: 1fr; }
  .c-form { flex-direction: column; align-items: stretch; }
}
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } }
