* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #141420;
    --bg-card: #1c1c2e;
    --bg-hover: #252538;
    --text-primary: #ffffff;
    --text-secondary: #8b8b9e;
    --accent: #e50914;
    --accent-hover: #ff2525;
    --border: #2a2a3e;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

html {
    scroll-behavior: smooth;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Prevent CLS - reserve space */
.main-content {
    min-height: calc(100vh - 140px);
}

.drama-grid {
    min-height: 200px;
}

.header {
    background: linear-gradient(180deg, var(--bg-primary) 0%, transparent 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    backdrop-filter: blur(10px);
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.nav {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.nav a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav a:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.nav a.active {
    color: var(--text-primary);
    background: var(--accent);
}

.search-box {
    display: inline-flex;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 25px;
    padding: 0.25rem 0.25rem 0.25rem 1rem;
    transition: border-color 0.2s;
    margin: 0;
}

.search-box:focus-within {
    border-color: var(--accent);
}

.search-box input {
    background: transparent;
    border: none;
    padding: 0.5rem 0;
    color: var(--text-primary);
    width: 200px;
    font-size: 0.9rem;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.search-box select {
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    padding: 0.5rem 0.5rem 0.5rem 0;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.search-box select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.search-box button {
    background: var(--accent);
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.search-box button:hover {
    background: var(--accent-hover);
}

.main-content {
    padding: 80px 0 100px;
    min-height: 100vh;
}

.section {
    padding: 1.5rem;
}

.section-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.section-title.clickable {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title.clickable:hover {
    color: var(--accent);
}

.section-title.clickable::after {
    content: '→';
    font-size: 1rem;
    opacity: 0.6;
}

.drama-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.drama-card {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.25s, box-shadow 0.25s;
    position: relative;
}

.drama-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: var(--shadow);
}

.drama-card:active {
    transform: scale(0.98);
}

.drama-card .poster {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: var(--bg-secondary);
    contain: layout style paint;
}

.drama-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s, opacity 0.3s;
    content-visibility: auto;
}

.drama-card:hover img {
    transform: scale(1.05);
}

.drama-card .card-title {
    padding: 0.5rem 0.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    overflow: hidden;
    text-align: center;
}

.drama-card .badge {
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.6);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.drama-card .progress-badge {
    background: var(--accent);
    color: white;
    left: 0.5rem;
    right: auto;
}

.drama-card .trending-badge {
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: white;
    font-weight: 700;
    left: 0.5rem;
    right: auto;
}

.drama-card .source-badge {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.6rem;
    text-transform: capitalize;
    top: auto;
    bottom: 0.5rem;
}

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.5rem;
    z-index: 100;
    justify-content: space-around;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.bottom-nav::-webkit-scrollbar {
    display: none;
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.65rem;
    transition: all 0.2s;
    flex-shrink: 0;
}

.bottom-nav a.active {
    color: var(--accent);
}

.bottom-nav svg {
    width: 22px;
    height: 22px;
}

.player-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

.player-container {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1.5rem;
    aspect-ratio: 16/9;
    position: relative;
}

.player-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.player-container.portrait {
    aspect-ratio: 9/16;
    max-height: 80vh;
    margin: 0 auto 1.5rem;
    width: auto;
}

.subtitle-overlay {
    position: absolute;
    left: 5%;
    right: 5%;
    bottom: 33%;
    text-align: center;
    pointer-events: none;
    z-index: 10;
    display: none;
}

.subtitle-text {
    display: inline-block;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    line-height: 1.5;
    padding: 0.4em 0.8em;
    border-radius: 6px;
    text-shadow: 1px 1px 2px black;
    max-width: 100%;
}

.next-episode-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.next-episode-overlay.show {
    display: flex;
}

.next-episode-content {
    text-align: center;
    color: white;
}

.next-episode-content p {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.countdown-number {
    display: block;
    font-size: 4rem;
    font-weight: 700;
    color: var(--accent);
    margin: 0.5rem 0 1rem;
}

.next-episode-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.next-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.next-btn.cancel {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.next-btn.cancel:hover {
    background: rgba(255, 255, 255, 0.1);
}

.next-btn.play {
    background: var(--accent);
    color: white;
}

.next-btn.play:hover {
    filter: brightness(1.1);
}

@media (max-width: 768px) {
    .subtitle-text {
        font-size: 1rem;
        padding: 0.3em 0.6em;
    }

    .player-container.portrait {
        max-height: 70vh;
    }
}

.drama-header {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.drama-header .poster {
    width: 120px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.drama-header .poster img {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
}

.drama-header .info {
    flex: 1;
}

.drama-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    line-height: 1.3;
}

.drama-header .synopsis {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.episode-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.episode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 0.5rem;
}

.episode-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
}

.episode-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-secondary);
}

.episode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4rem 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-card);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-card {
    aspect-ratio: 2/3;
    margin-bottom: 0.5rem;
}

.skeleton-text {
    height: 14px;
    margin-bottom: 0.5rem;
}

.skeleton-text.short {
    width: 60%;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.loading-more {
    display: flex;
    justify-content: center;
    padding: 2rem;
    grid-column: 1 / -1;
}

.loading-more .spinner {
    width: 30px;
    height: 30px;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
        gap: 1rem;
    }

    .logo {
        font-size: 1.2rem;
    }

    .nav {
        display: none;
    }

    .search-box {
        flex: 1;
        padding: 0.2rem 0.2rem 0.2rem 0.5rem;
    }

    .search-box select {
        font-size: 0.75rem;
        padding: 0.4rem 0.3rem 0.4rem 0;
    }

    .search-box input {
        width: 100%;
        font-size: 0.85rem;
    }

    .search-box button {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }

    .bottom-nav {
        display: flex;
    }

    .main-content {
        padding: 70px 0 80px;
    }

    .section {
        padding: 1rem;
    }

    .section-title {
        font-size: 1.1rem;
    }

    .drama-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.6rem;
    }

    .drama-card .card-title {
        font-size: 0.7rem;
        padding: 0.4rem 0.15rem;
    }

    .drama-card .badge {
        font-size: 0.6rem;
    }

    .modal-content {
        padding: 1rem 0.75rem 1.5rem;
    }

    .player-container {
        border-radius: 0;
        margin: 0 -0.75rem 1rem;
    }

    .drama-header {
        gap: 1rem;
    }

    .drama-header .poster {
        width: 100px;
    }

    .drama-header h2 {
        font-size: 1.1rem;
    }

    .drama-header .synopsis {
        font-size: 0.8rem;
    }

    .episode-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 0.4rem;
    }

    .episode-btn {
        padding: 0.6rem 0.25rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 380px) {
    .drama-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .episode-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1200px) {
    .section {
        padding: 2rem 3rem;
    }

    .drama-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 1.25rem;
    }

    .modal-content {
        max-width: 1000px;
    }
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Share Modal */
.share-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10001;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.share-overlay.show {
    opacity: 1;
    visibility: visible;
}

.share-modal {
    background: var(--bg-card);
    border-radius: 1rem 1rem 0 0;
    width: 100%;
    max-width: 400px;
    padding: 1rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.share-overlay.show .share-modal {
    transform: translateY(0);
}

.share-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bg-secondary);
    margin-bottom: 1rem;
}

.share-header span {
    font-weight: 600;
    font-size: 1.1rem;
}

.share-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.share-options {
    display: flex;
    justify-content: space-around;
    gap: 0.5rem;
    padding-bottom: 1rem;
}

.share-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.75rem;
    border-radius: var(--radius);
    transition: background 0.2s;
    min-width: 60px;
}

.share-option:hover {
    background: var(--bg-secondary);
}

.share-option svg {
    width: 32px;
    height: 32px;
}

.share-option span {
    font-size: 0.75rem;
}

/* Install PWA Popup */
.install-popup {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 9999;
    max-width: 360px;
    width: calc(100% - 2rem);
    opacity: 0;
    transition: all 0.3s ease;
}

.install-popup.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.install-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.install-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
}

.install-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.install-text strong {
    font-size: 0.95rem;
}

.install-text span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.install-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.install-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

/* Favorite button on cards */
.fav-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 5;
}

.fav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.fav-btn svg {
    width: 18px;
    height: 18px;
    stroke: white;
    fill: none;
}

.fav-btn.active svg {
    fill: var(--accent);
    stroke: var(--accent);
}

/* Action buttons in modal */
.action-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-hover);
    border: 1px solid var(--bg-card);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--bg-card);
}

.action-btn svg {
    width: 16px;
    height: 16px;
}

.action-btn.active {
    background: var(--accent);
    border-color: var(--accent);
}

.action-btn.active svg {
    fill: white;
}

/* Static pages */
.static-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem;
}

.static-page h1 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.static-page h2 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--text-primary);
}

.static-page p {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 1rem;
}

.static-page ul {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.static-page li {
    margin-bottom: 0.5rem;
}

.static-page a {
    color: var(--accent);
    text-decoration: none;
}

.static-page a:hover {
    text-decoration: underline;
}

.contact-info {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-top: 1rem;
}

/* Footer */
.footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 1.5rem;
    margin-top: 2rem;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
}

.footer-links a:hover {
    color: var(--accent);
}

.footer-copy {
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.7;
}

@media (max-width: 600px) {
    .footer {
        padding-bottom: 5rem;
    }
}