/* HomeMedia — цвета берутся из темы Telegram, с запасными значениями для браузера */
:root {
  --bg: var(--tg-theme-bg-color, #0f1012);
  --bg2: var(--tg-theme-secondary-bg-color, #1a1b1f);
  --card: var(--tg-theme-section-bg-color, #1f2025);
  --text: var(--tg-theme-text-color, #f2f2f4);
  --hint: var(--tg-theme-hint-color, #8e8f96);
  --accent: var(--tg-theme-button-color, #3d8bfd);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, #5aa2ff);
  --danger: var(--tg-theme-destructive-text-color, #ff5a5f);
  --ok: #34c77b;
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --radius: 14px;
  --tabs-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root:not(.tg) { --bg:#f4f4f7; --bg2:#fff; --card:#fff; --text:#16171a; --hint:#6e6f76; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
.hint, small { color: var(--hint); }
.boot { padding: 40vh 0; text-align: center; color: var(--hint); }

#view { padding: 0 0 calc(var(--tabs-h) + var(--safe-b) + 16px); min-height: 100vh; }
.page { padding: 12px 16px 0; }
.page-title { font-size: 26px; font-weight: 700; margin: 8px 0 14px; letter-spacing: -0.02em; }
h2.sec { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 16px; margin: 22px 0 10px; gap: 12px; }
.sec-head a { color: var(--link); font-size: 14px; white-space: nowrap; }

/* ---------- Нижняя панель ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg2) 88%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--hint); font-size: 11px; }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#tabs a.on { color: var(--accent); }
#tabs a.on svg { fill: color-mix(in srgb, var(--accent) 22%, transparent); }
body.immersive #tabs { display: none; }
body.immersive #view { padding-bottom: 0; }

/* ---------- Полки и постеры ---------- */
.rail { display: flex; gap: 10px; overflow-x: auto; padding: 0 16px 4px; scroll-padding-inline: 16px; scroll-snap-type: x proximity; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; flex: 0 0 auto; }
.poster { width: 118px; }
.poster .img { width: 118px; aspect-ratio: 2/3; border-radius: 10px; background: var(--bg2) center/cover no-repeat; position: relative; overflow: hidden; }
.poster .img.noimg { display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; font-size: 13px; color: var(--hint); }
.poster .t { font-size: 13px; font-weight: 600; margin-top: 6px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.poster .s { font-size: 12px; color: var(--hint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-r { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.66); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.badge-r.top { left: auto; right: 6px; background: var(--accent); color: var(--accent-text); }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.18); }
.bar i { display: block; height: 100%; background: var(--accent); }
.wide { width: 240px; }
.wide .img { width: 240px; aspect-ratio: 16/9; border-radius: 10px; background: var(--bg2) center/cover no-repeat; position: relative; overflow: hidden; }
.wide .play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.wide .play span { width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; }
.wide .play svg { width: 18px; height: 18px; fill: #fff; margin-left: 3px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; padding: 0 16px; }
.grid .poster, .grid .poster .img { width: 100%; }

/* ---------- Кнопки, чипы, поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 16px; border-radius: 12px; border: 0; background: var(--bg2); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 2px; scroll-padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding: 0; }
.chip { flex: 0 0 auto; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: transparent; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.seg { display: flex; background: var(--bg2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 34px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--hint); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 5px 2px; }
.input, select.input, textarea.input { width: 100%; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); outline: none; }
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); }
.search { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 16px; }
.search .input { padding-left: 38px; background: var(--bg2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8f96' stroke-width='2'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m20 20-4.5-4.5'/%3E%3C/svg%3E") 11px center/18px no-repeat; }

/* ---------- Списки-строки ---------- */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 50px; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { font-size: 13px; color: var(--hint); margin-top: 2px; overflow-wrap: anywhere; }
.row .chev { color: var(--hint); }
.row.link { cursor: pointer; }
.list-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 4px 6px; }
.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 15px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--bg2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 16px; }
.icon-btn[disabled] { opacity: .3; }

/* ---------- Метки раздач ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--bg2); color: var(--hint); }
.tag.q { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.tag.v { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.h { background: rgba(255, 184, 0, .18); color: #e5a500; }

/* ---------- Карточка фильма ---------- */
.hero { position: relative; min-height: 270px; background: var(--bg2) center/cover no-repeat; display: flex; align-items: flex-end; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.05) 0%, color-mix(in srgb, var(--bg) 55%, transparent) 55%, var(--bg) 100%); }
.hero-in { position: relative; z-index: 1; display: flex; gap: 14px; padding: 16px; align-items: flex-end; width: 100%; }
.hero-in .p { width: 96px; flex: 0 0 96px; aspect-ratio: 2/3; border-radius: 10px; background: var(--bg2) center/cover; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.hero-in h1 { font-size: 23px; line-height: 1.15; margin: 0 0 4px; letter-spacing: -0.02em; }
.meta { font-size: 13px; color: var(--hint); }
.rating { color: #f5c518; font-weight: 700; }
.overview { padding: 0 16px; margin: 6px 0 14px; color: color-mix(in srgb, var(--text) 85%, transparent); }
.overview.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.actions { padding: 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn { height: 46px; }
.actions .full { grid-column: 1 / -1; }
.ep { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.ep:last-child { border-bottom: 0; }
.ep .num { width: 30px; text-align: center; font-weight: 700; color: var(--hint); }
.ep.done .num { color: var(--ok); }
.ep .grow { flex: 1; min-width: 0; }
.ep .t1 { font-weight: 600; }
.ep .t2 { font-size: 12px; color: var(--hint); }
.person { width: 76px; text-align: center; font-size: 12px; }
.person .ph { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 4px; background: var(--bg2) center/cover; }

.release { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.release .t1 { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.release .t2 { font-size: 12px; color: var(--hint); margin-top: 4px; }
.release .btns { margin-top: 10px; }

/* ---------- Плеер ---------- */
.player { background: #000; position: sticky; top: 0; z-index: 6; }
.player video { width: 100%; max-height: 62vh; display: block; background: #000; }

/* ---------- Нижний лист и уведомления ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .15s; }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); animation: up .2s ease-out; }
.sheet-body::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-title { font-size: 18px; font-weight: 700; margin: 0 0 12px; }
.sheet-opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; border: 0; border-radius: 12px; background: var(--card); margin-bottom: 8px; text-align: left; cursor: pointer; font-weight: 600; }
.sheet-opt small { display: block; font-weight: 400; margin-top: 2px; }
.sheet-opt .ico { font-size: 20px; width: 26px; text-align: center; }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + var(--safe-b) + 12px); z-index: 60; background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; text-align: center; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

.empty { text-align: center; color: var(--hint); padding: 40px 24px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.notice { margin: 12px 16px; padding: 12px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 14%, transparent); font-size: 14px; }
.notice.warn { background: rgba(255, 184, 0, .14); }
.skeleton { background: linear-gradient(90deg, var(--bg2), color-mix(in srgb, var(--bg2) 70%, var(--text) 6%), var(--bg2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; }
@keyframes sk { to { background-position: -200% 0; } }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.ok-t { color: var(--ok); } .bad-t { color: var(--danger); }

/* ---------- Отметки на карточках (полупрозрачные) ---------- */
.marks { position: absolute; top: 6px; right: 6px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.mk { min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff;
  background: rgba(0, 0, 0, .42); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, .14); }
.mk.w { background: rgba(52, 199, 123, .55); }
.mk.l { background: rgba(61, 139, 253, .5); }
.mk.v { opacity: .75; }
.poster.seen .t { color: color-mix(in srgb, var(--text) 75%, transparent); }

/* ---------- Сиды / пиры ---------- */
.health { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.health i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--danger); }
.health.mid i { background: #e5a500; }
.health.good i { background: var(--ok); }

/* ---------- Панель справа (другие раздачи) ---------- */
#panel { position: fixed; inset: 0; z-index: 55; }
#panel .sheet-bg { animation: fade .15s; }
.panel-body { position: absolute; top: 0; right: 0; bottom: 0; width: min(92vw, 440px); background: var(--bg); overflow-y: auto; padding: 14px 14px calc(20px + var(--safe-b)); animation: left .22s ease-out; box-shadow: -8px 0 30px rgba(0,0,0,.4); }
@keyframes left { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.edge-hint { position: fixed; right: 0; top: 45%; width: 6px; height: 64px; border-radius: 4px 0 0 4px; background: color-mix(in srgb, var(--accent) 55%, transparent); z-index: 7; opacity: .7; }

/* ---------- Красные точки ---------- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); margin-left: 6px; vertical-align: middle; }
#tabs a { position: relative; }
#tabs a.has-dot::after { content: ""; position: absolute; top: 7px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bg2); }

/* ---------- Библиотека: список и свайп ---------- */
.tools { display: flex; gap: 8px; align-items: center; padding: 0 16px; margin-top: 10px; }
.tools .chips { padding: 0; flex: 1; }
select.chip { appearance: none; -webkit-appearance: none; background: transparent; padding-right: 12px; }
select.chip.on { background: var(--accent); color: var(--accent-text); }
.swipe { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.swipe:last-child { border-bottom: 0; }
.swipe .del { position: absolute; top: 0; right: 0; bottom: 0; width: 96px; background: var(--danger); color: #fff; border: 0; font-weight: 700; }
.swipe .row { background: var(--card); border-bottom: 0; transition: transform .2s; position: relative; z-index: 1; }
.swipe .row .th { width: 46px; height: 68px; border-radius: 8px; background: var(--bg2) center/cover; flex: 0 0 46px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--card); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 18px; }
.stat small { font-size: 12px; }
#tabs[hidden] { display: none; }

/* ---------- Встроенный плеер ---------- */
.vp { position: sticky; top: 0; z-index: 6; background: #000; aspect-ratio: 16 / 9; max-height: 62vh; width: 100%; overflow: hidden; user-select: none; -webkit-user-select: none; }
.vp video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.vp.full { position: fixed; inset: 0; z-index: 50; aspect-ratio: auto; max-height: none; height: 100vh; height: 100dvh; }
body.vp-lock { overflow: hidden; }
.vp-sub { position: absolute; left: 4%; right: 4%; bottom: 7%; text-align: center; pointer-events: none; z-index: 2; transition: bottom .2s; }
.vp-ui.show ~ .vp-sub, .vp:has(.vp-ui.show) .vp-sub { bottom: 26%; }
.vp-sub span { display: inline; background: rgba(0,0,0,.55); color: #fff; font-size: clamp(14px, 3.6vw, 26px); line-height: 1.35; padding: 2px 8px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone; text-shadow: 0 1px 2px #000; }
.vp.big-subs .vp-sub span { font-size: clamp(18px, 5vw, 36px); }
.vp-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #fff; font-size: 14px; text-align: center; padding: 20px; z-index: 3; pointer-events: none; background: rgba(0,0,0,.35); }
.vp-msg[hidden] { display: none; }
.vp-spin { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: vpspin 0.9s linear infinite; }
@keyframes vpspin { to { transform: rotate(360deg); } }
.vp-ui { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; justify-content: space-between; opacity: 0; transition: opacity .2s; background: linear-gradient(rgba(0,0,0,.55), transparent 28%, transparent 62%, rgba(0,0,0,.7)); }
.vp-ui.show { opacity: 1; }
.vp-ui:not(.show) * { pointer-events: none; }
.vp-top { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); color: #fff; }
.vp-ttl { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vp-mid { display: flex; align-items: center; justify-content: center; gap: 36px; }
.vp-bot { padding: 0 10px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.vp-line { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.vp-line input { flex: 1; accent-color: #fff; height: 28px; }
.vp-row { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.vp-b { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 18px; height: 34px; min-width: 34px; padding: 0 10px; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.vp-b[hidden] { display: none; }
.vp-b.on { background: rgba(255,255,255,.85); color: #000; }
.vp-b.big { width: 50px; height: 50px; border-radius: 50%; font-size: 22px; position: relative; padding: 0; }
.vp-b.big small { position: absolute; font-size: 9px; font-weight: 700; }
.vp-b.huge { width: 66px; height: 66px; border-radius: 50%; font-size: 26px; padding: 0; }
@media (max-width: 380px) { .vp-b span { display: none; } }
