:root {
  --bg: #0b0d14;
  --bg-elevated: #131623;
  --bg-card: #171b2b;
  --border: #262c42;
  --text: #eef0f8;
  --text-dim: #9aa0b8;
  --text-faint: #656b85;
  --accent: #ff3d68;
  --accent-2: #7c5cff;
  --accent-gradient: linear-gradient(135deg, #ff3d68 0%, #7c5cff 100%);
  --success: #35d488;
  --warning: #ffb547;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Poppins", "Segoe UI", system-ui, -apple-system, sans-serif;
  --nav-h: 64px;
  --bottom-nav-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(var(--bottom-nav-h) + 12px);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Top Nav ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: rgba(11, 13, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topnav .container { display: flex; align-items: center; gap: 20px; width: 100%; }
.brand { font-weight: 800; font-size: 1.4rem; letter-spacing: -0.02em; }
.brand span { background: var(--accent-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav-links { display: none; gap: 18px; align-items: center; }
.nav-links a { color: var(--text-dim); font-size: 0.92rem; font-weight: 500; }
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-search {
  flex: 1;
  max-width: 420px;
  display: none;
}
.nav-search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.88rem;
}
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  font-size: 0.88rem;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent-gradient); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (min-width: 900px) {
  .nav-links { display: flex; }
  .nav-search { display: block; }
  body { padding-bottom: 0; }
  .bottom-nav { display: none; }
}

/* ---------- Bottom mobile nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.65rem;
  color: var(--text-faint);
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav svg { width: 20px; height: 20px; }

/* ---------- Hero ---------- */
.hero {
  padding: 32px 0 24px;
}
.hero h1 { font-size: 1.8rem; margin: 0 0 6px; letter-spacing: -0.02em; }
.hero p { color: var(--text-dim); margin: 0 0 18px; font-size: 0.95rem; }
.hero-search { position: relative; max-width: 560px; }
.hero-search input {
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
}
.random-cta {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

@media (min-width: 700px) {
  .hero h1 { font-size: 2.4rem; }
}

/* ---------- Section headers ---------- */
.section { padding: 22px 0; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h2 { font-size: 1.15rem; margin: 0; }
.section-head a { font-size: 0.8rem; color: var(--accent); font-weight: 600; }

/* ---------- Rails / grids ---------- */
.rail {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 6px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail .anime-card { flex: 0 0 145px; scroll-snap-align: start; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(6, 1fr); } }

/* ---------- Anime card ---------- */
.anime-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.anime-card:hover { transform: translateY(-4px); border-color: var(--accent); }
.anime-card .poster-wrap { position: relative; aspect-ratio: 2/3; background: var(--bg-elevated); overflow: hidden; }
.anime-card img { width: 100%; height: 100%; object-fit: cover; }
.anime-card .score-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(11,13,20,0.85);
  color: var(--warning);
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 7px; border-radius: 999px;
}
.anime-card .card-body { padding: 10px 10px 12px; }
.anime-card .card-title {
  font-size: 0.82rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 2.2em;
}
.anime-card .card-meta { font-size: 0.7rem; color: var(--text-faint); margin-top: 4px; }

/* ---------- Skeletons ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 37%, var(--bg-card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-card { aspect-ratio: 2/3.55; }

/* ---------- Empty / error states ---------- */
.state-box {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.state-box h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- Genre chips ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.chip.active, .chip:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Detail page ---------- */
.detail-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 24px 0;
}
@media (min-width: 780px) { .detail-hero { grid-template-columns: 260px 1fr; } }
.detail-poster { border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); }
.detail-title { font-size: 1.6rem; margin: 0 0 2px; }
.detail-title-jp { color: var(--text-faint); font-size: 0.9rem; margin-bottom: 10px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.tag { padding: 4px 11px; border-radius: 999px; background: var(--bg-card); border: 1px solid var(--border); font-size: 0.75rem; color: var(--text-dim); }
.meta-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 20px; font-size: 0.85rem; margin: 16px 0; }
.meta-list dt { color: var(--text-faint); }
.meta-list dd { margin: 0; font-weight: 600; }
.synopsis { color: var(--text-dim); font-size: 0.9rem; max-width: 70ch; }

.watchlist-controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
.status-select {
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text); font-size: 0.85rem; font-weight: 600;
}

.rating-widget { display: flex; align-items: center; gap: 6px; margin: 14px 0; }
.star { font-size: 1.3rem; color: var(--text-faint); cursor: pointer; }
.star.filled { color: var(--warning); }

/* ---------- Where to watch ---------- */
.wtw-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.wtw-country { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 0.85rem; }
.wtw-country select { padding: 6px 10px; border-radius: var(--radius-sm); background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text); }
.wtw-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  gap: 10px;
}
.wtw-row:last-child { border-bottom: none; }
.wtw-service { display: flex; align-items: center; gap: 10px; }
.wtw-badge { font-size: 0.68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.wtw-badge.free { background: rgba(53,212,136,0.15); color: var(--success); }
.wtw-badge.cheapest { background: rgba(255,181,71,0.15); color: var(--warning); }
.wtw-price { font-size: 0.8rem; color: var(--text-dim); }
.wtw-checked { font-size: 0.72rem; color: var(--text-faint); margin-top: 12px; }

/* ---------- Recap cards ---------- */
.recap-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md);
  overflow: hidden; flex: 0 0 260px; scroll-snap-align: start;
}
.recap-card .thumb { aspect-ratio: 16/9; background: var(--bg-elevated); overflow: hidden; }
.recap-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.recap-card .recap-body { padding: 12px 14px; }
.recap-card h4 { font-size: 0.88rem; margin: 0 0 4px; }
.recap-card p { font-size: 0.75rem; color: var(--text-dim); margin: 0 0 10px; }

