/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-input: #1a1a25;
    --bg-hover: #22222f;
    --text: #e8e8f0;
    --text-dim: #8888a0;
    --text-muted: #555568;
    --accent: #6c5ce7;
    --accent-hover: #7c6ef7;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --green: #00b894;
    --red: #e74c3c;
    --border: #2a2a3a;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app {
    max-width: 640px;
    margin: 0 auto;
    padding: 2rem 1.25rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}



.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a29bfe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    font-weight: 400;
}

/* ===== Input ===== */
.main { flex: 1; }

.input-section {
    margin-bottom: 1.5rem;
}

.input-wrapper {
    display: flex;
    gap: 0;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#urlInput {
    flex: 1;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    font-family: var(--font);
    background: transparent;
    border: none;
    color: var(--text);
    outline: none;
    min-width: 0;
}

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

.paste-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    background: var(--bg-hover);
    color: var(--text-dim);
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

.paste-btn:hover {
    color: var(--text);
    background: var(--bg-card);
}

#analyzeBtn {
    padding: 1rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font);
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

#analyzeBtn:hover {
    background: var(--accent-hover);
}

#analyzeBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.spinner {
    width: 20px;
    height: 20px;
}

.spinner.big {
    width: 28px;
    height: 28px;
}

/* ===== Platform badges ===== */
.platforms-hint {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.platform-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    user-select: none;
}

/* ===== Error ===== */
.error-msg {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #ff6b6b;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    animation: slideDown 0.25s ease;
}

/* ===== Playlist Dialog ===== */
.playlist-dialog {
    animation: slideDown 0.35s ease;
    margin-bottom: 1.5rem;
}
.playlist-dialog-inner {
    background: rgba(108, 92, 231, 0.08);
    border: 1px solid rgba(108, 92, 231, 0.25);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    text-align: center;
}
.playlist-dialog-inner h3 {
    color: var(--accent);
    font-size: 1rem;
    margin-bottom: 0.5rem;
}
.playlist-dialog-inner p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.playlist-dialog-btns {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}
.playlist-btn {
    padding: 0.6rem 1.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}
