:root {
  /* Тёмная тема по умолчанию */
  --bg: #0e1014;
  --panel: #15181f;
  --panel-alt: #1c202a;
  --panel-hover: #232936;
  --ink: #f0f3f8;
  --ink-secondary: #c5cbd6;
  --muted: #7e8798;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #2f80ed;
  --accent-hover: #4b92f1;
  --accent-soft: rgba(47, 128, 237, 0.16);
  --accent-text: #66a7ff;
  --card-bg: #161922;
  --card-hover: #1d222e;
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --thumb-bg: #222634;
  --badge-bg: rgba(14, 16, 20, 0.82);
  --badge-text: #f0f3f8;
  --radius: 10px;
  --radius-sm: 8px;
  --grid-card-min: 210px;
}

[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-alt: #f0f2f5;
  --panel-hover: #e5e8ee;
  --ink: #111418;
  --ink-secondary: #3b424f;
  --muted: #646c7c;
  --line: rgba(0, 0, 0, 0.09);
  --line-strong: rgba(0, 0, 0, 0.18);
  --accent: #1769d1;
  --accent-hover: #0f5dbf;
  --accent-soft: rgba(23, 105, 209, 0.12);
  --accent-text: #1769d1;
  --card-bg: #ffffff;
  --card-hover: #fcfcfd;
  --card-shadow: 0 4px 18px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --thumb-bg: #eaecef;
  --badge-bg: rgba(255, 255, 255, 0.94);
  --badge-text: #111418;
}

/* ========================================================
   СВЕТЛАЯ ТЕМА — СТИЛИЗАЦИЯ И КОНТРАСТ ЭЛЕМЕНТОВ (APPLE HIG)
   ======================================================== */
[data-theme="light"] #loginForm {
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .input-wrap input {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.15);
}

/* Сайдбар */
[data-theme="light"] #sidebar {
  border-right-color: rgba(0, 0, 0, 0.09);
}
[data-theme="light"] .sidebar-header {
  border-bottom-color: rgba(0, 0, 0, 0.09);
}
[data-theme="light"] .badge-count {
  background: #eef1f6;
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--muted);
}
[data-theme="light"] .tree button:hover {
  background: #eef1f6;
  color: var(--ink);
}
[data-theme="light"] .tree button.active {
  background: var(--accent-soft);
  color: var(--accent);
}
[data-theme="light"] .chip {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  color: var(--ink-secondary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
[data-theme="light"] .chip:hover {
  background: var(--panel-hover);
  border-color: rgba(0, 0, 0, 0.2);
  color: var(--ink);
}

/* Выпадающие меню (Custom Select) */
[data-theme="light"] .custom-select-trigger {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .custom-select-trigger:hover {
  background: var(--panel-alt);
  border-color: rgba(0, 0, 0, 0.22);
}
[data-theme="light"] .custom-select.is-open .custom-select-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  background: #ffffff;
}
[data-theme="light"] .custom-select-menu {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .custom-select-item:hover {
  background: #f0f2f5;
  color: var(--ink);
}
[data-theme="light"] .custom-select-item.is-selected {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Шапка и поиск */
[data-theme="light"] #topbar {
  border-bottom-color: rgba(0, 0, 0, 0.09);
}
[data-theme="light"] .icon-btn {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color: var(--muted);
}
[data-theme="light"] .icon-btn:hover {
  background: var(--panel-hover);
  border-color: rgba(0, 0, 0, 0.22);
  color: var(--ink);
}
[data-theme="light"] .icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] #search {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) inset;
}
[data-theme="light"] #search:focus {
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
[data-theme="light"] .type-pills,
[data-theme="light"] .view-toggle {
  background: #ebedf2;
  border-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .type-pills .pill.active,
[data-theme="light"] .view-toggle .icon-btn.active {
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  color: var(--accent);
}

/* Карточки в галерее */
[data-theme="light"] .card {
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .card:hover {
  border-color: rgba(0, 0, 0, 0.16);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .badge-type {
  background: rgba(255, 255, 255, 0.94);
  color: #111418;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .badge-res {
  background: rgba(255, 255, 255, 0.92);
  color: #111418;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .thumb-fallback {
  background: #eef1f6;
}
[data-theme="light"] .btn-secondary {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.14);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .btn-secondary:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
}

/* Модальное окно (Lightbox) на десктопе */
[data-theme="light"] .modal-bg {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
[data-theme="light"] .modal-box {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18), 0 4px 16px rgba(15, 23, 42, 0.08);
}
[data-theme="light"] .modal-close {
  background: #ffffff;
  color: #111418;
  border: 1px solid rgba(0, 0, 0, 0.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .modal-close:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
[data-theme="light"] .modal-nav {
  background: rgba(255, 255, 255, 0.92);
  color: #111418;
  border: 1px solid rgba(0, 0, 0, 0.14);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .modal-nav:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}
[data-theme="light"] .modal-nav:disabled {
  opacity: 0.25;
}
[data-theme="light"] .modal-media {
  background-color: #eef2f7;
}
[data-theme="light"] .modal-side {
  background: #ffffff;
  border-left-color: rgba(0, 0, 0, 0.09);
  border-top-color: rgba(0, 0, 0, 0.09);
}
[data-theme="light"] .modal-side-top {
  border-bottom-color: rgba(0, 0, 0, 0.09);
}
[data-theme="light"] .btn-action {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.14);
  color: #111418;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .btn-action:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] .btn-action:active {
  background: #f0f2f5;
  transform: scale(0.98);
}
[data-theme="light"] .note {
  background: #f4f6fa;
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--ink-secondary);
}
[data-theme="light"] .meta-row {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

/* Просмотрщики PDF, Office, Fonts, Text, Media */
[data-theme="light"] .pdf-viewer {
  background: #f0f2f5;
}
[data-theme="light"] .pdf-toolbar {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .pdf-tool-btn {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.14);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .pdf-tool-btn:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] .pdf-scroll {
  background: #e5e8ee;
}
[data-theme="light"] .pdf-page-card {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .pdf-fallback-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .doc-viewer {
  background: #f0f2f5;
}
[data-theme="light"] .doc-topbar {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .docx-render-container {
  background: #e5e8ee;
}
[data-theme="light"] .docx-render-container .docx-wrapper > section.docx {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12) !important;
}
[data-theme="light"] .doc-sheet-card {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .doc-sheet-fallback {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .font-viewer {
  background: #f5f6f8;
}
[data-theme="light"] .font-toolbar {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .font-specimen-box {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .glyph-row {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .text-viewer {
  background: #ffffff;
}
[data-theme="light"] .text-toolbar {
  background: #f7f8fa;
  border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .text-pre {
  color: #111418;
}
[data-theme="light"] .media-error-card,
[data-theme="light"] .archive-card,
[data-theme="light"] .url-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .archive-viewer,
[data-theme="light"] .url-viewer,
[data-theme="light"] .audio-viewer {
  background: #f0f2f5;
}
[data-theme="light"] .url-icon-box,
[data-theme="light"] .audio-icon-box,
[data-theme="light"] .archive-thumb-wrap {
  background: #f4f6fa;
  border-color: rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; border: 0; background: none; }

/* Тонкий скроллбар */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Login ---------- */
#login {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 100;
  background: radial-gradient(1000px 600px at 50% 10%, var(--panel-alt), var(--bg));
}
#loginForm {
  width: min(380px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 32px 28px;
  display: grid;
  gap: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand .brand-icon { color: var(--accent); }
.login-brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
#loginForm p { margin: 0; color: var(--muted); font-size: 13px; }
.input-wrap input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.input-wrap input:focus { border-color: var(--accent); }
.btn-primary {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--accent-hover); }
.err { color: #f25555; font-size: 12px; margin: 0; min-height: 16px; }

/* ---------- App Layout ---------- */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  transition: grid-template-columns 0.2s ease;
}
#app.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}
#app.sidebar-collapsed #sidebar {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  min-width: 0 !important;
  width: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

/* Мобильный бэкдроп сайдбара */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 80;
}

/* ---------- Sidebar ---------- */
#sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  height: 100%;
  z-index: 90;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}
.brand-icon { color: var(--accent); flex-shrink: 0; }
.badge-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-alt);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.side-block { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.side-grow { flex: 1; }
.side-title-row { display: flex; align-items: center; justify-content: space-between; }
.lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.select-wrap select {
  display: none !important;
}

/* ========================================================
   CUSTOM DROPDOWN SELECT (Native OS picker replacement)
   ======================================================== */
.custom-select {
  position: relative;
  display: inline-block;
  width: 100%;
  user-select: none;
  font-family: inherit;
  box-sizing: border-box;
}

.custom-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.custom-select-trigger:hover {
  background: var(--card-bg);
  border-color: var(--line-strong);
}

.custom-select.is-open .custom-select-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  background: var(--card-bg);
}

.custom-select-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  flex: 1;
}

.custom-select-arrow {
  width: 10px;
  height: 6px;
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), color 0.15s ease;
}

.custom-select.is-open .custom-select-arrow {
  transform: rotate(180deg);
  color: var(--accent);
}

/* Floating Dropdown Menu */
.custom-select-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5), 0 3px 10px rgba(0, 0, 0, 0.2);
  padding: 6px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(0.98);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}

.custom-select.is-open .custom-select-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.custom-select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  transition: background-color 0.1s ease, color 0.1s ease;
  box-sizing: border-box;
}

.custom-select-item:hover {
  background: var(--panel-alt);
  color: var(--ink);
}

.custom-select-item.is-selected {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.custom-select-item-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-item-check {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.custom-select-item.is-selected .custom-select-item-check {
  opacity: 1;
  transform: scale(1);
}

/* Мобильные контролы в сайдбаре */
.mobile-only-block { display: none; }
.mobile-type-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.mobile-type-pills .pill {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
}
.mobile-type-pills .pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Дерево папок */
.tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding-right: 4px;
  flex: 1;
}
.tree button {
  text-align: left;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--ink-secondary);
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.12s ease, color 0.12s ease;
}
.tree button svg { flex-shrink: 0; color: var(--muted); }
.tree button:hover {
  background: var(--panel-hover);
  color: var(--ink);
}
.tree button.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
.tree button.active svg { color: var(--accent); }

/* Теги */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 20vh;
  overflow-y: auto;
  padding-right: 4px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink-secondary);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.chip .chip-count {
  font-size: 10px;
  color: var(--muted);
}
.chip:hover {
  background: var(--panel-hover);
  color: var(--ink);
  border-color: var(--line-strong);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.active .chip-count { color: rgba(255, 255, 255, 0.8); }

/* ---------- Main Area ---------- */
main {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
}

/* ---------- Topbar ---------- */
#topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  z-index: 10;
  flex-shrink: 0;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel-alt);
  transition: all 0.12s ease;
}

.course-root-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
  padding: 20px;
  align-content: start;
}
.course-root-card {
  min-height: 150px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(47,128,237,.22), rgba(24,31,48,.95));
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font: inherit;
}

.course-root-preview { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; margin-bottom: 10px; background: #111; }
.course-root-description { color: var(--muted); font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.course-description { grid-column: 1 / -1; display: flex; gap: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.course-description img { width: 180px; height: 110px; object-fit: cover; border-radius: 10px; background: #111; }

.course-description img { cursor: zoom-in; }
.preview-lightbox { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(0, 0, 0, .9); cursor: zoom-out; }
.preview-lightbox img { max-width: 94vw; max-height: 92vh; width: auto; height: auto; border-radius: 10px; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); }
.pptx-render-container { padding: 16px; display: flex; justify-content: center; overflow: auto; background: #0b0f16; }
.pptx-render-container .pptx-preview-wrapper { max-width: 100%; }
@media (max-width: 600px) { .preview-lightbox { padding: 10px; } .pptx-render-container { padding: 8px; } }
.course-description h2 { margin: 0 0 8px; font-size: 21px; }
.course-description p { margin: 0 0 10px; color: var(--muted); line-height: 1.5; }
.course-description a { color: var(--accent); }

.course-intro-main { flex: 1; min-width: 0; }
.course-about { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.course-about summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; list-style: none; color: var(--ink-secondary); font-size: 13px; font-weight: 600; }
.course-about summary::-webkit-details-marker { display: none; }
.course-about summary::after { content: "›"; color: var(--muted); font-size: 20px; line-height: 1; transform: rotate(90deg); transition: transform .15s ease; }
.course-about[open] summary::after { transform: rotate(-90deg); }
.course-about-body { margin-top: 10px; padding-right: 6px; color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.course-about-body p { margin: 0 0 9px; }
.course-about-body h4 { margin: 14px 0 6px; color: var(--ink); font-size: 14px; line-height: 1.35; }
.course-about-body ul { margin: 6px 0 10px; padding-left: 18px; }
.course-about-body li { margin: 4px 0; }
.course-secondary-links { margin-top: 12px; font-size: 12px; opacity: .78; }
.course-info-btn { width: 28px; height: 28px; flex: 0 0 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: rgba(255, 255, 255, .04); font-size: 13px; font-weight: 700; cursor: pointer; }
.course-info-btn:hover, .course-info-btn:focus-visible { color: var(--ink); border-color: var(--accent); outline: none; }
.course-popup-backdrop { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, .72); }
.course-popup { position: relative; width: min(760px, 100%); max-height: 86vh; overflow-y: auto; padding: 22px; border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(145deg, rgba(27, 36, 53, .98), rgba(13, 17, 25, .99)); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.course-popup-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255, 255, 255, .05); color: var(--muted); font-size: 14px; cursor: pointer; }
.course-popup-close:hover { color: var(--ink); border-color: var(--accent); }
.course-popup-head { display: flex; align-items: center; gap: 16px; padding-right: 34px; }
.course-popup-head img { width: 150px; height: 94px; object-fit: cover; border-radius: 12px; background: #090d14; }
.course-popup-title h3 { margin: 0 0 4px; font-size: 20px; line-height: 1.3; }
.course-popup-title span { color: var(--muted); font-size: 12.5px; }
.course-popup-body { margin-top: 16px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.course-popup-body p { margin: 0 0 10px; }
.course-popup-body h4 { margin: 16px 0 6px; color: var(--ink); font-size: 15px; line-height: 1.35; }
.course-popup-body ul { margin: 6px 0 12px; padding-left: 20px; }
.course-popup-body li { margin: 4px 0; }
.course-popup-links { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12.5px; }
.course-popup-links a { color: var(--accent-text); }
@media (max-width: 600px) {
  .course-popup { padding: 16px; }
  .course-popup-head { flex-direction: column; align-items: flex-start; }
  .course-popup-head img { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .course-about-body { max-height: none; }
}
@media (max-width: 600px) { .course-description { flex-direction: column; } .course-description img { width: 100%; height: auto; aspect-ratio: 16 / 9; } }

/* ---------- Course reader visual system ---------- */
.courses-mode {
  --bg: #090b10;
  --panel: #11151e;
  --panel-alt: #171d29;
  --panel-hover: #202a3a;
  --line: rgba(190, 208, 240, 0.14);
  --line-strong: rgba(190, 208, 240, 0.24);
  --accent: #2188ff;
  --accent-hover: #4aa0ff;
  --accent-soft: rgba(33, 136, 255, 0.16);
  --accent-text: #8bc2ff;
  background: radial-gradient(circle at 70% -10%, rgba(33, 136, 255, 0.12), transparent 34%), var(--bg);
}
.courses-mode #sidebar,
.courses-mode #topbar { background: rgba(17, 21, 30, 0.86); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.courses-mode #topbar { border-bottom-color: rgba(190, 208, 240, 0.13); padding: 12px 18px; }
.courses-mode .card { border: 1px solid rgba(190, 208, 240, 0.12); border-radius: 18px; background: linear-gradient(145deg, rgba(25, 33, 48, 0.96), rgba(12, 16, 24, 0.98)); box-shadow: 0 12px 32px rgba(0,0,0,.22); overflow: hidden; }
.courses-mode .card:hover { border-color: rgba(33, 136, 255, 0.65); box-shadow: 0 18px 42px rgba(0,0,0,.34), 0 0 0 1px rgba(33,136,255,.12); transform: translateY(-2px); }
.courses-mode .card-cap { padding: 14px 15px 16px; }
.courses-mode .card-title { font-size: 15px; line-height: 1.3; font-weight: 650; }
.courses-mode .card-sub { margin-top: 9px; }
.card-description { margin-top: 10px; color: var(--ink-secondary); font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.card-status { display: inline-flex; margin-top: 11px; width: fit-content; padding: 4px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
.card-status--ready { color: #9dd0ff; border-color: rgba(33,136,255,.35); background: rgba(33,136,255,.1); }
.courses-mode .course-root-grid { padding: 24px; gap: 20px; }
.courses-mode .course-root-card { min-height: 180px; padding: 18px; border-radius: 22px; background: linear-gradient(145deg, rgba(33,136,255,.2), rgba(17,21,30,.96)); box-shadow: 0 16px 34px rgba(0,0,0,.22); }
.courses-mode .course-root-card:hover { transform: translateY(-3px); box-shadow: 0 22px 44px rgba(0,0,0,.32), 0 0 0 1px rgba(33,136,255,.18); }
.courses-mode .course-root-name { font-size: 18px; }
.courses-mode .course-description { padding: 22px; border-radius: 22px; background: linear-gradient(145deg, rgba(27, 36, 53, .95), rgba(13, 17, 25, .98)); box-shadow: 0 16px 36px rgba(0,0,0,.18); }

/* Fixed folder browser: compact list (variant B) */
.courses-mode #grid.course-folder-list {
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  padding: 20px clamp(14px, 3vw, 28px) 28px;
  align-content: stretch;
}
.courses-mode .course-list-row {
  width: 100%;
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid rgba(190, 208, 240, .13);
  border-radius: 13px;
  background: linear-gradient(100deg, rgba(24, 34, 50, .94), rgba(13, 18, 27, .98));
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: border-color .14s ease, background .14s ease, transform .14s ease;
}
.courses-mode .course-list-row:hover,
.courses-mode .course-list-row:focus-visible {
  border-color: rgba(139, 194, 255, .58);
  background: linear-gradient(100deg, rgba(29, 48, 72, .98), rgba(15, 23, 35, .98));
  transform: translateX(2px);
  outline: none;
}
.courses-mode .course-list-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  border: 1px solid rgba(139, 194, 255, .27);
  border-radius: 9px;
  color: var(--accent-text);
  background: rgba(33, 136, 255, .10);
  font-size: 18px;
  line-height: 1;
}
.courses-mode .course-list-back-icon { color: #b7d8ff; }
.courses-mode .course-list-preview {
  width: 64px;
  height: 44px;
  flex: 0 0 64px;
  object-fit: cover;
  border-radius: 9px;
  background: #090d14;
}
.courses-mode .course-list-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.courses-mode .course-list-row .course-root-name { font-size: 15px; line-height: 1.3; }
.courses-mode .course-list-row .course-root-meta { font-size: 12px; }
.courses-mode .course-list-chevron { flex: 0 0 auto; color: #8295b2; font-size: 28px; font-weight: 300; line-height: 1; }
.courses-mode .course-back-row { background: rgba(33, 136, 255, .08); }
.courses-mode .course-empty-state {
  padding: 56px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}
.courses-mode .course-file-row {
  min-height: 76px;
  cursor: pointer;
}
.courses-mode .course-file-iconbox {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid color-mix(in srgb, var(--course-file-accent) 42%, transparent);
  border-radius: 11px;
  color: var(--course-file-accent);
  background: linear-gradient(145deg, var(--course-file-surface), rgba(12, 16, 24, .72));
}
.courses-mode .course-file-ext {
  font-size: 9px;
  line-height: 1;
  font-weight: 750;
  letter-spacing: .08em;
  opacity: .82;
}
.courses-mode .course-file-icon { display: grid; place-items: center; line-height: 0; }
.courses-mode .course-file-icon svg { width: 24px; height: 24px; stroke-width: 1.8; }
.courses-mode .course-file-title { font-size: 15px; font-weight: 650; line-height: 1.32; }
.courses-mode .course-file-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--course-file-accent);
  font-size: 12px;
  line-height: 1.25;
}
.courses-mode .course-file-description {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  color: var(--ink-secondary);
  font-size: 12.5px;
  line-height: 1.4;
}
.courses-mode .course-file-status {
  width: fit-content;
  padding: 3px 7px;
  border: 1px solid rgba(33, 136, 255, .32);
  border-radius: 999px;
  color: #9dd0ff;
  background: rgba(33, 136, 255, .08);
  font-size: 11px;
}
.courses-mode .course-content-files {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.courses-mode .course-content-files .card {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  min-height: 84px;
  border-radius: 15px;
  transform: none;
}
.courses-mode .course-content-files .card:hover { transform: translateX(2px); }
.courses-mode .course-content-files .thumb-wrap { width: 128px; height: 84px; aspect-ratio: auto !important; }
.courses-mode .course-content-files .card-cap { padding: 12px 14px; align-self: center; }
.courses-mode .course-content-files .card-title { font-size: 14px; }
.courses-mode .course-content-files .card-description { margin-top: 6px; -webkit-line-clamp: 2; }
.courses-mode .course-content-files .card-status { margin-top: 6px; }
.courses-mode #grid.view-grid {
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  align-content: stretch;
}
.courses-mode #grid.view-grid > .card {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  min-height: 84px;
  border-radius: 15px;
  transform: none;
}
.courses-mode #grid.view-grid > .card:hover { transform: translateX(2px); }
.courses-mode #grid.view-grid > .card .thumb-wrap { width: 128px; height: 84px; aspect-ratio: auto !important; }
.courses-mode #grid.view-grid > .card .card-cap { padding: 12px 14px; align-self: center; }

@media (max-width: 600px) {
  .courses-mode #grid.course-folder-list { padding: 8px 12px 22px; gap: 8px; }
  .courses-mode .course-list-row { min-height: 62px; padding: 9px 11px; gap: 11px; }
  .courses-mode .course-list-icon { width: 34px; height: 34px; flex-basis: 34px; border-radius: 9px; }
  .courses-mode .course-list-preview { width: 58px; height: 40px; flex-basis: 58px; }
  .courses-mode .course-file-row { min-height: 68px; }
  .courses-mode .course-file-iconbox { width: 48px; height: 48px; flex-basis: 48px; border-radius: 10px; }
  .courses-mode .course-file-icon svg { width: 21px; height: 21px; }
  .courses-mode .course-file-title { font-size: 14px; }
  .courses-mode .course-file-description { -webkit-line-clamp: 2; font-size: 12px; }
  .courses-mode .course-content-files .card { grid-template-columns: 96px minmax(0, 1fr); min-height: 72px; }
  .courses-mode .course-content-files .thumb-wrap { width: 96px; height: 72px; }
  .courses-mode .course-content-files .card-cap { padding: 10px 11px; }
  .courses-mode #grid.view-grid > .card { grid-template-columns: 96px minmax(0, 1fr); min-height: 72px; }
  .courses-mode #grid.view-grid > .card .thumb-wrap { width: 96px; height: 72px; }
  .courses-mode #grid.view-grid > .card .card-cap { padding: 10px 11px; }
}

.modal-context { color: var(--muted); font-size: 12.5px; line-height: 1.4; margin-top: -4px; }
.modal-description-section { padding: 16px; border: 1px solid rgba(33,136,255,.22); border-radius: 16px; background: linear-gradient(145deg, rgba(33,136,255,.11), rgba(24,31,44,.72)); }
.modal-description-section p { margin: 8px 0 10px; color: var(--ink-secondary); font-size: 14px; line-height: 1.5; }
.description-source { color: var(--accent-text); font-size: 12px; text-decoration: none; }
.description-source:hover { color: var(--ink); text-decoration: underline; }
.description-toggle { display: block; margin-top: 10px; padding: 0; border: 0; background: none; color: var(--accent-text); font: inherit; font-size: 12px; cursor: pointer; }
.description-toggle:hover { color: var(--ink); }
.btn-primary-action { color: #fff; background: linear-gradient(135deg, #1682ff, #386af3); border-color: rgba(139,194,255,.5); box-shadow: 0 8px 20px rgba(33,136,255,.22); }
.btn-primary-action:hover { color: #fff; background: linear-gradient(135deg, #3294ff, #547dff); }
.properties-disclosure { gap: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(23,29,41,.7); }
.properties-disclosure summary { cursor: pointer; list-style: none; color: var(--ink-secondary); font-size: 13px; font-weight: 600; }
.properties-disclosure summary::-webkit-details-marker { display: none; }
.properties-disclosure summary::after { content: "›"; float: right; font-size: 19px; color: var(--muted); transform: rotate(90deg); transition: transform .15s ease; }
.properties-disclosure[open] summary::after { transform: rotate(-90deg); }
.properties-disclosure .meta { margin-top: 12px; }
.courses-mode .modal-side { width: 380px; padding: 24px 22px; gap: 16px; background: rgba(17,21,30,.96); }
.courses-mode .modal-side h2 { font-size: 21px; line-height: 1.25; }
.courses-mode .modal-actions-bar { gap: 8px; }
.courses-mode .btn-action { min-height: 38px; padding: 9px 12px; border-radius: 12px; background: rgba(23,29,41,.9); font-size: 12px; }
.courses-mode .modal-media { background: #05070b; }

@media (max-width: 900px) {
  .courses-mode .modal-box { width: 100vw; height: 100dvh; border: 0; border-radius: 0; display: flex; flex-direction: column; overflow-y: auto; background: #0a0d13; }
  .courses-mode .modal-media { flex: 0 0 auto; min-height: 0; }
  .courses-mode .modal-side { width: 100%; border-left: 0; border-top: 1px solid var(--line); padding: 22px 18px calc(30px + env(safe-area-inset-bottom)); gap: 16px; overflow: visible; }
  .courses-mode .modal-side-top { padding-right: 0; }
  .courses-mode .modal-side h2 { font-size: 22px; }
  .courses-mode .modal-actions-bar .btn-action { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .courses-mode .modal-open-separate { display: none; }
  .courses-mode .modal-actions-bar #modalFullscreen { display: none; }
}
.course-root-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.course-root-icon { color: var(--accent-text); font-size: 24px; }
.course-root-name { font-size: 17px; font-weight: 650; line-height: 1.25; }
.course-root-meta { color: var(--muted); font-size: 13px; }
.brand-home { border: 0; background: transparent; padding: 0; color: inherit; cursor: pointer; font: inherit; }
.course-back-card { background: rgba(47,128,237,.10); }
.course-content-files {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.icon-btn:hover {
  color: var(--ink);
  background: var(--panel-hover);
  border-color: var(--line-strong);
}
.icon-btn.active {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.course-nav:disabled {
  opacity: .35;
  cursor: default;
}

/* Поиск */
.search-box {
  position: relative;
  flex: 1;
  min-width: 120px;
  max-width: 420px;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 11px;
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 8px 30px 8px 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
#search:focus {
  border-color: var(--accent);
  background: var(--panel);
}
.search-clear {
  position: absolute;
  right: 8px;
  color: var(--muted);
  font-size: 12px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.search-clear:hover { color: var(--ink); background: var(--line); }

/* Быстрые фильтры типов (десктоп) */
.type-pills {
  display: flex;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.type-pills .pill {
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.12s ease;
  white-space: nowrap;
}
.type-pills .pill:hover { color: var(--ink); }
.type-pills .pill.active {
  background: var(--card-bg);
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.type-wrap {
  width: auto;
  min-width: 136px;
  max-width: 165px;
  flex-shrink: 0;
}
.type-wrap .custom-select-trigger {
  height: 34px;
  padding: 6px 11px;
  font-size: 12.5px;
}
.sort-wrap {
  width: auto;
  min-width: 154px;
  flex-shrink: 0;
}
.sort-wrap .custom-select-trigger {
  height: 34px;
  padding: 6px 11px;
  font-size: 12.5px;
}

/* Переключатель сетки (Водопад / Плитка) */
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.view-toggle .icon-btn {
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
}
.view-toggle .icon-btn.active {
  background: var(--card-bg);
  color: var(--accent-text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Слайдер масштаба */
.zoom-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}
.zoom-label {
  font-size: 11px;
  color: var(--muted);
}
#zoomSlider {
  width: 68px;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Тумблер темы */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.status-badge {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* Активные фильтры */
.filters {
  padding: 6px 18px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
}
.filters:empty { display: none; }

/* ---------- ОБЛАСТЬ ПРОКРУТКИ ---------- */
.scroll-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

/* ---------- СЕТКА КАРТОЧЕК ---------- */
#grid {
  padding: 16px 20px 24px;
  flex: 1;
}

/* Режим 1: ВОДОПАД (Flex multi-column) */
#grid.view-waterfall {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.waterfall-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Режим 2: СЕТКА (CSS Grid с max-content) */
#grid.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-card-min), 1fr));
  grid-auto-rows: max-content !important;
  gap: 14px;
  align-content: start;
}
#grid.view-grid .thumb-wrap {
  aspect-ratio: 9 / 16 !important;
  position: relative !important;
  width: 100% !important;
}
#grid.view-grid .thumb-wrap img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
}
.courses-mode #grid .card.course-video .thumb-wrap {
  aspect-ratio: 16 / 9 !important;
}
.courses-mode #grid:not(.course-root-grid) .thumb-wrap {
  aspect-ratio: 16 / 9 !important;
}
.courses-mode .course-content-files .thumb-wrap {
  aspect-ratio: 16 / 9 !important;
}
.courses-mode .course-file {
  --course-file-accent: #94a3b8;
  --course-file-surface: rgba(148, 163, 184, .12);
  border-color: color-mix(in srgb, var(--course-file-accent) 28%, var(--line));
}
.courses-mode .course-file .thumb-wrap,
.courses-mode .course-file .thumb-fallback {
  background: linear-gradient(135deg, var(--course-file-surface), rgba(18, 22, 30, .96));
}
.courses-mode .course-file .thumb-fallback {
  color: var(--course-file-accent);
}
.courses-mode .course-file .fallback-icon,
.courses-mode .course-file .fallback-text,
.courses-mode .course-file .card-tag {
  color: var(--course-file-accent);
}
.courses-mode .course-file .badge-type {
  background: color-mix(in srgb, var(--course-file-accent) 20%, #11151f);
  border-color: color-mix(in srgb, var(--course-file-accent) 45%, transparent);
  color: #f8fafc;
}
.courses-mode .course-file .card-cap {
  border-top: 3px solid var(--course-file-accent);
  padding-top: 9px;
}
.courses-mode .course-file--video { --course-file-accent: #60a5fa; --course-file-surface: rgba(37, 99, 235, .23); }
.courses-mode .course-file--pdf { --course-file-accent: #fb7185; --course-file-surface: rgba(225, 29, 72, .18); }
.courses-mode .course-file--text { --course-file-accent: #c084fc; --course-file-surface: rgba(147, 51, 234, .18); }
.courses-mode .course-file--audio { --course-file-accent: #fb923c; --course-file-surface: rgba(234, 88, 12, .18); }
.courses-mode .course-file--document { --course-file-accent: #38bdf8; --course-file-surface: rgba(2, 132, 199, .18); }
.courses-mode .course-file--sheet { --course-file-accent: #4ade80; --course-file-surface: rgba(22, 163, 74, .18); }
.courses-mode .course-file--slides { --course-file-accent: #fbbf24; --course-file-surface: rgba(217, 119, 6, .18); }
.courses-mode .course-file--archive { --course-file-accent: #facc15; --course-file-surface: rgba(202, 138, 4, .18); }
.courses-mode .course-file--image { --course-file-accent: #f472b6; --course-file-surface: rgba(190, 24, 93, .18); }
.courses-mode .course-file--link { --course-file-accent: #2dd4bf; --course-file-surface: rgba(13, 148, 136, .18); }
.courses-mode .course-file--file { --course-file-accent: #94a3b8; --course-file-surface: rgba(100, 116, 139, .18); }
.courses-mode .modal-nav {
  display: none !important;
}

/* КАРТОЧКА */
.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  position: relative;
  width: 100%;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--card-shadow);
}
.card:active {
  transform: translateY(0);
}

/* КОНТЕЙНЕР ПРЕВЬЮ */
.thumb-wrap {
  position: relative;
  width: 100%;
  background: var(--thumb-bg);
  overflow: hidden;
  display: block;
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.24s ease;
}
.card:hover .thumb-wrap img {
  transform: scale(1.02);
}

/* Ограничение для сверхдлинных скриншотов лендингов */
.thumb-wrap.tall-media {
  max-height: 440px !important;
}
.thumb-wrap.tall-media img {
  object-fit: cover !important;
  object-position: top !important;
}

/* Видео предпросмотра при наведении курсора */
.thumb-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
  pointer-events: none;
}
.video-scrub-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
  pointer-events: none;
}
.video-scrub-prog {
  height: 100%;
  width: 0%;
  background: var(--accent);
}
.card.touch-scrubbing {
  transform: scale(0.98);
  transition: transform 0.15s ease;
}
.card.touch-scrubbing .thumb-video {
  box-shadow: 0 0 0 2px var(--accent);
}
.card.touch-scrubbing .video-scrub-bar {
  height: 6px;
  background: rgba(0, 0, 0, 0.7);
}

/* Бейджи на превью */
.badge-type {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--badge-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--badge-text);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2.5px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  z-index: 3;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.badge-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
}
.badge-res {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #d0d5dd;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.card:hover .badge-res {
  opacity: 1;
}
.badge-tall {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  z-index: 3;
  text-transform: uppercase;
}
.card-play-icon {
  width: 10px;
  height: 10px;
  fill: currentColor;
}

/* Заглушка для ссылок и файлов без превью */
.thumb-fallback {
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--panel-alt);
  color: var(--muted);
  padding: 24px 16px;
}
.thumb-fallback .fallback-icon {
  width: 32px;
  height: 32px;
  color: var(--muted);
}
.thumb-fallback .fallback-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
  text-align: center;
  word-break: break-all;
}

/* Подпись карточки */
.card-cap {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--card-bg);
}
.card-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.card-sub {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.card-tag {
  color: var(--accent-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-size {
  flex-shrink: 0;
  color: var(--muted);
}

/* Кнопка в самом низу списка карточек */
.more {
  padding: 16px 20px 48px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.btn-secondary {
  padding: 11px 26px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  transition: all 0.15s ease;
}
.btn-secondary:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
}

/* ---------- MODAL (ЛАЙТБОКС) ---------- */
#modal {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 1000;
}
.modal-bg {
  position: absolute; inset: 0;
  background: rgba(6, 8, 12, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.modal-box {
  position: relative;
  width: min(1280px, 95vw);
  height: min(90vh, 860px);
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.7);
  z-index: 2;
}

/* Стрелки навигации модалки */
.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(18, 22, 30, 0.85);
  color: #fff;
  font-size: 24px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  z-index: 20;
  transition: all 0.15s ease;
}
.modal-nav:hover {
  background: var(--accent);
  color: #fff;
}
.modal-nav:disabled {
  opacity: 0.25;
  pointer-events: none;
}
.modal-nav-prev { left: 16px; }
.modal-nav-next { right: 356px; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 0;
  background: var(--panel-alt);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  z-index: 20;
  font-size: 14px;
  border: 1px solid var(--line);
  transition: all 0.15s ease;
}
.modal-close:hover {
  background: var(--accent);
  color: #fff;
}

/* Медиа вьюпорт модалки (чистый темный студийный фон по умолчанию) */
.modal-media {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background-color: #0b0d13;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 0;
}
/* Анимация перелистывания роликов при свайпе или клике навигации */
@keyframes modalSlideNext {
  0% { opacity: 0.35; transform: translateX(30px); }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes modalSlidePrev {
  0% { opacity: 0.35; transform: translateX(-30px); }
  100% { opacity: 1; transform: translateX(0); }
}
.modal-media.slide-next {
  animation: modalSlideNext 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.modal-media.slide-prev {
  animation: modalSlidePrev 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

[data-theme="light"] .modal-media {
  background-color: #eef2f7;
}

/* Шахматный фон ТОЛЬКО для PNG без фона (темный, деликатный паттерн) */
.modal-media.checkerboard-bg,
.image-viewer-stage.checkerboard-bg {
  background-color: #0d1017;
  background-image: 
    linear-gradient(45deg, #151922 25%, transparent 25%), 
    linear-gradient(-45deg, #151922 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #151922 75%), 
    linear-gradient(-45deg, transparent 75%, #151922 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
[data-theme="light"] .modal-media.checkerboard-bg,
[data-theme="light"] .image-viewer-stage.checkerboard-bg {
  background-color: #e2e6ec;
  background-image: 
    linear-gradient(45deg, #d3d8e2 25%, transparent 25%), 
    linear-gradient(-45deg, #d3d8e2 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #d3d8e2 75%), 
    linear-gradient(-45deg, transparent 75%, #d3d8e2 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
.modal-media .modal-video-viewer {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  padding: 16px;
  box-sizing: border-box;
}

/* В courses видео всегда смотрим в горизонтальном 16:9-плеере, не в режиме Reels. */
.courses-mode .modal-media .modal-video-viewer {
  aspect-ratio: 16 / 9;
  width: min(100%, 960px);
  height: auto;
  max-height: none;
  object-fit: contain;
  padding: 0;
}

/* Просмотрщик изображений с зумом и поддержкой длинных лендингов */
.image-viewer-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-stage {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.image-viewer-stage::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.image-viewer-stage::-webkit-scrollbar-track {
  background: transparent;
}
.image-viewer-stage::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}
.image-viewer-stage::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.45);
}

.image-viewer-canvas {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  min-width: 100%;
  min-height: 100%;
}

.image-viewer-img {
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  touch-action: pan-x pan-y;
  border-radius: 4px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  transition: width 0.12s ease-out, height 0.12s ease-out;
}
.checkerboard-bg .image-viewer-img {
  box-shadow: none;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
}

/* Плавающая панель управления зумом (стиль Eagle / Figma) */
.image-zoom-bar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: rgba(18, 22, 30, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .image-zoom-bar {
  background: rgba(240, 244, 250, 0.92);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.zoom-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}
.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent);
}
[data-theme="light"] .zoom-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.zoom-label-btn {
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  min-width: 44px;
  text-align: center;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease;
}
.zoom-label-btn:hover {
  color: var(--accent);
}

.zoom-divider {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 2px;
}
[data-theme="light"] .zoom-divider {
  background: rgba(0, 0, 0, 0.12);
}

.zoom-pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.zoom-pill:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}
.zoom-pill.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
[data-theme="light"] .zoom-pill:hover {
  background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .zoom-pill.active {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 768px) {
  .image-zoom-bar {
    bottom: 12px;
    padding: 4px 6px;
    gap: 4px;
  }
  .zoom-pill {
    padding: 3px 7px;
    font-size: 11px;
  }
  .zoom-label-btn {
    min-width: 36px;
    font-size: 11px;
  }
  .image-viewer-stage {
    padding-bottom: 50px;
  }
}

/* Обертка видео и оверлей фонового транскодирования */
.video-viewer-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.video-transcode-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 16, 23, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}
.transcode-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Карточка ошибки воспроизведения медиа */
.media-error-card {
  max-width: 440px;
  padding: 32px 24px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  margin: auto;
  z-index: 10;
}
.media-error-icon {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(224, 90, 71, 0.12);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-bottom: 2px;
}
.media-error-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.media-error-desc {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 13px;
  line-height: 1.5;
}
.media-error-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}
.media-error-badge {
  font-size: 11.5px;
  padding: 4px 8px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
}
.media-error-actions {
  margin-top: 6px;
  display: flex;
  gap: 8px;
}

/* ---------- PDF VIEWER (PDF.JS) ---------- */
.pdf-viewer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #11141c;
  overflow: hidden;
}
.pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  z-index: 10;
  flex-shrink: 0;
}
.pdf-toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pdf-tool-btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  transition: all 0.15s ease;
  text-decoration: none;
}
.pdf-tool-btn:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: var(--accent-text);
}
.pdf-tool-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}
.pdf-page-display {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  padding: 0 4px;
  min-width: 60px;
  text-align: center;
}
.pdf-zoom-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  min-width: 44px;
  text-align: center;
}
.pdf-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  -webkit-overflow-scrolling: touch;
  background: #0d1017;
}
.pdf-loader {
  color: var(--muted);
  font-size: 14px;
  margin: auto;
  padding: 40px;
}
.pdf-page-card {
  position: relative;
  background: #ffffff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}
.pdf-canvas-wrap {
  position: relative;
  display: block;
  max-width: 100%;
  line-height: 0;
}
.pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 3px;
}
.pdf-annot-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}
.pdf-link-overlay {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 2px;
  background: rgba(0, 102, 255, 0.08);
  border-bottom: 1px dashed rgba(0, 102, 255, 0.5);
  transition: background 0.15s ease, border-color 0.15s ease;
  box-sizing: border-box;
}
.pdf-link-overlay:hover {
  background: rgba(0, 102, 255, 0.25);
  border-bottom: 2px solid #0066cc;
}
.pdf-scroll::-webkit-scrollbar,
.docx-render-container::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.pdf-scroll::-webkit-scrollbar-track,
.docx-render-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 5px;
}
.pdf-scroll::-webkit-scrollbar-thumb,
.docx-render-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 5px;
}
.pdf-scroll::-webkit-scrollbar-thumb:hover,
.docx-render-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.45);
}
.pdf-page-badge {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 500;
}
.pdf-fallback-card {
  margin: auto;
  text-align: center;
  max-width: 440px;
  padding: 32px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
}
.pdf-fallback-card h3 {
  margin: 14px 0 8px;
  font-size: 16px;
}
.pdf-fallback-card p {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ---------- OFFICE VIEWER (DOCX, XLSX, PPTX) ---------- */
.doc-viewer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0f121a;
  overflow: hidden;
}
.doc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.doc-badge-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}
.doc-badge-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.doc-badge-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}
.doc-badge-size {
  font-size: 11.5px;
  color: var(--muted);
}
.doc-preview-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  -webkit-overflow-scrolling: touch;
}
.docx-render-container {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  background: #11141c;
  padding: 24px 16px;
  -webkit-overflow-scrolling: touch;
}
.docx-render-container .docx-wrapper {
  background: transparent !important;
  padding: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  gap: 24px !important;
}
.docx-render-container .docx-wrapper > section.docx {
  background: #ffffff !important;
  color: #1a1a1a !important;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6) !important;
  border-radius: 2px !important;
  margin-bottom: 24px !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}
.docx-render-container a {
  color: #0066cc !important;
  text-decoration: underline !important;
  cursor: pointer !important;
  pointer-events: auto !important;
  transition: opacity 0.15s ease;
}
.docx-render-container a:hover {
  opacity: 0.75;
}
.docx-loading {
  color: var(--muted);
  font-size: 14px;
  margin: auto;
  padding: 40px;
  text-align: center;
}
.doc-sheet-card {
  position: relative;
  max-width: min(100%, 720px);
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: 4px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}
.doc-sheet-image {
  max-width: 100%;
  max-height: min(68vh, 720px);
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}
.doc-sheet-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  background: var(--panel);
  color: var(--ink);
}
.doc-fallback-title {
  margin: 12px 0 6px;
  font-size: 16px;
}
.doc-fallback-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- FONT VIEWER (TTF, OTF) ---------- */
.font-viewer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #10131b;
  overflow: hidden;
}
.font-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.font-meta-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.font-tag-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
}
.font-title-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.font-size-group {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-secondary);
}
.font-size-label {
  min-width: 40px;
  font-weight: 600;
  color: var(--ink);
}
.font-slider {
  width: 110px;
  accent-color: var(--accent);
  cursor: pointer;
}
.font-scroll-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
}
.font-specimen-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
}
.font-box-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  letter-spacing: 0.06em;
}
.font-sample-editable {
  color: var(--ink);
  line-height: 1.45;
  outline: none;
  border-bottom: 1px dashed var(--line-strong);
  padding-bottom: 14px;
  word-break: break-word;
  min-height: 80px;
}
.font-sample-editable:focus {
  border-bottom-color: var(--accent);
}
.font-glyphs-matrix {
  color: var(--ink-secondary);
  font-size: 18px;
  line-height: 1.8;
  letter-spacing: 1.5px;
  word-break: break-all;
}
.glyph-row {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.glyph-row:last-child {
  border-bottom: none;
}

/* ---------- TEXT VIEWER (TXT, JSON, MD, CODE) ---------- */
.text-viewer {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0b0d13;
  overflow: hidden;
}
.text-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.text-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  background: var(--panel-hover);
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.text-filename {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.text-pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #e6edf3;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- ARCHIVE, URL & AUDIO VIEWERS ---------- */
.archive-viewer,
.url-viewer,
.audio-viewer {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #0f121a;
  overflow-y: auto;
}
.archive-card,
.url-card {
  max-width: 440px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.archive-thumb-wrap {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
}
.archive-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.archive-badge {
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
}
.archive-title,
.url-title,
.audio-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}
.archive-info {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.url-address {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-all;
}
.url-icon-box,
.audio-icon-box {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--accent);
}
.audio-player {
  width: 100%;
  margin-top: 10px;
}

/* Правая панель модалки */
.modal-side {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 22px 20px;
  gap: 20px;
}
.modal-side-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 28px;
}
.modal-side h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}
.modal-actions-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-action {
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.12s ease;
}
.btn-action:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* Полноэкранный и «картинка в картинке» — только на телефоне: на десктопе
   у плеера свои кнопки, а на iPhone это единственный способ включить оба режима */
#modalFullscreen, #modalPip { display: none; }
@media (max-width: 900px) {
  #modalFullscreen:not([hidden]),
  #modalPip:not([hidden]) { display: inline-flex; }
  #modalPip.active { border-color: var(--accent); color: var(--accent-text); }

.meta-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.meta {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
}
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--line);
}
.meta-row .k { color: var(--muted); }
.meta-row .v { color: var(--ink); font-weight: 500; text-align: right; }
.meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.note {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-secondary);
  background: var(--panel-alt);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.4;
}

