/* Layout: экран выбора (слева аниме, справа фильмы, граница с наклоном) и два полноэкранных слоя-лица.
   Слои переключаются маской clip-path с наклонным краем, поверх бегут две цветные полосы.
   Тема каждого лица задаётся токенами в [data-kind]. Аниме: палитра #6b2065. Фильмы: палитра #060f0a. */
:root {
  --b50: #f0e9f0;
  --b100: #e1d2e0;
  --b300: #c4a6c1;
  --b400: #a679a3;
  --b500: #894d84;
  --b600: #6b2065;
  --b700: #561a51;
  --b800: #40133d;
  --b900: #2b0d28;
  --b950: #150614;

  --f950: #060f0a;
  --gold: #d9b45b;

  --font-body: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --slant: 6vw;
}

/* ---------- Лицо первое: аниме ---------- */
[data-kind="anime"] {
  --bg: #faf6fa;
  --surface: #ffffff;
  --surface-2: var(--b50);
  --fg: var(--b950);
  --muted: #6f5a6d;
  --line: #e6d9e5;
  --field-line: #cdb6cb;
  --accent: var(--b600);
  --accent-hover: var(--b700);
  --accent-fg: #ffffff;
  --link: var(--b600);
  --mast-bg: var(--b600);
  --mast-fg: #ffffff;
  --mast-muted: var(--b100);
  --mast-line: transparent;
  --star-on: var(--b600);
  --star-off: #e1d2e0;
  --star-preview: var(--b400);
  --danger: #a3261f;
  --ring: var(--b500);
  --font-display: 'Unbounded', 'Onest', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  [data-kind="anime"] {
    --bg: #150614;
    --surface: #1e0a1c;
    --surface-2: #2b0d28;
    --fg: #f0e9f0;
    --muted: #b9a0b6;
    --line: #3a1a37;
    --field-line: #5a3556;
    --accent: #894d84;
    --accent-hover: #9a5f95;
    --link: var(--b300);
    --mast-bg: #40133d;
    --mast-fg: #f0e9f0;
    --mast-muted: #c4a6c1;
    --star-on: #cfa3ca;
    --star-off: #3d2a3b;
    --star-preview: #a679a3;
    --danger: #ff9a93;
    --ring: #c4a6c1;
    color-scheme: dark;
  }
}

/* ---------- Лицо второе: фильмы (всегда тёмное, как кинозал) ---------- */
[data-kind="films"] {
  --bg: #0a1610;
  --surface: #101f17;
  --surface-2: #172b20;
  --fg: #e8f2ec;
  --muted: #87a595;
  --line: #1d3528;
  --field-line: #31503f;
  --accent: var(--gold);
  --accent-hover: #e8c773;
  --accent-fg: #1a1304;
  --link: #e2bb62;
  --mast-bg: var(--f950);
  --mast-fg: #eef6f1;
  --mast-muted: #8fae9d;
  --mast-line: rgba(226, 187, 98, 0.35);
  --star-on: #e2bb62;
  --star-off: #2d4a38;
  --star-preview: #9f8442;
  --danger: #ff9a93;
  --ring: #e2bb62;
  --font-display: 'Oswald', 'Onest', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--f950);
  color: #fff;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- Экран выбора ---------- */
.gate { position: fixed; inset: 0; z-index: 1; display: flex; background: var(--f950); overflow: hidden; }
.gate-title {
  position: absolute;
  top: clamp(16px, 4vh, 36px);
  left: 0;
  right: 0;
  z-index: 2;
  margin: 0;
  text-align: center;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  pointer-events: none;
}
.gate-hint {
  position: absolute;
  bottom: clamp(14px, 3vh, 28px);
  left: 0;
  right: 0;
  z-index: 2;
  margin: 0;
  text-align: center;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}
