/* ============================================================
   Design tokens — Noir (default)
   ============================================================ */
:root {
    --bg:              #0f0f0f;
    --surface:         #1a1a1a;
    --surface-2:       #242424;
    --border:          #2e2e2e;
    --text:            #e8e8e8;
    --muted:           #888;
    --accent:          #e8a020;
    --accent-dim:      #b37d18;
    --bg-glass:        rgba(15, 15, 15, 0.92);
    --badge-movie-bg:  #1d3557;
    --badge-movie-txt: #a8d8ff;
    --badge-tv-bg:     #1d3d2e;
    --badge-tv-txt:    #7fda9f;
    --radius:          6px;
    --max-width:       1100px;
}

/* ============================================================
   Themes
   ============================================================ */
html[data-theme="midnight"] {
    --bg:              #080d1a;
    --surface:         #0f1829;
    --surface-2:       #162035;
    --border:          #1e2d4a;
    --text:            #cdd8f0;
    --muted:           #6b7fa8;
    --accent:          #4d9fff;
    --accent-dim:      #2d7fd4;
    --bg-glass:        rgba(8, 13, 26, 0.92);
    --badge-movie-bg:  #0d2a4a;
    --badge-movie-txt: #7bb8ff;
    --badge-tv-bg:     #0d2d3a;
    --badge-tv-txt:    #7fd4e8;
}

html[data-theme="slate"] {
    --bg:              #111318;
    --surface:         #1c1f26;
    --surface-2:       #22262f;
    --border:          #2d3140;
    --text:            #dde1ec;
    --muted:           #7b82a0;
    --accent:          #a78bfa;
    --accent-dim:      #7c5fd4;
    --bg-glass:        rgba(17, 19, 24, 0.92);
    --badge-movie-bg:  #1e1a3a;
    --badge-movie-txt: #c4b5fd;
    --badge-tv-bg:     #1a1e3a;
    --badge-tv-txt:    #93c5fd;
}

html[data-theme="forest"] {
    --bg:              #0a0f0c;
    --surface:         #111a14;
    --surface-2:       #162019;
    --border:          #1e3024;
    --text:            #d4e8d8;
    --muted:           #6a9070;
    --accent:          #4ade80;
    --accent-dim:      #22c55e;
    --bg-glass:        rgba(10, 15, 12, 0.92);
    --badge-movie-bg:  #0d2a1a;
    --badge-movie-txt: #86efac;
    --badge-tv-bg:     #0d2410;
    --badge-tv-txt:    #6ee7b7;
}

html[data-theme="crimson"] {
    --bg:              #0f0808;
    --surface:         #1a0e0e;
    --surface-2:       #221212;
    --border:          #331818;
    --text:            #f0e0e0;
    --muted:           #9a7070;
    --accent:          #f05050;
    --accent-dim:      #c83030;
    --bg-glass:        rgba(15, 8, 8, 0.92);
    --badge-movie-bg:  #2a0d0d;
    --badge-movie-txt: #fca5a5;
    --badge-tv-bg:     #2a1a0d;
    --badge-tv-txt:    #fed7aa;
}

html[data-theme="paper"] {
    --bg:              #f5f0eb;
    --surface:         #ffffff;
    --surface-2:       #ede8e2;
    --border:          #ddd5c8;
    --text:            #1a1208;
    --muted:           #7a6a55;
    --accent:          #b35c00;
    --accent-dim:      #8c4800;
    --bg-glass:        rgba(245, 240, 235, 0.95);
    --badge-movie-bg:  #dde8f5;
    --badge-movie-txt: #1d3557;
    --badge-tv-bg:     #ddf0e4;
    --badge-tv-txt:    #1d4a2e;
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text); }

img { display: block; max-width: 100%; }

/* ============================================================
   Layout
   ============================================================ */
.page-wrap {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

/* ============================================================
   Site header
   ============================================================ */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
}

.site-logo {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}
.site-logo:hover { color: var(--accent); opacity: 0.85; }

.settings-link {
    color: var(--muted);
    font-size: 1.1rem;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.15s, color 0.15s;
    line-height: 1;
}
.settings-link:hover { opacity: 1; color: var(--text); }

/* ============================================================
   Search bar & wrap
   ============================================================ */
.search-bar {
    display: flex;
    flex: 1;
    max-width: 560px;
}

/* When JS wraps the search-bar in .search-wrap */
.search-wrap {
    position: relative;
    flex: 1;
    max-width: 560px;
}
.search-wrap .search-bar {
    flex: none;
    max-width: none;
    width: 100%;
}

