/* ==========================================================================
   Paper Design System – Light & Dark Theme
   Inspired by Material You / Material Design 3
   ========================================================================== */

/* ---------- Theme Tokens ---------- */
:root,
[data-theme="light"] {
    /* Surfaces */
    --surface-base: #f5f3f0;
    --surface-card: #ffffff;
    --surface-card-hover: #faf9f7;
    --surface-input: #f0eee9;
    --surface-input-hover: #e8e5df;
    --surface-badge: #e9e6e0;

    /* Text */
    --text-primary: #1a1a1a;
    --text-secondary: #5f5f5f;
    --text-tertiary: #8a8a8a;
    --text-on-accent: #ffffff;

    /* Accent */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-subtle: rgba(79, 70, 229, 0.08);
    --accent-ring: rgba(79, 70, 229, 0.25);

    /* Status */
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.08);
    --success-border: rgba(22, 163, 74, 0.2);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.06);
    --danger-border: rgba(220, 38, 38, 0.15);

    /* Borders & Shadows */
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);

    /* Progress */
    --progress-bg: #e5e2dc;
    --progress-fill: var(--accent);

    /* Misc */
    --toggle-bg: #d4d0c8;
    --toggle-knob: #ffffff;
    --scrollbar-thumb: #c8c4bc;
    --select-arrow: var(--text-tertiary);
    --skeleton-from: #ece9e3;
    --skeleton-via: #f5f3f0;
    --skeleton-to: #ece9e3;

    color-scheme: light;
}

[data-theme="dark"] {
    --surface-base: #121212;
    --surface-card: #1e1e1e;
    --surface-card-hover: #252525;
    --surface-input: #2a2a2a;
    --surface-input-hover: #333333;
    --surface-badge: #2f2f2f;

    --text-primary: #e8e6e3;
    --text-secondary: #a0a0a0;
    --text-tertiary: #6b6b6b;
    --text-on-accent: #ffffff;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-subtle: rgba(129, 140, 248, 0.1);
    --accent-ring: rgba(129, 140, 248, 0.3);

    --success: #4ade80;
    --success-bg: rgba(74, 222, 128, 0.08);
    --success-border: rgba(74, 222, 128, 0.2);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.08);
    --danger-border: rgba(248, 113, 113, 0.15);

    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);

    --progress-bg: #2a2a2a;
    --progress-fill: var(--accent);

    --toggle-bg: #3a3a3a;
    --toggle-knob: #e8e6e3;
    --scrollbar-thumb: #3a3a3a;
    --select-arrow: var(--text-tertiary);
    --skeleton-from: #1e1e1e;
    --skeleton-via: #2a2a2a;
    --skeleton-to: #1e1e1e;

    color-scheme: dark;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--surface-base);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.35s ease, color 0.35s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 99px;
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4 {
    font-family: 'Outfit', system-ui, sans-serif;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    transition: color 0.35s ease;
}

.hidden { display: none !important; }

/* ==========================================================================
   App Shell
   ========================================================================== */
.app-container {
    width: 100%;
    max-width: 720px;
    padding: 2rem 1.25rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon { font-size: 1.35rem; }

.logo-text {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    transition: color 0.35s ease;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Status Pill */
.badge-status {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
    padding: 0.2rem 0.65rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.35s ease;
}

.status-dot {
    width: 5px;
    height: 5px;
    background-color: var(--success);
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: .4; transform: scale(.9); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
    width: 44px;
    height: 26px;
    background: var(--toggle-bg);
    border: none;
    border-radius: 99px;
    cursor: pointer;
    position: relative;
    transition: background 0.35s ease;
    flex-shrink: 0;
}

.theme-toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--toggle-knob);
    top: 3px;
    left: 3px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .theme-toggle::after {
    transform: translateX(18px);
}

.theme-toggle-icons {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5px;
    font-size: 0.7rem;
    pointer-events: none;
    z-index: 1;
}

/* ==========================================================================
   Intro / Hero
   ========================================================================== */
.intro-section {
    text-align: center;
    margin-bottom: 2rem;
}

.intro-section h1 {
    font-size: 2.5rem;
    line-height: 1.15;
    margin-bottom: 0.75rem;
}

.intro-section .subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    max-width: 440px;
    margin: 0 auto;
    transition: color 0.35s ease;
}

/* ==========================================================================
   Paper Card (Main Container)
   ========================================================================== */
.downloader-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1.75rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2.5rem;
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

.downloader-card:focus-within {
    box-shadow: var(--shadow-xl);
    border-color: var(--accent-ring);
}

/* ---------- Input Row ---------- */
.input-group {
    display: flex;
    gap: 0.75rem;
}

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

