/* =====================================================================
   MovieDB.wiki — app.css
   All component styles. IMDB-inspired, responsive, large-touch targets.
   ===================================================================== */

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: 0.7em 1.3em; border-radius: var(--radius-md);
    font-size: var(--text-sm); font-weight: 600; line-height: 1;
    border: 2px solid transparent; cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
    min-height: 44px; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn svg { flex: none; }
.btn-primary { background: var(--yellow); color: var(--text-inverse); }
.btn-primary:hover { background: var(--yellow-hover); color: var(--text-inverse); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--yellow); color: var(--yellow); }
.btn-ghost { background: rgba(255,255,255,.08); color: var(--text); }
.btn-ghost:hover { background: rgba(255,255,255,.16); }
.btn-lg { padding: 0.9em 1.6em; font-size: var(--text-base); min-height: 52px; }
.btn-sm { padding: 0.5em 0.9em; font-size: var(--text-xs); min-height: 36px; }
.btn.danger { color: var(--error); border-color: transparent; }
.btn.danger:hover { background: rgba(229,9,20,.15); }

/* ---------- Layout containers ---------- */
.page-container { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--space-6) var(--space-12); }
.section-title { font-size: var(--text-lg); margin-bottom: var(--space-4); }
.page-title { font-size: var(--text-xl); margin-bottom: var(--space-2); }

/* ---------- Header / Nav ---------- */
.site-header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(0,0,0,.92); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.header-inner {
    max-width: var(--content-max); margin: 0 auto; padding: 0 var(--space-4);
    height: var(--header-h); display: flex; align-items: center; gap: var(--space-4);
}
.brand { display: inline-flex; align-items: center; gap: var(--space-2); flex: none; }
.brand-badge {
    display: inline-grid; place-items: center;
    width: 36px; height: 30px; border-radius: var(--radius-sm);
    background: var(--yellow); color: var(--text-inverse);
    font-weight: 700; line-height: 1; overflow: hidden;
}
.brand-badge svg { width: 22px; height: 22px; }
/* When the user sets a custom logo image in Settings, app.js adds a bg image. */
.brand-badge.has-logo svg { display: none; }
.brand-badge.has-logo { background-size: contain; background-position: center; background-repeat: no-repeat; background-color: var(--yellow); }
.brand-badge.small { width: 30px; height: 26px; }
.brand-badge.small svg { width: 18px; height: 18px; }
.brand-text { font-weight: 700; font-size: var(--text-lg); letter-spacing: -.01em; }
.brand-text.small { font-size: var(--text-base); }

.primary-nav { display: flex; align-items: center; gap: var(--space-1); flex: none; }
.nav-link {
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 0.55em 0.9em; border-radius: var(--radius-md);
    font-size: var(--text-sm); font-weight: 500; color: var(--text-muted);
    min-height: 40px;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,.07); }
.nav-link.is-active { color: var(--yellow); }
.nav-link-icon { position: relative; }
.watchlist-count {
    background: var(--yellow); color: var(--text-inverse);
    font-size: 0.7rem; font-weight: 700; min-width: 18px; height: 18px;
    border-radius: var(--radius-full); padding: 0 5px;
    display: inline-grid; place-items: center;
}
.watchlist-count[data-count="0"] { display: none; }

/* Search — constrained so it never overflows the header. */
.search-form {
    flex: 1 1 auto; min-width: 0; max-width: 340px; margin: 0 auto;
    display: flex; align-items: center; gap: var(--space-2);
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-full); padding: 0.35em 0.35em 0.35em 0.9em;
    transition: border-color var(--transition), box-shadow var(--transition);
    overflow: hidden;
}
.search-form:focus-within { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(245,197,24,.25); }
.search-icon { color: var(--text-faint); flex: none; }
.search-input {
    flex: 1 1 auto; min-width: 0; border: none; background: transparent; outline: none;
    font-size: var(--text-sm); color: var(--text);
}
.search-input::placeholder { color: var(--text-faint); }
.search-submit {
    background: var(--yellow); color: var(--text-inverse);
    border-radius: var(--radius-full); padding: 0.4em 0.9em; font-weight: 600;
    font-size: var(--text-xs); flex: none; opacity: 0; width: 0; overflow: hidden; white-space: nowrap;
    transition: opacity var(--transition), width var(--transition), padding var(--transition);
}
.search-form:focus-within .search-submit,
.search-form.is-expanded .search-submit { opacity: 1; width: auto; padding: 0.4em 0.9em; }

