:root {
    color-scheme: dark;
    --bg: #0f1118;
    --panel: #191c27;
    --panel-2: #242838;
    --text: #f3f5ff;
    --muted: #a8adbd;
    --line: rgba(218, 225, 255, 0.11);
    --accent: #9b8cff;
    --accent-hover-border: rgba(155, 140, 255, 0.58);
    --accent-active-border: rgba(155, 140, 255, 0.76);
    --accent-hover-bg: rgba(155, 140, 255, 0.1);
    --accent-active-bg: rgba(155, 140, 255, 0.18);
    --accent-soft-bg: rgba(155, 140, 255, 0.16);
    --accent-glow: rgba(155, 140, 255, 0.22);
    --soft-action: #8ec5ff;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-dialog-open {
    overflow: hidden;
    overscroll-behavior: none;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    grid-column: 1;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px;
    border-right: 1px solid var(--line);
    background: #141722;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 34px;
}

.brand-mark {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    flex: 0 0 auto;
    user-select: none;
}

.brand-mark svg {
    display: block;
    width: 100%;
    height: 100%;
}

.brand-mark rect {
    fill: var(--accent);
}

.brand-mark path {
    fill: #10111a;
}

.brand h1,
.brand p,
.section-head h2,
.hero-content h2,
.panel-head h2 {
    margin: 0;
}

.brand h1 {
    font-size: 21px;
}

.brand p,
.eyebrow {
    color: var(--muted);
    font-size: 12px;
}

.tabs {
    display: grid;
    gap: 8px;
}

.tab,
.shuffle-button,
.actions button,
.text-button {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--panel);
}