.input-icon {
    position: absolute;
    left: 1rem;
    font-size: 1.1rem;
    color: var(--text-tertiary);
    pointer-events: none;
    transition: color 0.35s ease;
}

.input-group input[type="url"] {
    width: 100%;
    background: var(--surface-input);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    padding: 0.85rem 6.5rem 0.85rem 2.75rem;
    border-radius: 14px;
    outline: none;
    transition: all 0.25s ease;
}

.input-group input[type="url"]::placeholder {
    color: var(--text-tertiary);
}

.input-group input[type="url"]:hover {
    background: var(--surface-input-hover);
}

.input-group input[type="url"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
    background: var(--surface-card);
}

/* Paste chip inside input */
.btn-paste {
    position: absolute;
    right: 0.5rem;
    background: var(--surface-badge);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.35rem 0.75rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-paste:hover {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent-ring);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.85rem 1.75rem;
    border-radius: 14px;
    cursor: pointer;
    border: none;
    outline: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 48px;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-on-accent);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-block { width: 100%; }

.btn-loader {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.25);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ==========================================================================
   Shimmer Loading Skeleton
   ========================================================================== */
.shimmer-loader {
    margin-top: 1.75rem;
    display: flex;
    gap: 1.25rem;
    padding: 1.25rem;
    border-radius: 14px;
    border: 1px dashed var(--border-strong);
    background: var(--surface-card);
}

.shimmer-thumbnail {
    width: 160px;
    height: 100px;
    border-radius: 10px;
    background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-via) 50%, var(--skeleton-to) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
    flex-shrink: 0;
}

.shimmer-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    justify-content: center;
}

.shimmer-line {
    background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-via) 50%, var(--skeleton-to) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
    border-radius: 6px;
}

.shimmer-line.title  { width: 75%; height: 1rem; }
.shimmer-line.subtitle { width: 45%; height: 0.75rem; }
.shimmer-line.button { width: 90px; height: 2rem; margin-top: 0.25rem; border-radius: 10px; }

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   Preview Card
   ========================================================================== */
.preview-box {
    margin-top: 1.75rem;
    animation: slideUp 0.35s ease-out;
}

.preview-card {
    display: flex;
    gap: 1.25rem;
    background: var(--surface-base);
    border: 1px solid var(--border);
    padding: 1.25rem;
    border-radius: 16px;
    transition: all 0.35s ease;
}

.preview-media {
    position: relative;
    width: 180px;
    min-width: 180px;
    height: 115px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    box-shadow: var(--shadow-sm);
}

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

.platform-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.preview-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.media-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 0.15rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.media-uploader {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.65rem;
}

.media-details {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.85rem;
    flex-wrap: wrap;
}

.detail-tag {
    background: var(--surface-badge);
    color: var(--text-secondary);
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.35s ease;
}

/* ---------- Quality Dropdown ---------- */
.format-selection-wrapper {
    margin-bottom: 1rem;
}

.format-selection-wrapper label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.select-wrapper {
    position: relative;
    width: 100%;
}

.select-wrapper select {
    width: 100%;
    background: var(--surface-input);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    padding: 0.65rem 2.5rem 0.65rem 0.85rem;
    border-radius: 10px;
    outline: none;
    font-size: 0.85rem;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: all 0.2s ease;
}

.select-wrapper select:hover {
    background: var(--surface-input-hover);
    border-color: var(--border-strong);
}

.select-wrapper select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.select-wrapper select option {
    background-color: var(--surface-card);
    color: var(--text-primary);
    padding: 0.5rem;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--select-arrow);
    pointer-events: none;
    transition: border-color 0.35s ease;
}

/* ==========================================================================
   Progress Bar
   ========================================================================== */
.progress-box {
    margin-top: 1.75rem;
    background: var(--surface-base);
    border: 1px solid var(--border);
    padding: 1.25rem;
    border-radius: 16px;
    animation: slideUp 0.3s ease-out;
    transition: all 0.35s ease;
}

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

.progress-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.progress-bar-wrapper {
    height: 6px;
    background: var(--progress-bg);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 0.85rem;
    transition: background 0.35s ease;
}

.progress-bar {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 99px;
    transition: width 0.15s ease, background 0.35s ease;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.stat-badge {
    background: var(--surface-badge);
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 0.3rem 0.65rem;
    border-radius: 8px;
    flex-grow: 1;
    text-align: center;
    transition: all 0.35s ease;
}

/* ==========================================================================
   Error
   ========================================================================== */
.error-box {
    margin-top: 1.5rem;
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger);
    padding: 0.85rem 1rem;
    border-radius: 14px;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    animation: shake 0.35s ease-in-out;
    font-size: 0.9rem;
    transition: all 0.35s ease;
}