/* User avatar */
.user-menu { position: relative; flex: none; }
.avatar-btn {
    width: 40px; height: 40px; border-radius: var(--radius-full);
    overflow: hidden; border: 2px solid var(--border);
    transition: border-color var(--transition);
}
.avatar-btn:hover, .avatar-btn[aria-expanded="true"] { border-color: var(--yellow); }
.avatar-img { width: 100%; height: 100%; object-fit: cover; }
.user-dropdown {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: var(--space-2);
    min-width: 240px; box-shadow: var(--shadow-lg); z-index: 120;
}
.user-dropdown[hidden] { display: none; }
.user-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.user-card-avatar { border-radius: var(--radius-full); border: 2px solid var(--yellow); }
.user-name { font-weight: 700; font-size: var(--text-sm); }
.user-id { font-size: var(--text-xs); color: var(--text-faint); }
.dropdown-link {
    display: flex; align-items: center; gap: var(--space-2);
    padding: 0.7em 0.9em; border-radius: var(--radius-md);
    color: var(--text-muted); font-size: var(--text-sm);
}
.dropdown-link:hover { background: rgba(255,255,255,.07); color: var(--text); }
.dropdown-link svg { color: var(--text-faint); }

/* Nav toggle (mobile) */
.nav-toggle {
    display: none; width: 44px; height: 44px; flex-direction: column;
    justify-content: center; gap: 5px; align-items: center;
}
.nav-toggle span { width: 24px; height: 3px; background: var(--text); border-radius: 2px; transition: transform var(--transition), opacity var(--transition); }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* ---------- Main ---------- */
.site-main { min-height: 50vh; }

/* ---------- Hero carousel ---------- */
.hero-carousel {
    position: relative; width: 100%; height: clamp(420px, 62vh, 720px);
    overflow: hidden; background: var(--surface);
}
.hero-track { display: flex; height: 100%; scroll-behavior: smooth; scroll-snap-type: x mandatory; overflow-x: auto; }
.hero-track::-webkit-scrollbar { display: none; }
.hero-slide {
    flex: 0 0 100%; position: relative; scroll-snap-align: start;
    display: flex; align-items: flex-end;
}
.hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.hero-overlay {
    position: absolute; inset: 0; z-index: 1;
    background: linear-gradient(90deg, rgba(0,0,0,.92) 0%, rgba(0,0,0,.55) 45%, rgba(0,0,0,.2) 100%),
                linear-gradient(0deg, rgba(0,0,0,.95) 5%, rgba(0,0,0,0) 40%);
}
.hero-content { position: relative; z-index: 2; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 0 84px var(--space-12); }
.hero-logo { max-width: min(420px, 60%); margin-bottom: var(--space-3); filter: drop-shadow(0 4px 20px rgba(0,0,0,.6)); }
.hero-title { font-size: var(--text-2xl); margin-bottom: var(--space-3); }
.hero-rating { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--yellow); font-weight: 700; margin-bottom: var(--space-3); }
.hero-overview { max-width: 640px; color: var(--text-muted); margin-bottom: var(--space-5); font-size: var(--text-sm); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.hero-nav {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
    width: 56px; height: 56px; background: rgba(0,0,0,.5); color: var(--text);
    font-size: 2rem; font-weight: 700; border-radius: var(--radius-full);
    display: grid; place-items: center; border: 1px solid var(--border);
}
.hero-nav:hover { background: rgba(0,0,0,.8); color: var(--yellow); }
.hero-nav.prev { left: var(--space-3); }
.hero-nav.next { right: var(--space-3); }
.hero-dots { position: absolute; bottom: var(--space-4); left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: var(--space-2); }
.hero-dot { width: 10px; height: 10px; border-radius: var(--radius-full); background: rgba(255,255,255,.4); }
.hero-dot.is-active { background: var(--yellow); width: 28px; }

/* ---------- Slider rows ---------- */
.slider-row { margin: var(--space-10) 0; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); padding: 0 var(--space-6); max-width: var(--content-max); margin-left: auto; margin-right: auto; }
.slider-title { font-size: var(--text-lg); }
.view-all { font-size: var(--text-sm); font-weight: 600; color: var(--yellow); white-space: nowrap; flex: none; }
.view-all:hover { color: var(--yellow-hover); }
.slider-viewport { position: relative; }
.slider-track {
    display: flex; gap: var(--space-3); overflow-x: auto; scroll-behavior: smooth;
    padding: var(--space-2) var(--space-6) var(--space-2); scroll-snap-type: x proximity;
    scrollbar-width: none; -ms-overflow-style: none;
}
.slider-track::-webkit-scrollbar { display: none; height: 0; }
.slider-item { flex: 0 0 auto; width: clamp(150px, 18vw, 200px); scroll-snap-align: start; }
.slider-nav {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 6;
    width: 48px; height: 48px; border-radius: var(--radius-full);
    background: rgba(20,20,20,.92); border: 1px solid var(--border);
    color: var(--text); font-size: 1.7rem; font-weight: 700; line-height: 1;
    display: none; place-items: center;
}
.slider-nav:hover { background: var(--yellow); color: var(--text-inverse); border-color: var(--yellow); }
.slider-nav.prev { left: var(--space-2); }
.slider-nav.next { right: var(--space-2); }
.slider-viewport:hover .slider-nav { display: grid; }
.slider-viewport:hover .slider-nav[hidden] { display: none; }

