/* ==========================================================================
   Aniwave UI Refresh  (loaded AFTER custom.css)
   Root-cause fixes for layout/theme + responsive polish.
   ========================================================================== */

/* ---------- 1. Design tokens (extends the tokens in custom.css) ---------- */
:root {
    --bg: #0d0e14;
    --surface: #161722;
    --surface-2: #1d1f2c;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text: #f1f1f7;
    --text-dim: #a3a6b8;
    --brand: #8c43e6;
    --brand-deep: #5a2e98;
    --pink: #ff4d8d;
    --page-gutter: clamp(14px, 3.2vw, 36px);
    --content-max: 1440px;
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    color-scheme: dark;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    background:
        radial-gradient(900px 500px at 85% -120px, rgba(140, 67, 230, 0.14), transparent 70%),
        radial-gradient(700px 420px at -10% 8%, rgba(255, 77, 141, 0.07), transparent 70%),
        var(--bg);
    background-attachment: fixed;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

img {
    max-width: 100%;
}

/* ---------- 2. Page container (was undefined -> content hit screen edges) ---------- */
.main-container,
.app-container {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--page-gutter);
    box-sizing: border-box;
    min-width: 0;
}

/* Header: keep inner row aligned with the content column */
.header-inner {
    padding-left: var(--page-gutter);
    padding-right: var(--page-gutter);
}

/* ---------- 3. Pages that were hidden by default (blank Series/Watch pages) ---------- */
#detail-view,
#player-view,
#watch-view {
    display: block;
    min-width: 0;
}

/* ---------- 4. Grid / card overflow fix ---------- */
.anime-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
    gap: clamp(12px, 1.8vw, 22px);
}

.anime-grid > *,
.watch-layout > * {
    min-width: 0;
}

.anime-grid .poster-card {
    max-width: none;
}

.poster-card,
.landscape-card {
    min-width: 0;
}

.card-meta-wrap {
    min-width: 0;
}

.card-meta-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.poster-card-img-wrap img,
.landscape-card-img-wrap img {
    display: block;
}

/* ---------- 5. Catalog header: wrap instead of overflowing ---------- */
.catalog-full-header {
    flex-wrap: wrap;
    gap: 12px 16px;
}

.catalog-full-header > div:last-child {
    flex-wrap: wrap;
    row-gap: 8px;
}

/* ---------- 6. Softer ambient glow (was a harsh white blob) ---------- */
.home-ambient-glow {
    background: radial-gradient(circle, rgba(140, 67, 230, 0.35) 0%, rgba(140, 67, 230, 0.12) 45%, transparent 72%);
    filter: blur(24px);
    opacity: 0.7;
    width: 260px;
    height: 260px;
    top: -10px;
}

/* ---------- 7. Section headers & sliders ---------- */
.home-section-header {
    gap: 12px;
}

.home-section-title {
    font-size: clamp(18px, 2.2vw, 24px);
    line-height: 1.25;
}

.home-cards-slider {
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    /* let cards bleed to the screen edge on small screens, keep gutter alignment */
    scroll-padding-left: 2px;
}

.home-cards-slider > * {
    scroll-snap-align: start;
}

/* ---------- 8. Accessibility & interaction polish ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 8px;
}

.btn-header-round,
.home-arrow-btn,
.nav-pill,
.btn-watch-now {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (hover: none) {

    .poster-card:hover,
    .landscape-card:hover {
        transform: none;
    }

    .poster-card:hover .poster-card-img-wrap img,
    .landscape-card:hover .landscape-card-img-wrap img {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 9. Responsive tuning ---------- */
@media (max-width: 992px) {

    .main-container,
    .app-container {
        padding-left: var(--page-gutter);
        padding-right: var(--page-gutter);
    }
}

@media (max-width: 768px) {
    .anime-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr));
    }

    .catalog-full-header {
        align-items: flex-start;
    }

    .catalog-full-header > div:last-child {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .anime-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .home-ambient-glow {
        width: 160px;
        height: 160px;
        right: -20px;
    }
}

