* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-gradient-1: #667eea;
    --bg-gradient-2: #764ba2;
    --container-bg: #ffffff;
    --container-shadow: rgba(0, 0, 0, 0.3);
    --heading-color: #333333;
    --text-color: #666666;
    --input-border: #e0e0e0;
    --input-focus-border: #667eea;
    --button-bg: #667eea;
    --button-hover: #5568d3;
    --error-text: #d32f2f;
    --error-bg: #ffebee;
    --search-overlay: rgba(0, 0, 0, 0.55);
    --tab-active-bg: #667eea;
    --tab-active-color: #ffffff;
    --tab-inactive-color: #666666;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 100%);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease;
}

html {
    scroll-behavior: smooth;
}

body.search-only {
    overflow-y: hidden;
}

body.player-ready {
    overflow-y: auto;
}

.app-shell {
    width: 100%;
}

.page-section {
    width: 100%;
    min-height: calc(100vh - 40px);
}

.search-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.player-section {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 40px);
    min-height: calc(100vh - 40px);
}

.player-section.hidden {
    display: none;
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--button-bg);
    color: white;
    border: none;
    border-radius: 50px;
    width: 50px;
    height: 50px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.theme-toggle:hover {
    background: var(--button-hover);
    transform: scale(1.1);
}

.container {
    background: var(--container-bg);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--container-shadow);
    padding: 40px;
    max-width: 800px;
    width: 100%;
    transition: all 0.3s ease;
}

.search-panel {
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.player-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    max-width: min(1280px, 100%);
    overflow: hidden;
    padding: 16px;
}

h1 {
    color: var(--heading-color);
    margin-bottom: 30px;
    text-align: center;
    font-size: 28px;
    transition: color 0.3s ease;
}

.error {
    color: var(--error-text);
    padding: 12px;
    background: var(--error-bg);
    border-radius: 8px;
    margin: 0 24px 24px;
    display: none;
    transition: all 0.3s ease;
}

.movie-details {
    border: 1px solid var(--input-border);
    border-radius: 8px;
    flex: 0 0 auto;
    padding: 12px 16px;
    margin-bottom: 10px;
    background: rgba(102, 126, 234, 0.08);
    transition: all 0.3s ease;
}

.movie-details.hidden {
    display: none;
}

.movie-details h2 {
    color: var(--heading-color);
    font-size: 20px;
    line-height: 1.3;
    margin-bottom: 6px;
    transition: color 0.3s ease;
}

.movie-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--text-color);
    font-size: 14px;
    font-weight: 600;
    transition: color 0.3s ease;
}

.movie-meta span:not(:empty) {
    background: var(--container-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 6px 10px;
}

.season-list,
.episode-list {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 50px;
    margin: 0 0 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 2px 8px;
    scrollbar-color: var(--button-bg) transparent;
    scrollbar-width: thin;
}

.season-list.hidden,
.episode-list.hidden {
    display: none;
}

.season-list::-webkit-scrollbar,
.episode-list::-webkit-scrollbar {
    height: 8px;
}

.season-list::-webkit-scrollbar-track,
.episode-list::-webkit-scrollbar-track {
    background: transparent;
}

.season-list::-webkit-scrollbar-thumb,
.episode-list::-webkit-scrollbar-thumb {
    background: var(--button-bg);
    border-radius: 8px;
}

.episode-list {
    margin-top: 0;
}

.season-button,
.episode-button {
    box-sizing: border-box;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-width: 124px;
    min-height: 38px;
    padding: 9px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--container-bg);
    color: var(--heading-color);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    transition: transform 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    white-space: nowrap;
}

.episode-button {
    max-width: 260px;
    min-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    justify-content: flex-start;
}

.season-button:hover,
.season-button:focus-visible,
.episode-button:hover,
.episode-button:focus-visible,
.season-button.active,
.episode-button.active {
    background: rgba(102, 126, 234, 0.08);
    border-color: var(--button-bg);
    color: var(--button-bg);
    outline: none;
}

.season-button:hover,
.season-button:focus-visible,
.episode-button:hover,
.episode-button:focus-visible {
    transform: translateY(-1px);
}

.season-button:active,
.episode-button:active {
    transform: translateY(0);
}

.episode-status {
    flex: 0 0 auto;
    color: var(--text-color);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 2px;
}