/* ---------- Forms ---------- */
.auth-page { min-height: calc(100vh - var(--nav-h)); display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 30px; width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.4rem; margin: 0 0 4px; }
.auth-card p.sub { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 22px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); font-size: 0.9rem;
}
.form-error { color: var(--accent); font-size: 0.82rem; margin-bottom: 12px; min-height: 1em; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-dim); }
.auth-switch a { color: var(--accent); font-weight: 600; }

/* ---------- Watchlist / profile ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 18px; }
.tab-btn {
  padding: 8px 16px; border-radius: 999px; background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.82rem; font-weight: 600; white-space: nowrap;
}
.tab-btn.active { background: var(--accent-gradient); color: #fff; border-color: transparent; }
.wl-row {
  display: flex; gap: 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px; margin-bottom: 10px; align-items: center;
}
.wl-row img { width: 56px; height: 78px; object-fit: cover; border-radius: var(--radius-sm); }
.wl-row .wl-info { flex: 1; min-width: 0; }
.wl-row .wl-info h4 { margin: 0 0 4px; font-size: 0.88rem; }
.wl-row .wl-meta { font-size: 0.72rem; color: var(--text-faint); }
.wl-row .wl-actions { display: flex; gap: 6px; align-items: center; }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 999px; font-size: 0.82rem; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: all 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
@media (min-width: 900px) { #toast-root { bottom: 24px; } }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--border); padding: 30px 0 50px; color: var(--text-faint); font-size: 0.8rem; }
footer a { color: var(--text-dim); }

/* ---------- Ad slots ---------- */
.ad-slot {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 0.75rem;
  margin: 18px 0;
}

/* ===== Enhanced Where to Watch ===== */
.wtw-intro { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:16px; }
.wtw-intro-text { color:var(--text-dim); font-size:.82rem; margin-top:4px; }
.wtw-results-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin:4px 0 12px; font-size:.85rem; }
.wtw-results-head span { display:block; color:var(--text-faint); font-size:.72rem; margin-top:2px; }
.wtw-online { color:var(--success)!important; white-space:nowrap; font-size:.75rem!important; margin:0!important; }
.wtw-list { display:grid; gap:10px; }
.wtw-card { display:grid; grid-template-columns:32px minmax(0,1fr) auto auto; align-items:center; gap:12px; padding:13px; border:1px solid var(--border); border-radius:var(--radius-md); background:var(--bg-elevated); }
.wtw-card.is-best { border-color:var(--success); }
.wtw-rank { width:28px; height:28px; display:grid; place-items:center; border-radius:50%; background:var(--bg-card); color:var(--text-dim); font-size:.75rem; font-weight:700; }
.wtw-service-title { display:flex; align-items:center; flex-wrap:wrap; gap:7px; }
.wtw-details { display:flex; flex-wrap:wrap; gap:5px; color:var(--text-faint); font-size:.72rem; margin-top:4px; }
.wtw-price-box { min-width:105px; text-align:right; }
.wtw-price { display:block; font-size:.9rem; font-weight:700; color:var(--text); }
.wtw-price-box small { color:var(--text-faint); font-size:.65rem; }
.wtw-badge.best { background:rgba(53,212,136,.15); color:var(--success); }
.wtw-empty { color:var(--text-dim); font-size:.85rem; padding:10px 0; }
.wtw-elsewhere { color:var(--text-faint); font-size:.78rem; margin:8px 0 0; }
.wtw-loading { display:grid; gap:8px; }
.wtw-loading p { color:var(--text-faint); font-size:.78rem; margin:2px 0; }
@media (max-width: 620px) {
  .wtw-intro { align-items:flex-start; flex-direction:column; }
  .wtw-intro .btn { width:100%; }
  .wtw-card { grid-template-columns:28px minmax(0,1fr); }
  .wtw-price-box { grid-column:2; text-align:left; min-width:0; }
  .wtw-card > .btn { grid-column:2; justify-self:start; }
  .wtw-results-head { align-items:flex-start; flex-direction:column; }
}