.error-icon { font-size: 1.15rem; }
.error-text {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.4rem;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* ==========================================================================
   Platforms Grid
   ========================================================================== */
.platforms-section {
    margin-bottom: 2.5rem;
}

.platforms-section h3 {
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 1.25rem;
}

.platforms-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.platform-item {
    background: var(--surface-card);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    cursor: default;
    box-shadow: var(--shadow-sm);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.platform-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--brand-color);
}

.platform-item .icon {
    width: 26px;
    height: 26px;
    color: var(--brand-color);
    transition: transform 0.25s ease;
}

.platform-item:hover .icon {
    transform: scale(1.1);
}

.platform-item span {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.25s ease;
}

.platform-item:hover span {
    color: var(--text-primary);
}

/* ==========================================================================
   Download History
   ========================================================================== */
.history-section {
    margin-bottom: 2.5rem;
}

.history-section h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.history-item {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease-out;
    transition: all 0.35s ease;
}

.history-item:hover {
    box-shadow: var(--shadow-md);
}

.history-item-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.history-item-icon {
    font-size: 1.15rem;
    background: var(--surface-badge);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.35s ease;
}

.history-item-details { min-width: 0; }

.history-item-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.1rem;
}

.history-item-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.btn-history-dl {
    background: var(--accent-subtle);
    color: var(--accent);
    border: 1px solid transparent;
    padding: 0.4rem 0.85rem;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
    min-height: auto;
}

.btn-history-dl:hover {
    background: var(--accent);
    color: var(--text-on-accent);
}

/* ==========================================================================
   Auth Overlay
   ========================================================================== */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: var(--surface-base);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    animation: fadeIn 0.3s ease-out;
    transition: background 0.35s ease;
}

.auth-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    padding: 2.5rem 2rem;
    border-radius: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-xl);
    text-align: center;
    transition: all 0.35s ease;
}

.auth-logo { margin-bottom: 1.25rem; }

.auth-logo span {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
}

.auth-card h2 {
    font-size: 1.35rem;
    margin-bottom: 0.5rem;
}

.auth-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
}

.auth-form input[type="password"] {
    width: 100%;
    background: var(--surface-input);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    padding: 0.85rem;
    font-size: 0.95rem;
    border-radius: 14px;
    outline: none;
    margin-bottom: 1rem;
    text-align: center;
    transition: all 0.25s ease;
}

.auth-form input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
    margin-top: auto;
    padding: 1.75rem 0;
    text-align: center;
    border-top: 1px solid var(--border);
    transition: border-color 0.35s ease;
}

.app-footer p {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-bottom: 0.35rem;
}

.app-footer .disclaimer {
    font-size: 0.7rem;
    max-width: 420px;
    margin: 0 auto;
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

/* ==========================================================================
   Navigation Tabs
   ========================================================================== */
.tab-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.4rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.35s ease;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.65rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--surface-input);
}

.tab-btn.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.tab-panel {
    animation: fadeIn 0.35s ease-out;
}

/* ==========================================================================
   Server Library Layout
   ========================================================================== */
.library-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.library-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.download-action-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.library-item-progress-container {
    width: 100%;
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.library-item-progress-bar-wrapper {
    height: 5px;
    background: var(--progress-bg);
    border-radius: 99px;
    overflow: hidden;
    width: 100%;
    transition: background 0.35s ease;
}

.library-item-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    transition: width 0.15s ease, background 0.35s ease;
}

.library-item {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
    animation: slideUp 0.3s ease-out;
}

.library-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
}

.library-item-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    flex-grow: 1;
}

.library-item-thumb {
    width: 110px;
    height: 70px;
    border-radius: 8px;
    object-fit: cover;
    background: #000;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.library-item-info {
    min-width: 0;
    flex-grow: 1;
}

.library-item-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.library-item-meta span {
    display: inline-flex;
    align-items: center;
}

.library-item-meta .separator {
    color: var(--text-tertiary);
}

.library-item-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--surface-card);
    border: 1.5px dashed var(--border-strong);
    border-radius: 20px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
}

.empty-state p {
    font-weight: 500;
    font-size: 1rem;
}

/* Button modifiers */
.btn-sm {
    min-height: 36px;
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    border-radius: 10px;
}

.btn-danger-subtle {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid transparent;
}

.btn-danger-subtle:hover {
    background: var(--danger);
    color: #fff;
}

.btn-secondary-subtle {
    background: var(--surface-badge);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary-subtle:hover {
    background: var(--surface-input-hover);
    color: var(--text-primary);
}

/* ==========================================================================
   Frame Viewer Modal & Timeline
   ========================================================================== */
.frame-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    animation: fadeIn 0.3s ease-out;
}

