* {
    box-sizing: border-box;
}

:root {
    --bg: #0b0b0d;
    --surface: #151518;
    --surface-2: #1d1d21;
    --border: #303036;
    --text: #f5f5f7;
    --muted: #a2a2aa;
    --accent: #e50914;
    --accent-2: #ff3340;
    --person: #5f8cff;
    --genre: #43c59e;
    --category: #d993ff;
    --shadow: 0 14px 35px rgba(0, 0, 0, .3);
}

html {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
                 "Segoe UI", sans-serif;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% -10%, rgba(229, 9, 20, .2), transparent 34rem),
        var(--bg);
}

button, input, select {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(11, 11, 13, .86);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand,
.shell {
    width: min(1180px, calc(100% - 28px));
    margin-inline: auto;
}

.brand {
    min-height: 86px;
    display: flex;
    gap: 14px;
    align-items: center;
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    box-shadow: none;
    filter: none;
    transition: transform .15s ease;
}

.brand-mark:hover {
    transform: scale(1.06);
}

.brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

h1, h2, p {
    margin: 0;
}

.brand h1 {
    font-size: clamp(1.15rem, 4vw, 1.55rem);
}

.brand p,
.result-head p {
    color: var(--muted);
    margin-top: 4px;
    font-size: .92rem;
}

.shell {
    padding: 22px 0 52px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 17px;
}

.stat strong {
    display: block;
    font-size: 1.45rem;
    font-variant-numeric: tabular-nums;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: .84rem;
    margin-top: 4px;
}

.panel {
    background: rgba(21, 21, 24, .92);
    border: 1px solid var(--border);
    border-radius: 17px;
    box-shadow: var(--shadow);
}

.controls {
    padding: 15px;
}

.search-row,
.filter-row,
.result-head,
.page-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.searchbox {
    flex: 1;
    position: relative;
}

.searchbox input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #0f0f12;
    color: var(--text);
    padding: 13px 48px 13px 14px;
    outline: none;
}

.searchbox input:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(229, 9, 20, .15);
}

.searchbox kbd {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: .8rem;
}

.filter-row {
    margin-top: 12px;
    flex-wrap: wrap;
}

.segmented {
    display: flex;
    flex-wrap: wrap;
    background: #0f0f12;
    border: 1px solid var(--border);
    padding: 4px;
    border-radius: 12px;
}

.segmented button,
.ghost {
    border: 0;
    color: var(--muted);
    background: transparent;
    border-radius: 9px;
    padding: 9px 12px;
}

.segmented button:hover,
.segmented button.active {
    color: white;
    background: var(--surface-2);
}

.segmented button.active {
    box-shadow: inset 0 0 0 1px #3b3b42;
}

.ghost {
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.ghost:hover:not(:disabled) {
    color: white;
    border-color: #4b4b53;
}

.ghost:disabled {
    opacity: .38;
    cursor: default;
}

.select-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--muted);
    font-size: .86rem;
    margin-left: auto;
}

.select-wrap + .select-wrap {
    margin-left: 0;
}

select {
    background: #0f0f12;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 10px;
}

.result-head {
    justify-content: space-between;
    margin: 24px 2px 12px;
}

.page-actions {
    color: var(--muted);
    font-size: .86rem;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
    padding: 15px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    text-align: left;
    color: var(--text);
    transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.card:hover {
    transform: translateY(-1px);
    border-color: #4a4a52;
    background: var(--surface-2);
}

.card-main {
    min-width: 0;
}

.card-name {
    display: block;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    color: var(--muted);
    font-size: .82rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid currentColor;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .72rem;
}

.badge.person { color: var(--person); }
.badge.genre { color: var(--genre); }
.badge.category { color: var(--category); }

.card-id {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: .82rem;
}

.arrow {
    align-self: center;
    color: #666670;
    font-size: 1.25rem;
}

.empty,
.loading {
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: 15px;
    color: var(--muted);
    padding: 48px 20px;
}

.empty strong {
    color: var(--text);
    font-size: 1.15rem;
}

.empty p {
    margin-top: 6px;
}

dialog {
    width: min(620px, calc(100% - 26px));
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 24px 90px rgba(0, 0, 0, .65);
}

dialog::backdrop {
    background: rgba(0, 0, 0, .72);
    backdrop-filter: blur(3px);
}

.dialog-close {
    position: absolute;
    right: 13px;
    top: 11px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: white;
    font-size: 1.35rem;
}

.detail-title {
    padding-right: 44px;
    font-size: 1.4rem;
    overflow-wrap: anywhere;
}

.detail-grid {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 10px 15px;
    margin-top: 20px;
    font-size: .92rem;
}

.detail-grid dt {
    color: var(--muted);
}

.detail-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.netflix-link {
    display: inline-flex;
    margin-top: 20px;
    color: white;
    background: var(--accent);
    text-decoration: none;
    font-weight: 700;
    padding: 10px 13px;
    border-radius: 10px;
}

.netflix-link:hover {
    background: var(--accent-2);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 760px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-grid {
        grid-template-columns: 1fr;
    }

    .result-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .filter-row {
        align-items: stretch;
    }

    .segmented {
        width: 100%;
    }

    .segmented button {
        flex: 1;
    }

    .select-wrap {
        margin-left: 0;
        flex: 1;
    }

    .select-wrap select {
        flex: 1;
    }
}

@media (max-width: 500px) {
    .brand p {
        display: none;
    }

    .search-row {
        align-items: stretch;
    }

    #clearSearch {
        padding-inline: 10px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .detail-grid dd {
        margin-bottom: 9px;
    }
}

/* Lazy Loading Animations & Performance */
.card.lazy-card {
    content-visibility: auto;
    contain-intrinsic-size: 1px 72px;
    animation: lazyFadeIn 0.22s ease-out forwards;
}

@keyframes lazyFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sentinel {
    height: 30px;
    margin-top: 10px;
}
