/* Аниме-календарь: тёмная тема по умолчанию (в духе прототипа). Светлая включается атрибутом data-theme="light" на <html>:
   его ставит theme-init.js по сохранённому выбору или системной настройке, а кнопка в шапке переключает. */

:root {
  --gutter: clamp(16px, 3vw, 56px); /* боковые поля растут вместе с экраном */
  --bg: #14121a;
  --bg-2: #1b1923;
  --card: #1e1c26;
  --card-2: #272433;
  --text: #f5f0e6;
  --muted: #a39dac;
  --border: #302c3b;
  --primary: #f2a93b;
  --primary-rgb: 242, 169, 59;
  --on-primary: #1a1108;
  --accent: #ff3b81;
  --good: #34d399;
  --warn: #f2a93b;
  --danger: #ff5d78;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 64px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f3ee;
  --bg-2: #ece8e1;
  --card: #ffffff;
  --card-2: #f1ede6;
  --text: #231f2b;
  --muted: #6c6676;
  --border: #ddd7cd;
  --primary: #b86e00;
  --primary-rgb: 184, 110, 0;
  --on-primary: #ffffff;
  --accent: #d11d64;
  --good: #0f8a5f;
  --warn: #a35f00;
  --danger: #c9304c;
  --shadow: 0 10px 30px rgba(40, 30, 10, 0.12);
  color-scheme: light;
}

/* Тонкие полосы прокрутки. WebKit/Blink: размер задаём сами (6 px вместо ~15 px системных); Firefox: стандартные свойства. */
:root {
  --scroll-thumb: color-mix(in srgb, var(--muted) 45%, transparent);
  --scroll-thumb-hover: color-mix(in srgb, var(--muted) 75%, transparent);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border: 2px solid transparent; border-radius: 999px; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
@supports (-moz-appearance: none) {
  * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: var(--on-primary); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.demo-banner { background: var(--accent); color: #fff; text-align: center; padding: 6px 12px; font-size: 13px; font-weight: 600; }

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

.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: none; margin: 0 auto; padding: 10px var(--gutter); display: flex; align-items: center; gap: 18px; min-height: var(--topbar-h); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; text-decoration: none; color: var(--primary); white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; padding: 8px 12px; border-radius: 999px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--card); }
.nav a[aria-current="page"] { color: var(--on-primary); background: var(--primary); }
.nav-badge, .nav-count { font-size: 12px; font-weight: 800; border-radius: 999px; padding: 0 7px; line-height: 18px; min-width: 18px; text-align: center; }
.nav-badge { background: var(--accent); color: #fff; }
.nav-count { background: color-mix(in srgb, currentColor 18%, transparent); }
.nav-count:empty { display: none; }

.theme-toggle { flex: none; cursor: pointer; color: var(--text); }
.theme-toggle svg { display: block; }
.sync-btn { flex: none; position: relative; cursor: pointer; color: var(--muted); }
.sync-btn[hidden] { display: none; }
.sync-btn svg { display: block; }
.sync-btn .sync-tick { opacity: 0; }
.sync-btn[data-state="idle"] { color: var(--good); }
.sync-btn[data-state="idle"] .sync-tick { opacity: 1; }
.sync-btn[data-state="syncing"] { color: var(--primary); }
.sync-btn[data-state="syncing"] svg { animation: sync-pulse 1.1s ease-in-out infinite; }
.sync-btn[data-state="needs-login"], .sync-btn[data-state="error"] { color: var(--warn); }
.sync-btn[data-state="needs-login"]::after, .sync-btn[data-state="error"]::after { content: ""; position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
@keyframes sync-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
:root[data-theme="light"] .theme-toggle .icon-sun, :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }

.search { position: relative; margin-left: auto; width: min(340px, 100%); }
.search > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding: 9px 14px 9px 36px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); }
.search input::placeholder { color: var(--muted); }
.search-panel { position: absolute; right: 0; top: calc(100% + 8px); width: min(440px, calc(100vw - 32px)); max-height: 70vh; overflow: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.sug { display: flex; align-items: center; gap: 6px; border-radius: var(--radius-sm); }
.sug:hover, .sug:focus-within { background: var(--card-2); }
.sug-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; text-decoration: none; }
.sug-text { display: flex; flex-direction: column; min-width: 0; }
.sug-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-meta { font-size: 12px; color: var(--muted); }
.sug-note { padding: 12px; color: var(--muted); font-size: 14px; }
.sug-all { display: block; padding: 10px 12px; text-align: center; font-weight: 700; color: var(--primary); text-decoration: none; border-top: 1px solid var(--border); margin-top: 4px; }