.frame-modal-content {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    width: 100%;
    max-width: 960px;
    max-height: 90vh;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: background 0.35s ease, border-color 0.35s ease;
}

.frame-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border);
}

.frame-modal-title-group h2 {
    font-size: 1.25rem;
    margin-bottom: 0.15rem;
}

.frame-modal-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.frame-modal-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-close-modal {
    background: transparent;
    border: none;
    outline: none;
    font-size: 1.75rem;
    font-weight: 300;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.btn-close-modal:hover {
    background: var(--surface-input);
    color: var(--text-primary);
}

/* Content Area */
.frame-display-container {
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
}

/* Large HQ Active Preview */
.active-frame-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: var(--surface-base);
    padding: 1.25rem;
    border-radius: 18px;
    border: 1px solid var(--border);
    transition: background 0.35s ease, border-color 0.35s ease;
}

.active-frame-image-container {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.frame-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
    z-index: 10;
}

.prev-btn {
    left: 0.75rem;
}

.next-btn {
    right: 0.75rem;
}

.frame-nav-btn:hover:not(:disabled) {
    background: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
    transform: translateY(-50%) scale(1.08);
}

.frame-nav-btn:active:not(:disabled) {
    transform: translateY(-50%) scale(0.95);
}

.frame-nav-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.active-frame-image-wrapper {
    position: relative;
    max-width: 100%;
    width: 100%;
    height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #05050f;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.active-frame-image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.active-frame-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    backdrop-filter: blur(4px);
}

/* Timeline Timeline Range Slider */
.frame-timeline-section {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.timeline-controls {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.timeline-controls input[type="range"] {
    flex-grow: 1;
    height: 8px;
    border-radius: 99px;
    outline: none;
    cursor: pointer;
    background: var(--progress-bg);
    accent-color: var(--accent);
    appearance: none;
    -webkit-appearance: none;
}

.timeline-controls input[type="range"]::-webkit-slider-runnable-track {
    height: 8px;
    border-radius: 99px;
}

.timeline-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    margin-top: -6px;
    transition: transform 0.1s ease;
}

.timeline-controls input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#timeline-indicator {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    min-width: 110px;
    text-align: right;
}

/* Frame Thumbnails Grid */
.frame-grid-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.frame-grid-wrapper h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.frame-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
    gap: 0.6rem;
    max-height: 220px;
    overflow-y: auto;
    padding: 0.6rem;
    background: var(--surface-base);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: background 0.35s ease, border-color 0.35s ease;
}

.frame-item {
    position: relative;
    cursor: pointer;
    aspect-ratio: 16/10;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.frame-item:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
}

.frame-item.active {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-ring);
}

.frame-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.frame-item-number {
    position: absolute;
    bottom: 0.3rem;
    right: 0.3rem;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}

/* Frame Extraction Live Progress Status Overlay */
.frame-extraction-status {
    background: var(--accent-subtle);
    border-bottom: 1px solid var(--accent-ring);
    padding: 0.75rem 1.75rem;
    animation: pulse-bg 2.5s ease-in-out infinite;
}

.extraction-status-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.extraction-status-content p {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent);
}

.extraction-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--accent-ring);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    flex-shrink: 0;
}

@keyframes pulse-bg {
    0%, 100% { background-color: var(--accent-subtle); }
    50% { background-color: rgba(129, 140, 248, 0.15); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
    .intro-section h1 { font-size: 1.85rem; }

    .input-group { flex-direction: column; }
    .btn { width: 100%; }

    .platforms-grid { grid-template-columns: repeat(2, 1fr); }

    .preview-card { flex-direction: column; }
    .preview-media { width: 100%; min-width: unset; height: 170px; }

    .shimmer-loader { flex-direction: column; }
    .shimmer-thumbnail { width: 100%; height: 120px; }

    /* Frame Modal Mobile Optimization */
    .frame-modal {
        padding: 0;
    }

    .frame-modal-content {
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .frame-modal-header {
        padding: 1rem;
    }

    .frame-display-container {
        padding: 1rem;
        gap: 1rem;
    }

    .active-frame-image-wrapper {
        height: 220px;
    }

    .frame-nav-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .prev-btn {
        left: 0.5rem;
    }

    .next-btn {
        right: 0.5rem;
    }

    .frame-grid {
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
        max-height: 140px;
        padding: 0.4rem;
    }

    .frame-timeline-section {
        padding: 0.75rem;
    }

    .timeline-controls input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
        margin-top: -8px;
    }
    
    .timeline-controls {
        gap: 0.75rem;
    }
    
    #timeline-indicator {
        min-width: 90px;
        font-size: 0.8rem;
    }

    .library-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .library-item-actions {
        justify-content: flex-end;
        width: 100%;
    }
}
