:root {
  --bg: #100f14;
  --panel: #1a1820;
  --panel-2: #24212c;
  --line: #322e3c;
  --text: #f1eef5;
  --muted: #9a94a6;
  --accent: #f5b942;
  --accent-ink: #201603;
  --danger: #ef6a6a;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

.logo { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; }
.logo span { color: var(--accent); }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { width: 100%; resize: vertical; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); margin-left: auto; }

/* ---------- login / profile picker ---------- */

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.profiles-screen { display: grid; justify-items: center; gap: 28px; text-align: center; width: 100%; }
.profiles-screen .logo { font-size: 22px; }
.profiles-screen h1 { margin: 0 0 26px; font-size: clamp(26px, 5vw, 40px); font-weight: 600; letter-spacing: -0.02em; }
.profiles { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(18px, 5vw, 40px); }
.profile { background: none; border: 0; padding: 0; cursor: pointer; display: grid; gap: 12px; justify-items: center; color: var(--muted); }
.avatar {
  display: grid;
  place-items: center;
  width: clamp(110px, 28vw, 160px);
  aspect-ratio: 1;
  border-radius: 14px;
  border: 3px solid transparent;
  font-size: clamp(48px, 12vw, 72px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.92);
  transition: border-color 0.15s, transform 0.15s;
}
.avatar.a1 { background: linear-gradient(140deg, #f5b942, #e0602f); }
.avatar.a2 { background: linear-gradient(140deg, #b06ef0, #e0508c); }
.profile-name { font-size: 18px; transition: color 0.15s; }
.profile:hover .avatar, .profile:focus-visible .avatar { border-color: var(--text); transform: scale(1.04); }
.profile:hover .profile-name, .profile:focus-visible .profile-name { color: var(--text); }
.profile:focus-visible { outline: none; }
.unlock { display: grid; justify-items: center; gap: 14px; width: 100%; max-width: 300px; }
.unlock .avatar { width: 110px; font-size: 48px; }
.unlock h1 { margin: 0 0 6px; font-size: 26px; }
.unlock input, .unlock .btn { width: 100%; }
.unlock input { padding: 11px 14px; text-align: center; }
.unlock .btn.ghost { border-color: transparent; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* ---------- header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(16, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.add { position: relative; flex: 1; max-width: 520px; margin: 0 auto; }
.add input { width: 100%; padding: 10px 14px; }
.who { display: flex; align-items: center; gap: 10px; }
.me { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; }
.me:hover { color: var(--accent); }
.me .avatar { width: 30px; font-size: 15px; border-radius: 7px; border: 0; }

.add-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  max-height: 70vh;
  overflow-y: auto;
  padding: 6px;
}
.result {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
}
.result:hover:not(:disabled) { background: var(--panel-2); }
.result:disabled { opacity: 0.5; cursor: default; }
.result img, .thumb-blank { width: 40px; height: 60px; object-fit: cover; border-radius: 5px; background: var(--panel-2); flex: none; }
.result-title { font-weight: 600; }
.result.manual { color: var(--accent); padding: 10px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; }
.result-note { padding: 10px; color: var(--muted); }

/* ---------- toolbar ---------- */

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 4px; }
.tab { background: none; border: 0; border-radius: 8px; padding: 6px 14px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab::after { content: attr(data-count); margin-left: 7px; font-size: 12px; opacity: 0.7; }
.tab.active { background: var(--panel-2); color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters input { width: 170px; }
.summary { margin: 14px 2px 12px; min-height: 1.5em; }

/* ---------- grid ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px 16px; }
.card { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; min-width: 0; align-self: start; }
.poster-wrap { position: relative; }
.poster {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.card:hover .poster { border-color: var(--accent); transform: translateY(-2px); }
.poster { transition: transform 0.15s, border-color 0.15s; }
.poster.placeholder { display: grid; place-items: center; padding: 14px; text-align: center; color: var(--muted); font-weight: 700; }
.card.is-watched .poster { opacity: 0.55; }
.badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}
.badge.late { background: var(--panel-2); color: var(--muted); }
.badge.seen { background: rgba(0, 0, 0, 0.75); color: var(--text); }
.card-title { margin-top: 8px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 70px 20px; }

/* ---------- detail ---------- */

.detail {
  width: min(820px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
}
.detail::backdrop { background: rgba(0, 0, 0, 0.7); }
.detail-body { display: grid; grid-template-columns: 260px 1fr; gap: 24px; padding: 24px; }
.detail-info { display: grid; gap: 12px; align-content: start; min-width: 0; }
.detail-info h2 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -0.02em; padding-right: 30px; }
.detail-info p { margin: 0; }
.picked { color: var(--accent); font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 0.08em; }
.overview { color: #d5d0de; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 1px 10px; font-size: 13px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field textarea { color: var(--text); font-size: 15px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions { margin-top: 4px; }
.stars { display: flex; gap: 2px; }
.star { background: none; border: 0; padding: 0 2px; font-size: 28px; line-height: 1; cursor: pointer; color: var(--line); }
.star.on { color: var(--accent); }
.other-rating { font-size: 14px; }
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: var(--panel-2);
  cursor: pointer;
  z-index: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 99px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
  max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  .top { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .add { order: 3; flex-basis: 100%; max-width: none; }
  .who { margin-left: auto; }
  main { padding: 14px; }
  .filters { width: 100%; }
  .filters input, .filters select { flex: 1 1 140px; }
  .filters .btn { flex: 1 1 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 16px 10px; }
  .detail-body { grid-template-columns: 1fr; padding: 18px; }
  .detail-body > .poster { max-width: 170px; }
}