@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px 12px; }
  .search { order: 3; width: 100%; margin-left: 0; }
  .nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav a { padding: 7px 10px; font-size: 14px; }
  .brand span { display: none; }
}

/* --- общая раскладка ---------------------------------------------------------- */

.container { max-width: none; width: 100%; margin: 0 auto; padding: 22px var(--gutter) 60px; flex: 1; outline: none; }
.page-title { font-size: clamp(24px, 4vw, 34px); font-weight: 800; letter-spacing: -0.01em; margin-bottom: 14px; }
.lead { color: var(--muted); margin-bottom: 16px; max-width: 70ch; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--card-2); }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, white); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 14%, var(--card)); border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--danger) 88%, black); }

.loading, .empty, .notice, .error-box { padding: 28px 16px; border-radius: var(--radius); text-align: center; color: var(--muted); }
.empty { border: 1px dashed var(--border); }
.empty-hero { padding: 48px 20px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty-hero h2 { color: var(--text); font-size: 20px; }
.empty-hero p { max-width: 56ch; }
.notice { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); padding: 12px 16px; margin-bottom: 16px; text-align: left; }
.error-box { border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--text); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.loading::before { content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 10px; vertical-align: -3px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- сезоны и фильтры ----------------------------------------------------------- */

.season-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 16px; }
.year-nav { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--card); border: 1px solid var(--border); text-decoration: none; font-size: 22px; line-height: 1; }
.icon-btn:hover { background: var(--card-2); }
.icon-btn.is-disabled { opacity: 0.35; }
.year-select { padding: 7px 36px 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-weight: 700; appearance: none; cursor: pointer; }
.year-select option { background: var(--card); color: var(--text); }

/* Поле выбора: стрелку рисует CSS, поэтому она одного размера и цвета везде и подстраивается под тему. */
.select-field { position: relative; display: inline-flex; align-items: center; }
.select-field::after { content: ""; position: absolute; right: 15px; top: 50%; width: 6px; height: 6px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-75%) rotate(45deg); pointer-events: none; transition: border-color 0.18s ease; }
.select-field:hover::after, .select-field:focus-within::after { border-color: var(--primary); }
.year-select:focus { outline: none; }
.year-select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Chromium с настраиваемым <select>: оформляем и сам выпадающий список; в остальных браузерах он системный. */
@supports (appearance: base-select) {
  .select-field select, .select-field select::picker(select) { appearance: base-select; }
  .select-field select::picker-icon { display: none; }
  .select-field select::picker(select) { margin-top: 6px; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); color: var(--text); box-shadow: var(--shadow); }
  .select-field option { padding: 8px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; }
  .select-field option:hover, .select-field option:focus-visible { background: var(--card-2); outline: none; }
  .select-field option:checked { color: var(--primary); font-weight: 800; }
  .select-field option::checkmark { display: none; }
}
.season-tabs { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 999px; }
.season-tab { position: relative; text-decoration: none; padding: 7px 16px; border-radius: 999px; font-weight: 700; color: var(--muted); }
.season-tab:hover { color: var(--text); }
.season-tab[aria-current="page"] { background: var(--primary); color: var(--on-primary); }
.now-dot { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--good); vertical-align: middle; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 14px; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.inline-filter { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); min-width: 240px; flex: 1 1 240px; max-width: 360px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; cursor: pointer; font-weight: 600; font-size: 14px; }
.filter-chip:hover { background: var(--card); }
.filter-chip[aria-pressed="true"] { background: rgba(var(--primary-rgb), 0.18); border-color: var(--primary); color: var(--primary); }
.result-count { color: var(--muted); margin-bottom: 8px; font-size: 14px; }

