:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-card: #1d212b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #9b7bff;
  --ok: #4cd77c;
  --warn: #f5b74f;
  --danger: #ff6b6b;
  --radius: 10px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-padding-top: 70px; } /* keep anchored/scrolled-to elements clear of the sticky topbar */
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, select, input {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8rem; }
[hidden] { display: none !important; }

/* Layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.nav a { color: var(--muted); }
.nav a.active { color: var(--text); font-weight: 600; }
.nav .user { color: var(--muted); font-size: 0.9rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 0.45rem 0.9rem; border-radius: 8px; transition: 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1020; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #0b1020; font-weight: 600; }
.btn.sm { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.icon { padding: 0.3rem 0.5rem; }
input[type=text], input[type=email], input[type=password], select {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.75rem; color: var(--text); outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
select { width: auto; cursor: pointer; }
.status-select { font-size: 0.85rem; padding: 0.3rem 0.5rem; max-width: 100%; }

/* Auth */
.auth { max-width: 400px; margin: 3rem auto; background: var(--bg-card); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.auth h1 { text-align: center; margin-bottom: 1.2rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.3rem; }
.auth .btn { width: 100%; justify-content: center; margin-top: 0.5rem; }
.auth .alt { text-align: center; color: var(--muted); margin-top: 1rem; font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.5rem 0; min-height: 1.2em; }

/* Home sections */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.section-list { display: flex; flex-direction: column; gap: 0.9rem; margin-bottom: 2rem; }
.section-card {
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
}
.section-card .icon { font-size: 2rem; }
.section-card .body { flex: 1; }
.section-card .title { font-size: 1.15rem; font-weight: 600; color: var(--text); }
.section-card .stats { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }
.section-card .actions { display: flex; gap: 0.3rem; }
.add-sections { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.empty { color: var(--muted); padding: 1.5rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.hint { color: var(--muted); font-size: 0.9rem; }
.notice { background: rgba(245, 183, 79, 0.12); border: 1px solid rgba(245, 183, 79, 0.4); color: var(--warn); padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }

/* Search */
.searchbar { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.searchbar input { flex: 1; min-width: 220px; padding: 0.7rem 0.9rem; font-size: 1rem; }
.mode-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-toggle button { background: var(--bg-elev); border: 0; padding: 0.5rem 0.9rem; color: var(--muted); }
.mode-toggle button.active { background: var(--accent); color: #0b1020; font-weight: 600; }
.search-results { margin-bottom: 2rem; }
.search-results h2 { display: flex; align-items: center; gap: 0.6rem; }
.search-results h2 .btn { margin-left: auto; }

/* Status blocks */
.status-block { margin-bottom: 2rem; }
.status-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; }
.status-head h2 { margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.status-head .count { color: var(--muted); font-weight: 400; font-size: 0.95rem; }
.load-more { display: flex; justify-content: center; margin-top: 0.8rem; }

/* Cards grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; }
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: transform 0.15s, border-color 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: #3a4150; }
.card .thumb { display: block; aspect-ratio: 2 / 3; background: #0b0d12 center/cover no-repeat; position: relative; }
.card.wide .thumb { aspect-ratio: 460 / 215; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb .badge { position: absolute; top: 6px; left: 6px; }
.card .thumb .rating { position: absolute; top: 6px; right: 6px; }
.card .body { padding: 0.6rem 0.7rem 0.7rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.card .title { font-weight: 600; font-size: 0.95rem; color: var(--text); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { color: var(--muted); font-size: 0.82rem; }
.card .foot { margin-top: auto; padding-top: 0.3rem; }
.badge { display: inline-block; background: rgba(0,0,0,0.65); color: #fff; border-radius: 6px; padding: 0.1rem 0.45rem; font-size: 0.75rem; backdrop-filter: blur(4px); }
.badge.tv { background: rgba(155, 123, 255, 0.85); }
.badge.movie { background: rgba(110, 168, 254, 0.85); color: #0b1020; }
.progress { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }

/* Detail pages */
.detail-hero { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 1.5rem; background: var(--bg-card); min-height: 240px; }
.detail-hero .backdrop { position: absolute; inset: 0; background: center/cover no-repeat; opacity: 0.25; filter: blur(2px); }
.detail-hero .inner { position: relative; display: flex; gap: 1.5rem; padding: 1.5rem; }
.detail-hero .poster { width: 220px; flex-shrink: 0; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.detail-hero .poster.wide { width: 380px; }
.detail-hero .info { flex: 1; min-width: 0; }
.detail-hero .tagline { color: var(--muted); font-style: italic; }
.meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0.8rem; }
.meta b { color: var(--text); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.chip { background: rgba(255,255,255,0.07); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.7rem; font-size: 0.82rem; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.ratings { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 0.8rem 0; }
.rating-pill { display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,0.35); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.8rem; min-width: 84px; color: var(--text); }
.rating-pill:hover { text-decoration: none; border-color: var(--accent); }
.rating-pill .src { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.rating-pill .val { font-weight: 700; font-size: 1.1rem; }
.rating-pill .votes { font-size: 0.7rem; color: var(--muted); }
.section { margin-bottom: 2rem; }
.description { color: #cfd4de; line-height: 1.6; }
.description img { max-width: 100%; border-radius: 6px; margin: 0.5rem 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
.gallery img { aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--border); }
.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.videos video { width: 100%; border-radius: 8px; background: #000; }
.trailer { aspect-ratio: 16 / 9; max-width: 860px; border-radius: 8px; overflow: hidden; background: #000; }
.trailer iframe { width: 100%; height: 100%; border: 0; }
.people { display: flex; gap: 0.8rem; overflow-x: auto; padding-bottom: 0.5rem; }
.person { flex: 0 0 110px; text-align: center; font-size: 0.82rem; }
.person .avatar { width: 110px; height: 150px; border-radius: 8px; object-fit: cover; background: var(--bg-elev); margin-bottom: 0.3rem; }
.person .name { font-weight: 600; }
.person .role { color: var(--muted); }
.crew { color: var(--muted); font-size: 0.9rem; }
.crew b { color: var(--text); font-weight: 500; }
.back { display: inline-block; margin-bottom: 1rem; color: var(--muted); }

/* Localized title & Kinopoisk link */
.localized { font-size: 1.1rem; color: #cfd4de; }
.localized:empty { display: none; }
.kp-link .searchbar { margin-top: 0.8rem; }
.kp-candidates { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.candidate { display: flex; align-items: center; gap: 0.8rem; padding: 0.5rem 0.7rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; }
.cand-poster { width: 40px; height: 60px; flex-shrink: 0; background: var(--bg-elev); border-radius: 4px; overflow: hidden; }
.cand-poster img { width: 100%; height: 100%; object-fit: cover; }
.cand-body { flex: 1; min-width: 0; }
.kp-linked .status-buttons { margin: 0.6rem 0 0; }

/* Episodes */
.season { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.8rem; background: var(--bg-card); }
.season-head { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1rem; cursor: pointer; }
.season-head h3 { margin: 0; flex: 1; }
.season-head .prog { color: var(--muted); font-size: 0.85rem; }
.season-body { border-top: 1px solid var(--border); }
.episode { display: flex; align-items: center; gap: 0.8rem; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
.episode:last-child { border-bottom: 0; }
.episode input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ok); cursor: pointer; }
.episode .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; font-size: 0.85rem; }
.episode .ep-title { flex: 1; }
.episode .ep-title small { display: block; color: var(--muted); font-size: 0.8rem; }
.episode .date { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.episode.watched .ep-title { color: var(--muted); }
.episode.future { opacity: 0.6; }

/* Misc */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #2a2f3a; color: #fff; padding: 0.7rem 1.2rem; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.error { background: #4a1f24; border: 1px solid var(--danger); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center; z-index: 60; cursor: zoom-out; padding: 2rem; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.loading { color: var(--muted); padding: 1rem 0; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 0.4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .detail-hero .inner { flex-direction: column; }
  .detail-hero .poster { width: 160px; }
  .detail-hero .poster.wide { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