.tab {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 14px;
    text-align: left;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.tab span {
    color: var(--muted);
}

.shuffle-button {
    width: 100%;
    margin: 0 0 8px;
    padding: 14px 16px;
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 700;
    color: #10111a;
    box-shadow: 0 6px 16px rgba(155, 140, 255, 0.18);
    transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.shuffle-button:hover {
    filter: brightness(1.06);
    box-shadow: 0 8px 20px var(--accent-glow);
}

.shuffle-button:active,
.shuffle-button.is-pressing {
    background: #8c7dff;
    border-color: #8c7dff;
    box-shadow: 0 4px 12px rgba(155, 140, 255, 0.18);
}

.shuffle-button.is-loading {
    opacity: 0.82;
    pointer-events: none;
}

.backup-tools {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 14px;
}

.backup-button {
    flex: 0 1 auto;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.loading-line {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 20;
    height: 3px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 140ms ease;
}

.loading-line::before {
    content: "";
    display: block;
    width: 42%;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 18px var(--accent-glow);
    animation: loading-slide 900ms ease-in-out infinite;
}

body.is-loading .loading-line {
    opacity: 1;
}

@keyframes loading-slide {
    0% {
        transform: translateX(-110%);
    }

    100% {
        transform: translateX(250%);
    }
}

.workspace {
    grid-column: 2;
    padding: 24px;
    padding-right: max(24px, env(safe-area-inset-right));
    padding-left: max(24px, env(safe-area-inset-left));
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 8px;
}

.search {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.search input,
.local-filter,
select {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 12px 13px;
    outline: none;
}

.search input:focus,
.local-filter:focus,
select:focus {
    border-color: var(--accent-active-border);
}

.actions button,
.text-button {
    padding: 12px 14px;
}

.load-more-button {
    display: block;
    min-height: 46px;
    width: min(360px, 100%);
    margin: 18px auto 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    font-weight: 800;
    transition: border-color 140ms ease, background 140ms ease;
}

.load-more-button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.close-search-button {
    border-color: var(--accent-hover-border);
    background: var(--accent-soft-bg);
    color: var(--text);
    font-weight: 800;
    transition: border-color 140ms ease, background 140ms ease;
}

.panel,
.list-section {
    margin-bottom: 18px;
}

.discover-controls {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.mode-buttons,
.genre-chips,
.year-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.genre-toggle {
    display: none;
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    font-weight: 800;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.mode-button,
.genre-chip,
.year-controls label {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
}

.mode-button,
.genre-chip {
    padding: 10px 12px;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.tab.is-active,
.mode-button.is-active,
.genre-chip.is-active {
    border-color: var(--accent-active-border);
    background: var(--accent-active-bg);
}

.tab:hover,
.backup-button:hover,
.load-more-button:hover,
.mode-button:hover,
.genre-chip:hover,
.genre-toggle:hover,
.close-search-button:hover,
.dialog-close:hover,
.actions button:hover,
.movie-card:hover,
.trailer-link:hover {
    border-color: var(--accent-hover-border);
    background: var(--accent-hover-bg);
}

.tab:active,
.backup-button:active,
.load-more-button:active,
.mode-button:active,
.genre-chip:active,
.genre-toggle:active,
.close-search-button:active,
.dialog-close:active,
.actions button:active,
.movie-card:active {
    border-color: var(--accent-active-border);
    background: var(--accent-active-bg);
}

.year-controls label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    padding: 8px 10px;
}

.year-controls select {
    border: 0;
    background: transparent;
    padding: 0;
}

.panel-head,
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.result-grid,
.movie-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}

.movie-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease;
}

.history-card .movie-card-body {
    min-height: 132px;
}

.history-card .movie-status {
    min-height: 0;
    margin-top: auto;
    color: var(--accent);
    font-weight: 700;
}

.poster {
    aspect-ratio: 2 / 3;
    background: var(--panel-2);
    background-size: cover;
    background-position: center;
}

.poster.is-empty {
    display: grid;
    place-items: center;
    color: var(--muted);
    padding: 18px;
    text-align: center;
}

.movie-card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 12px;
}

.movie-title {
    min-height: 36px;
    margin: 0 0 5px;
    font-size: 15px;
    line-height: 1.35;
}

.movie-meta,
.movie-status,
.movie-list-status {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.movie-meta {
    min-height: 40px;
}

.movie-status {
    min-height: 0;
    margin-top: 8px;
}

.movie-list-status {
    min-height: 0;
    margin-top: 4px;
    color: var(--accent);
    font-weight: 700;
}

.movie-status:empty,
.movie-list-status:empty {
    display: none;
}

.card-actions {
    display: grid;
    gap: 7px;
    margin-top: auto;
    padding-top: 8px;
}

.card-actions button {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #262b3d;
    color: var(--text);
    padding: 9px;
    cursor: pointer;
}

.card-actions .primary {
    background: var(--accent);
    border-color: var(--accent);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.actions button {
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.actions button[data-action="watched"],
.actions button[data-status="rewatch"] {
    background: var(--soft-action);
    border-color: var(--soft-action);
    color: #07111d;
}

.actions button:not(.danger):hover,
.actions button:not(.danger):active {
    color: var(--text);
}

.actions button.danger,
.card-actions button.danger {
    border-color: rgba(255, 120, 149, 0.38);
    background: rgba(255, 120, 149, 0.1);
    color: #ffc4d0;
}

.actions button.danger:hover,
.card-actions button.danger:hover {
    border-color: rgba(255, 120, 149, 0.72);
    background: rgba(255, 120, 149, 0.16);
}

.empty {
    padding: 24px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.movie-dialog {
    position: fixed;
    top: max(18px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    width: auto;
    height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    max-width: 860px;
    max-height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0;
    background: var(--panel);
    color: var(--text);
    overflow: hidden;
    overscroll-behavior: contain;
}

.dialog-body {
    height: 100%;
    max-height: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.dialog-body::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.movie-dialog::backdrop {
    background: rgba(0, 0, 0, 0.68);
}

.dialog-close {
    display: grid;
    place-items: center;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    width: 38px;
    height: 38px;
    margin: 0;
    border: 1px solid var(--accent-hover-border);
    border-radius: var(--radius);
    background: var(--accent-hover-bg);
    color: var(--accent);
    font-size: 0;
    backdrop-filter: blur(10px);
    transition: border-color 140ms ease, background 140ms ease;
}

.dialog-close::before,
.dialog-close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 17px;
    height: 3px;
    border-radius: 999px;
    background: var(--accent);
    transform-origin: center;
}

.dialog-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.dialog-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.dialog-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 18px;
    padding: 18px;
}

.dialog-media {
    display: grid;
    align-content: start;
    gap: 12px;
}

.dialog-media .poster {
    border-radius: var(--radius);
}

.dialog-actions {
    display: grid;
    margin-top: 0;
}

.dialog-actions button {
    width: 100%;
}

.dialog-text h2 {
    margin: 0 42px 8px 0;
    font-size: 28px;
}

.dialog-kicker {
    display: inline-flex;
    margin: 0 0 10px;
    border: 1px solid var(--accent-hover-border);
    border-radius: var(--radius);
    padding: 5px 8px;
    color: var(--accent);
    font-size: 12px;
}

.dialog-text p {
    color: var(--muted);
    line-height: 1.6;
}

.trailer {
    margin-top: 16px;
}

.trailer-frame {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: var(--radius);
    background: #000;
}

.trailer-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 230px;
    margin-top: 10px;
    margin-right: auto;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 10px 14px;
    text-decoration: none;
    transition: border-color 140ms ease, background 140ms ease;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
    border-radius: var(--radius);
    border: 1px solid var(--accent-hover-border);
    background: #202436;
    color: var(--text);
    padding: 11px 14px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

@media (max-width: 820px) {
    .app {
        display: flex;
        flex-direction: column;
    }

    .sidebar {
        order: 2;
        position: static;
        height: auto;
        padding: max(16px, calc(env(safe-area-inset-top) + 12px)) 16px 16px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .brand {
        margin-bottom: 16px;
    }

    .tabs {
        grid-template-columns: repeat(2, 1fr);
    }

    .tab {
        min-height: 48px;
        padding: 10px 12px;
        font-size: 15px;
    }

    .tab:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        justify-content: center;
        text-align: center;
    }

    .workspace {
        order: 3;
        padding: 14px;
        padding-right: max(14px, env(safe-area-inset-right));
        padding-left: max(14px, env(safe-area-inset-left));
    }

    .toolbar {
        grid-template-columns: 1fr;
        margin-bottom: 8px;
    }

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

    .backup-tools {
        margin-top: 8px;
    }

    .genre-toggle {
        display: block;
    }

    .genre-chips {
        display: none;
    }

    .discover-controls.is-genres-open .genre-chips {
        display: flex;
    }

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

    .dialog-layout {
        grid-template-columns: 1fr;
    }

    .dialog-layout {
        padding: 12px;
    }
}

@media (max-width: 520px) {
    .brand-mark {
        width: 42px;
        height: 42px;
    }

    .brand h1 {
        font-size: 18px;
    }

    .tabs {
        gap: 7px;
    }

    .tab {
        gap: 10px;
    }

    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .local-filter {
        width: 100%;
    }

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

    .mode-button,
    .genre-chip {
        flex: 1 1 calc(50% - 8px);
    }

    .result-grid,
    .movie-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .movie-card-body {
        padding: 10px;
    }

    .movie-title {
        font-size: 14px;
    }

    .card-actions button {
        padding: 8px 6px;
        font-size: 13px;
    }

    .movie-dialog {
        top: max(18px, env(safe-area-inset-top));
        right: max(7px, env(safe-area-inset-right));
        bottom: max(7px, env(safe-area-inset-bottom));
        left: max(7px, env(safe-area-inset-left));
        width: auto;
        height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(7px, env(safe-area-inset-bottom)));
        max-height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(7px, env(safe-area-inset-bottom)));
        margin: 0;
    }

    .dialog-text h2 {
        margin-right: 42px;
        font-size: 24px;
    }
}