.playlist-btn.single {
    background: var(--bg-input);
    color: var(--text);
}
.playlist-btn.single:hover {
    background: var(--bg-hover);
}
.playlist-btn.all {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.playlist-btn.all:hover {
    background: var(--accent-hover);
}

/* ===== Playlist Section ===== */
.playlist-section {
    animation: slideDown 0.35s ease;
    margin-bottom: 1.5rem;
}
.playlist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.playlist-header h3 {
    color: var(--text);
    font-size: 1rem;
}
.playlist-controls label {
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.playlist-format-pick {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.playlist-format-pick span {
    color: var(--text-dim);
    font-size: 0.85rem;
}
.playlist-format-pick select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.75rem;
    font-family: var(--font);
    font-size: 0.85rem;
}
.playlist-download-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
}
.playlist-download-btn:hover {
    background: var(--accent-hover);
}
.playlist-download-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.playlist-items {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.playlist-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
.playlist-item input[type="checkbox"] {
    flex-shrink: 0;
}
.playlist-item .pi-num {
    color: var(--text-muted);
    min-width: 1.5rem;
    text-align: right;
}
.playlist-item .pi-title {
    color: var(--text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.playlist-item .pi-dur {
    color: var(--text-muted);
    font-size: 0.8rem;
    flex-shrink: 0;
}
.playlist-item .pi-status {
    font-size: 0.8rem;
    flex-shrink: 0;
    min-width: 60px;
    text-align: center;
}
.playlist-item .pi-status.done { color: var(--green); }
.playlist-item .pi-status.error { color: var(--red); }
.playlist-item .pi-status.waiting { color: var(--text-muted); }
.playlist-item .pi-status.downloading { color: var(--accent); }

.playlist-progress {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.progress-bar-outer {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-inner {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}
#playlistProgressText {
    color: var(--text-dim);
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ===== Cookie Upload Section ===== */
.cookie-section {
    animation: slideDown 0.35s ease;
    margin-bottom: 1.5rem;
}
.cookie-inner {
    background: rgba(255, 165, 0, 0.08);
    border: 1px solid rgba(255, 165, 0, 0.25);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.cookie-inner h3 {
    color: #ffa500;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}
.cookie-inner p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    line-height: 1.5;
}
.cookie-inner ol {
    color: var(--text-dim);
    font-size: 0.85rem;
    padding-left: 1.25rem;
    margin-bottom: 1rem;
    line-height: 1.8;
}
.cookie-inner a {
    color: var(--accent);
    text-decoration: none;
}
.cookie-inner a:hover {
    text-decoration: underline;
}
.cookie-upload {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.cookie-upload-btn {
    background: rgba(255, 165, 0, 0.15);
    color: #ffa500;
    border: 1px solid rgba(255, 165, 0, 0.35);
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font);
    transition: background 0.2s;
}
.cookie-upload-btn:hover {
    background: rgba(255, 165, 0, 0.25);
}
#cookieStatus {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* ===== Results ===== */
.results {
    display: flex;
    flex-direction: column;
    animation: slideDown 0.35s ease;
}

/* Desktop: preview first, then formats */
@media (min-width: 481px) {
    .result-platform { order: 1; }
    .download-progress { order: 4; }
    .formats-section { order: 3; }
    .preview-card { order: 2; }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-platform {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Preview card ===== */
.preview-card {
    display: flex;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.preview-thumb {
    flex-shrink: 0;
    width: 140px;
    height: 105px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    background: var(--bg-input);
}

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-duration {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0,0,0,0.8);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

.preview-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.preview-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.preview-author {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.preview-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Formats ===== */
.formats-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

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

.format-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.85rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.format-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.format-btn .fmt-icon {
    font-size: 1.5rem;
}

.format-btn .fmt-label {
    font-size: 0.8rem;
    font-weight: 600;
}

.format-btn .fmt-ext {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.format-btn.video .fmt-icon::after { content: "MP4"; font-size: 0.7rem; font-weight: 700; color: var(--accent); }
.format-btn.audio .fmt-icon::after { content: "MP3"; font-size: 0.7rem; font-weight: 700; color: var(--green); }

/* ===== Download progress ===== */
.download-progress {
    margin-bottom: 1rem;
    animation: slideDown 0.25s ease;
}

.progress-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    font-weight: 500;
    font-size: 0.9rem;
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding-top: 2rem;
    margin-top: auto;
}

.footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Cookie banner ===== */
.cookie-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 1000;
    max-width: 920px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 1rem 1.2rem;
    border: 1px solid rgba(108, 92, 231, 0.26);
    border-radius: 16px;
    background: rgba(13, 13, 19, 0.96);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.cookie-banner p {
    color: var(--text);
    font-size: 0.88rem;
    line-height: 1.55;
}

.cookie-banner-btn {
    align-self: flex-start;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1rem;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.cookie-banner-btn:hover {
    background: var(--accent-hover);
}

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .app { padding: 1.25rem 1rem; }
    .logo h1 { font-size: 1.35rem; }
    .subtitle { font-size: 0.8rem; }

    .input-wrapper {
        flex-direction: column;
    }

    .paste-btn {
        justify-content: center;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #analyzeBtn {
        justify-content: center;
        padding: 0.85rem;
    }

    /* Mobile: reorder so formats + progress are on top, preview on bottom */
    .results {
        display: flex;
        flex-direction: column;
    }

    .result-platform { order: 1; }
    .download-progress { order: 2; }
    .formats-section { order: 3; }
    .preview-card { order: 4; margin-top: 1rem; margin-bottom: 0; }

    .preview-card {
        flex-direction: column;
    }

    .preview-thumb {
        width: 100%;
        height: 180px;
    }

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

    .cookie-banner {
        left: 0.75rem;
        right: 0.75rem;
        bottom: 0.75rem;
        padding: 0.95rem 1rem;
    }
}