.pick {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  padding: clamp(24px, 5vw, 64px);
  padding-bottom: clamp(56px, 12vh, 120px);
  border: 0;
  border-radius: 0;
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: flex-grow 0.5s cubic-bezier(0.2, 0.7, 0.2, 1), filter 0.3s;
}
.pick:hover, .pick:focus-visible { flex-grow: 1.35; }
.pick:focus-visible { outline: 3px solid rgba(255, 255, 255, 0.85); outline-offset: -14px; }
.pick-name {
  display: block;
  max-width: 100%;
  font-size: clamp(1.9rem, 8.5vw, 6.2rem);
  line-height: 1.02;
  overflow-wrap: anywhere;
}
.pick-note { display: block; max-width: 28ch; font-size: clamp(0.8125rem, 1.6vw, 1.0625rem); opacity: 0.82; }

/* Левая половина, аниме */
.pick-anime {
  padding-right: calc(var(--slant) + clamp(24px, 5vw, 64px));
  background: var(--b600);
  clip-path: polygon(0 0, 100% 0, calc(100% - var(--slant)) 100%, 0 100%);
}
.pick-anime .pick-name { font-family: 'Unbounded', 'Onest', sans-serif; font-weight: 700; letter-spacing: -0.01em; }
.pick-mark {
  position: absolute;
  top: 16%;
  left: 50%;
  width: min(46%, 300px);
  fill: rgba(240, 233, 240, 0.12);
  transform: translateX(-50%) rotate(-8deg);
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1), fill 0.3s;
}
.pick-anime:hover .pick-mark, .pick-anime:focus-visible .pick-mark {
  fill: rgba(240, 233, 240, 0.2);
  transform: translateX(-50%) rotate(4deg) scale(1.06);
}

/* Правая половина, фильмы */
.pick-films {
  margin-left: calc(var(--slant) * -1);
  padding-left: calc(var(--slant) + clamp(24px, 5vw, 64px));
  background: var(--f950);
  clip-path: polygon(var(--slant) 0, 100% 0, 100% 100%, 0 100%);
}
.pick-films .pick-name {
  font-family: 'Oswald', 'Onest', sans-serif;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #e8c773;
}
/* Перфорация киноплёнки у правого края */
.pick-films::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: clamp(10px, 2.4vw, 28px);
  width: clamp(10px, 1.6vw, 18px);
  background: repeating-linear-gradient(to bottom, rgba(226, 187, 98, 0.22) 0 clamp(10px, 2vh, 18px), transparent clamp(10px, 2vh, 18px) clamp(22px, 4vh, 36px));
  border-radius: 3px;
  transition: background-color 0.3s;
}
.pick-films:hover::before { filter: brightness(1.5); }

/* ---------- Слои-лица ---------- */
.face {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
}
h1:focus { outline: none; }

/* Шапка */
.mast {
  background: var(--mast-bg);
  color: var(--mast-fg);
  padding-block: 14px 26px;
  border-bottom: 1px solid var(--mast-line);
}
.wrap { max-width: 760px; margin-inline: auto; padding-inline: 16px; }
.mast .wrap { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; }
.swapbar { flex: 0 0 100%; order: -1; display: flex; justify-content: flex-end; }
[data-kind="films"] .swapbar { justify-content: flex-start; }
.swap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--mast-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
}
.swap:hover { color: var(--mast-fg); }
.swap:focus-visible { outline: 2px solid var(--mast-fg); outline-offset: 2px; }
.swap span { display: inline-block; transition: transform 0.2s; }
.swap:hover span { transform: translateX(4px); }
[data-kind="films"] .swap:hover span { transform: translateX(-4px); }