/* ---------- Poster card ---------- */
.poster-card {
    position: relative; width: 100%; background: var(--surface);
    border-radius: var(--radius-md); overflow: hidden; transition: transform var(--transition);
}
.poster-card:hover { transform: translateY(-4px); }
.poster-link { display: block; }
.poster-media { position: relative; aspect-ratio: 2 / 3; background: var(--surface-2); overflow: hidden; }
.poster-img { width: 100%; height: 100%; object-fit: cover; }
.poster-hover {
    position: absolute; inset: 0; display: grid; place-items: center;
    background: rgba(0,0,0,.4); color: var(--text); opacity: 0; transition: opacity var(--transition);
}
.poster-card:hover .poster-hover { opacity: 1; }
.poster-hover svg { width: 44px; height: 44px; filter: drop-shadow(0 2px 8px rgba(0,0,0,.6)); }
.poster-watchlist-btn {
    position: absolute; top: var(--space-2); right: var(--space-2);
    width: 38px; height: 38px; border-radius: var(--radius-full);
    background: rgba(0,0,0,.6); color: var(--text); display: grid; place-items: center;
    backdrop-filter: blur(4px); transition: background var(--transition), color var(--transition), transform var(--transition);
}
.poster-watchlist-btn:hover { background: var(--yellow); color: var(--text-inverse); transform: scale(1.08); }
.poster-watchlist-btn svg { fill: none; stroke: currentColor; stroke-width: 2; transition: fill var(--transition); }
/* Bookmarked: solid yellow circle with a filled bookmark icon. */
.poster-watchlist-btn.is-on { background: var(--yellow); color: var(--text-inverse); }
.poster-watchlist-btn.is-on svg { fill: currentColor; stroke: none; }
.poster-remove-btn {
    position: absolute; top: calc(var(--space-2) + 42px); right: var(--space-2);
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: rgba(0,0,0,.6); color: var(--text); display: none; place-items: center;
    backdrop-filter: blur(4px); transition: background var(--transition), color var(--transition);
}
.poster-card:hover .poster-remove-btn { display: grid; }
.poster-remove-btn.hist-remove { display: grid; }
.poster-remove-btn:hover { background: var(--error); color: var(--text); }
.poster-watched {
    position: absolute; top: var(--space-2); left: var(--space-2);
    width: 30px; height: 30px; border-radius: var(--radius-full);
    background: var(--success); color: var(--text-inverse); display: grid; place-items: center;
}
.poster-watched[hidden] { display: none; }
.poster-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.5); }
.poster-progress i { display: block; height: 100%; width: var(--p,0%); background: var(--yellow); }
.poster-info { padding: var(--space-3); height: 78px; display: flex; flex-direction: column; gap: var(--space-1); overflow: hidden; }
.poster-title {
    height: 22px; line-height: 22px; flex: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 600; font-size: var(--text-sm); color: var(--text);
}
.poster-title:hover { color: var(--yellow); }
.poster-meta { flex: none; display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.poster-meta .rating { display: inline-flex; align-items: center; gap: 3px; color: var(--yellow); font-weight: 600; }
.poster-sub { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-1); }

/* Rank badge (top 5 numbered) */
.rank-badge {
    position: absolute; left: -8px; top: -8px; z-index: 4;
    font-size: clamp(3.5rem, 8vw, 6rem); font-weight: 900;
    line-height: 1; color: transparent;
    -webkit-text-stroke: 3px var(--text-faint);
    font-family: 'Inter', sans-serif;
}

/* ---------- Poster grid ---------- */
.poster-grid {
    display: grid; gap: var(--space-4);
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 700px) { .poster-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }

/* ---------- Listing layout ---------- */
.listing-layout { display: grid; grid-template-columns: 1fr; gap: var(--space-6); max-width: var(--content-max); margin: 0 auto; padding: var(--space-6); }
@media (min-width: 1024px) { .listing-layout { grid-template-columns: 260px 1fr; } }
.listing-main { min-width: 0; background: var(--bg); border-radius: var(--radius-lg); }
.filters-sidebar {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: var(--space-4);
    height: fit-content; position: sticky; top: calc(var(--header-h) + var(--space-4));
}
/* On mobile the layout stacks to a single column. The sticky sidebar must
   become static so the results + pagination scroll normally underneath it
   instead of being overlapped (which also hid the pagination and let the
   transparent results show the filters through). Placed AFTER the base rule
   so it wins the cascade at narrow widths. */
@media (max-width: 1023px) {
    .filters-sidebar { position: static; height: auto; top: auto; }
}
.filter-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.filter-title { font-size: var(--text-base); }
.filter-reset { font-size: var(--text-xs); color: var(--yellow); }
.filter-group { border-top: 1px solid var(--divider); padding: var(--space-4) 0; }
.filter-group legend { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: var(--space-2); }
.filter-select {
    width: 100%; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 0.6em 0.8em; font-size: var(--text-sm); color: var(--text);
}
.genre-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.genre-chip {
    display: inline-flex; align-items: center; gap: var(--space-1);
    padding: 0.4em 0.7em; border-radius: var(--radius-full);
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: var(--text-xs); cursor: pointer; transition: all var(--transition);
}
.genre-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.genre-chip.is-on { background: var(--yellow); color: var(--text-inverse); border-color: var(--yellow); }
.range-row { display: flex; align-items: center; gap: var(--space-2); }
.range-row input { width: 0; flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.5em; color: var(--text); }
.switch-row { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.switch-inline { display: inline-flex; align-items: center; gap: var(--space-2); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--yellow); }
.filter-apply { width: 100%; margin-top: var(--space-4); }
.listing-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--space-4); flex-wrap: wrap; gap: var(--space-2); }
.listing-count { color: var(--text-muted); font-size: var(--text-sm); }
.results-count { color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-4); }

