:root {
  color-scheme: dark;
  --bg: #090a0c;
  --panel: #121419;
  --panel-2: #1a1d24;
  --text: #f5f7fb;
  --muted: #9ea5b2;
  --line: rgba(255,255,255,.10);
  --accent: #e53935;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, Arial, sans-serif; }
body { padding: 28px; }
button, input, textarea { font: inherit; }
a { color: inherit; }
.shell { width: min(1240px, 100%); margin: 0 auto; }
.header { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 24px; }
.header h1 { margin: 0; font-size: clamp(28px, 5vw, 54px); letter-spacing: -.04em; }
.header p { margin: 8px 0 0; color: var(--muted); max-width: 760px; line-height: 1.5; }
.badge { display: inline-flex; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.notice { margin: 0 0 22px; padding: 14px 16px; border: 1px solid rgba(229,57,53,.35); background: rgba(229,57,53,.08); border-radius: 14px; color: #ffd7d5; line-height: 1.45; }
.section { margin-top: 34px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 21px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.card { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; cursor: pointer; transition: transform .18s ease, border-color .18s ease; }
.card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.22); }
.thumb { aspect-ratio: 16/9; background: linear-gradient(135deg, #171a21, #0c0d10); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play { position: absolute; left: 16px; top: 16px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.22); background: rgba(0,0,0,.58); color: #fff; display: grid; place-items: center; font-size: 18px; backdrop-filter: blur(8px); }
.meta { padding: 14px 15px 16px; }
.meta h3 { margin: 0; font-size: 16px; line-height: 1.35; }
.meta p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.empty, .error { border: 1px dashed var(--line); border-radius: var(--radius); padding: 22px; color: var(--muted); }
.error { color: #ffb8b6; border-color: rgba(229,57,53,.45); }
.modal { position: fixed; inset: 0; z-index: 99999; background: rgba(0,0,0,.88); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.open { display: flex; }
.modal-card { width: min(1280px, 100%); background: #000; border: 1px solid rgba(255,255,255,.16); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 100px rgba(0,0,0,.55); }
.modal-top { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 14px; background: #111318; }
.modal-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: #fff; cursor: pointer; }
.player-stage { width: 100%; aspect-ratio: 16/9; min-height: 300px; background: #000; }
.player-stage iframe { width: 100%; height: 100%; border: 0; display: block; }
.admin-link { color: var(--muted); font-size: 13px; text-decoration: none; }
.admin-link:hover { color: #fff; }
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field textarea { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 12px; padding: 12px 14px; outline: none; }
.field textarea { min-height: 230px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 180px; gap: 14px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; background: var(--accent); color: #fff; font-weight: 700; }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--line); }
.status { min-height: 24px; color: var(--muted); }

.sphere-player { position: relative; width: 100%; height: 100%; min-height: 300px; background: #000; overflow: hidden; user-select: none; overscroll-behavior: contain; }
.sphere-player canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.sphere-player canvas:active { cursor: grabbing; }
.sphere-video { display: none; }
.sphere-controls { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 22px 14px 12px; background: linear-gradient(transparent, rgba(0,0,0,.88)); }
.sphere-controls button { border: 0; background: rgba(0,0,0,.52); color: #fff; border-radius: 999px; min-width: 38px; height: 38px; cursor: pointer; }
.sphere-controls input[type="range"] { width: 100%; }
.sphere-time { font-size: 12px; color: #fff; min-width: 84px; text-align: center; }
.sphere-hint { position: absolute; top: 14px; left: 14px; padding: 8px 10px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; pointer-events: none; }
.sphere-error { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: #ffb8b6; background: #090a0c; }
@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) {
  body { padding: 16px; }
  .header { align-items: start; flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .modal { padding: 0; }
  .modal-card { border-radius: 0; border: 0; height: 100%; display: flex; flex-direction: column; }
  .player-stage { flex: 1; aspect-ratio: auto; }
  .sphere-controls { grid-template-columns: auto 1fr auto; }
  .sphere-time { display: none; }
}

.field select { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 12px; padding: 12px 14px; outline: none; }
details { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: rgba(255,255,255,.02); }
details summary { cursor: pointer; color: var(--muted); }
.details-field { margin-top: 14px; }
.player-loading, .player-failure { width: 100%; height: 100%; display: grid; place-items: center; padding: 28px; text-align: center; color: var(--muted); }
.player-failure { color: #ffb8b6; }
.sphere-source { position: absolute; top: 14px; right: 14px; z-index: 5; padding: 7px 11px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(0,0,0,.58); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .02em; text-decoration: none; pointer-events: auto; backdrop-filter: blur(8px); transition: background .18s ease, border-color .18s ease, transform .18s ease; }
.sphere-source:hover { background: rgba(0,0,0,.82); border-color: rgba(255,255,255,.34); transform: translateY(-1px); }
.sphere-source:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.sphere-transient { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); max-width: min(540px, calc(100% - 40px)); padding: 12px 16px; border-radius: 12px; background: rgba(0,0,0,.82); color: #fff; text-align: center; font-size: 13px; z-index: 4; }
.sphere-controls { grid-template-columns: auto minmax(80px,1fr) auto auto 90px minmax(92px,auto) auto auto; }
.sphere-controls button.active { background: var(--accent); }
.sphere-volume { width: 90px !important; }
.sphere-quality {
  min-width: 96px;
  max-width: 178px;
  height: 38px;
  padding: 0 30px 0 12px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(0,0,0,.58);
  color: #fff;
  cursor: pointer;
  outline: none;
}
.sphere-quality:disabled { opacity: .52; cursor: default; }
.sphere-quality:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (max-width: 760px) {
  .sphere-controls { grid-template-columns: auto minmax(70px,1fr) auto auto auto; }
  .sphere-volume, .sphere-time, .sphere-quality { display: none; }
}

/* v2.2: состояние загрузки HLS и блокировка преждевременного запуска */
.sphere-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(560px, calc(100% - 40px));
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .76);
  color: #fff;
  text-align: center;
  font-size: 13px;
  z-index: 3;
}
.sphere-controls button:disabled {
  cursor: wait;
  opacity: .45;
}

/* v2.3.2: чистое встраивание в Tilda */
html.is-embedded body { overflow-x: hidden; }
html.is-embedded .shell { width: min(1240px, 100%); }

/* v2.4.0: каталог, плейлисты и редактируемая публичная страница */
.catalog-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(240px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
}
.catalog-field { display: grid; gap: 7px; }
.catalog-field > span { color: var(--muted); font-size: 12px; }
.catalog-field input,
.catalog-field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 13px;
  outline: none;
}
.catalog-field input:focus,
.catalog-field select:focus { border-color: rgba(255,255,255,.28); }
.result-count { align-self: center; color: var(--muted); font-size: 12px; white-space: nowrap; }

.admin-shell { width: min(1120px, 100%); }
.admin-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.02);
}
.admin-panel-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.admin-panel-head h2 { margin: 0; font-size: 20px; }
.admin-panel-head p { margin: 6px 0 0; color: var(--muted); line-height: 1.45; font-size: 13px; }
.row-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.textarea-compact { min-height: 100px !important; font-family: Inter, Arial, sans-serif !important; font-size: 14px !important; }
.field small { color: var(--muted); line-height: 1.4; }
.btn.danger { background: rgba(229,57,53,.12); border: 1px solid rgba(229,57,53,.42); color: #ffb8b6; }
.playlist-create { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.playlist-create input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.playlist-editor { display: grid; gap: 14px; }
.playlist-search-field { margin-top: 4px; }
.playlist-video-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
  padding: 4px;
  border-radius: 14px;
}
.playlist-video-item {
  display: grid;
  grid-template-columns: auto 96px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  cursor: pointer;
}
.playlist-video-item:hover { border-color: rgba(255,255,255,.22); }
.playlist-video-item > input { width: 18px; height: 18px; }
.playlist-video-item img { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 9px; background: #08090b; }
.playlist-video-item span { min-width: 0; display: grid; gap: 5px; }
.playlist-video-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.playlist-video-item small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 760px) {
  .catalog-toolbar { grid-template-columns: 1fr; }
  .result-count { justify-self: start; }
  .row-even { grid-template-columns: 1fr; }
  .admin-panel-head { flex-direction: column; }
  .playlist-create { grid-template-columns: 1fr; }
  .playlist-video-item { grid-template-columns: auto 72px minmax(0,1fr); }
  .playlist-video-item img { width: 72px; }
}

/* v2.5.0: commercial stability core */
.sphere-error {
  display: grid;
  gap: 12px;
  justify-items: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  max-width: min(420px, calc(100% - 36px));
  padding: 18px;
  border-radius: 14px;
  background: rgba(15, 16, 19, .94);
  border: 1px solid rgba(255, 255, 255, .14);
  color: #fff;
  text-align: center;
}
.sphere-error button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
}
.sphere-error button:hover { background: rgba(255,255,255,.14); }
.admin-help { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.ops-output {
  margin-top: 14px;
  min-height: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--muted);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.ops-output.is-error { color: #ffb8b6; }
.backup-list { display: grid; gap: 8px; margin-top: 12px; }
.backup-item {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
}
.backup-item span { min-width: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.backup-item button { flex: 0 0 auto; }

/* v2.6.0: Professional Player UX */
.sphere-poster {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 1;
  transition: opacity .32s ease;
}
.sphere-poster::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.25);
}
.sphere-poster.is-hidden { opacity: 0; pointer-events: none; }
.sphere-player canvas { position: relative; z-index: 2; outline: none; }
.sphere-player canvas:focus-visible { box-shadow: inset 0 0 0 2px rgba(255,255,255,.8); }
.sphere-hint, .sphere-source, .sphere-loading, .sphere-controls, .sphere-settings, .sphere-transient, .sphere-error { z-index: 5; }
.sphere-controls {
  grid-template-columns: auto minmax(100px,1fr) auto auto auto auto;
  gap: 9px;
  padding: 24px 14px 12px;
}
.sphere-controls button.active { background: var(--accent); }
.sphere-settings {
  position: absolute;
  right: 14px;
  bottom: 64px;
  width: min(340px, calc(100% - 28px));
  padding: 16px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 16px;
  background: rgba(12,13,16,.96);
  box-shadow: 0 18px 60px rgba(0,0,0,.48);
  backdrop-filter: blur(16px);
  display: grid;
  gap: 14px;
}
.sphere-settings[hidden] { display: none !important; }
.sphere-settings-title { font-size: 14px; font-weight: 800; }
.sphere-settings > label { display: grid; grid-template-columns: 118px minmax(0,1fr); gap: 12px; align-items: center; color: #fff; font-size: 12px; }
.sphere-settings > label > span { color: rgba(255,255,255,.74); }
.sphere-settings input[type="range"] { width: 100% !important; display: block !important; }
.sphere-settings .sphere-quality {
  display: block !important;
  width: 100%;
  max-width: none;
  min-width: 0;
  height: 36px;
  border-radius: 10px;
}
.sphere-settings .sphere-check { grid-template-columns: auto 1fr; }
.sphere-settings .sphere-check input { width: 18px; height: 18px; }
.sphere-settings-actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.sphere-settings-actions button {
  min-height: 38px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
}
.sphere-settings-actions button:hover { background: rgba(255,255,255,.12); }
.sphere-settings-actions button.active { background: var(--accent); border-color: transparent; }
.sphere-settings-toggle { font-size: 17px; }

@media (max-width: 760px) {
  .sphere-controls { grid-template-columns: auto minmax(70px,1fr) auto auto auto; }
  .sphere-time { display: none; }
  .sphere-settings { right: 10px; bottom: 60px; width: calc(100% - 20px); }
  .sphere-settings > label { grid-template-columns: 104px minmax(0,1fr); }
  .sphere-hint { max-width: calc(100% - 110px); white-space: normal; border-radius: 12px; }
}

/* v2.7 final commercial administration */
.catalog-manager {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(320px, 1.1fr);
  gap: 16px;
  align-items: start;
}
.catalog-manager-list,
.catalog-manager-editor {
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
  padding: 12px;
}
.catalog-manager-list {
  max-height: 680px;
  overflow: auto;
}
.catalog-manager-item {
  width: 100%;
  display: grid;
  grid-template-columns: 62px minmax(0,1fr) auto 12px;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.catalog-manager-item:hover,
.catalog-manager-item.is-active {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
}
.catalog-manager-item img {
  width: 62px;
  height: 38px;
  object-fit: cover;
  border-radius: 8px;
  background: #111;
}
.catalog-manager-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.catalog-manager-copy strong,
.catalog-manager-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.catalog-manager-copy small { opacity: .55; }
.catalog-status {
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
  background: rgba(255,255,255,.08);
}
.status-published { background: rgba(64,190,120,.16); color: #aaf0c8; }
.status-draft { background: rgba(247,191,72,.16); color: #ffe0a1; }
.status-hidden { background: rgba(150,150,165,.16); color: #d2d2dc; }
.status-review { background: rgba(102,158,255,.16); color: #bdd4ff; }
.status-error { background: rgba(255,91,87,.16); color: #ffc0be; }
.health-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #777;
}
.health-dot.is-ok { background: #42d27d; box-shadow: 0 0 8px rgba(66,210,125,.5); }
.health-dot.is-error { background: #ff6863; box-shadow: 0 0 8px rgba(255,104,99,.45); }
.health-summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(255,255,255,.045);
  font-size: 13px;
  line-height: 1.35;
}
.analytics-cards {
  display: grid;
  grid-template-columns: repeat(5,minmax(100px,1fr));
  gap: 10px;
  margin: 14px 0;
}
.analytics-cards > div {
  display: grid;
  gap: 4px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.05);
}
.analytics-cards strong { font-size: 22px; }
.analytics-cards span { opacity: .65; font-size: 12px; }
.analytics-table {
  display: grid;
  gap: 8px;
}
.analytics-table > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.analytics-table span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.analytics-table strong { white-space: nowrap; font-size: 12px; }

@media (max-width: 900px) {
  .catalog-manager { grid-template-columns: 1fr; }
  .catalog-manager-list { max-height: 420px; }
  .analytics-cards { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