/* Safe-area support for notched phones */
@supports (padding: max(0px)) {
    .site-header {
        padding-top: env(safe-area-inset-top, 0);
    }

    .main-container {
        padding-left: max(var(--page-gutter), env(safe-area-inset-left));
        padding-right: max(var(--page-gutter), env(safe-area-inset-right));
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
}

/* ==========================================================================
   ROUND 2: Series hero, CTAs, watch page, glow
   ========================================================================== */

/* ---------- 10. Unified primary action (brand gradient instead of off-brand red) ---------- */
.btn-hero-watch,
.btn-watch-now {
    background: linear-gradient(135deg, #7b42cc 0%, #5a2e98 55%, #c2428f 130%);
    box-shadow: 0 8px 24px rgba(140, 67, 230, 0.38);
    text-decoration: none;
}

.btn-hero-watch:hover,
.btn-watch-now:hover {
    background: linear-gradient(135deg, #8c52dc 0%, #6a38ae 55%, #d34d9f 130%);
    box-shadow: 0 10px 28px rgba(140, 67, 230, 0.5);
}

.anime-hero-status-pill {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    color: #34d399;
}

/* ---------- 11. Series hero: remove duplicate title, proper two-column layout ---------- */
.anime-hero-stylized-logo {
    display: none;
}

.anime-hero-title {
    font-size: clamp(22px, 3.4vw, 38px);
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.15;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.anime-hero-meta-row {
    font-size: clamp(12.5px, 1.4vw, 14px);
}

.anime-hero-synopsis {
    max-width: 78ch;
}

@media (min-width: 768px) {

    /* Flatten wrappers so the poster spans every row beside the info column */
    .anime-hero-inner {
        display: grid;
        grid-template-columns: clamp(170px, 20vw, 250px) minmax(0, 1fr);
        column-gap: clamp(22px, 3vw, 40px);
        align-items: start;
    }

    .anime-hero-top-row,
    .anime-hero-header-info {
        display: contents;
    }

    .anime-hero-poster-wrap {
        grid-column: 1;
        grid-row: 1 / span 12;
        align-self: start;
        width: 100%;
        max-width: none;
        flex: none;
        position: sticky;
        top: 84px;
    }

    .anime-hero-inner>*:not(.anime-hero-top-row),
    .anime-hero-title,
    .anime-hero-meta-row,
    .anime-hero-status-pill {
        grid-column: 2;
    }

    .anime-hero-status-pill {
        justify-self: start;
        margin-bottom: 16px;
    }

    .anime-hero-actions {
        max-width: 520px;
    }
}

@media (max-width: 767px) {
    .anime-hero-top-row {
        gap: 14px;
    }

    .anime-hero-poster-wrap {
        flex-basis: 104px;
        width: 104px;
    }

    .anime-hero-status-pill {
        font-size: 11.5px;
        padding: 5px 12px;
    }

    .anime-hero-actions>* {
        flex: 1 1 100%;
    }

    .anime-hero-card {
        border-radius: 18px;
    }
}

/* ---------- 12. Season tabs: scroll instead of clip ---------- */
.detail-seasons-tabs {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.detail-seasons-tabs::-webkit-scrollbar {
    display: none;
}

.detail-season-tab-btn {
    flex: none;
    white-space: nowrap;
}

.detail-episodes-header {
    flex-wrap: wrap;
    gap: 10px;
}

/* ---------- 13. Watch page ---------- */
.player-top-bar {
    gap: 10px 14px;
}

.player-watching-title {
    min-width: 0;
    flex-wrap: wrap;
}

.player-frame-box iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.player-controls-bar,
.player-actions,
.server-selector-group {
    flex-wrap: wrap;
}

/* Episode jump row no longer overflows the panel */
.ep-jump-row {
    min-width: 0;
}

.ep-jump-row input {
    min-width: 0;
    width: 100%;
}

.btn-ep-current {
    flex: none;
    padding-left: 16px;
    padding-right: 16px;
}

.ep-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ep-info-wrap {
    min-width: 0;
}

@media (min-width: 1025px) {
    .episodes-panel {
        position: sticky;
        top: 78px;
        align-self: start;
        max-height: calc(100vh - 100px);
        min-height: 320px;
    }
}

@media (max-width: 1024px) {
    .episodes-panel {
        max-height: 560px;
    }
}

@media (max-width: 600px) {
    .btn-back-catalog {
        padding: 8px 14px;
        font-size: 13px;
    }

    .episodes-panel {
        border-radius: 16px;
        padding: 18px 14px;
        max-height: 480px;
    }

    .player-actions {
        width: 100%;
    }

    .player-actions>* {
        flex: 1 1 0;
        justify-content: center;
    }
}

/* ---------- 14. Ambient glows stay inside the layout (no horizontal scroll) ---------- */
.home-layout {
    overflow-x: clip;
}

@media (max-width: 480px) {
    .home-ambient-glow {
        right: 0;
    }
}

.ep-ambient-glow {
    pointer-events: none;
    z-index: 0;
}

/* ---------- 15. Small-screen header safety ---------- */
@media (max-width: 380px) {
    .header-side-action {
        gap: 6px;
    }

    .btn-header-round {
        width: 34px;
        height: 34px;
    }

    .header-brand-center {
        padding: 0 4px;
    }

    .header-brand-center .logo-wrap img {
        height: 26px;
    }
}
/* ---------- 16. Component sizing & status label ---------- */
.rating-modal-card {
    max-width: 480px;
}

.watchlist-modal-card {
    max-width: 520px;
}

#watchlist-modal-body {
    padding: 14px;
}

.embed-player-body {
    padding: 0;
    background: #000;
}

#embed-player-modal .embed-player-note {
    margin: 0;
    padding: 12px 18px;
    text-align: center;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

#embed-player-modal .modal-footer .btn-anivid-custom {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
}

.tmdb-live-badge {
    cursor: default;
    user-select: none;
}

.tmdb-live-badge:hover {
    background: rgba(1, 180, 228, 0.12);
    border-color: rgba(1, 180, 228, 0.35);
    color: #01b4e4;
}

img[data-fallback] {
    background-color: var(--surface-2);
}

@media (max-width: 640px) {
    #embed-player-modal {
        padding: 10px;
    }

    .embed-player-card {
        border-radius: 14px;
    }

    .embed-player-card .modal-header {
        padding: 12px 14px;
    }

    .embed-player-card .modal-header h3 {
        font-size: 14px;
        line-height: 1.3;
    }

    .embed-player-note {
        display: none;
    }
}