:root {
    --bg-main: #0c0e17;
    --bg-card: #151824;
    --bg-card-hover: #1b2030;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(99, 102, 241, 0.4);
    --primary: #6366f1;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --primary-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --error: #ef4444;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
}

body {
    display: flex;
    justify-content: center;
    position: relative;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}

/* Background Ambient Glows */
.background-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
}

.glow-1 {
    width: clamp(280px, 45vw, 500px);
    height: clamp(280px, 45vw, 500px);
    background: radial-gradient(circle, rgba(99, 102, 241, 0.18) 0%, rgba(99, 102, 241, 0) 70%);
    top: -80px;
    left: 10%;
}

.glow-2 {
    width: clamp(250px, 40vw, 450px);
    height: clamp(250px, 40vw, 450px);
    background: radial-gradient(circle, rgba(168, 85, 247, 0.14) 0%, rgba(168, 85, 247, 0) 70%);
    top: 250px;
    right: 5%;
}

.container {
    width: 100%;
    max-width: 820px;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(18px, 4vw, 28px);
}

/* Header */
.app-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 30px;
    font-size: 12px;
    color: #a5b4fc;
    font-weight: 600;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #22c55e;
    box-shadow: 0 0 10px #22c55e;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: clamp(26px, 6vw, 42px);
    font-weight: 800;
    letter-spacing: -0.8px;
    line-height: 1.2;
}

.app-header h1 span {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: clamp(14px, 3.5vw, 16px);
    max-width: 580px;
    line-height: 1.5;
    padding: 0 8px;
}

/* Card base */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Search Box */
.search-box {
    padding: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
    border: 1px solid var(--border-highlight);
    box-shadow: 0 0 25px var(--accent-glow);
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-height: 48px;
    position: relative;
}

.search-icon {
    width: 20px;
    height: 20px;
    stroke: var(--text-muted);
    flex-shrink: 0;
}

.input-wrapper input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    /* 16px prevents iOS Safari from automatically zooming in on focus */
    font-size: 16px;
    font-weight: 500;
}

.input-wrapper input::placeholder {
    color: #64748b;
    font-size: 15px;
}

/* Clear Button */
.clear-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.clear-btn:active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    user-select: none;
    touch-action: manipulation;
    min-height: 46px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    flex-shrink: 0;
}

.btn-primary:hover {
    opacity: 0.95;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    padding: 8px 14px;
    min-height: 38px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.btn-secondary:active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.35);
}

.btn-block {
    width: 100%;
}

/* Platforms tags */
.platforms {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.platform-tag {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* Alert */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}

.alert.error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Video Card */
.video-card {
    padding: clamp(16px, 3.5vw, 24px);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.video-meta {
    display: flex;
    gap: 18px;
}

.thumb-container {
    position: relative;
    width: 220px;
    height: 130px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    background: #000;
}

.thumb-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 5px;
    backdrop-filter: blur(4px);
}

.meta-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    min-width: 0;
}

.source-badge {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    padding: 3px 8px;
    border-radius: 5px;
    width: fit-content;
    font-weight: 700;
}

.meta-details h2 {
    font-size: clamp(16px, 3vw, 20px);
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-main);
    word-break: break-word;
}

.author-name {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Formats Grid */
.formats-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.formats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.format-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    touch-action: manipulation;
}

.format-item:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
    border-color: rgba(99, 102, 241, 0.5);
}

.format-item .top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.format-label {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-main);
}

.format-ext {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    color: #cbd5e1;
}

.format-btn {
    width: 100%;
    padding: 8px;
    font-size: 13px;
    min-height: 38px;
}

/* Download & Progress Card */
.download-card {
    padding: clamp(16px, 3.5vw, 22px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.download-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.download-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.download-info h4 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.download-info p {
    font-size: 13px;
    color: var(--text-muted);
}

.download-pct {
    font-size: clamp(18px, 4vw, 22px);
    font-weight: 800;
    color: #a5b4fc;
    flex-shrink: 0;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    overflow: hidden;
}

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

.complete-action {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.success-message {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #6ee7b7;
    text-align: center;
}

/* Spinners */
.btn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-icon {
    width: 22px;
    height: 22px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.hidden {
    display: none !important;
}

/* Footer */
.app-footer {
    text-align: center;
    font-size: 12px;
    color: #475569;
    margin-top: 10px;
}

/* Mobile Responsive Optimization (< 640px) */
@media (max-width: 640px) {
    body {
        padding: 12px 12px 32px 12px;
    }

    .container {
        gap: 16px;
    }

    .search-box {
        flex-direction: column;
        padding: 6px;
    }

    .input-wrapper {
        width: 100%;
        padding: 6px 10px;
    }

    #fetchBtn {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }

    .video-meta {
        flex-direction: column;
        gap: 14px;
    }

    .thumb-container {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
    }

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

    .format-item {
        padding: 10px 12px;
    }

    .format-btn {
        min-height: 42px;
        font-size: 13px;
    }
}

/* Very small mobile screens (< 380px) */
@media (max-width: 380px) {
    .formats-grid {
        grid-template-columns: 1fr;
    }
}