.search-bar input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
    padding: 0.5rem 0.875rem;
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.15s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--muted); }

.search-bar button {
    background: var(--accent);
    color: #000;
    font-weight: 600;
    font-size: 0.875rem;
    border: none;
    padding: 0.5rem 1.1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.search-bar button:hover { background: var(--accent-dim); }

/* Hero variant */
.search-bar--hero { max-width: 520px; width: 100%; }
.search-bar--hero input { padding: 0.75rem 1rem; font-size: 1rem; }
.search-bar--hero button { padding: 0.75rem 1.5rem; font-size: 1rem; }

.home-hero .search-wrap { max-width: 520px; width: 100%; }
.home-hero .search-wrap .search-bar { max-width: none; width: 100%; }

/* ============================================================
   Autocomplete dropdown
   ============================================================ */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 200;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    border-top: 1px solid var(--border);
}
.autocomplete-item:first-child { border-top: none; }
.autocomplete-item:hover,
.autocomplete-item--active { background: var(--surface-2); color: var(--text); }

.autocomplete-thumb {
    width: 32px;
    height: 48px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    background: var(--surface-2);
}

.autocomplete-thumb--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
}

.autocomplete-info { flex: 1; min-width: 0; }

.autocomplete-title {
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autocomplete-meta {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ============================================================
   Home hero
   ============================================================ */
.home-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 5rem 1rem 3rem;
    gap: 1rem;
}

.home-wordmark {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--accent);
    line-height: 1;
}

.home-tagline {
    color: var(--muted);
    font-size: 1.05rem;
    max-width: 420px;
    margin-bottom: 0.5rem;
}

/* ============================================================
   Cards & grid
   ============================================================ */
.cast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--text);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    border-color: #555;
    color: var(--text);
}

.card-img-wrap { position: relative; }

.card-img {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    background: var(--surface-2);
}

.card-img--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-2);
    width: 100%;
    aspect-ratio: 2 / 3;
}

.card-body { padding: 0.6rem 0.75rem 0.75rem; }

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 0.25rem;
}

.card-meta {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.2rem;
}

.card-meta--char { font-style: italic; }

/* ============================================================
   List view
   ============================================================ */
.cast-grid--list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.cast-grid--list .card {
    display: flex;
    flex-direction: row;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.cast-grid--list .card:last-child { border-bottom: none; }
.cast-grid--list .card:hover {
    transform: none;
    box-shadow: none;
    background: var(--surface-2);
}

.cast-grid--list .card-img-wrap { flex-shrink: 0; width: 44px; }

.cast-grid--list .card-img,
.cast-grid--list .card-img--placeholder {
    width: 44px;
    height: 66px;
    aspect-ratio: unset;
    font-size: 1rem;
}

.cast-grid--list .card-body {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    min-width: 0;
}

.cast-grid--list .card-title { font-size: 0.875rem; margin-top: 0; }

.cast-grid--list .card-meta--char::before { content: "as "; font-style: normal; color: var(--muted); }

.cast-grid--list .badge { margin-left: auto; align-self: center; flex-shrink: 0; }

/* ============================================================
   Section header + view toggle
   ============================================================ */
.section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.section-header .section-heading,
.section-header .results-heading {
    flex: 1;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.view-toggle {
    display: flex;
    gap: 0.2rem;
    flex-shrink: 0;
}

.view-toggle__btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.3rem 0.45rem;
    border-radius: var(--radius);
    cursor: pointer;
    line-height: 0;
    transition: color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
}
.view-toggle__btn:hover { color: var(--text); border-color: var(--accent); }
.view-toggle__btn--active { color: var(--accent); border-color: var(--accent); }

/* ============================================================
   Badge
   ============================================================ */
.badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.15em 0.5em;
    border-radius: 3px;
    line-height: 1.5;
}

.badge--movie { background: var(--badge-movie-bg); color: var(--badge-movie-txt); }
.badge--tv    { background: var(--badge-tv-bg);    color: var(--badge-tv-txt); }

/* ============================================================
   Page header (title & person)
   ============================================================ */
.page-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2.5rem;
    align-items: flex-start;
}

.page-header__poster { flex-shrink: 0; width: 200px; }
.page-header__poster--person { width: 160px; }

.poster-img {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.poster-img--person { aspect-ratio: 2 / 3; object-fit: cover; }

.poster-img--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-2);
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.page-header__meta { flex: 1; min-width: 0; }

.meta-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.meta-year { color: var(--muted); font-size: 0.9rem; }