/* ---------- Pagination ---------- */
.pagination { display: flex; justify-content: center; align-items: center; gap: var(--space-1); margin-top: var(--space-8); flex-wrap: wrap; }
.page-link {
    min-width: 44px; height: 44px; padding: 0 0.7em; display: grid; place-items: center;
    border-radius: var(--radius-md); background: var(--surface-2); border: 1px solid var(--border);
    font-size: var(--text-sm); font-weight: 600;
}
.page-link:hover { border-color: var(--yellow); color: var(--yellow); }
.page-link.is-active { background: var(--yellow); color: var(--text-inverse); border-color: var(--yellow); }
.page-link.is-disabled { opacity: .4; pointer-events: none; }
.page-ellipsis { color: var(--text-faint); padding: 0 var(--space-2); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--space-16) var(--space-4); color: var(--text-muted); }
.empty-state svg { margin: 0 auto var(--space-4); color: var(--text-faint); }
.empty-state h2 { font-size: var(--text-lg); margin-bottom: var(--space-2); color: var(--text); }

/* ---------- Detail page ---------- */
.detail-hero {
    position: relative; min-height: clamp(480px, 70vh, 680px);
    background-image: linear-gradient(180deg, rgba(0,0,0,.6), rgba(0,0,0,.95)), var(--bg);
    background-size: cover; background-position: center;
    display: flex; align-items: flex-end;
}
.detail-hero-overlay { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.85), rgba(0,0,0,.3) 70%); }
.detail-hero-inner { position: relative; z-index: 2; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-12) var(--space-6) var(--space-8); display: flex; gap: var(--space-8); }
.detail-poster-col { flex: none; }
.detail-poster { width: clamp(180px, 22vw, 280px); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.detail-info-col { flex: 1 1 auto; min-width: 0; }
.detail-logo { max-width: min(480px, 70%); margin-bottom: var(--space-4); filter: drop-shadow(0 4px 16px rgba(0,0,0,.6)); }
.detail-title { font-size: var(--text-2xl); }
.detail-year { color: var(--text-muted); font-weight: 500; }
.detail-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-4) 0; }
.detail-rating { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--yellow); font-weight: 700; }
.meta-pill { background: var(--surface-3); padding: 0.3em 0.8em; border-radius: var(--radius-full); font-size: var(--text-xs); color: var(--text-muted); }
.detail-genres { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.genre-tag { padding: 0.3em 0.9em; border-radius: var(--radius-full); background: rgba(255,255,255,.08); font-size: var(--text-xs); }
.genre-tag:hover { background: var(--yellow); color: var(--text-inverse); }
.detail-tagline { font-style: italic; color: var(--text-muted); margin-bottom: var(--space-3); }
.detail-overview { max-width: 720px; color: var(--text-muted); margin-bottom: var(--space-5); }
.detail-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.watchlist-add.is-on { background: var(--yellow); color: var(--text-inverse); border-color: var(--yellow); }
.watchlist-add.is-on .btn-label::before { content: "In watchlist"; }
.watchlist-add.is-on .btn-label { font-size: 0; }
.watchlist-add.is-on .btn-label::before { font-size: var(--text-sm); }

.detail-body { display: grid; grid-template-columns: 1fr; gap: var(--space-8); max-width: var(--content-max); margin: var(--space-8) auto; padding: 0 var(--space-6); }
@media (min-width: 1024px) { .detail-body { grid-template-columns: 1fr 320px; } }
.detail-main { min-width: 0; }

/* Episodes */
.episodes-section { margin-bottom: var(--space-10); }
.episodes-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); flex-wrap: wrap; }
.season-picker .filter-select { min-width: 220px; }
.episode-list { display: flex; flex-direction: column; gap: var(--space-3); }
.episode-loading, .episode-empty { padding: var(--space-8); text-align: center; color: var(--text-muted); }
.ep-card {
    display: flex; gap: var(--space-4); background: var(--surface);
    border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border);
    transition: border-color var(--transition);
}
.ep-card:hover { border-color: var(--yellow); }
.ep-card.is-watched { border-color: var(--success); }
.ep-thumb { position: relative; width: clamp(140px, 30%, 220px); aspect-ratio: 16/9; flex: none; background: var(--surface-2); overflow: hidden; }
.ep-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ep-play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.3); color: var(--text); opacity: 0; transition: opacity var(--transition); }
.ep-card:hover .ep-play { opacity: 1; }
.ep-watched-mark { position: absolute; top: var(--space-2); right: var(--space-2); width: 26px; height: 26px; border-radius: var(--radius-full); background: var(--success); color: var(--text-inverse); display: grid; place-items: center; }
.ep-watched-mark[hidden] { display: none; }
.ep-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.5); }
.ep-progress i { display: block; height: 100%; background: var(--yellow); }
.ep-info { flex: 1; padding: var(--space-3); min-width: 0; }
.ep-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.ep-num { font-weight: 700; font-size: var(--text-sm); }
.ep-name { font-size: var(--text-sm); color: var(--text); }
.ep-overview { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-3); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep-air { font-size: var(--text-xs); color: var(--text-faint); }
.ep-actions { display: flex; gap: var(--space-2); align-items: center; }
.ep-continue { font-size: var(--text-xs); color: var(--yellow); }

