:root {
  --bg: #0b0b10;
  --surface: #14141b;
  --surface-2: #1c1c26;
  --border: #2a2a37;
  --text: #f4f4f7;
  --text-muted: #9a9aae;
  --primary: #7c5cff;
  --primary-hover: #9378ff;
  --star: #f5b83d;
  --danger: #ff5c6c;
  --plan: #7c5cff;
  --watching: #38bdf8;
  --completed: #34d399;
  --on_hold: #f5b83d;
  --dropped: #ff5c6c;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --radius: 12px;
  --font: "Inter", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(ellipse 90% 50% at 50% -10%, #1a1430 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding-bottom: 5rem;
}
img { display: block; max-width: 100%; height: auto; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button, input, select, textarea { font: inherit; }
[x-cloak] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff; padding: .5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.site-header {
  position: sticky; top: 0; z-index: 40;
  display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center;
  padding: .9rem 1.25rem;
  background: rgba(11,11,16,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--display); font-size: 1.6rem; color: var(--text); letter-spacing: -.02em;
}
.nav { display: flex; gap: .85rem; align-items: center; }
.nav a, .linkish { color: var(--text-muted); background: none; border: 0; cursor: pointer; padding: 0; }
.nav a:hover, .linkish:hover { color: var(--text); }
.inline { display: inline; margin: 0; }

.search { position: relative; max-width: 28rem; width: 100%; justify-self: center; }
.search input {
  width: 100%; padding: .7rem 2.2rem .7rem .9rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.search input:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.search kbd {
  position: absolute; right: .7rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); border: 1px solid var(--border); border-radius: 4px;
  padding: 0 .35rem; font-size: .75rem;
}
.search-dropdown {
  position: absolute; left: 0; right: 0; top: calc(100% + .35rem);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.45); overflow: hidden; z-index: 50;
}
.search-dropdown:empty { display: none; }
.dropdown-list { list-style: none; margin: 0; padding: 0; }
.dropdown-list a {
  display: flex; gap: .75rem; align-items: center; padding: .65rem .8rem; color: var(--text);
}
.dropdown-list a:hover { background: var(--surface); }
.dropdown-list img { width: 40px; height: 60px; object-fit: cover; border-radius: 6px; }
.dropdown-list small { display: block; color: var(--text-muted); }
.dropdown-empty { margin: 0; padding: .8rem; color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .7rem 1rem; border: 0; border-radius: 8px;
  background: var(--primary); color: #fff; font-weight: 600; cursor: pointer;
  transition: background 200ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--primary-hover); color: #fff; }
.btn:active { transform: scale(.98); }
.btn-sm { padding: .45rem .75rem; font-size: .9rem; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.display {
  font-family: var(--display); font-weight: 600; line-height: 1.15;
  letter-spacing: -.02em; margin: 0 0 .5rem;
}
.muted, .eyebrow { color: var(--text-muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; }

.hero {
  position: relative; min-height: min(70vh, 36rem);
  display: flex; align-items: flex-end;
  background:
    linear-gradient(180deg, rgba(11,11,16,.2), var(--bg)),
    var(--hero-image, none) center/cover no-repeat;
  margin-bottom: 1rem;
}
.hero-scrim { padding: 2.5rem 1.5rem; max-width: 40rem; }
.hero .display { font-size: clamp(2rem, 5vw, 3.5rem); }
.hero-actions { display: flex; gap: .75rem; margin-top: 1rem; }

.rail { padding: 1rem 0 1.5rem; }
.rail-head { padding: 0 1.25rem 0.75rem; }
.rail-head h2 { margin: 0; font-size: 1.2rem; }
.rail-track {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(8.5rem, 11rem);
  gap: .85rem; overflow-x: auto; padding: 0 1.25rem 0.5rem;
  scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.poster-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (min-width: 640px) {
  .poster-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .poster-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (min-width: 1440px) {
  .poster-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

.poster-card { color: inherit; scroll-snap-align: start; }
.poster-frame {
  position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  transition: transform 200ms var(--ease);
}
.poster-card:hover .poster-frame { transform: scale(1.03); }
.poster-frame img { width: 100%; height: 100%; object-fit: cover; }
.poster-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  padding: 1rem; text-align: center; color: var(--text-muted); background: var(--surface-2);
}
.poster-fallback.sm { min-height: 8rem; }
.poster-overlay {
  position: absolute; inset: auto 0 0 0; padding: .75rem;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  opacity: 0; transition: opacity 200ms var(--ease);
  display: flex; flex-direction: column; gap: .15rem;
}
.poster-card:hover .poster-overlay { opacity: 1; }
.status-dot {
  position: absolute; top: .5rem; right: .5rem; width: .7rem; height: .7rem;
  border-radius: 999px; border: 2px solid #0b0b10;
}
.rating-pill {
  position: absolute; left: .5rem; bottom: .5rem;
  background: rgba(0,0,0,.7); color: var(--star); border-radius: 999px;
  padding: .15rem .45rem; font-size: .75rem; font-weight: 600;
}
.status-plan, .status-dot.status-plan { background: var(--plan); }
.status-watching, .status-dot.status-watching { background: var(--watching); }
.status-completed, .status-dot.status-completed { background: var(--completed); }
.status-on_hold, .status-dot.status-on_hold { background: var(--on_hold); }
.status-dropped, .status-dot.status-dropped { background: var(--danger); }
.status-none { background: var(--primary); }

.page { padding: 1.5rem 1.25rem 3rem; max-width: 90rem; margin: 0 auto; }
.empty { color: var(--text-muted); margin-top: 2rem; }

.title-hero {
  background:
    linear-gradient(180deg, rgba(11,11,16,.55), var(--bg) 75%),
    var(--backdrop, none) center/cover no-repeat;
  padding: 2rem 1.25rem 1rem;
}
.title-layout {
  display: grid; gap: 1.5rem; max-width: 90rem; margin: 0 auto;
}
@media (min-width: 800px) {
  .title-layout { grid-template-columns: 18rem 1fr; align-items: start; }
}
.title-poster img, .title-poster .poster-fallback {
  border-radius: var(--radius); border: 1px solid var(--border); width: 100%;
}
.title-copy .display { font-size: clamp(2rem, 4vw, 3rem); }
.meta { color: var(--text-muted); margin: 0 0 .75rem; }
.genres { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.genres span {
  border: 1px solid var(--border); border-radius: 999px; padding: .2rem .65rem;
  color: var(--text-muted); font-size: .85rem;
}
.tagline { font-style: italic; color: var(--text-muted); }
.overview { max-width: 42rem; }
.action-bar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin: 1.25rem 0; }

.status-menu { position: relative; }
.status-panel {
  position: absolute; top: calc(100% + .4rem); left: 0; min-width: 12rem; z-index: 20;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.45); padding: .35rem; display: grid; gap: .2rem;
}
.status-panel button {
  width: 100%; text-align: left; background: transparent; border: 0; color: var(--text);
  padding: .55rem .7rem; border-radius: 8px; cursor: pointer;
}
.status-panel button:hover { background: var(--surface); }
.status-panel .danger { color: var(--danger); }

.stars { display: flex; gap: .15rem; }
.star-form { margin: 0; }
.star {
  background: none; border: 0; color: var(--border); font-size: 1.4rem; cursor: pointer;
  transition: color 120ms var(--ease), transform 120ms var(--ease);
}
.star.filled, .star:hover { color: var(--star); }
.star:active { transform: scale(1.15); }

.review-box {
  margin-top: 1rem; display: grid; gap: .5rem; max-width: 36rem;
}
.review-box textarea {
  width: 100%; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: .75rem;
}
.review-box label { color: var(--text-muted); font-size: .9rem; }

.cast-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 8rem;
  gap: .85rem; overflow-x: auto; padding-bottom: .5rem;
}
.cast-card { color: var(--text); }
.cast-card img, .cast-card .poster-fallback {
  border-radius: 10px; aspect-ratio: 2/3; object-fit: cover; margin-bottom: .4rem;
  border: 1px solid var(--border); background: var(--surface);
}
.cast-card strong, .cast-card span { display: block; font-size: .85rem; }
.cast-card span { color: var(--text-muted); }
.provider-list { display: flex; flex-wrap: wrap; gap: .5rem; list-style: none; padding: 0; }
.provider-list li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .35rem .8rem;
}

.status-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.tab {
  color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px;
  padding: .35rem .8rem; background: transparent;
}
.tab.active, .tab:hover { color: var(--text); border-color: var(--primary); }
.filters { margin: 0 0 1.25rem; }
.filters select {
  margin-left: .5rem; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem;
}

.search-page-form { display: flex; gap: .75rem; margin: 1rem 0 1.5rem; max-width: 36rem; }
.search-page-form input {
  flex: 1; padding: .7rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}

.site-footer {
  padding: 2rem 1.25rem 6rem; color: var(--text-muted); font-size: .85rem;
  border-top: 1px solid var(--border); text-align: center;
}
.site-footer a { color: var(--text-muted); text-decoration: underline; }

#toast-root {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%);
  z-index: 60; display: grid; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: .7rem 1rem; border-radius: 999px; box-shadow: 0 8px 30px rgba(0,0,0,.45);
  animation: rise 200ms var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.mobile-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(11,11,16,.94); border-top: 1px solid var(--border);
  padding: .55rem .25rem calc(.55rem + env(safe-area-inset-bottom));
}
.mobile-nav a {
  text-align: center; color: var(--text-muted); font-size: .8rem; padding: .35rem;
}
.mobile-nav a:hover { color: var(--text); }
@media (min-width: 900px) {
  .mobile-nav { display: none; }
  body { padding-bottom: 0; }
  .site-footer { padding-bottom: 2rem; }
  #toast-root { bottom: 1.5rem; }
}

.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.auth-card {
  width: min(100%, 24rem); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 1.75rem; box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.auth-form { display: grid; gap: .9rem; margin: 1.25rem 0; }
.auth-form label { display: grid; gap: .35rem; color: var(--text-muted); font-size: .9rem; }
.auth-form input {
  width: 100%; padding: .7rem .85rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.form-error {
  background: rgba(255,92,108,.12); border: 1px solid rgba(255,92,108,.35);
  color: var(--danger); padding: .7rem .85rem; border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important; transition: none !important; scroll-behavior: auto !important;
  }
}
