:root {
    --bg-base: #050505;
    --card-bg: #111111;
    --card-hover: #1a1a1a;
    --primary: #ffffff;
    --primary-dim: rgba(255, 255, 255, 0.7);
    --text-main: #f5f5f5;
    --text-muted: #888888;
    --border: #222222;
    --accent: #3b82f6;
    --error: #ef4444;
}

[data-theme="light"] {
    --bg-base: #f9fafb;
    --card-bg: #ffffff;
    --card-hover: #f3f4f6;
    --primary: #0f172a;
    --primary-dim: rgba(15, 23, 42, 0.7);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 2rem 1rem;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    padding-top: 4vh;
}

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

header {
    text-align: center;
}

.theme-btn {
    position: absolute;
    right: 1rem;
    top: 1rem;
    z-index: 10;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: color 0.3s, background 0.3s;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.theme-btn:hover {
    color: var(--primary);
    background: var(--card-hover);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 2.8rem;
    margin-bottom: 0.75rem;
}

.custom-img-logo {
    height: 220px;
    width: auto;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

.subtitle::before,
.subtitle::after {
    content: '';
    width: 30px;
    height: 1px;
    background: var(--border);
}

/* Search Bar */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 0.5rem;
    transition: border-color 0.3s ease;
}

.search-box:focus-within {
    border-color: var(--primary-dim);
}

.input-icon {
    position: absolute;
    left: 1.5rem;
    color: var(--text-muted);
    font-size: 1.1rem;
}

input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 1rem 0.5rem 1rem 3rem;
    color: var(--text-main);
    font-size: 1.05rem;
    outline: none;
    min-width: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

input::placeholder {
    color: var(--text-muted);
}

.search-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-right: 0.5rem;
}

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.icon-btn:hover {
    color: var(--text-main);
    background: var(--card-hover);
}

#searchBtn {
    background: var(--primary);
    color: var(--bg-base);
}

#searchBtn:hover {
    transform: scale(1.05);
    background: #e0e0e0;
}

#searchBtn:active {
    transform: scale(0.95);
}

.hidden {
    display: none !important;
}

/* Loading & Error states */
#loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 0;
    gap: 1.25rem;
}

#loading p {
    color: var(--text-muted);
    font-size: 0.9rem;
    letter-spacing: 0.03em;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--text-main);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#errorBox {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    font-size: 0.95rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Result Card */
#resultCard {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.video-info {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: center;
}

.video-info img {
    width: 250px;
    flex-shrink: 0;
    height: auto;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
}

@media (max-width: 600px) {
    .video-info {
        flex-direction: column;
        align-items: stretch;
    }
    
    .video-info img {
        width: 100%;
    }
}

.video-details h2 {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.meta-row > span {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.meta-row > span i {
    font-size: 0.75rem;
    opacity: 0.7;
}

.duration-meta > span {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.2);
    color: var(--accent);
    font-weight: 600;
}

/* Format Section */
.format-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    width: fit-content;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.6rem 1.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 10px;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: var(--bg-base);
    font-weight: 600;
}

/* Format Grid */
.format-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.format-chip {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.format-chip:hover {
    background: var(--card-hover);
    border-color: var(--primary-dim);
    transform: translateY(-2px);
}

.chip-res {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.chip-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.chip-ext {
    text-transform: uppercase;
    background: var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.download-icon {
    margin-left: auto;
    color: var(--text-muted);
    transition: color 0.2s;
}

.format-chip:hover .download-icon {
    color: var(--primary);
}

footer {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: auto;
    padding-bottom: 1rem;
}

/* Overlay */
#downloadOverlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(5, 5, 5, 0.9);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s;
}

.overlay-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    width: 90%;
    max-width: 420px;
}

.overlay-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.overlay-content p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.85rem;
    color: var(--text-main);
    font-weight: 500;
}

.progress-bar-bg {
    width: 100%;
    height: 10px;
    background: var(--card-hover);
    border-radius: 99px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* Footer Links */
.footer-links {
    margin-top: 0.5rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* Legal Pages */
.legal-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-main);
    line-height: 1.6;
    animation: fadeIn 0.4s ease-out;
}

.legal-container h1 {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.legal-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
}

.last-updated {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.legal-container h2 {
    font-size: 1.3rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.legal-container p {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.legal-container ul {
    margin-left: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

.legal-container li {
    margin-bottom: 0.5rem;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 1.5rem;
    font-weight: 500;
    transition: color 0.2s;
}

.back-btn:hover {
    color: var(--primary);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    body {
        padding: 1rem;
    }
    
    .custom-img-logo {
        height: 120px;
    }
    
    .video-info {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .video-info img {
        width: 100%;
        max-width: 320px;
    }
    
    .meta-row {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .search-box {
        padding: 0.3rem;
    }
    
    .input-icon {
        left: 1rem;
    }
    
    input {
        padding: 0.8rem 0.5rem 0.8rem 2.8rem;
        font-size: 0.95rem;
    }
    
    .icon-btn {
        width: 38px;
        height: 38px;
    }
    
    .search-actions {
        padding-right: 0;
    }
    
    .legal-container {
        padding: 1.25rem;
    }
    
    .legal-container h1 {
        font-size: 1.6rem;
    }
}