/* Cast */
.cast-section, .reviews-section { margin-bottom: var(--space-10); }
.cast-row { display: flex; gap: var(--space-4); overflow-x: auto; padding-bottom: var(--space-2); scroll-behavior: smooth; }
.cast-row::-webkit-scrollbar { height: 6px; }
.cast-row::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--radius-full); }
.cast-card { flex: 0 0 auto; width: 110px; }
.cast-photo { width: 110px; height: 165px; border-radius: var(--radius-md); overflow: hidden; background: var(--surface-2); margin-bottom: var(--space-2); }
.cast-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-md); }
.cast-name { font-size: var(--text-xs); font-weight: 600; }
.cast-char { font-size: var(--text-xs); color: var(--text-faint); }

/* Reviews */
.reviews-list { display: grid; gap: var(--space-4); }
.review-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); }
.review-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-2); }
.review-author { font-weight: 700; font-size: var(--text-sm); }
.review-rating { color: var(--yellow); font-weight: 700; font-size: var(--text-xs); }
.review-text { color: var(--text-muted); font-size: var(--text-sm); }

/* Detail aside */
.facts-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-4); }
.fact { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--divider); }
.fact:first-child { border-top: none; }
.fact-label { color: var(--text-muted); font-size: var(--text-xs); }
.fact-value { font-size: var(--text-xs); text-align: right; }
.trailer-preview { position: relative; border-radius: var(--radius-lg); overflow: hidden; cursor: pointer; }
.trailer-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; filter: brightness(.7); }
.trailer-play { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text); }
.trailer-label { position: absolute; bottom: var(--space-3); left: var(--space-3); font-weight: 600; font-size: var(--text-sm); }

/* Trailer modal */
.trailer-modal { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.9); display: grid; place-items: center; padding: var(--space-4); }
.trailer-modal[hidden] { display: none; }
.trailer-modal-inner { position: relative; width: min(960px, 100%); aspect-ratio: 16/9; background: #000; border-radius: var(--radius-lg); overflow: hidden; }
.trailer-embed { width: 100%; height: 100%; }
.trailer-embed iframe { width: 100%; height: 100%; border: 0; }
.trailer-close { position: absolute; top: -16px; right: -8px; width: 44px; height: 44px; border-radius: var(--radius-full); background: var(--yellow); color: var(--text-inverse); font-size: 1.6rem; display: grid; place-items: center; z-index: 2; }

/* ---------- Watch page ---------- */
.watch-page { max-width: 1600px; margin: 0 auto; padding: var(--space-4) var(--space-4) var(--space-12); }
.player-wrap { background: #000; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); }
.player-frame { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; }
.player-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-empty { display: grid; place-items: center; height: 100%; color: var(--text-muted); text-align: center; padding: var(--space-8); }
.next-ep-btn {
    position: absolute; right: var(--space-4); bottom: var(--space-4); z-index: 5;
    display: inline-flex; align-items: center; gap: var(--space-2);
    background: var(--yellow); color: var(--text-inverse); padding: 0.8em 1.4em;
    border-radius: var(--radius-md); font-weight: 700; font-size: var(--text-sm);
    box-shadow: var(--shadow-lg); animation: pulse-next 2s infinite;
}
.next-ep-btn[hidden] { display: none; }
@keyframes pulse-next { 0%,100% { box-shadow: 0 0 0 0 rgba(245,197,24,.5); } 50% { box-shadow: 0 0 0 12px rgba(245,197,24,0); } }

/* ---- Next-episode countdown overlay ---- */
.next-countdown {
    position: absolute; right: var(--space-4); bottom: var(--space-4); z-index: 8;
}
.next-countdown[hidden] { display: none; }
.next-countdown .nc-card {
    display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5);
    background: rgba(0,0,0,.85); border: 1px solid var(--border); border-radius: var(--radius-lg);
    color: var(--text); box-shadow: var(--shadow-lg); cursor: pointer; backdrop-filter: blur(6px);
}
.next-countdown .nc-card:hover { background: rgba(0,0,0,.95); }
.next-countdown .nc-ring { color: var(--yellow); flex: none; }
.next-countdown .nc-label { display: flex; flex-direction: column; line-height: 1.2; font-size: var(--text-sm); }
.next-countdown .nc-seconds { font-size: 1.6rem; font-weight: 800; color: var(--yellow); }
.next-countdown .nc-cancel { font-size: var(--text-xs); color: var(--text-faint); margin-left: var(--space-2); }

.source-bar { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-3) var(--space-4); background: var(--surface); flex-wrap: wrap; }
.source-label { font-weight: 600; font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; }
.source-settings-link { margin-left: auto; font-size: var(--text-sm); color: var(--yellow); font-weight: 600; white-space: nowrap; }
.source-settings-link:hover { color: var(--yellow-hover); }
.next-ep-bar-btn { display: inline-flex; align-items: center; gap: var(--space-1); margin-left: auto; padding: 0.5em 0.9em; border-radius: var(--radius-md); background: var(--yellow); color: var(--text-inverse); font-weight: 700; font-size: var(--text-sm); white-space: nowrap; }
.next-ep-bar-btn[hidden] { display: none; }
.next-ep-bar-btn:hover { background: var(--yellow-hover); color: var(--text-inverse); }