.video-container {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
    border-radius: 8px;
    background: #000;
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* ── search overlay ── */
.search-overlay {
    position: fixed;
    inset: 0;
    background: var(--search-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    transition: opacity 0.2s ease;
}

.search-overlay.hidden {
    display: none;
}

/* ── search card ── */
.search-container {
    background: var(--container-bg);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 500px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.container > .search-container {
    margin: 0 auto;
}

.search-body .search-container {
    border-radius: 8px;
    box-shadow: none;
    max-width: none;
    overflow: visible;
}

/* ── Tabs ── */
.search-tabs {
    display: flex;
    border-bottom: 2px solid var(--input-border);
}

.search-tab {
    flex: 1;
    padding: 16px 12px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--tab-inactive-color);
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.search-tab:hover {
    color: var(--button-bg);
    background: rgba(102, 126, 234, 0.05);
}

.search-tab.active {
    color: var(--button-bg);
    border-bottom-color: var(--button-bg);
}

/* ── search body ── */
.search-body {
    padding: 24px;
}

.recent-watched {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 24px 24px;
    color: var(--text-color);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
}

.recent-watched:empty {
    display: none;
}

.recent-watched p {
    margin: 0;
}

.recent-watched h2 {
    color: var(--heading-color);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 2px;
}

.recent-watched a,
.recent-watched a:visited {
    color: var(--text-color);
    font: inherit;
    text-decoration: none;
    text-underline-offset: 3px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.recent-watched a:hover,
.recent-watched a:focus-visible,
.recent-watched a:active {
    color: var(--text-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
}

.recent-watched a:focus-visible {
    outline: 2px solid var(--input-focus-border);
    outline-offset: 3px;
    border-radius: 4px;
}

.tab-panel.hidden {
    display: none;
}

/* ── Search input inside search ── */
.search-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--input-border);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: var(--container-bg);
    color: var(--heading-color);
}

.search-input:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-input::placeholder {
    color: var(--text-color);
    opacity: 0.7;
}

.search-result-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--input-border);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-results {
    display: none;
    width: 100%;
    max-height: min(340px, 42vh);
    overflow-y: auto;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    margin-top: 10px;
    background: var(--container-bg);
    scrollbar-color: var(--button-bg) transparent;
    scrollbar-width: thin;
}

.search-results.active {
    display: block;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(102, 126, 234, 0.08);
}

.search-result-item:active {
    background: rgba(102, 126, 234, 0.15);
}

.search-result-poster {
    width: 40px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--input-border);
    flex-shrink: 0;
}

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

.search-result-title {
    color: var(--heading-color);
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    color: var(--text-color);
    font-size: 13px;
    display: flex;
    gap: 10px;
}

.search-loading,
.search-empty {
    padding: 20px 15px;
    text-align: center;
    color: var(--text-color);
    font-size: 14px;
}

/* ── ID tab ── */
.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.input-group input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid var(--input-border);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
    background: var(--container-bg);
    color: var(--heading-color);
}

.input-group input:focus {
    outline: none;
    border-color: var(--input-focus-border);
}

.input-group button {
    padding: 12px 24px;
    background: var(--button-bg);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    white-space: nowrap;
}

.input-group button:hover {
    background: var(--button-hover);
}

.input-group button:active {
    transform: scale(0.98);
}

.info-text {
    color: var(--text-color);
    font-size: 13px;
    line-height: 1.7;
    transition: color 0.3s ease;
}

.info-text code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--heading-color);
    background: rgba(102, 126, 234, 0.08);
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 6px;
}

.info-text code strong {
    color: var(--button-bg);
}

.top-anchor {
    flex: 0 0 auto;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 14px;
    margin-bottom: 10px;
    border-radius: 8px;
    background: var(--button-bg);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.3s ease, transform 0.2s ease;
}

.top-anchor:hover,
.top-anchor:focus-visible {
    background: var(--button-hover);
    outline: none;
    transform: translateY(-1px);
}

@media (max-width: 600px) {
    body {
        padding: 12px;
    }

    .page-section {
        min-height: calc(100vh - 24px);
    }

    .player-section {
        height: calc(100vh - 24px);
        min-height: calc(100vh - 24px);
    }

    .container {
        padding: 20px;
    }

    .search-panel {
        max-height: calc(100vh - 24px);
        overflow-y: auto;
    }

    .player-panel {
        padding: 12px;
    }

    .video-container {
        min-height: 0;
    }

    h1 {
        font-size: 22px;
    }

    .movie-details h2 {
        font-size: 18px;
    }

    .search-tab {
        font-size: 13px;
        padding: 14px 8px;
    }

    .theme-toggle {
        top: 10px;
        right: 10px;
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
}

@media (min-width: 601px) and (max-width: 1180px) {
    .player-panel {
        max-width: 100%;
    }
}

.instructions {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-left: 4px solid var(--button-bg);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    transition: all 0.3s ease;
}

.instructions h2 {
    color: var(--heading-color);
    font-size: 18px;
    margin-bottom: 15px;
    transition: color 0.3s ease;
}

.instructions ol {
    list-style: decimal inside;
    color: var(--text-color);
    line-height: 1.8;
}

.instructions li {
    margin-bottom: 12px;
    transition: color 0.3s ease;
}

.instructions strong {
    color: var(--heading-color);
    font-weight: 600;
}

.instructions a {
    color: var(--button-bg);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.instructions a:hover {
    color: var(--button-hover);
    text-decoration: underline;
}
