:root {
  --bg: #0d0d10;
  --panel: #17171c;
  --line: #2a2a31;
  --text: #ececf1;
  --muted: #9a9aa6;
  --accent: #f5c542;
  --accent-ink: #1a1400;
  --good: #6fd08c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 14px 24px;
  background: rgba(13, 13, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button {
  border: 0; background: none; padding: 7px 12px; border-radius: 999px;
  color: var(--muted); cursor: pointer;
}
nav button:hover { color: var(--text); }
nav button[aria-selected="true"] { background: var(--text); color: var(--bg); }
#wl-count:not(:empty) { opacity: 0.7; }
#search {
  margin-left: auto; min-width: 0; width: 220px;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
}

main { padding: 8px 24px 40px; max-width: 1400px; margin: 0 auto; }
h3.group {
  margin: 28px 0 12px; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}
.grid {
  display: grid; gap: 22px 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.grid.row {
  grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: minmax(160px, 1fr);
  overflow-x: auto; padding: 4px 2px 8px; scroll-snap-type: x proximity;
}
.grid.row .card { scroll-snap-align: start; }
.card { position: relative; cursor: pointer; }
.card .poster {
  display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 10px; background: var(--panel);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card .poster.blank {
  display: flex; align-items: center; justify-content: center; padding: 12px;
  text-align: center; color: var(--muted);
}
.card:hover .poster, .card:focus-visible .poster {
  transform: translateY(-3px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.card:focus-visible { outline: none; }
.card:focus-visible .poster { outline: 2px solid var(--accent); outline-offset: 3px; }
.card .title { margin: 8px 0 2px; font-weight: 600; font-size: 14px; }
.card .sub { margin: 0; font-size: 13px; color: var(--muted); }
.badge {
  position: absolute; top: 8px; left: 8px;
  padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
}
.badge.out { background: rgba(0, 0, 0, 0.7); color: var(--text); }
.star {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(0, 0, 0, 0.6); color: var(--text); font-size: 16px;
}
.star[aria-pressed="true"] { color: var(--accent); }
.card.watched .poster { opacity: 0.45; }

.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.keyform { max-width: 420px; margin: 40px auto; text-align: center; color: var(--muted); }
.keyform form { display: flex; gap: 8px; margin-top: 12px; }
.keyform input {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel);
}

.btn {
  border: 1px solid var(--line); background: var(--panel);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text);
  font-size: 14px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn:hover { filter: brightness(1.15); }
.ghost { border: 0; background: none; cursor: pointer; font-size: 18px; color: var(--muted); }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; }

dialog {
  width: min(1000px, 94vw); max-height: 92vh; padding: 0; overflow: auto;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.8); }
.frame { aspect-ratio: 16 / 9; background: #000; }
.frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.info { padding: 16px 22px 22px; }
.info-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.info h2 { margin: 0; font-size: 22px; }
.meta { margin: 4px 0; color: var(--muted); }
.dates { margin: 4px 0 12px; }
.dates strong { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.videos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.videos .btn[aria-current="true"] { border-color: var(--accent); }

footer { padding: 24px; color: var(--muted); font-size: 12px; text-align: center; border-top: 1px solid var(--line); }
footer p { margin: 4px 0; }

@media (max-width: 640px) {
  header { padding: 12px 16px; }
  #search { width: 100%; margin-left: 0; }
  main { padding: 4px 16px 32px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 18px 12px; }
  .grid.row { grid-template-columns: none; grid-auto-columns: 130px; }
  .info { padding: 14px 16px 18px; }
}