/* ---------- Share bar ---------- */
.share-bar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-5) 0; padding-top: var(--space-4); border-top: 1px solid var(--divider); }
.share-label { font-weight: 600; font-size: var(--text-sm); color: var(--text-muted); margin-right: var(--space-1); }
.share-icon { width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-muted); transition: all var(--transition); }
.share-icon:hover { background: var(--yellow); color: var(--text-inverse); border-color: var(--yellow); transform: translateY(-2px); }
.share-icon.copy-link.copied { background: var(--success); color: var(--text-inverse); border-color: var(--success); }
.source-dropdown { position: relative; }
.source-toggle {
    display: inline-flex; align-items: center; gap: var(--space-2);
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 0.6em 1em; font-weight: 600; font-size: var(--text-sm); min-height: 44px;
}
.source-toggle:hover { border-color: var(--yellow); }
.source-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 280px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-2); box-shadow: var(--shadow-lg); z-index: 50; max-height: 360px; overflow-y: auto; }
.source-menu[hidden] { display: none; }
.source-option { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); width: 100%; padding: 0.7em 0.8em; border-radius: var(--radius-md); text-align: left; }
.source-option:hover { background: rgba(255,255,255,.08); }
.source-option.is-active { background: rgba(245,197,24,.15); }
.source-name { font-weight: 600; font-size: var(--text-sm); }
.source-badges { display: flex; gap: var(--space-1); flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 0.2em 0.5em; border-radius: var(--radius-full); white-space: nowrap; }
.badge-best-sync { background: var(--success); color: var(--text-inverse); }
.badge-skip-intro { background: var(--info); color: var(--text-inverse); }
.badge-no-ads { background: var(--yellow); color: var(--text-inverse); }
.badge-alternative { background: var(--info); color: var(--text-inverse); }
.badge-ads { background: var(--error); color: var(--text-inverse); }
.player-meta { flex: 1; min-width: 0; }
.player-title { font-size: var(--text-lg); }
.ep-tag { color: var(--yellow); font-size: var(--text-sm); margin-left: var(--space-2); }

.watch-body { display: grid; grid-template-columns: 1fr; gap: var(--space-8); margin-top: var(--space-6); }
@media (min-width: 1024px) { .watch-body { grid-template-columns: 1fr 340px; } }
.watch-header { display: flex; gap: var(--space-4); align-items: flex-start; }
.watch-poster { width: 100px; border-radius: var(--radius-md); flex: none; }
.watch-h1 { font-size: var(--text-xl); }
.watch-sub { display: flex; gap: var(--space-3); color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--space-2); flex-wrap: wrap; }
.back-link { color: var(--yellow); }
.watch-overview { color: var(--text-muted); margin-top: var(--space-4); }
.watch-episodes { margin-top: var(--space-8); }
.ep-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.view-more-seasons { font-size: var(--text-sm); font-weight: 600; color: var(--yellow); white-space: nowrap; }
.view-more-seasons:hover { color: var(--yellow-hover); }
.watch-ep-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); }
.watch-ep { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); transition: border-color var(--transition); }
.watch-ep:hover { border-color: var(--yellow); }
.watch-ep.is-current { border-color: var(--yellow); }
.watch-ep-thumb { position: relative; aspect-ratio: 16/9; background: var(--surface-2); }
.watch-ep-thumb img { width: 100%; height: 100%; object-fit: cover; }
.watch-ep-play { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text); background: rgba(0,0,0,.35); opacity: 0; transition: opacity var(--transition); }
.watch-ep:hover .watch-ep-play { opacity: 1; }
.watch-ep-info { padding: var(--space-2) var(--space-3) var(--space-3); }
.watch-ep-num { font-size: var(--text-xs); color: var(--text-faint); }
.watch-ep-name { font-size: var(--text-sm); font-weight: 600; }
.watch-ep-air { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-1); }
.watch-aside { display: flex; flex-direction: column; gap: var(--space-4); }
.watch-backdrop { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--radius-lg); }
.next-ep-card { display: flex; flex-direction: column; gap: var(--space-1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); }
.next-ep-label { font-size: var(--text-xs); color: var(--yellow); font-weight: 700; text-transform: uppercase; }
.next-ep-title { font-weight: 700; }
.next-ep-go { color: var(--yellow); font-size: var(--text-sm); }

