:root {
  --bg: #141716;
  --panel: #1c201e;
  --line: rgba(236, 235, 231, 0.09);
  --text: #e8e7e2;
  --dim: #969b96;
  --accent: #8fb59a;
  --accent-dark: #1d2420;
  --serif: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f1ec;
    --panel: #ffffff;
    --line: rgba(20, 23, 22, 0.1);
    --text: #1b1f1d;
    --dim: #636964;
    --accent: #3f7a53;
    --accent-dark: #ffffff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

button, input { font: inherit; color: inherit; }

/* ---------- шапка ---------- */
header {
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 1400px;
  margin: 0 auto;
}
.tools { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }

.wordmark {
  font: 600 16px/1 var(--sans);
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex: 1;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  flex: none;
  font-size: 16px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--dim);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { display: block; }
.icon-btn:hover { color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

form.search { display: flex; gap: 8px; margin: 0; width: min(560px, 42vw); flex: none; }

/* Узкие экраны (iPhone SE и подобные): в одну строку не влезает,
   поэтому название и кнопки сверху, поиск во всю ширину под ними. */
@media (max-width: 720px) {
  .bar { flex-wrap: wrap; gap: 10px; }
  .wordmark { flex: 1; font-size: 15px; }
  .tools { flex: none; }
  form.search { order: 3; width: 100%; flex: auto; }
  header { padding-bottom: 12px; }
  .icon-btn { width: 40px; height: 40px; }
}
form.search .primary { padding: 9px 18px; font-size: 14px; }
form.search input {
  flex: 1;
  min-width: 0;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
form.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- библиотека ---------- */
.lib-tabs { display: flex; gap: 20px; padding: 14px 0 0; border-bottom: 1px solid var(--line); }
.lib-tabs button {
  border: 0;
  background: none;
  padding: 0 0 10px;
  margin-bottom: -1px;
  color: var(--dim);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.lib-tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.lib-add { display: flex; gap: 8px; margin: 18px 0 6px; max-width: 520px; }
.lib-add input {
  flex: 1;
  min-width: 0;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.lib-head { display: flex; align-items: baseline; gap: 12px; margin-top: 18px; }
.lib-head h2 { font: 600 15px/1.2 var(--sans); margin: 0; flex: 1; }

/* ---------- список ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 4px 16px 64px; }

/* На странице ролика колонка расширяется под плеер. */
body.watching main { max-width: min(1400px, 94vw); }
body.watching .watch-title,
body.watching .watch-meta,
body.watching .watch-desc,
body.watching .back { max-width: 76ch; }

.item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  width: 100%;
  text-align: left;
  background: none;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  -webkit-tap-highlight-color: transparent;
}
.item:hover .title { color: var(--accent); }
.item[data-seen="1"] .title { color: var(--dim); }

.item img {
  width: clamp(160px, 32vw, 336px);
  aspect-ratio: 16 / 9;
  height: auto;
  object-fit: cover;
  border-radius: 10px;
  flex: none;
  background: var(--panel);
}

.item .body { min-width: 0; flex: 1; }

.title {
  font: 500 17px/1.4 var(--sans);
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.meta { font-size: 13.5px; color: var(--dim); }
.meta .dur { font-variant-numeric: tabular-nums; }

.empty { padding: 64px 8px; text-align: center; color: var(--dim); }
.empty strong { display: block; font: 600 18px/1.3 var(--sans); color: var(--text); margin-bottom: 6px; }

.note { padding: 12px 0; color: var(--dim); font-size: 13px; }
.error { color: #e08f7f; padding: 14px 0; font-size: 14px; }

/* ---------- плеер ---------- */
/* Свет живёт в сцене вокруг кадра, а не под ним: иначе его целиком
   закрывает сам плеер. */
.player-stage { position: relative; margin: 0 -16px; }
@media (min-width: 760px) {
  .player-stage { margin: 0; padding: 56px 70px; }
}

/* Без подложки: плеер закрывает контейнер сам, а чёрный фон только
   перекрывал бы свет по краям кадра. */
.player-wrap { background: transparent; position: relative; z-index: 1; }

/* Живой свет вокруг кадра. Доступа к пикселям видео у встраиваемого плеера
   нет, поэтому свет собственный: несколько блёклых пятен с разными
   периодами — вместе они не повторяются на глаз. */
.glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.9;
}
.glow span {
  position: absolute;
  border-radius: 50%;
}
/* Пятна держатся у краёв: середину закрывает сам кадр, и свет оттуда не виден. */
.glow span:nth-child(1) {
  inset: 2% 52% 30% 2%;
  background: radial-gradient(circle, rgba(232, 235, 238, 0.85), transparent 70%);
  animation: drift1 13s ease-in-out infinite;
}
.glow span:nth-child(2) {
  inset: 24% 2% 2% 48%;
  background: radial-gradient(circle, rgba(205, 213, 216, 0.75), transparent 70%);
  animation: drift2 19s ease-in-out infinite;
}
.glow span:nth-child(3) {
  inset: 62% 26% 0% 26%;
  background: radial-gradient(circle, rgba(176, 192, 184, 0.6), transparent 70%);
  animation: drift3 29s ease-in-out infinite;
}
@keyframes drift1 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.75; }
  35% { transform: translate3d(5%, -4%, 0) scale(1.18); opacity: 1; }
  70% { transform: translate3d(-4%, 3%, 0) scale(0.92); opacity: 0.55; }
}
@keyframes drift2 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1.06); opacity: 0.6; }
  40% { transform: translate3d(-6%, 4%, 0) scale(0.88); opacity: 1; }
  75% { transform: translate3d(4%, -5%, 0) scale(1.2); opacity: 0.7; }
}
@keyframes drift3 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(0.95); opacity: 0.45; }
  45% { transform: translate3d(6%, 5%, 0) scale(1.24); opacity: 0.9; }
  80% { transform: translate3d(-5%, -3%, 0) scale(1); opacity: 0.5; }
}

