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

:root {
    --bg: #06060a;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.07);
    --surface-hover: rgba(255, 255, 255, 0.09);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(139, 92, 246, 0.5);
    --text: #f0f0f5;
    --text-secondary: #9898b0;
    --text-muted: #5e5e78;
    --accent: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.25);
    --accent-hover: #a78bfa;
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.08);
    --error-border: rgba(248, 113, 113, 0.2);
    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.08);
    --success-border: rgba(52, 211, 153, 0.25);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 3rem 1.25rem 2rem;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Ambient glow */
.glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.35;
    pointer-events: none;
    z-index: 0;
}
.glow-1 {
    width: 500px;
    height: 500px;
    background: var(--accent);
    top: -200px;
    left: -100px;
    opacity: 0.12;
}
.glow-2 {
    width: 400px;
    height: 400px;
    background: #ec4899;
    bottom: -150px;
    right: -100px;
    opacity: 0.08;
}

.app {
    width: 100%;
    max-width: 580px;
    position: relative;
    z-index: 1;
}

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

.logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.logo svg {
    color: var(--accent);
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    font-weight: 400;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
    flex-shrink: 0;
}

#url-input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.75rem;
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(12px);
}

#url-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

#fetch-btn {
    padding: 0 1.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font);
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    flex-shrink: 0;
}

#fetch-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

#fetch-btn:active:not(:disabled) {
    transform: scale(0.97);
}

#fetch-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Toast / Error */
.toast {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    font-weight: 500;
    animation: slideIn 0.25s ease;
}

.toast-error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
}

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

/* Card */
.card {
    margin-top: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow);
    animation: fadeUp 0.3s ease;
}

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

.card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

#video-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.duration-badge {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

.platform-icon {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
}

.card-body {
    padding: 1.25rem;
}

.card-body h2 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.uploader {
    font-size: 0.825rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    font-weight: 500;
}

/* Controls row */
.format-tabs {
    display: flex;
    gap: 0.35rem;
    margin-top: 1rem;
    padding: 3px;
    background: var(--surface-2);
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font);
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

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

.tab.active {
    background: var(--accent);
    color: #fff;
}

.tab.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.select-wrap {
    flex: 1;
    position: relative;
}

#format-select {
    width: 100%;
    padding: 0.7rem 2.25rem 0.7rem 0.85rem;
    font-size: 0.85rem;
    font-family: var(--font);
    font-weight: 500;
    background: #1a1a26;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.2s;
}

#format-select option {
    background: #1a1a26;
    color: var(--text);
}

#format-select:focus {
    border-color: var(--border-focus);
}

.select-wrap-sm {
    flex: 0 0 auto;
}

.select-wrap-sm select {
    width: 100%;
    padding: 0.7rem 2rem 0.7rem 0.85rem;
    font-size: 0.85rem;
    font-family: var(--font);
    font-weight: 500;
    background: #1a1a26;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.2s;
}

.select-wrap-sm select option {
    background: #1a1a26;
    color: var(--text);
}

.select-wrap-sm select:focus {
    border-color: var(--border-focus);
}

.select-chevron {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.btn-download {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font);
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-download:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-download:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-download:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loader */
.btn-loader {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.55s linear infinite;
}

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

.hidden {
    display: none !important;
}

/* Slideshow */
.slideshow-section {
    margin-top: 1rem;
}

.slides-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.slides-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
}

.check-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.slides-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    max-height: 450px;
    overflow-y: auto;
    padding-right: 4px;
}

.slides-grid::-webkit-scrollbar {
    width: 4px;
}

.slides-grid::-webkit-scrollbar-track {
    background: transparent;
}

.slides-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.slide-card {
    position: relative;
    border-radius: var(--radius-xs);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.1s;
}

.slide-card:hover {
    transform: scale(1.03);
}

.slide-card.selected {
    border-color: var(--accent);
}

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

.slide-number {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slide-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s, transform 0.2s;
}

.slide-card.selected .slide-check {
    opacity: 1;
    transform: scale(1);
}

.slides-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.slides-actions .btn-download {
    flex: 1;
    justify-content: center;
    padding: 0.65rem 1rem;
}

.btn-outline {
    background: transparent !important;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface-hover) !important;
    border-color: var(--accent);
    color: var(--accent);
}

/* Setup page */
.setup-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

.setup-desc strong {
    color: var(--error);
    font-weight: 600;
}

.auth-status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding: 0.7rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.linked {
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.status-dot.unlinked {
    background: var(--text-muted);
}

.setup-btn {
    width: 100%;
    justify-content: center;
    padding: 0.8rem;
    margin-top: 0.75rem;
}

/* Cookie guide */
.cookie-guide {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.cookie-guide-title {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.85rem;
}

.cookie-guide-title svg {
    color: var(--accent);
    flex-shrink: 0;
}

.cookie-steps {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.cookie-step {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
}

.step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    margin-top: 1px;
}

.step-body {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

.step-body a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.step-body a:hover {
    text-decoration: underline;
}

.step-body strong {
    color: var(--text);
    font-weight: 600;
}

.step-body code {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

.step-tags {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.35rem;
}

.step-tag {
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: inline-block;
    width: fit-content;
}

.step-tag strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* Cookie input */
.cookie-input-group {
    margin-bottom: 0.25rem;
}

.cookie-input-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.45rem;
}

.cookie-textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.cookie-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.cookie-textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
    font-style: italic;
}

/* Divider */
.cookie-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.85rem 0;
}

.cookie-divider-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.cookie-divider-text {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Upload area */
.cookie-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1.1rem;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    text-align: center;
}

.cookie-upload-area:hover {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.04);
}

.cookie-upload-area svg {
    color: var(--text-muted);
    transition: color 0.2s;
}

.cookie-upload-area:hover svg {
    color: var(--accent);
}

.upload-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.upload-label strong {
    color: var(--text);
}

.upload-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Error */
.import-error {
    margin-top: 0.65rem;
    padding: 0.6rem 0.85rem;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: var(--radius-xs);
    font-size: 0.8rem;
    color: var(--error);
    line-height: 1.5;
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--accent);
}

/* Debug output */
.setup-debug {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.85rem;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 0.7rem;
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
}

/* Playlist */
.playlist-header {
    margin-bottom: 0.75rem;
}

.playlist-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    font-weight: 500;
}

.playlist-items {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 480px;
    overflow-y: auto;
    padding-right: 4px;
}

.playlist-items::-webkit-scrollbar {
    width: 4px;
}

.playlist-items::-webkit-scrollbar-track {
    background: transparent;
}

.playlist-items::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.playlist-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}

.playlist-item:hover {
    background: var(--surface-hover);
    border-color: var(--border);
}

.playlist-item-thumb {
    position: relative;
    width: 120px;
    min-width: 120px;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
}

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

.playlist-item-duration {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.playlist-item-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    min-width: 0;
}

.playlist-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
}

.playlist-item-uploader {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 3rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--accent);
}

.dot {
    opacity: 0.4;
}

/* Responsive */
@media (max-width: 480px) {
    body {
        padding: 2rem 1rem 1.5rem;
    }

    .search-bar {
        flex-direction: column;
    }

    #fetch-btn {
        justify-content: center;
        padding: 0.8rem;
    }

    .controls {
        flex-direction: column;
    }

    .btn-download {
        justify-content: center;
        padding: 0.75rem;
    }
}