.brand { display: grid; gap: 8px; min-width: 0; }
h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 5.5vw, 2.25rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
[data-kind="films"] h1 {
  font-weight: 600;
  font-size: clamp(2rem, 7vw, 3rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.stats { margin: 0; min-height: 1.5em; color: var(--mast-muted); font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.stats b { color: var(--mast-fg); font-weight: 600; }
.who { display: flex; align-items: center; gap: 12px; }
.uname { color: var(--mast-muted); font-size: 0.9375rem; overflow-wrap: anywhere; }
.ghost {
  padding: 8px 16px;
  background: transparent;
  color: var(--mast-fg);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s;
}
.ghost:hover { background: rgba(255, 255, 255, 0.14); }
.ghost:focus-visible { outline: 2px solid var(--mast-fg); outline-offset: 2px; }

.main { display: grid; gap: 18px; padding-block: 24px 72px; padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

/* Форма добавления */
.add {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.lbl {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.field {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--field-line);
  border-radius: 10px;
}
.field::placeholder { color: var(--muted); opacity: 0.8; }
.field:focus-visible, select:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.add-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 20px; }
.picker { min-width: 0; }
.picker-line { display: flex; align-items: center; gap: 12px; }
.out {
  min-width: 3.6rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}
.out small, .score small { color: var(--muted); font-family: var(--font-body); font-weight: 400; font-size: 0.75rem; }
.btn {
  padding: 11px 22px;
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.sec { background: transparent; color: var(--fg); border-color: var(--field-line); }
.btn.sec:hover { background: var(--surface-2); }
.err { margin: 0; color: var(--danger); font-size: 0.9rem; }

/* Звёзды */
.stars { display: flex; gap: 2px; --s: 22px; }
.star {
  appearance: none;
  display: block;
  margin: 0;
  padding: 3px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--star-off);
  line-height: 0;
  cursor: pointer;
}
.star svg { display: block; width: var(--s); height: var(--s); fill: currentColor; }
.star.on { color: var(--star-on); }
.star.pv { color: var(--star-preview); }
.star:focus-visible { outline: 2px solid var(--ring); outline-offset: 0; }
.stars.ro .star { cursor: default; }

/* Поиск и сортировка */
.tools { display: flex; flex-wrap: wrap; gap: 10px; }
.tools .search { flex: 1 1 200px; min-width: 0; }
.tools select {
  flex: 0 1 auto;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--field-line);
  border-radius: 10px;
}

/* Сообщения */
.hint, .notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.hint { background: var(--surface-2); }
.hint p { margin: 0; }
.notice { background: var(--surface); border: 1px solid var(--danger); color: var(--danger); }
.link {
  padding: 4px 6px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--link);
  font-weight: 600;
  cursor: pointer;
}
.link:focus-visible { outline: 2px solid var(--ring); }

/* Список */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 3.6rem 2.25rem;
  grid-template-areas: "name stars score del";
  align-items: center;
  gap: 8px 14px;
  padding: 10px 8px 10px 18px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.name { grid-area: name; margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.row .stars { grid-area: stars; }
.score {
  grid-area: score;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.delcell { grid-area: del; position: relative; height: 34px; }
.del {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s;
}
.row:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { color: var(--danger); opacity: 1; }
.del:focus-visible { outline: 2px solid var(--ring); }
.del.confirm {
  z-index: 1;
  width: auto;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 1;
}
.empty { padding: 30px 18px; color: var(--muted); }

/* Режим просмотра: без колонки удаления */
.list.ro .row {
  grid-template-columns: minmax(0, 1fr) auto 3.6rem;
  grid-template-areas: "name stars score";
  padding-right: 18px;
}

/* ---------- Слои маски при переключении ---------- */
.veil { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.veil[data-for="anime"].a { background: var(--b600); }
.veil[data-for="anime"].b { background: var(--b300); }
.veil[data-for="films"].a { background: var(--f950); }
.veil[data-for="films"].b { background: var(--gold); }

/* ---------- Окно входа ---------- */
dialog {
  width: min(380px, calc(100% - 32px));
  padding: 0;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 14px;
}
dialog::backdrop { background: rgba(6, 15, 10, 0.65); }
.dlg { display: grid; gap: 14px; padding: 20px; }
.dlg h2 { margin: 0; font-family: var(--font-display); font-size: 1.125rem; font-weight: 600; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 560px) {
  :root { --slant: 9vw; }
  .row {
    grid-template-columns: minmax(0, 1fr) auto 2.25rem;
    grid-template-areas: "name score del" "stars stars stars";
    gap: 4px 10px;
    padding: 12px 8px 12px 16px;
  }
  .list.ro .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name score" "stars stars";
    padding-right: 16px;
  }
  .row .stars { --s: 24px; margin-right: 8px; }
  .list.ro .row .stars { margin-right: 0; }
  .row .star { flex: 1 1 0; display: grid; place-items: center; padding: 4px 0; }
  .add { padding: 16px; }
  .add-row .btn { width: 100%; }
  .picker { width: 100%; }
  .pick-note { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }