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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #222240;
    --bg-input: #16162a;
    --border: #2a2a45;
    --border-focus: #6c5ce7;
    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #00cec9;
    --success-glow: rgba(0, 206, 201, 0.2);
    --error: #ff6b6b;
    --error-glow: rgba(255, 107, 107, 0.2);
    --audio-color: #fd79a8;
    --video-color: #74b9ff;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== APP LAYOUT ===== */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===== HEADER ===== */
.header {
    padding: 24px 0 8px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), #a29bfe);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
    font-weight: 400;
}

.backend-toggle {
    margin-left: auto;
    background: rgba(0, 206, 201, 0.15);
    border: 1px solid rgba(0, 206, 201, 0.3);
    color: var(--success);
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.backend-toggle.cloud {
    background: rgba(108, 92, 231, 0.15);
    border-color: rgba(108, 92, 231, 0.3);
    color: var(--accent-light);
}

.backend-toggle:active {
    transform: scale(0.92);
}

/* ===== MAIN ===== */
.main {
    flex: 1;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===== INPUT SECTION ===== */
.input-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 4px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

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

.input-icon {
    padding: 12px;
    flex-shrink: 0;
}

.input-icon svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

#url-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    padding: 12px 4px;
    min-width: 0;
}

#url-input::placeholder {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.paste-btn {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition), transform var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.paste-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.paste-btn:hover {
    background: var(--accent-light);
}

.paste-btn:active {
    transform: scale(0.92);
}

/* ===== PREVIEW SECTION ===== */
.preview-section {
    animation: slideUp 0.4s ease;
}

.preview-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

.thumbnail-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--bg-secondary);
}

.thumbnail-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.preview-info {
    padding: 14px 16px;
}

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

.preview-channel {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* ===== FORMAT SECTION ===== */
.format-section {
    animation: slideUp 0.4s ease;
}

.format-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.format-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    position: relative;
    font-family: inherit;
    color: var(--text-primary);
}

.format-card:hover {
    background: var(--bg-card-hover);
}

.format-card.active {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.08);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.format-card:active {
    transform: scale(0.97);
}

.format-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.format-icon.audio {
    background: rgba(253, 121, 168, 0.15);
}

.format-icon.audio svg {
    color: var(--audio-color);
    width: 24px;
    height: 24px;
}

.format-icon.video {
    background: rgba(116, 185, 255, 0.15);
}

.format-icon.video svg {
    color: var(--video-color);
    width: 24px;
    height: 24px;
}

.format-details {
    text-align: center;
}

.format-name {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.format-desc {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.format-check {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: all var(--transition);
}

.format-check svg {
    width: 14px;
    height: 14px;
    color: white;
}

.format-card.active .format-check {
    opacity: 1;
    transform: scale(1);
}

/* ===== QUALITY SECTION ===== */
.quality-section {
    animation: slideUp 0.3s ease;
}

.quality-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quality-pill {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 100px;
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    flex: 1;
    min-width: 0;
    text-align: center;
}

.quality-pill:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.quality-pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.quality-pill:active {
    transform: scale(0.95);
}

/* ===== DOWNLOAD BUTTON ===== */
.download-section {
    animation: slideUp 0.3s ease;
    margin-top: 8px;
}

.download-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), #a29bfe);
    border: none;
    border-radius: var(--radius-lg);
    padding: 18px;
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all var(--transition);
    font-family: inherit;
    letter-spacing: 0.01em;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.download-btn:hover {
    box-shadow: 0 6px 30px rgba(108, 92, 231, 0.5);
    transform: translateY(-1px);
}

.download-btn:active {
    transform: translateY(0) scale(0.98);
}

.download-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.download-icon {
    width: 22px;
    height: 22px;
}

/* ===== PROGRESS SECTION ===== */
.progress-section {
    animation: slideUp 0.3s ease;
}

.progress-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.progress-label {
    font-size: 0.9rem;
    font-weight: 600;
}

.progress-percent {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-light);
    font-variant-numeric: tabular-nums;
}

.progress-bar-wrapper {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 100px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 100px;
    transition: width 0.3s ease;
}

.progress-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 10px;
}

/* Pulsing animation for indeterminate progress */
.progress-bar.indeterminate {
    width: 40% !important;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* ===== ERROR SECTION ===== */
.error-section {
    animation: shake 0.4s ease;
}

.error-card {
    background: rgba(255, 107, 107, 0.08);
    border: 1px solid rgba(255, 107, 107, 0.25);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
}

.error-icon {
    margin-bottom: 12px;
}

.error-icon svg {
    width: 40px;
    height: 40px;
    color: var(--error);
}

.error-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 16px;
}

.error-retry {
    background: var(--error);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.error-retry:hover {
    opacity: 0.9;
}

.error-retry:active {
    transform: scale(0.95);
}

/* ===== SUCCESS SECTION ===== */
.success-section {
    animation: slideUp 0.4s ease;
}

.success-card {
    background: rgba(0, 206, 201, 0.08);
    border: 1px solid rgba(0, 206, 201, 0.25);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
}

.success-icon {
    margin-bottom: 12px;
}

.success-icon svg {
    width: 48px;
    height: 48px;
    color: var(--success);
}

.success-message {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--success);
}

.success-new {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 28px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.success-new:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

.success-new:active {
    transform: scale(0.95);
}

/* ===== FOOTER ===== */
.footer {
    padding: 20px 0;
    text-align: center;
}

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

/* ===== ANIMATIONS ===== */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ===== LOADING SPINNER (for paste button) ===== */
.paste-btn.loading svg {
    animation: spin 1s linear infinite;
}

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

/* ===== TABLET/DESKTOP ===== */
@media (min-width: 481px) {
    .app {
        padding: 0 32px;
    }

    .header {
        padding: 32px 0 16px;
    }
}

@media (min-width: 768px) {
    .app {
        max-width: 560px;
    }

    .main {
        padding: 32px 0;
        gap: 24px;
    }
}

/* ===== SAFE AREA (notch devices) ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .header {
        padding-top: calc(24px + env(safe-area-inset-top));
    }
}