/* ---------- Watchlist ---------- */
.watchlist-page { max-width: var(--content-max); margin: 0 auto; padding: var(--space-6) var(--space-6) var(--space-12); }
.watchlist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); flex-wrap: wrap; gap: var(--space-3); }
.wl-head-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
#historyToggleBtn.is-paused { border-color: var(--yellow); color: var(--yellow); }
.wl-tabs { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--border); margin-bottom: var(--space-6); }
.wl-tab { display: inline-flex; align-items: center; gap: var(--space-2); padding: 0.8em 1.2em; border-bottom: 3px solid transparent; color: var(--text-muted); font-weight: 600; font-size: var(--text-sm); min-height: 44px; }
.wl-tab.is-active { color: var(--text); border-bottom-color: var(--yellow); }
.tab-count { background: var(--surface-3); padding: 0.1em 0.5em; border-radius: var(--radius-full); font-size: 0.7rem; }
.wl-panel { display: block; }
.wl-panel[hidden] { display: none; }
.wl-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.wl-count { color: var(--text-muted); font-size: var(--text-sm); }
.wl-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.wl-panel .poster-grid { margin-bottom: var(--space-4); }

/* ---------- Search ---------- */
.search-page { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--space-6) var(--space-12); }
.search-page .listing-layout { max-width: none; padding: 0; }
.search-hero { padding: var(--space-8) 0; margin-bottom: var(--space-8); }
.search-title { font-size: var(--text-xl); margin-bottom: var(--space-4); }
.search-big-form { display: flex; align-items: center; gap: var(--space-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-full); padding: 0.5em 0.5em 0.5em 1.2em; }
.search-big-form:focus-within { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(245,197,24,.2); }
.search-big-icon { color: var(--text-faint); }
.search-big-input { flex: 1; border: none; background: transparent; outline: none; font-size: var(--text-base); min-width: 0; }
.search-big-form .btn { border-radius: var(--radius-full); }
.search-tabs { display: flex; gap: var(--space-2); margin-top: var(--space-4); flex-wrap: wrap; }
.search-tab { padding: 0.5em 1em; border-radius: var(--radius-full); background: var(--surface-2); font-size: var(--text-sm); font-weight: 600; }
.search-tab.is-active { background: var(--yellow); color: var(--text-inverse); }
.search-grid { margin-top: var(--space-4); }
.person-card .cast-photo { width: 100%; height: auto; aspect-ratio: 2/3; }
.person-card .poster-img { width: 100%; height: 100%; }

/* ---------- Settings ---------- */
.settings-page { max-width: 760px; margin: 0 auto; padding: var(--space-8) var(--space-6) var(--space-12); }
.settings-head { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-8); }
.settings-avatar { border-radius: var(--radius-full); border: 3px solid var(--yellow); }
.settings-sub { color: var(--text-muted); font-size: var(--text-sm); }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-6); margin-bottom: var(--space-5); }
.card-title { font-size: var(--text-lg); margin-bottom: var(--space-4); padding-bottom: var(--space-3); border-bottom: 1px solid var(--divider); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-top: 1px solid var(--divider); }
.settings-row:first-of-type { border-top: none; }
.settings-label { flex: 1; min-width: 0; }
.settings-hint { display: block; color: var(--text-faint); font-size: var(--text-xs); margin-top: 2px; }
.settings-value { color: var(--text-muted); font-size: var(--text-sm); }
.mono { font-family: 'Inter', monospace; word-break: break-all; }
.text-input { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.6em 0.8em; font-size: var(--text-sm); min-width: 200px; }
.settings-select { max-width: 260px; }
.danger.armed { background: rgba(229,9,20,.2); border-color: var(--error); }
.avatar-options { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.avatar-option { width: 40px; height: 40px; border-radius: var(--radius-full); border: 2px solid var(--border); overflow: hidden; cursor: pointer; }
.avatar-option.is-active { border-color: var(--yellow); }
.avatar-option img { width: 100%; height: 100%; }
.range-control { display: flex; align-items: center; gap: var(--space-3); }
.range-value { color: var(--yellow); font-weight: 700; min-width: 48px; text-align: right; }
input[type="range"] { accent-color: var(--yellow); width: 160px; }
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--surface-3); border-radius: var(--radius-full); transition: background var(--transition); }
.switch-track::before { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: var(--radius-full); transition: transform var(--transition); }
.switch input:checked + .switch-track { background: var(--yellow); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }
.settings-foot { text-align: center; color: var(--text-faint); font-size: var(--text-sm); margin-top: var(--space-6); }
.settings-foot a { color: var(--yellow); }