/* ---------- АДАПТИВНОСТЬ ПОД ПЛАНШЕТЫ И ТЕЛЕФОНЫ (APPLE HIG) ---------- */
@media (max-width: 900px) {
  .modal-box {
    flex-direction: column;
    height: 94vh;
  }
  .modal-media {
    flex: 1;
    height: 55vh;
  }
  .modal-side {
    width: 100%;
    height: 39vh;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .modal-nav-next { right: 16px; }
}

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
  }

  /* Сайдбар на мобилке как всплывающий Drawer */
  #sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 86vw;
    max-width: 320px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    padding-top: max(16px, env(safe-area-inset-top, 0px));
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }
  #app.mobile-sidebar-open #sidebar {
    transform: translateX(0);
  }
  #app.mobile-sidebar-open + #sidebarBackdrop,
  body:has(#app.mobile-sidebar-open) #sidebarBackdrop {
    display: block !important;
  }

  .sidebar-opener { display: grid !important; }
  .desktop-only { display: none !important; }
  .mobile-only-block { display: flex !important; }

  .select-wrap select {
    height: 44px;
    font-size: 15px;
    border-radius: 9px;
  }

  /* УДОБНЫЕ КНОПКИ И ПОИСК НА МОБИЛКЕ (44x44px Touch Targets) + Безопасный отступ iOS Dynamic Island / Notch */
  #topbar {
    padding-top: calc(env(safe-area-inset-top, 0px) + 2px);
    padding-bottom: 8px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    gap: 10px;
    height: auto;
    min-height: calc(env(safe-area-inset-top, 0px) + 54px);
    box-sizing: border-box;
  }
  .courses-mode #topbar {
    padding-top: calc(env(safe-area-inset-top, 0px) + 2px);
    padding-bottom: 8px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    min-height: calc(env(safe-area-inset-top, 0px) + 54px);
  }
  .icon-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 9px;
  }
  .icon-btn svg {
    width: 22px;
    height: 22px;
  }
  .search-box {
    max-width: none;
    height: 44px;
  }
  #search {
    height: 44px;
    padding: 0 34px 0 38px;
    font-size: 16px; /* Предотвращает зум в iOS Safari при тапе! */
    border-radius: 9px;
  }
  .search-icon {
    left: 11px;
    width: 18px;
    height: 18px;
  }
  .search-clear {
    right: 9px;
    width: 26px;
    height: 26px;
    font-size: 14px;
  }
  .view-toggle {
    padding: 2px;
    border-radius: 9px;
    gap: 3px;
  }
  .view-toggle .icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 7px;
  }
  .view-toggle .icon-btn svg {
    width: 20px;
    height: 20px;
  }

  /* СЕТКА НА МОБИЛКЕ: ВСЕГДА 2 РОВНЫЕ КОЛОНКИ */
  #grid {
    padding: 10px 10px 24px;
  }
  #grid.view-waterfall {
    gap: 10px;
  }
  .waterfall-col {
    gap: 10px;
  }
  #grid.view-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-auto-rows: max-content !important;
    gap: 10px;
  }

  .card-cap {
    padding: 8px 10px;
  }
  .card-title {
    font-size: 11.5px;
  }
  .card-sub {
    font-size: 10.5px;
  }

  .modal-box {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    background: var(--panel);
  }
  .modal-close {
    position: fixed;
    width: 40px;
    height: 40px;
    top: max(12px, calc(env(safe-area-inset-top, 0px) + 6px));
    right: max(12px, calc(env(safe-area-inset-right, 0px) + 6px));
    font-size: 16px;
    background: rgba(18, 22, 30, 0.85);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    z-index: 50;
  }
  [data-theme="light"] .modal-close {
    background: rgba(255, 255, 255, 0.92);
    color: #111418;
    border: 1px solid rgba(0, 0, 0, 0.14);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  }
  .modal-nav {
    position: fixed;
    width: 40px;
    height: 40px;
    font-size: 24px;
    top: 42%;
    transform: translateY(-50%);
    background: rgba(18, 22, 30, 0.75);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    z-index: 40;
  }
  [data-theme="light"] .modal-nav {
    background: rgba(255, 255, 255, 0.92);
    color: #111418;
    border: 1px solid rgba(0, 0, 0, 0.14);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  }
  .modal-nav-prev { left: 8px; }
  .modal-nav-next { right: 8px; }
  .modal-media {
    width: 100%;
    height: calc(100dvh - 155px);
    min-height: calc(100vh - 155px);
    flex-shrink: 0;
    padding-top: max(16px, env(safe-area-inset-top, 0px));
    padding-bottom: 6px;
    padding-left: 6px;
    padding-right: 6px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #0b0d13;
  }
  [data-theme="light"] .modal-media {
    background-color: #eef2f7;
  }
  .modal-media .modal-video-viewer {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    padding: 0;
    border-radius: 8px;
    box-sizing: border-box;
  }
  .courses-mode .modal-media .modal-video-viewer {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: none;
    object-fit: contain;
  }
  .courses-mode .modal-media.course-video-media {
    height: auto;
    min-height: 0;
    aspect-ratio: auto;
    padding: max(56px, env(safe-area-inset-top, 0px)) 0 0;
  }
  .courses-mode .modal-media.course-video-media .video-viewer-wrap {
    width: 100%;
    height: auto;
  }
  .courses-mode .modal-media.course-video-media .modal-video-viewer {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    border-radius: 0;
  }
  .modal-side {
    width: 100%;
    height: auto;
    flex-shrink: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 14px 16px;
    padding-bottom: max(32px, calc(env(safe-area-inset-bottom, 0px) + 24px));
    overflow: visible;
    box-sizing: border-box;
    gap: 16px;
  }
  .modal-side-top {
    padding-right: 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }
  .modal-side h2 {
    font-size: 15px;
    line-height: 1.35;
  }
  .modal-actions-bar {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
  }
  .modal-actions-bar .btn-action {
    flex: 1;
    min-width: 0;
    justify-content: center;
    padding: 8px 6px;
    font-size: 12px;
  }
  [data-theme="light"] #sidebar {
    box-shadow: 0 0 32px rgba(0, 0, 0, 0.12);
  }
  [data-theme="light"] .sidebar-backdrop {
    background: rgba(15, 23, 42, 0.35);
  }
  [data-theme="light"] .mobile-type-pills .pill {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
    color: var(--ink-secondary);
  }
  .doc-topbar {
    padding-top: max(10px, calc(env(safe-area-inset-top, 0px) + 8px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .scroll-area {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }
  .pdf-toolbar,
  .font-toolbar {
    padding: 6px 10px;
    gap: 6px;
  }
  .pdf-tool-btn {
    min-height: 36px;
    padding: 6px 8px;
  }
}

/* Rich course descriptions: article-ui-kit inspired */
.rich-lead { margin: 0 0 14px; padding: 16px 18px; border: 1px solid rgba(33, 136, 255, .28); border-left: 3px solid var(--accent); border-radius: 14px; background: linear-gradient(135deg, rgba(33, 136, 255, .14), rgba(24, 31, 44, .55)); }
.rich-lead p { margin: 0 0 8px; color: var(--ink); font-size: 14.5px; line-height: 1.6; }
.rich-lead p:first-child { font-weight: 700; }
.rich-lead p:last-child { margin-bottom: 0; }
.rich-note { position: relative; margin: 14px 0; padding: 12px 16px 12px 42px; border: 1px solid rgba(33, 136, 255, .3); border-radius: 12px; background: rgba(33, 136, 255, .08); color: var(--ink-secondary); font-size: 14px; line-height: 1.55; }
.rich-note::before { content: "i"; position: absolute; left: 14px; top: 12px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; background: rgba(33, 136, 255, .2); color: #8bc2ff; font-size: 12px; font-weight: 800; }
.course-excerpt { margin: 6px 0 4px; color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.rich-checklist { margin: 12px 0 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(23, 29, 41, .65); }
.rich-checklist ul { list-style: none; margin: 0; padding: 0; }
.rich-checklist li { position: relative; margin: 8px 0; padding-left: 24px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.rich-checklist li:last-child { margin-bottom: 0; }
.rich-checklist li::before { content: "✓"; position: absolute; left: 0; top: 1px; color: var(--accent-text); font-weight: 800; }
.rich-checklist strong { color: var(--ink); font-weight: 700; }
.rich-section { display: flex; gap: 8px; margin: 20px 0 10px; color: var(--ink); font-size: 15px; line-height: 1.35; }
.rich-section::before { content: ""; width: 3px; flex: 0 0 3px; border-radius: 2px; background: var(--accent); }

.rubric-wrap { min-width: 190px; }
@media (max-width: 768px) { .rubric-wrap { min-width: 0; } }

/* ---------- Вкладки разделов и вкладка YouTube ---------- */
.view-tabs { display: flex; gap: 4px; flex: 0 0 auto; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-alt); }
.view-tab { min-height: 34px; padding: 6px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.view-tab:hover { color: var(--ink); }
.view-tab.is-active { color: #fff; background: linear-gradient(135deg, #1682ff, #386af3); box-shadow: 0 6px 16px rgba(33, 136, 255, .22); }
/* YouTube-раздел живёт в своей красной гамме */
#ytTabBtn.is-active { background: linear-gradient(135deg, #ff2f2f, #c40000); box-shadow: 0 6px 16px rgba(255, 20, 20, .28); }
#ytTabBtn.is-active:hover { background: linear-gradient(135deg, #ff4747, #d40000); }
.yt-view { flex: 1; min-height: 0; overflow-y: auto; padding: 18px clamp(12px, 3vw, 26px) 32px; }
.yt-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.yt-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: 20px; }
.yt-logo { width: 26px; height: 26px; flex: 0 0 26px; }
.yt-status { color: var(--muted); font-size: 12.5px; }
.yt-cats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.yt-chip { min-height: 34px; padding: 6px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-alt); color: var(--ink-secondary, var(--muted)); font: inherit; font-size: 13px; cursor: pointer; }
.yt-chip.is-active { color: #fff; border-color: transparent; background: linear-gradient(135deg, #ff2f2f, #c40000); box-shadow: 0 6px 16px rgba(255, 20, 20, .24); }
.yt-chip-count { opacity: .72; margin-left: 5px; font-size: 12px; }
.yt-chip:hover { border-color: rgba(255, 60, 60, .4); }
.yt-grid { display: flex; flex-direction: column; gap: 18px; max-width: 860px; }
.yt-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--panel); color: var(--ink); text-decoration: none; transition: border-color .15s ease; }
.yt-card.has-text { cursor: pointer; }
.yt-card:hover, .yt-card:focus-visible { border-color: rgba(255, 60, 60, .6); transform: translateY(-1px); outline: none; box-shadow: 0 10px 26px rgba(0, 0, 0, .3); }
.yt-thumb { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #05070b; }
.yt-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.yt-thumb.is-portrait { aspect-ratio: 16 / 10; }
.yt-thumb.is-portrait img { object-fit: contain; }
.yt-dur { position: absolute; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 5px; background: rgba(0, 0, 0, .78); color: #fff; font-size: 11.5px; font-weight: 600; }
.yt-file { position: absolute; left: 6px; bottom: 6px; padding: 2px 6px; border-radius: 5px; background: rgba(163, 0, 0, .9); color: #fff; font-size: 11px; }
.yt-body { display: flex; flex-direction: column; gap: 7px; padding: 14px 16px 16px; }
.yt-title { margin: 0; font-size: 17px; font-weight: 650; line-height: 1.3; }
.yt-meta { color: var(--muted); font-size: 12.5px; }
.yt-cat { align-self: flex-start; padding: 2px 9px; border-radius: 999px; background: rgba(255, 45, 45, .16); color: #ff9d9d; font-size: 11.5px; }
.yt-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 2px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.yt-card.is-open .yt-desc { display: block; overflow: visible; -webkit-line-clamp: unset; color: var(--ink-secondary, #b7bfcc); }
.yt-desc a { color: #ff8a8a; text-decoration: none; border-bottom: 1px solid rgba(255, 138, 138, .4); }
.yt-desc a:hover { color: #ffb3b3; border-bottom-color: rgba(255, 179, 179, .8); }
.yt-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.yt-hint { color: #ff9d9d; font-size: 12.5px; }
.yt-card.is-open .yt-hint { color: var(--muted); }
.yt-actions { display: none; margin-top: 4px; }
.yt-card.is-open .yt-actions { display: flex; }
/* Без описания раскрывать нечего — кнопка видна сразу */
.yt-card:not(.has-text) .yt-actions { display: flex; }
.yt-watch { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 9px 20px; border-radius: 10px; background: linear-gradient(135deg, #ff2f2f, #c40000); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
.yt-watch:hover { background: linear-gradient(135deg, #ff4747, #d40000); color: #fff; }
.yt-empty { padding: 48px 18px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; font-size: 14px; }
@media (max-width: 600px) {
  .view-tab { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }
  .yt-view { padding: 12px 8px 24px; }
  .yt-grid { gap: 14px; }
  .yt-title { font-size: 15.5px; }
  .yt-body { padding: 12px 13px 14px; gap: 6px; }
  .yt-desc { font-size: 13px; }
  .yt-watch { width: 100%; }
}

/* ---------- Reels: вертикальная лента 9:16 ---------- */
#reelsTabBtn.is-active { background: linear-gradient(135deg, #ff2f6d, #c4004b); box-shadow: 0 6px 16px rgba(255, 30, 100, .26); }
.reels-view { flex: 1; min-height: 0; overflow-y: auto; padding: 18px clamp(12px, 3vw, 26px) 32px; }
.reels-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.reels-head h2 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: 20px; }
.reels-logo { width: 26px; height: 26px; flex: 0 0 26px; }
.reels-status { margin-left: 8px; color: var(--muted); font-size: 12.5px; }
.reels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.reels-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--panel); color: var(--ink); }
.reels-card:hover { border-color: rgba(255, 60, 120, .55); }
.reels-poster { position: relative; aspect-ratio: 9 / 16 !important; width: 100% !important; height: auto !important; background: #05070b; cursor: pointer; }
.reels-poster img { width: 100%; height: 100%; display: block; object-fit: cover; }
.reels-play { position: absolute; inset: 0; display: grid; place-items: center; }
.reels-play span { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .55); border: 2px solid rgba(255, 255, 255, .8); }
.reels-play svg { width: 22px; height: 22px; fill: #fff; margin-left: 3px; }
.reels-kind { position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 11px; text-transform: lowercase; }
.reels-dur { position: absolute; right: 8px; bottom: 8px; padding: 2px 7px; border-radius: 5px; background: rgba(0, 0, 0, .78); color: #fff; font-size: 11.5px; font-weight: 600; }
.reels-body { display: flex; flex-direction: column; gap: 6px; padding: 11px 13px 13px; }
.reels-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; font-size: 14px; font-weight: 600; line-height: 1.3; }
.reels-meta { color: var(--muted); font-size: 12px; }
.reels-missing { color: #ffb37a; font-size: 12px; }
.reels-player { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .92); }
.reels-player video { max-width: min(96vw, 480px); max-height: 92vh; width: auto; height: auto; border-radius: 14px; background: #000; }
.reels-player-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .16); color: #fff; font-size: 22px; cursor: pointer; }
.reels-empty { padding: 48px 18px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; font-size: 14px; }
@media (max-width: 600px) {
  .reels-view { padding: 12px 8px 24px; }
  .reels-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .reels-body { padding: 8px 9px 10px; }
  .reels-title { font-size: 12.5px; }
  .reels-meta { font-size: 11px; }
}
.reels-source { align-self: flex-start; color: #ff9ab8; font-size: 12px; text-decoration: none; border-bottom: 1px solid rgba(255, 154, 184, .35); }
.reels-source:hover { color: #ffbdd2; }

/* Уведомление видео (ошибки «картинки в картинке» и пр.) */
.video-note {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  z-index: 10000;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(30, 36, 50, .96);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .15s ease, transform .15s ease;
}
.video-note.show {
  opacity: 1;
  transform: translateY(0);
}
