:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #1a1a24;
    --bg-tertiary: #252532;
    --bg-card: #1e1e2a;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-tertiary: #606070;
    --accent: #6366f1;
    --accent-dim: rgba(99, 102, 241, 0.15);
    --accent-bright: #818cf8;
    --success: #10b981;
    --success-dim: rgba(16, 185, 129, 0.15);
    --danger: #ef4444;
    --danger-dim: rgba(239, 68, 68, 0.15);
    --warning: #f59e0b;
    --warning-dim: rgba(245, 158, 11, 0.15);
    --border: #2a2a3a;
    --gradient-1: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-2: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

[data-theme="light"] {
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f1f5;
    --bg-card: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a70;
    --text-tertiary: #9090a0;
    --border: #e0e0e8;
    --accent-dim: rgba(99, 102, 241, 0.1);
}

[data-theme="midnight"] {
    --bg-primary: #030712;
    --bg-secondary: #0a0f1a;
    --bg-tertiary: #111827;
    --bg-card: #0d1320;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-bright: #60a5fa;
    --border: #1e293b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Animated Background */
.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.bg-animation::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 30%, var(--accent-dim) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(139, 92, 246, 0.1) 0%, transparent 40%);
    animation: bgRotate 40s linear infinite;
}

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

.container {
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(100px + var(--safe-area-bottom));
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 24px;
}

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

.logo-icon {
    width: 48px;
    height: 48px;
    background: var(--gradient-1);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.logo-text h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-text span {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

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

.icon-button {
    width: 44px;
    height: 44px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:active {
    transform: scale(0.92);
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 0.85rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--success);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Main Input Section */
.input-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 24px;
}

.input-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.input-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.mode-badge {
    padding: 4px 10px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.url-input-wrapper {
    position: relative;
    margin-bottom: 16px;
}

.url-input {
    width: 100%;
    padding: 16px 50px 16px 20px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 14px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.url-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}

.url-input::placeholder {
    color: var(--text-tertiary);
}

.paste-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 14px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.paste-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Quick Platforms */
.platforms-label {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.platforms-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.platform-btn {
    padding: 12px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.platform-btn span:first-child {
    font-size: 1.3rem;
}

.platform-btn:active {
    transform: scale(0.95);
}

.platform-btn.supported {
    background: var(--success-dim);
    border-color: var(--success);
    color: var(--success);
}

/* Download Button */
.download-btn {
    width: 100%;
    padding: 18px;
    background: var(--gradient-1);
    border: none;
    border-radius: 14px;
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

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

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

.download-btn.loading {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Progress Section */
.progress-section {
    display: none;
    margin-top: 20px;
}

.progress-section.show {
    display: block;
    animation: slideDown 0.3s ease;
}

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

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.progress-filename {
    color: var(--text-primary);
    font-weight: 500;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.progress-stats {
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.progress-bar-container {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--gradient-1);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-bar.complete {
    background: var(--gradient-2);
}

/* Download History */
.history-section {
    margin-top: 24px;
}

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

.section-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.clear-btn {
    padding: 6px 12px;
    background: var(--danger-dim);
    border: 1px solid var(--danger);
    border-radius: 8px;
    color: var(--danger);
    font-size: 0.75rem;
    cursor: pointer;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
}

.history-item:active {
    transform: scale(0.98);
}

.history-icon {
    width: 44px;
    height: 44px;
    background: var(--success-dim);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.history-icon.failed {
    background: var(--danger-dim);
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-filename {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

.history-actions {
    display: flex;
    gap: 6px;
}

.history-action-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: 24px 24px 0 0;
    padding: 24px;
    padding-bottom: calc(24px + var(--safe-area-bottom));
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1001;
    max-height: 85vh;
    overflow-y: auto;
}

.modal.show {
    transform: translateY(0);
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 20px;
}

.modal h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.modal p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 20px;
}

.modal-btn {
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-btn.primary {
    background: var(--gradient-1);
    color: white;
}

/* Theme Cards */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.theme-card {
    padding: 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.theme-card.active {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.theme-preview {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-bottom: 8px;
}

.theme-color {
    width: 20px;
    height: 20px;
    border-radius: 6px;
}

.theme-name {
    font-size: 0.8rem;
    font-weight: 600;
}

/* Install Banner */
.install-banner {
    background: var(--gradient-1);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    display: none;
    align-items: center;
    gap: 12px;
}

.install-banner.show {
    display: flex;
}

.install-banner-text {
    flex: 1;
    color: white;
}

.install-banner-title {
    font-weight: 600;
}

.install-banner-subtitle {
    font-size: 0.8rem;
    opacity: 0.9;
}

.install-btn {
    padding: 10px 20px;
    background: white;
    color: var(--accent);
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
}

.close-banner-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.8;
}

/* Toast */
.toast {
    position: fixed;
    top: calc(20px + var(--safe-area-top));
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: 14px;
    font-weight: 500;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
    background: var(--success-dim);
}

.toast.error {
    border-color: var(--danger);
    background: var(--danger-dim);
}

/* Responsive */
@media (max-width: 380px) {
    .platforms-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stat-value {
        font-size: 1.4rem;
    }
}
