:root {
  --bg: #0d0d12;
  --surface: #17171f;
  --surface-2: #1f1f2b;
  --border: #2a2a38;
  --text: #ececf1;
  --muted: #9a9aae;
  --accent: #6c8cff;
  --kid: #f5a623;
  --yes: #2ecc71;
  --no: #ff5b6e;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px calc(14px + env(safe-area-inset-top, 0));
  gap: 12px;
}
.brand { font-size: 1.15rem; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.progress { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.profile-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 6px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 0.82rem; cursor: pointer; font-weight: 600;
}
.profile-btn::before {
  content: attr(data-initial);
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
}

/* ---------- Profile gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.gate-inner { width: 100%; max-width: 460px; text-align: center; }
.gate-title { font-size: 1.6rem; font-weight: 700; margin: 0 0 28px; }
.gate-profiles {
  display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; margin-bottom: 28px;
}
.gate-profile {
  background: none; border: none; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 0.9rem; width: 96px; transition: color 0.15s;
}
.gate-profile:hover { color: var(--text); }
.gate-profile .avatar {
  width: 84px; height: 84px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: var(--accent);
  transition: border-color 0.15s;
}
.gate-profile:hover .avatar { border-color: var(--accent); }
.gate-add { display: flex; gap: 8px; max-width: 340px; margin: 0 auto; }
.gate-add input {
  flex: 1; padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 1rem; outline: none;
}
.gate-add input:focus { border-color: var(--accent); }
.gate-child {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px;
  color: var(--text); font-size: 0.9rem; cursor: pointer;
}
.gate-child input { width: 17px; height: 17px; accent-color: var(--kid); }
.gate-child span { color: var(--muted); font-size: 0.82rem; }
.gate-note { color: var(--muted); font-size: 0.82rem; margin-top: 18px; min-height: 1em; }

/* Child (kid) profiles get a warm accent instead of blue */
.gate-profile.child .avatar { color: var(--kid); border-color: var(--kid); }
.profile-btn.child::before { background: var(--kid); }

/* ---------- Views ---------- */
.views { flex: 1; position: relative; padding: 0 16px; }
.view { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Swipe deck ---------- */
.deck {
  position: relative;
  height: min(62vh, 560px);
  margin: 8px auto 0;
  max-width: 380px;
  touch-action: pan-y;
}
.card {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  will-change: transform;
  user-select: none;
}
.card img, .card .noposter {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface-2);
  pointer-events: none;
}
.card .noposter {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 3rem;
}
.card-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 40px 16px 16px;
  background: linear-gradient(180deg, rgba(13,13,18,0) 0%, rgba(13,13,18,0.85) 55%, rgba(13,13,18,0.96) 100%);
}
.card-title { font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.card-sub { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }
.franchise {
  display: inline-block; margin-top: 8px; padding: 3px 9px;
  background: rgba(108,140,255,0.15); color: var(--accent);
  border-radius: 999px; font-size: 0.72rem; font-weight: 600;
}
.stamp {
  position: absolute; top: 22px; padding: 6px 16px;
  font-weight: 800; font-size: 1.4rem; letter-spacing: 0.05em;
  border: 3px solid; border-radius: 10px; opacity: 0; text-transform: uppercase;
}
.stamp.seen { right: 18px; color: var(--yes); border-color: var(--yes); transform: rotate(14deg); }
.stamp.miss { left: 18px; color: var(--no); border-color: var(--no); transform: rotate(-14deg); }
.stamp.wishup { top: 18px; left: 50%; transform: translateX(-50%); color: #ffd54a; border-color: #ffd54a; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: var(--muted); gap: 14px; padding: 20px;
}
.empty .big { font-size: 3rem; }

/* ---------- Deck action buttons ---------- */
.deck-actions {
  display: flex; align-items: center; justify-content: center; gap: 22px;
  margin: 20px 0 6px;
}
.circle {
  width: 60px; height: 60px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 1.5rem; cursor: pointer;
  transition: transform 0.12s ease, background 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.circle:active { transform: scale(0.9); }
.circle.yes { color: var(--yes); border-color: rgba(46,204,113,0.4); }
.circle.no  { color: var(--no);  border-color: rgba(255,91,110,0.4); }
.circle.wish { color: #ffd54a; border-color: rgba(255,213,74,0.4); font-size: 1.6rem; }
.circle.undo { width: 48px; height: 48px; font-size: 1.2rem; color: var(--muted); }
.circle:disabled { opacity: 0.35; cursor: default; }
.hint { text-align: center; color: var(--muted); font-size: 0.82rem; margin: 4px 0 20px; }

/* ---------- Grids / lists ---------- */
.grid {
  display: grid; gap: 12px; padding: 12px 0 20px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; cursor: pointer; position: relative;
  transition: transform 0.12s ease;
}
.tile:active { transform: scale(0.96); }
.tile img, .tile .noposter { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: var(--surface-2); }
.tile .noposter { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.6rem; }
.tile-cap { padding: 7px 8px; }
.tile-cap b { font-size: 0.78rem; font-weight: 600; display: block; line-height: 1.2; }
.tile-cap span { color: var(--muted); font-size: 0.72rem; }
.tile .badge {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; background: rgba(0,0,0,0.6);
}

/* ---------- Controls ---------- */
.filterbar { display: flex; gap: 8px; padding: 12px 0 0; align-items: center; }
.sort {
  margin-left: auto;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 0.85rem; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.sort:focus { outline: none; border-color: var(--accent); }
.chip {
  padding: 7px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 0.85rem;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.segment {
  display: flex; gap: 6px; margin-top: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px;
}
.seg {
  flex: 1; padding: 8px 10px; border-radius: 999px; border: none;
  background: none; color: var(--muted); font-size: 0.85rem; cursor: pointer;
}
.seg.active { background: var(--accent); color: #fff; }

.search {
  width: 100%; margin: 12px 0 0; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-size: 1rem; outline: none;
}
.search:focus { border-color: var(--accent); }

.custom-add { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.custom-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.custom-row input[type=text] { flex: 1 1 160px; }
.custom-row input[type=number] { width: 90px; }
.custom-row input {
  padding: 11px 13px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 0.95rem; outline: none;
}
.btn {
  padding: 11px 18px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 0.9rem;
}
.btn.small { padding: 7px 12px; font-size: 0.8rem; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* Count header at the top of Watched / Not-seen lists */
.list-count {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); padding: 12px 0 10px;
  font-weight: 700; font-size: 1rem; color: var(--text);
}

/* ---------- Ranked watched list ---------- */
.rank-list { padding: 12px 0 24px; display: flex; flex-direction: column; gap: 10px; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px; cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  touch-action: pan-y;
}
.rank-row.dragging {
  box-shadow: var(--shadow); border-color: var(--accent);
  transition: none; opacity: 0.97;
}
.rank-num {
  flex: 0 0 34px; text-align: center; font-weight: 800; font-size: 1.05rem;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
.rank-row img, .rank-row .noposter {
  flex: 0 0 44px; width: 44px; height: 66px; object-fit: cover;
  border-radius: 6px; background: var(--surface-2);
}
.rank-row .noposter { display: flex; align-items: center; justify-content: center; font-size: 1.1rem; color: var(--muted); }
.rank-meta { flex: 1; min-width: 0; }
.rank-meta b { display: block; font-size: 0.92rem; line-height: 1.25; }
.rank-meta span { color: var(--muted); font-size: 0.78rem; }
.handle {
  flex: 0 0 28px; text-align: center; color: var(--muted);
  font-size: 1.3rem; cursor: grab; touch-action: none; user-select: none;
  padding: 6px 0;
}
.handle:active { cursor: grabbing; }

/* wishlist heart on tiles */
.tile .wish {
  position: absolute; top: 6px; left: 6px; width: 28px; height: 28px;
  border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
}
.tile .wish.on { color: #ffd54a; }

/* ---------- Edit bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; opacity: 0; transition: opacity 0.2s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 480px; background: var(--surface);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(24px + env(safe-area-inset-bottom,0));
  transform: translateY(100%); transition: transform 0.25s ease;
}
.sheet-backdrop.show .sheet { transform: none; }
.sheet-head { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.sheet-head img, .sheet-head .noposter {
  width: 54px; height: 80px; object-fit: cover; border-radius: 8px; background: var(--surface-2);
}
.sheet-head .noposter { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.sheet-head b { display: block; font-size: 1rem; }
.sheet-head span { color: var(--muted); font-size: 0.82rem; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }
.sheet-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 13px 15px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 0.95rem; cursor: pointer; text-align: left;
}
.sheet-btn:active { transform: scale(0.99); }
.sheet-btn.danger { color: var(--no); }
.rank-edit { display: flex; align-items: center; gap: 10px; }
.rank-edit input {
  width: 64px; padding: 10px; text-align: center; font-size: 1rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-weight: 700;
}

.hint-sub { font-size: 0.75rem; opacity: 0.6; }

/* ---------- Movie details modal ---------- */
.detail-backdrop {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; transition: opacity 0.2s;
}
.detail-backdrop.show { opacity: 1; }
.detail {
  position: relative; width: 100%; max-width: 460px;
  max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
  transform: translateY(14px) scale(0.98); transition: transform 0.22s ease;
}
.detail-backdrop.show .detail { transform: none; }
.detail-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 1rem; cursor: pointer;
}
.detail-loading { text-align: center; padding: 60px 20px; }
.detail-hero { display: flex; gap: 14px; padding: 18px; }
.detail-hero img, .detail-hero .noposter {
  width: 108px; height: 162px; flex: 0 0 108px;
  object-fit: cover; border-radius: 10px; background: var(--surface-2);
}
.detail-hero .noposter { display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--muted); }
.detail-head { flex: 1; min-width: 0; padding-right: 28px; }
.detail-head h2 { margin: 0 0 6px; font-size: 1.2rem; line-height: 1.25; }
.detail-head h2 span { color: var(--muted); font-weight: 500; }
.detail-tagline { margin: 6px 0; color: var(--muted); font-style: italic; font-size: 0.88rem; }
.detail-meta { margin-top: 8px; font-size: 0.82rem; color: var(--text); }
.detail-body { padding: 0 18px 20px; }
.detail-body p { margin: 10px 0; font-size: 0.9rem; line-height: 1.5; }
.detail-body b { color: var(--muted); font-weight: 600; }
.detail-overview { color: var(--text); }
.detail-facts {
  display: flex; flex-direction: column; gap: 8px; margin-top: 16px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.detail-facts span { font-size: 0.84rem; color: var(--muted); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: sticky; bottom: 0; display: flex;
  background: rgba(13,13,18,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 0 8px; font-size: 0.72rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab span { font-size: 1.25rem; }
.tab.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); padding: 10px 18px;
  border-radius: 999px; border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 0.85rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* ---------- Family Stats ---------- */
.stats-head { margin: 14px 4px 16px; }
.stats-head h2 { font-size: 1.4rem; margin-bottom: 2px; }
.stats-head .muted { font-size: 0.85rem; }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.stat-top { display: flex; align-items: center; gap: 12px; }
.stat-avatar {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px;
  background: var(--surface-2); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700; color: var(--accent);
}
.stat-avatar.child { color: var(--kid); border-color: var(--kid); }
.stat-id { flex: 1 1 auto; min-width: 0; }
.stat-id b { font-size: 1.05rem; }
.stat-persona {
  color: var(--accent); font-size: 0.98rem; font-weight: 700;
  margin-bottom: 6px;
}
.stat-count {
  flex: 0 0 auto; text-align: right; display: flex; align-items: baseline; gap: 5px;
}
.stat-count b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat-count span { color: var(--muted); font-size: 0.72rem; }

.stat-bar {
  height: 7px; border-radius: 99px; background: var(--surface-2);
  overflow: hidden; margin: 12px 0 10px;
}
.stat-bar > div {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #9db3ff);
  transition: width 0.5s ease;
}
.stat-blurb { color: var(--text); font-size: 0.9rem; line-height: 1.45; }
.stat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.stat-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 4px 10px; font-size: 0.76rem; color: var(--muted);
}

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  .tab span { font-size: 1.1rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
