:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-2: #272727;
  --surface-3: #3a3a3a;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --border: #303030;
  --accent: #ff3d3d;
  --accent-text: #ffffff;
  --primary-bg: #f1f1f1;
  --primary-text: #0f0f0f;
  --link: #3ea6ff;
  --danger: #ff6b6b;
  --ok: #3ddc84;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.5);
  --topbar-h: 56px;
  --sidebar-w: 224px;
  --radius: 12px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #f4f4f4;
    --surface-2: #ebebeb;
    --surface-3: #d9d9d9;
    --text: #0f0f0f;
    --muted: #606060;
    --border: #e2e2e2;
    --primary-bg: #0f0f0f;
    --primary-text: #ffffff;
    --link: #065fd4;
    --danger: #cc0000;
    --ok: #0a8a3a;
    --shadow: 0 8px 30px rgb(0 0 0 / 0.15);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
[hidden] { display: none !important; }

/* ---------- шапка ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.icon-btn:hover { background: var(--surface-2); }

.logo { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 19px; letter-spacing: -0.3px; }
.logo svg { width: 32px; height: 24px; stroke: none; }
.logo-bg { fill: var(--accent); }
.logo-play { fill: #fff; }

.search {
  flex: 1;
  min-width: 0;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
}
.search input {
  flex: 1;
  min-width: 0;
  width: 0;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 20px 0 0 20px;
  background: var(--bg);
}
.search input:focus { border-color: var(--link); outline: none; }
.search button {
  width: 64px;
  border: 1px solid var(--border);
  border-radius: 0 20px 20px 0;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}
.search button svg { width: 20px; height: 20px; }

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

/* ---------- боковое меню ---------- */

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  padding: 12px;
  overflow-y: auto;
  background: var(--bg);
  z-index: 25;
}
.sidebar a {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--surface-2); font-weight: 600; }
.sidebar hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.sidebar .sub-channel { gap: 16px; }
.sidebar .sub-channel .avatar { width: 24px; height: 24px; font-size: 11px; }
.sidebar-title { padding: 6px 12px; font-weight: 600; }

.scrim { display: none; }

main {
  padding: calc(var(--topbar-h) + 16px) 24px 48px calc(var(--sidebar-w) + 24px);
  min-height: 100vh;
  outline: none;
}

/* На узких экранах и на странице просмотра меню — выдвижная панель */
@media (max-width: 1100px) {
  main { padding-left: 24px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s, visibility .2s; visibility: hidden; }
  body.menu-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .5); }
}
@media (min-width: 1101px) {
  body.watch-page main { padding-left: 24px; }
  body.watch-page .sidebar { transform: translateX(-100%); transition: transform .2s, visibility .2s; visibility: hidden; }
  body.watch-page.menu-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow); }
  body.watch-page.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .5); }
}

@media (max-width: 640px) {
  .topbar { gap: 4px; padding: 0 8px; }
  .logo span { display: none; }
  .search button { width: 48px; }
  main { padding: calc(var(--topbar-h) + 12px) 16px 40px; }
  .topbar-actions .btn-label { display: none; }
  .topbar-actions .btn { padding: 0 8px; }
  .topbar-actions { gap: 4px; flex-shrink: 0; }
}

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: var(--primary-bg); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-bg); opacity: .88; }
.btn-accent { background: var(--accent); color: var(--accent-text); }
.btn-accent:hover { background: var(--accent); opacity: .9; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); }
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.input:focus { border-color: var(--link); outline: none; }
textarea.input { resize: vertical; min-height: 96px; }

.radio-row { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.radio-row label:has(input:checked) { border-color: var(--text); background: var(--surface); }

.form-error { color: var(--danger); min-height: 20px; margin: 0 0 12px; }

/* ---------- аватарки ---------- */

.avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  text-transform: uppercase;
  user-select: none;
}
.avatar-lg { width: 96px; height: 96px; font-size: 40px; }
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }

.account-btn { border: 0; padding: 0; background: none; border-radius: 50%; }
.account-menu {
  position: absolute;
  top: calc(var(--topbar-h) - 6px);
  right: 16px;
  width: 260px;
  padding: 8px 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 40;
}
.account-menu .who { display: flex; gap: 12px; padding: 8px 16px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.account-menu .who div { min-width: 0; }
.account-menu .who strong, .account-menu .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu .who span { color: var(--muted); }
.account-menu a, .account-menu button {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 9px 16px;
  border: 0;
  background: none;
  text-align: left;
}
.account-menu a:hover, .account-menu button:hover { background: var(--surface-2); }
.account-menu svg { width: 20px; height: 20px; }

/* ---------- сетка видео ---------- */

.page-title { font-size: 20px; margin: 0 0 20px; }

.chips { display: flex; gap: 10px; margin-bottom: 20px; overflow-x: auto; }
.chip {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 500;
  white-space: nowrap;
}
.chip.active { background: var(--primary-bg); color: var(--primary-text); }

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

.card { display: grid; gap: 12px; min-width: 0; }
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.thumb img.portrait { object-fit: contain; background: #000; }
.card:hover .thumb img { transform: scale(1.03); }
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.thumb .placeholder svg { width: 48px; height: 48px; }
.duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgb(0 0 0 / .8);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.card-body { display: flex; gap: 12px; min-width: 0; }
.card-text { min-width: 0; }
.card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 4px;
}
.meta { color: var(--muted); font-size: 13px; }
.meta a:hover { color: var(--text); }

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

.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 72px 16px;
  text-align: center;
  color: var(--muted);
}
.empty > svg { width: 64px; height: 64px; stroke-width: 1.2; }
.empty h2 { color: var(--text); font-size: 18px; }

/* Поиск: горизонтальные карточки */
.list { display: grid; gap: 16px; max-width: 1100px; }
.list .card { grid-template-columns: minmax(0, 360px) 1fr; gap: 16px; }
.list .card-title { font-size: 18px; font-weight: 500; }
.list .desc { color: var(--muted); font-size: 12px; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list .channel-line { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 12px; }
@media (max-width: 640px) {
  .list .card { grid-template-columns: 1fr; }
}

/* ---------- просмотр ---------- */

.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 30vw, 400px);
  gap: 24px;
  max-width: 1760px;
  margin: 0 auto;
}
.watch.solo { grid-template-columns: minmax(0, 1fr); max-width: 1280px; }
@media (max-width: 1000px) { .watch { grid-template-columns: minmax(0, 1fr); } }

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 170px);
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  justify-items: center;
  color: #fff;
  text-align: center;
  padding: 24px;
}
.player-message .bar { width: 260px; }

.quality {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  opacity: 0;
  transition: opacity .2s;
}
.player:hover .quality, .quality.open, .quality:focus-within { opacity: 1; }
.quality-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 16px;
  background: rgb(0 0 0 / .65);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.quality-btn svg { width: 18px; height: 18px; }
.quality-menu {
  position: absolute;
  right: 0;
  top: 38px;
  min-width: 160px;
  padding: 6px 0;
  border-radius: 10px;
  background: rgb(28 28 28 / .95);
  color: #fff;
}
.quality-menu button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 14px;
  border: 0;
  background: none;
  text-align: left;
}
.quality-menu button:hover { background: rgb(255 255 255 / .1); }
.quality-menu button[aria-checked="true"]::after { content: "✓"; }
.quality-menu .current { color: #aaa; font-size: 12px; padding: 4px 14px 6px; }

.watch-title { font-size: 20px; font-weight: 700; margin: 14px 0 10px; overflow-wrap: anywhere; }

.watch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.channel-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.channel-row .name { font-weight: 600; font-size: 16px; display: block; }
.channel-row .subs { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.reactions { display: flex; border-radius: 18px; background: var(--surface-2); overflow: hidden; }
.reactions button {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  background: none;
  font-weight: 600;
}
.reactions button:hover { background: var(--surface-3); }
.reactions button + button { border-left: 1px solid var(--surface-3); }
.reactions button svg { width: 20px; height: 20px; }
.reactions button[aria-pressed="true"] svg { fill: currentColor; }

.description {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
}
.description .stats { font-weight: 600; margin-bottom: 4px; }
.description .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.description .text a { color: var(--link); }
.description.collapsed .text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.description .more { border: 0; background: none; padding: 0; margin-top: 4px; font-weight: 600; }

.comments { margin-top: 24px; }
.comments h2 { font-size: 18px; margin-bottom: 20px; }
.comment-form { display: flex; gap: 14px; margin-bottom: 28px; }
.comment-form .body { flex: 1; display: grid; gap: 8px; }
.comment-form textarea {
  min-height: 28px;
  padding: 4px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  resize: none;
  overflow: hidden;
}
.comment-form textarea:focus { outline: none; border-bottom: 2px solid var(--text); }
.comment-form .buttons { display: flex; justify-content: flex-end; gap: 8px; }
.comment { display: flex; gap: 14px; margin-bottom: 20px; }
.comment .content { flex: 1; min-width: 0; }
.comment .head { font-size: 13px; }
.comment .head a { font-weight: 600; }
.comment .head time { color: var(--muted); margin-left: 6px; }
.comment p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment .del { opacity: 0; }
.comment:hover .del, .comment .del:focus-visible { opacity: 1; }

.related { display: grid; gap: 10px; align-content: start; }
.related .card { grid-template-columns: 168px minmax(0, 1fr); gap: 8px; }
.related .thumb { border-radius: 8px; }
.related .card-title { font-size: 14px; }
.related .duration { font-size: 11px; right: 4px; bottom: 4px; }
@media (max-width: 1000px) {
  .related .card { grid-template-columns: minmax(0, 200px) minmax(0, 1fr); }
}

/* ---------- канал ---------- */

.channel-banner {
  height: clamp(100px, 16vw, 200px);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.channel-head { display: flex; align-items: center; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.channel-head h1 { font-size: 30px; }
.channel-head .info { flex: 1; min-width: 220px; }
.channel-head .meta { margin: 4px 0 8px; }
.channel-head .bio { color: var(--muted); white-space: pre-wrap; margin: 0 0 12px; }

/* ---------- загрузка ---------- */

.narrow { max-width: 760px; margin: 0 auto; }

.dropzone {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 64px 24px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--link); background: var(--surface); }
.dropzone .circle { width: 120px; height: 120px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.dropzone .circle svg { width: 52px; height: 52px; color: var(--muted); }
.dropzone h2 { font-size: 18px; }
.dropzone p { margin: 0; color: var(--muted); }

.file-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 20px;
}
.file-pill .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.upload-progress { display: grid; gap: 8px; margin: 8px 0 20px; }
.upload-progress .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }

/* ---------- студия ---------- */

.studio-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.studio-head h1 { font-size: 22px; }
.studio-list { display: grid; gap: 4px; }
.studio-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 140px 110px auto;
  align-items: center;
  gap: 16px;
  padding: 10px;
  border-radius: 10px;
}
.studio-row:hover { background: var(--surface); }
.studio-row .thumb { border-radius: 8px; }
.studio-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.studio-row .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-row .row-actions { display: flex; gap: 4px; }
.studio-row .row-actions .icon-btn svg { width: 20px; height: 20px; }
.status { display: grid; gap: 6px; font-size: 13px; }
.status .bar { width: 120px; }
.status .ok { color: var(--ok); }
.status .err { color: var(--danger); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.badge svg { width: 16px; height: 16px; }
@media (max-width: 860px) {
  .studio-row { grid-template-columns: 120px minmax(0, 1fr) auto; }
  .studio-row .status-col, .studio-row .vis-col { grid-column: 2; }
  .studio-row .row-actions { grid-column: 3; grid-row: 1; }
}
@media (max-width: 640px) {
  .studio-row { grid-template-columns: 112px minmax(0, 1fr); gap: 4px 12px; padding: 8px 0; }
  .studio-row .thumb { grid-row: span 2; align-self: start; }
  .studio-row .title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .studio-row .vis-col, .studio-row .status-col, .studio-row .row-actions { grid-column: 2; grid-row: auto; }
  .studio-row .status { grid-auto-flow: column; justify-content: start; align-items: center; gap: 10px; }
  .studio-row .row-actions { margin-left: -8px; }
}

dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog h2 { font-size: 20px; margin-bottom: 18px; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- вход ---------- */

.auth {
  max-width: 400px;
  margin: 40px auto;
  padding: 32px;
  border-radius: 16px;
  background: var(--surface);
}
.auth h1 { font-size: 24px; margin-bottom: 6px; }
.auth > p { color: var(--muted); margin: 0 0 24px; }
.auth .switch { margin-top: 16px; text-align: center; color: var(--muted); }
.auth .switch a { color: var(--link); font-weight: 600; }
.auth .btn { width: 100%; height: 42px; }
@media (max-width: 640px) { .auth { padding: 24px 16px; margin-top: 16px; } }

/* ---------- прочее ---------- */

.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: calc(100vw - 48px);
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--primary-bg);
  color: var(--primary-text);
  box-shadow: var(--shadow);
  transform: translateY(calc(100% + 40px));
  visibility: hidden;
  transition: transform .25s, visibility .25s;
}
.toast.show { transform: none; visibility: visible; }

.skeleton .thumb, .skeleton .line { background: var(--surface-2); animation: pulse 1.2s infinite ease-in-out; }
.skeleton .line { height: 14px; border-radius: 4px; margin-bottom: 8px; }
@keyframes pulse { 50% { opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