/* ---------- FAQ ---------- */
.faq-section { background: var(--surface); border-top: 1px solid var(--border); padding: var(--space-12) var(--space-6); }
.faq-inner { max-width: 820px; margin: 0 auto; }
.faq-list { display: flex; flex-direction: column; gap: var(--space-3); }
.faq-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.faq-q { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4); font-weight: 600; cursor: pointer; list-style: none; }
.faq-q::-webkit-details-marker { display: none; }
.faq-q::after { content: '+'; color: var(--yellow); font-size: 1.4rem; transition: transform var(--transition); }
.faq-item[open] .faq-q::after { content: '−'; }
.faq-a { padding: 0 var(--space-4) var(--space-4); color: var(--text-muted); }

/* ---------- Static / 404 ---------- */
.static-page { max-width: 820px; margin: 0 auto; padding: var(--space-12) var(--space-6); color: var(--text-muted); line-height: 1.8; }
.static-page h1 { color: var(--text); margin-bottom: var(--space-2); }
.static-page h2 { color: var(--text); margin-top: var(--space-6); margin-bottom: var(--space-2); font-size: var(--text-lg); }
.static-page p, .static-page ul { margin-bottom: var(--space-3); }
.static-page a { color: var(--yellow); }
.static-page .btn-primary, .static-page .btn-primary:visited, .static-page .btn-primary:hover, .static-page .btn-primary:active { color: #000 !important; }
.static-page .updated { color: var(--text-faint); font-size: var(--text-xs); margin-bottom: var(--space-6); }
.notfound-page { text-align: center; padding: var(--space-20) var(--space-4); }
.notfound-code { font-size: 6rem; font-weight: 900; color: var(--yellow); line-height: 1; }
.notfound-page h1 { font-size: var(--text-xl); margin: var(--space-4) 0; }
.notfound-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; margin-top: var(--space-6); }

/* ---------- Footer ---------- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: var(--space-8) var(--space-6); margin-top: var(--space-12); }
.footer-inner { max-width: var(--content-max); margin: 0 auto; display: flex; flex-wrap: wrap; gap: var(--space-4) var(--space-6); align-items: center; justify-content: space-between; }
.footer-brand { display: flex; align-items: center; gap: var(--space-2); }
.footer-copy { color: var(--text-faint); font-size: var(--text-xs); }
.footer-links { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.footer-links a { color: var(--text-muted); font-size: var(--text-xs); }
.footer-links a:hover { color: var(--yellow); }
.footer-social { display: flex; gap: var(--space-2); }
.social-link { width: 36px; height: 36px; border-radius: var(--radius-full); background: var(--surface-2); display: grid; place-items: center; color: var(--text-muted); transition: all var(--transition); }
.social-link:hover { background: var(--yellow); color: var(--text-inverse); transform: translateY(-2px); }
.footer-tmdb { width: 100%; text-align: center; color: var(--text-faint); font-size: var(--text-xs); margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--divider); }

/* ---------- Toast ---------- */
.toast {
    position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--surface-3); color: var(--text); padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 300;
    font-size: var(--text-sm); font-weight: 500; opacity: 0; pointer-events: none;
    transition: opacity var(--transition), transform var(--transition); border: 1px solid var(--border);
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Preview notice ---------- */
.preview-notice {
    position: relative; z-index: 500;
    background: var(--yellow); color: var(--text-inverse);
    padding: var(--space-3) var(--space-6); font-size: var(--text-sm); font-weight: 500;
    display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
}
.preview-notice code { background: rgba(0,0,0,.15); padding: 1px 6px; border-radius: var(--radius-sm); font-family: 'Inter', monospace; }
.preview-notice-close { margin-left: auto; font-size: 1.4rem; font-weight: 700; color: var(--text-inverse); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .header-inner { gap: var(--space-2); flex-wrap: wrap; height: auto; padding: var(--space-2) var(--space-4); }
    .nav-toggle { display: flex; }
    .primary-nav {
        order: 3; flex-basis: 100%; flex-direction: column; align-items: stretch;
        max-height: 0; overflow: hidden; transition: max-height var(--transition);
    }
    .primary-nav.is-open { max-height: 300px; }
    .nav-link { min-height: 48px; }
    .search-form { order: 4; flex-basis: 100%; max-width: none; }
    .user-menu { order: 2; margin-left:auto;}
    .hero-actions .btn span { font-size: var(--text-sm); }
    .detail-hero-inner { flex-direction: column; padding: var(--space-8) var(--space-4); }
    .detail-poster-col { display: none; }
    .watch-header { flex-direction: column; }
    .watch-poster { width: 120px; }
}
@media (max-width: 600px) {
    .hero-content { padding: 0 var(--space-4) var(--space-8); }
    .hero-overview { display: none; }
    .source-menu { min-width: 200px; }
    .poster-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .search-page { padding-left: var(--space-4); padding-right: var(--space-4); }
    .listing-layout { padding: var(--space-4); }
}