.meta-detail {
    color: var(--muted);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ============================================================
   Title page
   ============================================================ */
.title-heading {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 0.35rem;
}

.title-tagline {
    font-style: italic;
    color: var(--muted);
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.title-overview {
    color: var(--text);
    opacity: 0.8;
    font-size: 0.9375rem;
    max-width: 640px;
    line-height: 1.65;
    margin-bottom: 1.25rem;
}

.crew-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    border-top: 1px solid var(--border);
    padding-top: 0.9rem;
}

.crew-row {
    display: flex;
    gap: 0.5rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
    align-items: baseline;
}

.crew-label { color: var(--muted); min-width: 110px; flex-shrink: 0; }
.crew-names a { color: var(--text); }
.crew-names a:hover { color: var(--accent); }

/* ============================================================
   Section headings
   ============================================================ */
.section-heading {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.cast-section { margin-top: 2rem; }

/* ============================================================
   Search results
   ============================================================ */
.results-heading {
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--muted);
    margin-bottom: 1.5rem;
}

.results-query { color: var(--text); font-weight: 600; }

.empty-state {
    color: var(--muted);
    padding: 3rem 0;
    text-align: center;
    font-size: 1rem;
}

/* ============================================================
   Person / bio
   ============================================================ */
.bio { margin-top: 0.75rem; max-width: 640px; }

.bio-text {
    font-size: 0.9375rem;
    color: var(--text);
    opacity: 0.8;
    line-height: 1.65;
}

.bio-toggle {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.875rem;
    margin-top: 0.4rem;
    padding: 0;
}
.bio-toggle:hover { color: var(--text); }

/* ============================================================
   Error / 404
   ============================================================ */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 5rem 1rem;
    gap: 1rem;
}

.error-code { font-size: 5rem; font-weight: 800; color: var(--border); line-height: 1; }
.error-message { color: var(--muted); font-size: 1.1rem; }
.error-link { margin-top: 0.5rem; font-size: 0.9rem; }

.error-debug {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 0.8rem;
    color: #f87171;
    max-width: 700px;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ============================================================
   Settings page
   ============================================================ */
.settings-page h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
}

.settings-section { margin-bottom: 2.5rem; }

.settings-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1rem;
}

.theme-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
    user-select: none;
}
.theme-card:hover { border-color: var(--muted); transform: translateY(-2px); }
.theme-card--active { border-color: var(--accent); }

.theme-swatches {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.9rem;
}

.theme-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(128,128,128,0.2);
    flex-shrink: 0;
}

.theme-name { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.2rem; }
.theme-desc { font-size: 0.78rem; color: var(--muted); }

/* ============================================================
   Title body — sidebar + sections
   ============================================================ */
.title-body {
    display: grid;
    grid-template-columns: 175px 1fr;
    gap: 2.5rem;
    align-items: start;
}

/* Sidebar */
.title-sidebar {
    position: sticky;
    top: calc(53px + 1.5rem); /* sticky site-header height + breathing room */
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
    border-left: 2px solid transparent;
    text-decoration: none;
}
.sidebar-link:hover {
    color: var(--text);
    background: var(--surface);
}
.sidebar-link--active {
    color: var(--accent);
    background: var(--surface);
    border-left-color: var(--accent);
}

.sidebar-link-name { flex: 1; }

.sidebar-link-count {
    font-size: 0.72rem;
    color: var(--muted);
    background: var(--surface-2);
    padding: 0.1em 0.5em;
    border-radius: 10px;
    flex-shrink: 0;
}
.sidebar-link--active .sidebar-link-count { color: var(--accent); }

/* Credit sections */
.credit-section {
    margin-bottom: 3rem;
    scroll-margin-top: 5rem;
}
.credit-section:last-child { margin-bottom: 0; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 1.25rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    max-width: var(--max-width);
    margin: 0 auto;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }

/* ============================================================
   Responsive
   ============================================================ */

/* Sidebar collapses to horizontal pill strip below 800px */
@media (max-width: 800px) {
    .title-body {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .title-sidebar {
        position: static;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.4rem;
    }

    .sidebar-link {
        white-space: nowrap;
        flex-shrink: 0;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: var(--radius) var(--radius) 0 0;
        padding: 0.4rem 0.75rem;
    }

    .sidebar-link--active { border-bottom-color: var(--accent); }
}

@media (max-width: 600px) {
    .page-header { flex-direction: column; gap: 1.25rem; }
    .page-header__poster,
    .page-header__poster--person { width: 120px; }

    .site-header { flex-wrap: wrap; gap: 0.75rem; }
    .search-bar,
    .search-wrap { max-width: 100%; flex-basis: 100%; }

    .cast-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .crew-label { min-width: 90px; }

    .theme-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
