/* ========== CSS Variables ========== */
:root {
    --bg-primary: #0a0a14;
    --bg-secondary: #111122;
    --bg-card: rgba(22, 33, 62, 0.6);
    --bg-card-solid: #16213e;
    --bg-input: rgba(15, 52, 96, 0.5);
    --bg-input-solid: #0f3460;
    --text-primary: #f0f0f5;
    --text-secondary: #8888a8;
    --text-muted: #5a5a7a;
    --accent: #e94560;
    --accent-hover: #d63050;
    --accent-glow: rgba(233, 69, 96, 0.3);
    --gradient-accent: linear-gradient(135deg, #e94560 0%, #c026d3 100%);
    --gradient-accent-hover: linear-gradient(135deg, #d63050 0%, #a020b0 100%);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.25);
    --success: #22c55e;
    --success-glow: rgba(34, 197, 94, 0.25);
    --warning: #f59e0b;
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.25);
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Ambient background glow */
body::before {
    content: '';
    position: fixed;
    top: -40%;
    left: -20%;
    width: 80%;
    height: 80%;
    background: radial-gradient(circle, rgba(233, 69, 96, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    bottom: -30%;
    right: -20%;
    width: 70%;
    height: 70%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.05) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* ========== Header ========== */
#app-header {
    background: rgba(17, 17, 34, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px 20px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.header-logo {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #f0f0f5 0%, #a0a0c0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.3px;
}

#tab-nav {
    display: flex;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 8px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.25s ease;
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px;
    letter-spacing: 0.2px;
}

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

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.badge {
    background: var(--gradient-accent);
    color: white;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
}

.badge.hidden { display: none; }

/* ========== Main Content ========== */
main {
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 14px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== Cards (Glass) ========== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    border-color: var(--border-light);
}

.card.hidden { display: none; }

/* ========== Forms ========== */
label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

input[type="url"],
input[type="text"],
select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    padding: 13px 14px;
    outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    min-height: 48px;
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

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

.input-row {
    display: flex;
    gap: 10px;
}

.input-row input { flex: 1; }

.select-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.select-group { flex: 1; }
.select-group.full { flex: 1 1 100%; }

.subtitle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.subtitle-row select {
    width: 80px;
    flex-shrink: 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    min-height: 44px;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

/* ========== Buttons ========== */
.btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    padding: 12px 22px;
    cursor: pointer;
    transition: all 0.25s ease;
    -webkit-user-select: none;
    user-select: none;
    min-height: 48px;
    white-space: nowrap;
    letter-spacing: 0.2px;
    position: relative;
    overflow: hidden;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--primary);
    box-shadow: 0 2px 12px var(--primary-glow);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 20px var(--primary-glow);
}

.btn-download {
    background: var(--gradient-accent);
    width: 100%;
    font-size: 16px;
    font-weight: 700;
    padding: 16px;
    border-radius: var(--radius);
    margin-top: 6px;
    box-shadow: 0 4px 20px var(--accent-glow);
    letter-spacing: 0.3px;
}
.btn-download:hover {
    box-shadow: 0 6px 30px var(--accent-glow);
    filter: brightness(1.1);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-light);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-small {
    font-size: 12px;
    padding: 8px 14px;
    min-height: 34px;
    border-radius: var(--radius-xs);
}

.btn-save {
    background: var(--success);
    box-shadow: 0 2px 12px var(--success-glow);
}
.btn-save:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 20px var(--success-glow);
}

.btn-cancel {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-cancel:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* ========== Status Text ========== */
.status-text {
    font-size: 13px;
    margin-top: 10px;
    color: var(--text-secondary);
}
.status-text.error { color: var(--error); }
.status-text.hidden { display: none; }

/* ========== Video Info ========== */
#video-info { text-align: center; }

.thumbnail {
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--bg-input);
    box-shadow: var(--shadow-md);
}

#info-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.4;
    text-align: left;
}

.info-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.meta-badge {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    white-space: nowrap;
    border: 1px solid var(--border);
}

.playlist-notice {
    color: var(--warning);
    font-size: 13px;
    font-weight: 600;
    margin-top: 8px;
}

.playlist-notice.hidden { display: none; }

/* ========== Playlist Selection ========== */
.playlist-header {
    margin-bottom: 12px;
}

.playlist-header h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.playlist-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.playlist-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background 0.2s ease;
}

.playlist-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.playlist-item:last-child { border-bottom: none; }

.playlist-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.playlist-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-item-duration {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

/* ========== Queue Items ========== */
.queue-item {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    animation: slideIn 0.3s ease;
}

.queue-item-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.queue-progress-bar {
    height: 100%;
    background: var(--gradient-accent);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
    position: relative;
}

.queue-progress-bar.downloading {
    background-size: 30px 30px;
    animation: shimmer 1.5s linear infinite;
}

.queue-progress-bar.complete {
    background: var(--success);
}

.queue-progress-bar.error {
    background: var(--error);
}

.queue-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.queue-actions {
    display: flex;
    gap: 8px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 50px 20px;
}

.empty-state-icon {
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state-desc {
    font-size: 13px;
    color: var(--text-muted);
}

/* Legacy empty message fallback */
.empty-message {
    text-align: center;
    color: var(--text-muted);
    padding: 50px 20px;
    font-size: 14px;
}

/* ========== How-To Steps ========== */
.how-to {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    padding: 0 4px;
}

.how-to-step {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    color: white;
}

.how-to-step:nth-child(1) .step-num { background: var(--primary); }
.how-to-step:nth-child(3) .step-num { background: var(--accent); }
.how-to-step:nth-child(5) .step-num { background: var(--success); }

/* Step connectors */
.step-connector {
    color: var(--text-muted);
    opacity: 0.2;
    flex-shrink: 0;
    font-size: 12px;
}

/* ========== Supported Platforms ========== */
.platforms {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    justify-content: center;
}

.platform-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    transition: all 0.25s ease;
    font-weight: 500;
}

.platform-tag:hover {
    border-color: var(--border-light);
    background: rgba(255, 255, 255, 0.06);
}

.platform-tag svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ========== Footer ========== */
#app-footer {
    text-align: center;
    padding: 24px 16px 36px;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

#app-footer p {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.5;
    line-height: 1.5;
}

/* ========== Toast Notifications ========== */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 90%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: rgba(22, 33, 62, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
    cursor: pointer;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--primary); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========== Loading Spinner ========== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* ========== Animations ========== */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
    from { background-position: -30px 0; }
    to { background-position: 30px 0; }
}

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

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ========== Tablet+ ========== */
@media (min-width: 600px) {
    main {
        max-width: 680px;
        padding: 24px;
    }

    .card { padding: 24px; }

    #app-header {
        padding: 20px 24px 0;
    }

    .header-brand h1 { font-size: 22px; }

    .tab-btn { font-size: 15px; }
}