.player-box { z-index: 1; }
@media (min-width: 760px) {
  .player-wrap { border-radius: 12px; overflow: hidden; }
}
.player-box { position: relative; width: 100%; aspect-ratio: 16 / 9; }
.player-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.watch-title { font: 600 20px/1.3 var(--sans); margin: 16px 0 6px; }
.watch-meta { color: var(--dim); font-size: 14px; }
.desc-toggle {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  color: var(--dim);
  padding: 8px 14px;
  font-size: 13.5px;
}
.desc-toggle:hover { color: var(--text); }

.watch-desc {
  margin-top: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--dim);
  font-size: 14px;
  line-height: 1.6;
  max-width: 62ch;
}

.back {
  border: 0;
  background: none;
  color: var(--dim);
  padding: 14px 0;
}
.back:hover { color: var(--text); }

/* ---------- пауза ---------- */
#break {
  position: absolute;
  z-index: 5;
  top: 14px;
  right: 14px;
  left: 14px;
  max-width: 300px;
  margin-left: auto;
  padding: 14px 16px 16px;
  border-radius: 14px;
  background: rgba(20, 23, 22, 0.95);
  border: 1px solid rgba(236, 235, 231, 0.12);
  color: #e8e7e2;
}
#break p { margin: 0 0 12px; font-size: 13px; color: #b4b8b3; }
#break strong { display: block; font-size: 15px; color: #e8e7e2; margin-bottom: 4px; }

.primary {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
}

/* ---------- панели ---------- */
dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: 100%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.sheet {
  width: min(440px, 100vw);
  background: var(--panel);
  border-radius: 16px;
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
}
.sheet h2 { font: 600 17px/1.2 var(--sans); margin: 0 0 4px; }
.sheet .hint { color: var(--dim); font-size: 13px; margin: 0 0 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--dim); }
.field input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.row span { flex: 1; }
.row small { display: block; color: var(--dim); font-size: 12px; }

.switch {
  width: 46px;
  height: 28px;
  flex: none;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f4f3ef;
  transition: transform 0.18s ease;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 34px; height: 30px; border: 0; border-radius: 8px; background: var(--bg); }
.stepper output { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

.chan { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.chan img { width: 28px; height: 28px; border-radius: 50%; flex: none; }
.chan span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chan button { border: 0; background: none; color: var(--dim); padding: 4px 6px; }
.chan button:hover { color: #e08f7f; }

.sheet .primary { width: 100%; margin-top: 16px; padding: 12px; }
.quota { margin-top: 12px; font-size: 12px; color: var(--dim); text-align: center; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .glow span { animation: none !important; }
}