/* группа-франшиза: свёрнутая шапка, внутри сезоны, фильмы и OVA */
.group { grid-column: 1 / -1; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.group + .group, .day-title + .group { margin-top: 10px; }
.group-head { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 16px 10px 10px; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.group-head:hover, .group-head:focus-visible { background: var(--card-2); }
.group-text { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 2px; }
.group-title { font-weight: 800; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-meta { font-size: 13px; color: var(--muted); }
.group-chevron { margin-left: auto; }
.group.is-open > .group-head .group-chevron { transform: translateY(2px) rotate(225deg); border-color: var(--primary); }
.group.is-open > .group-head { border-bottom: 1px solid var(--border); }
.group-body { padding: 14px; }
.group-body[hidden] { display: none; }
.group.is-opening .group-body { animation: fade-up 0.3s cubic-bezier(0.2, 0.7, 0.2, 1); }
.group.is-opening .group-body .tcard { animation: card-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.group.is-opening .group-body .tcard:nth-child(2) { animation-delay: 35ms; }
.group.is-opening .group-body .tcard:nth-child(3) { animation-delay: 70ms; }
.group.is-opening .group-body .tcard:nth-child(n + 4) { animation-delay: 105ms; }

/* то же в выпадающих подсказках поиска */
.group-compact { grid-column: auto; margin-bottom: 4px; background: var(--card-2); border-color: transparent; }
.group-compact .group-head { gap: 10px; padding: 6px 12px 6px 6px; }
.group-compact .group-title { font-size: 15px; }
.group-compact .group-body { padding: 4px; }
.group-compact .sug:hover, .group-compact .sug:focus-within { background: var(--card); }
.group-compact.is-open > .group-head { border-bottom: 1px solid var(--border); }
.sug-heading { padding: 8px 10px 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

.day-group { margin-bottom: 26px; }
.day-title { font-size: 17px; font-weight: 800; margin: 18px 0 10px; display: flex; align-items: center; gap: 10px; scroll-margin-top: calc(var(--topbar-h) + 10px); }
.day-group.is-past .day-title { color: var(--muted); }
.day-group.is-today .day-title { color: var(--primary); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(168px, 11vw, 240px), 1fr)); gap: 16px 14px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 14px 10px; } }

/* --- карточка тайтла -------------------------------------------------------------- */

.tcard { position: relative; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: transform 0.18s ease, box-shadow 0.18s ease; }
.tcard:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tcard.is-watched { border-color: color-mix(in srgb, var(--good) 55%, var(--border)); }
.tcard.is-watched .cover img, .tcard.is-watched .cover .ph { opacity: 0.55; }
.cover-link { display: block; position: relative; text-decoration: none; }
.cover { --c: #4a4560; display: block; position: relative; overflow: hidden; background: linear-gradient(160deg, color-mix(in srgb, var(--c) 80%, #000), color-mix(in srgb, var(--c) 40%, #000)); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.tcard .cover { aspect-ratio: 2 / 3; }
.cover .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 44px; font-weight: 800; color: rgba(255, 255, 255, 0.85); }
.cover-sm { width: 44px; height: 62px; border-radius: 8px; flex: none; }
.cover-xs { width: 34px; height: 48px; border-radius: 6px; flex: none; }
.cover-sm .ph, .cover-xs .ph { font-size: 18px; }
.cover-lg { width: 150px; aspect-ratio: 2 / 3; border-radius: var(--radius-sm); flex: none; }
.cover-badges { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }

.chip { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.cover-badges .chip { background: rgba(10, 8, 16, 0.78); color: #fff; border-color: transparent; backdrop-filter: blur(4px); }
.status-releasing { color: var(--good) !important; }
.cover-badges .status-releasing { color: #6ee7b7 !important; }
.status-not_yet_released { color: var(--warn); }
.cover-badges .status-not_yet_released { color: #ffd08a; }
.chip-new { background: var(--accent) !important; color: #fff !important; }
.chip-today { background: var(--primary); color: var(--on-primary); border-color: transparent; text-transform: none; }

.watch-btn { cursor: pointer; border: 1px solid var(--border); background: var(--card-2); display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; }
.watch-btn .icon { display: inline-flex; }
.watch-icon { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 50%; background: rgba(10, 8, 16, 0.72); color: #fff; border-color: transparent; backdrop-filter: blur(4px); }
.watch-icon:hover { background: rgba(10, 8, 16, 0.92); }
.watch-icon[aria-pressed="true"] { background: var(--good); color: #05261a; }
.watch-text { padding: 9px 16px; border-radius: 999px; margin-top: 4px; align-self: flex-start; }
.watch-text[aria-pressed="true"] { background: var(--good); color: #05261a; border-color: transparent; }
.rel-row .watch-icon { position: static; flex: none; background: var(--card-2); color: var(--text); border-color: var(--border); }
.rel-row .watch-icon[aria-pressed="true"] { background: var(--good); color: #05261a; }
.sug .watch-icon { position: static; flex: none; margin-right: 4px; background: var(--card-2); color: var(--text); border-color: var(--border); }
.sug .watch-icon[aria-pressed="true"] { background: var(--good); color: #05261a; }

.tcard-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.tcard-title { font-size: 14.5px; font-weight: 800; line-height: 1.3; }
.tcard-title a { text-decoration: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tcard-title a:hover { color: var(--primary); }
.tcard-title a::after { content: ""; position: absolute; inset: 0; z-index: 1; } /* вся карточка кликабельна */
.watch-icon { z-index: 2; }
.tcard-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard-meta { font-size: 12.5px; color: var(--muted); }
.tcard-next { font-size: 12.5px; color: var(--good); font-weight: 700; }
.tcard-rel { font-size: 12.5px; color: var(--primary); }
.tcard-genres { font-size: 12px; color: var(--muted); margin-top: auto; padding-top: 4px; }

/* --- окно тайтла ------------------------------------------------------------------- */

/* Выпадающий список (сортировка в «Просмотрено»): плавное появление, стрелка переворачивается при открытии. */
.dropdown { position: relative; display: inline-block; }
.dropdown-trigger, .dropdown-option { user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.dropdown-trigger { display: inline-flex; align-items: center; gap: 10px; padding: 7px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; transition: border-color 0.18s ease; }
.dropdown-trigger:hover, .dropdown.is-open .dropdown-trigger { border-color: var(--primary); }
.dropdown-trigger:focus, .dropdown-option:focus { outline: none; } /* кольцо только при навигации с клавиатуры */
.dropdown-trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dropdown-value { display: grid; text-align: left; }
.dropdown-value > span { grid-area: 1 / 1; visibility: hidden; white-space: nowrap; }
.dropdown-value > span.is-current { visibility: visible; }
.dropdown-chevron { flex: none; width: 6px; height: 6px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); transition: transform 0.2s ease, border-color 0.18s ease; }
.dropdown.is-open .dropdown-chevron { transform: translateY(2px) rotate(225deg); border-color: var(--primary); }
.dropdown-menu { position: absolute; left: 0; top: calc(100% + 6px); z-index: 15; min-width: 100%; margin: 0; padding: 4px; list-style: none; background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(-6px) scale(0.98); transform-origin: top left; transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s; }
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s; }
.dropdown-option { padding: 8px 12px; border-radius: 10px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.dropdown-option:hover { background: var(--card-2); }
.dropdown-option:focus-visible { background: var(--card-2); box-shadow: inset 0 0 0 2px var(--primary); }
.dropdown-option[aria-selected="true"] { color: var(--primary); font-weight: 800; }

dialog { color: var(--text); background: var(--bg-2); border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow); overflow: auto; }
dialog::backdrop { background: rgba(6, 5, 10, 0.72); backdrop-filter: blur(3px); }
/* Пока открыто окно, страница под ним не прокручивается; gutter не даёт ей «прыгнуть» при скрытии полосы прокрутки. */
html:has(dialog[open]) { overflow: hidden; scrollbar-gutter: stable; }
dialog { overscroll-behavior: contain; }
.dialog-body { padding: 24px; }
.dialog-close { position: sticky; top: 10px; float: right; margin: 10px 10px 0 0; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--card); cursor: pointer; z-index: 2; }
.dialog-head { display: flex; gap: 20px; margin-bottom: 18px; }
.dialog-info { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dialog-info h2, .error-box h2 { font-size: clamp(20px, 3.4vw, 26px); font-weight: 800; line-height: 1.2; }
.dialog-sub { color: var(--muted); font-size: 14px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 20px; margin: 0 0 18px; padding: 14px 16px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); }
.fact dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.fact dd { margin: 0; font-weight: 700; }
.dialog-section { margin-top: 18px; }
.dialog-section h3 { font-size: 16px; margin-bottom: 8px; }
.description { white-space: pre-line; max-width: 66ch; }
.rel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rel-group + .rel-group { margin-top: 14px; }
.rel-group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.rel-row { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: var(--radius-sm); border: 1px solid transparent; }
.rel-row:hover { background: var(--card); }
.rel-row.is-watched { border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.rel-link { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; text-decoration: none; }
.rel-text { display: flex; flex-direction: column; min-width: 0; }
.rel-kind { font-size: 12px; color: var(--primary); font-weight: 700; }
.rel-title { font-weight: 700; }
.rel-meta { font-size: 12.5px; color: var(--muted); }

@media (max-width: 560px) {
  .dialog-body { padding: 16px; }
  .dialog-head { flex-direction: column; }
  .cover-lg { width: 120px; }
}

/* --- уведомления --------------------------------------------------------------------- */

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: min(420px, calc(100vw - 24px)); }
.toast { background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow); font-weight: 600; text-align: center; }
.toast-accent { color: var(--primary); font-size: 16px; font-weight: 700; }
.toast-error { border-color: var(--danger); }
.toast-hint { display: block; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--primary); font-size: 16px; font-weight: 700; }

/* Окно подтверждения (очистка списка просмотренного и т. п.) */
.confirm-dialog { width: min(420px, calc(100vw - 24px)); }
.confirm-dialog.is-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.confirm-body { padding: 26px 24px 22px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.confirm-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 800; background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.is-danger .confirm-icon { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.confirm-body h2 { font-size: 20px; font-weight: 800; line-height: 1.25; }
.confirm-text { color: var(--muted); font-size: 14px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; margin-top: 8px; width: 100%; }
.confirm-actions .btn { flex: 1; }
.sync-icon.is-idle { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.sync-icon.is-needs-login, .sync-icon.is-error { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.sync-dialog { width: min(460px, calc(100vw - 24px)); }
.sync-dialog .confirm-actions .btn { white-space: nowrap; }
.sync-dialog .dialog-close { position: absolute; top: 10px; right: 10px; float: none; margin: 0; }
.sync-warn { color: var(--warn); font-weight: 700; }
.sync-facts { display: flex; flex-direction: column; gap: 2px; }
.sync-off { width: 100%; }
.confirm-actions .btn[disabled], .sync-off[disabled] { opacity: 0.5; pointer-events: none; }
.tcard-imported { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ignored-link[hidden] { display: none; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); font-weight: 700; text-decoration: none; }
.back-link:hover { color: var(--text); }
.dialog-menu { position: sticky; top: 10px; float: right; margin: 10px 8px 0 0; z-index: 3; }
.dialog-menu-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: inherit; font-size: 20px; line-height: 1; cursor: pointer; }
.dialog-menu-btn:hover { background: var(--card-2); }
.dialog-menu-list { position: absolute; top: 42px; right: 0; width: max-content; padding: 6px; display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.dialog-menu-list[hidden] { display: none; }
.dialog-menu-item { padding: 9px 12px; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; font-weight: 700; text-align: left; white-space: nowrap; cursor: pointer; }
.dialog-menu-item:hover, .dialog-menu-item:focus-visible { background: var(--card-2); }
.dialog-menu-item.is-danger { color: var(--danger); }
.list-menu { position: relative; }
.list-menu .btn[aria-expanded="true"] .dropdown-chevron { transform: translateY(2px) rotate(225deg); border-color: var(--primary); }
.list-menu-list { position: absolute; top: calc(100% + 6px); left: 0; z-index: 5; width: max-content; padding: 6px; display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.list-menu-list[hidden] { display: none; }
.replace-dialog { width: min(520px, calc(100vw - 24px)); }
.pick-body { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.pick-body h2 { font-size: 20px; font-weight: 800; line-height: 1.25; }
.pick-input { width: 100%; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit; }
.pick-input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: min(52vh, 420px); overflow-y: auto; }
.pick-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.pick-row:hover, .pick-row:focus-visible { background: var(--card-2); }
@media (max-width: 420px) { .confirm-actions { flex-direction: column-reverse; } }

/* --- анимации -------------------------------------------------------------------------
   Отключаются целиком при prefers-reduced-motion (правило выше). Появление страницы и карточек
   включается атрибутом html[data-enter] только на момент перехода (см. main.js), чтобы перерисовка
   списка при вводе в фильтр не запускала анимацию заново. */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(12px) scale(0.985); } }
@keyframes chip-pop { 0% { transform: scale(0.9); } 60% { transform: scale(1.07); } 100% { transform: none; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes card-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes panel-in { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.97); } }
@keyframes badge-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 129, 0.55); } 60% { box-shadow: 0 0 0 7px rgba(255, 59, 129, 0); } }

/* плавные состояния у всех интерактивных элементов */
.btn, .icon-btn, .filter-chip, .nav a, .season-tab, .watch-btn, .sug, .rel-row, .dialog-close, .dialog-menu-btn, .year-select, .inline-filter, .search input, .tcard-title a {
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease, opacity 0.18s ease;
}
.btn:active, .icon-btn:active, .filter-chip:active, .watch-btn:active, .dialog-close:active, .dialog-menu-btn:active { transform: scale(0.95); }
.btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.inline-filter:focus, .search input:focus, .year-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18); }
.nav a:hover, .season-tab:hover { transform: translateY(-1px); }

/* карточки */
.tcard { transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.22s ease, border-color 0.2s ease; }
.cover img { transition: transform 0.4s ease, opacity 0.25s ease; }
.tcard:hover .cover img { transform: scale(1.05); }
.tcard:active { transform: translateY(-1px) scale(0.99); }

/* окна, выпадающие панели, уведомления */
dialog[open]:not(.is-closing) { animation: dialog-in 0.24s cubic-bezier(0.2, 0.7, 0.2, 1); }
dialog[open]:not(.is-closing)::backdrop { animation: fade-in 0.22s ease-out; }
dialog.is-closing { animation: dialog-out 0.2s cubic-bezier(0.4, 0, 1, 1) forwards; }
dialog.is-closing::backdrop { animation: fade-out 0.2s ease-in forwards; }
.search-panel { transform-origin: top right; animation: panel-in 0.16s ease-out; }
.toast { animation: toast-in 0.25s cubic-bezier(0.2, 0.7, 0.2, 1); }
.toast.is-leaving { animation: toast-out 0.25s ease-in forwards; }
.loading { animation: fade-in 0.3s ease 0.2s backwards; }
.nav-badge { animation: badge-pulse 2.4s ease-out infinite; }

/* появление страницы при переходе */
.page-enter { animation: fade-in 0.25s ease-out; }
html[data-enter] .container > * { animation: fade-up 0.38s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
html[data-enter] .container > :nth-child(2) { animation-delay: 50ms; }
html[data-enter] .container > :nth-child(3) { animation-delay: 100ms; }
html[data-enter] .container > :nth-child(4) { animation-delay: 150ms; }
html[data-enter] .container > :nth-child(5) { animation-delay: 200ms; }
html[data-enter] .container > :nth-child(6) { animation-delay: 250ms; }
html[data-enter] .container > :nth-child(n + 7) { animation-delay: 300ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :is(.tcard, .group) { animation: card-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(2) { animation-delay: 35ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(3) { animation-delay: 70ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(4) { animation-delay: 105ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(5) { animation-delay: 140ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(6) { animation-delay: 175ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(7) { animation-delay: 210ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(8) { animation-delay: 245ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(9) { animation-delay: 280ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(10) { animation-delay: 315ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(11) { animation-delay: 350ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(12) { animation-delay: 385ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(13) { animation-delay: 420ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(14) { animation-delay: 455ms; }
:is(html[data-enter] .grid, .is-entering .grid) > :nth-child(n + 15) { animation-delay: 490ms; }

/* переход между связанными тайтлами в окне */
.dialog-body.is-leaving { animation: fade-out 0.14s ease-in forwards; }
.dialog-body.is-entering > * { animation: fade-up 0.34s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.dialog-body.is-entering > :nth-child(2) { animation-delay: 45ms; }
.dialog-body.is-entering > :nth-child(3) { animation-delay: 90ms; }
.dialog-body.is-entering > :nth-child(4) { animation-delay: 135ms; }
.dialog-body.is-entering > :nth-child(n + 5) { animation-delay: 180ms; }

/* смена фильтра: список выезжает заново */
.is-entering .result-count, .is-entering .day-title, .is-entering .empty { animation: fade-up 0.3s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.filter-chip[aria-pressed="true"] { animation: chip-pop 0.28s ease-out; }

/* кнопки в шапке карточки тайтла */
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }
.watch-online { text-decoration: none; }

/* --- мобильная афиша: компактные настройки ------------------------------------------- */
.day-group { scroll-margin-top: calc(var(--topbar-h) + 6px); }

@media (max-width: 640px) {
  .page-title { margin-bottom: 10px; }
  .season-nav { gap: 8px; margin-bottom: 10px; }
  .year-nav { order: 1; gap: 4px; }
  .icon-btn { width: 32px; height: 32px; font-size: 20px; }
  .year-select { padding: 5px 30px 5px 10px; font-size: 14px; }
  .select-field::after { right: 12px; }
  .dropdown-trigger { padding: 5px 12px; font-size: 14px; }
  .season-nav > .btn { order: 2; margin-left: auto; padding: 6px 12px; font-size: 13px; }
  .season-tabs { order: 3; width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 3px; }
  .season-tab { padding: 8px 0; text-align: center; font-size: 13px; white-space: nowrap; }
  .now-dot { position: absolute; top: 5px; right: 7px; margin: 0; width: 6px; height: 6px; }
  .toolbar { gap: 8px; margin-bottom: 10px; }
  .inline-filter { flex: 1 1 100%; min-width: 0; max-width: none; padding: 7px 14px; font-size: 14px; }
  .toolbar > .chip-row { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
  .toolbar > .chip-row::-webkit-scrollbar { display: none; }
  .toolbar > .chip-row .chip-row { flex-wrap: nowrap; }
  .filter-chip { flex: none; white-space: nowrap; padding: 5px 11px; font-size: 13px; }
}
