/* ============================================================
   AI Photo Swap - Main Styles
   Dark Theme + Glassmorphism + Gradient Accents
   ============================================================ */

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

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-hover: rgba(255,255,255,0.07);
    --border-color: rgba(255,255,255,0.08);
    --border-glow: rgba(124,58,237,0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-1: #7c3aed;
    --accent-2: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #7c3aed, #06b6d4);
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 8px 32px rgba(0,0,0,0.3);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
                 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---------- Animated Background ---------- */
.bg-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-glow::before,
.bg-glow::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.15;
    animation: float 20s ease-in-out infinite;
}

.bg-glow::before {
    width: 600px;
    height: 600px;
    background: #7c3aed;
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.bg-glow::after {
    width: 500px;
    height: 500px;
    background: #06b6d4;
    bottom: -10%;
    right: -10%;
    animation-delay: -10s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(60px, -60px) scale(1.1); }
    66% { transform: translate(-30px, 40px) scale(0.95); }
}

/* ---------- Layout ---------- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    position: relative;
    z-index: 1;
}

/* ---------- Navigation ---------- */
.navbar {
    padding: 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar .logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
}

.navbar .nav-links {
    display: flex;
    gap: 12px;
    align-items: center;
}

.navbar .nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: var(--transition);
}

.navbar .nav-links a:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

/* ---------- Hero ---------- */
.hero {
    text-align: center;
    padding: 60px 0 40px;
}

.hero .badge {
    display: inline-block;
    padding: 6px 16px;
    background: rgba(124,58,237,0.15);
    border: 1px solid rgba(124,58,237,0.3);
    border-radius: 100px;
    font-size: 0.8rem;
    color: #a78bfa;
    margin-bottom: 24px;
}

.hero h1 {
    font-size: clamp(2.2rem, 5vw, 3.5rem);
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 16px;
}

.hero h1 .gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 32px;
}

.hero .steps {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 40px;
}

.hero .step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 100px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.hero .step .step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-gradient);
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
}

/* ---------- Card ---------- */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 32px;
    transition: var(--transition);
}

.card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(124,58,237,0.25);
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(124,58,237,0.15);
}

.card-glow {
    position: relative;
}

.card-glow::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: var(--radius);
    background: var(--accent-gradient);
    opacity: 0;
    transition: var(--transition);
    z-index: -1;
}

.card-glow:hover::before {
    opacity: 0.5;
}

/* ---------- Upload Area ---------- */
.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

@media (max-width: 768px) {
    .upload-grid {
        grid-template-columns: 1fr;
    }
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    min-height: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-1);
    background: rgba(124,58,237,0.05);
}

.upload-zone .upload-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(124,58,237,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.upload-zone .upload-label {
    font-weight: 600;
    font-size: 1.05rem;
}

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

.upload-zone .preview {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    display: none;
}

.upload-zone .preview.show {
    display: block;
}

.upload-zone input[type="file"] {
    display: none;
}

.upload-zone .file-name {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 4px;
}

/* ---------- Key Input ---------- */
.key-section {
    margin-bottom: 32px;
}

.key-input-wrapper {
    display: flex;
    gap: 12px;
    max-width: 500px;
    margin: 0 auto;
}

.key-input-wrapper input {
    flex: 1;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.key-input-wrapper input:focus {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}

.key-input-wrapper input::placeholder {
    color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(124,58,237,0.35);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255,255,255,0.15);
}

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: var(--error);
    border: 1px solid rgba(239,68,68,0.3);
}

.btn-danger:hover {
    background: rgba(239,68,68,0.25);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

/* ---------- Generate Button ---------- */
.generate-section {
    text-align: center;
    margin-bottom: 32px;
}

.btn-generate {
    padding: 18px 48px;
    font-size: 1.1rem;
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
}

.btn-generate::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #7c3aed, #06b6d4, #7c3aed);
    background-size: 200% 200%;
    animation: shimmer 3s ease-in-out infinite;
    opacity: 0;
    transition: var(--transition);
}

.btn-generate:hover::before {
    opacity: 1;
}

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

.btn-generate span {
    position: relative;
    z-index: 1;
}

/* ---------- Loading ---------- */
.loading-overlay {
    display: none;
    text-align: center;
    padding: 48px 0;
}

.loading-overlay.active {
    display: block;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

/* ---------- Result ---------- */
.result-section {
    display: none;
    margin-top: 32px;
}

.result-section.active {
    display: block;
}

.result-image-wrapper {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-secondary);
    margin-bottom: 20px;
}

.result-image-wrapper img {
    width: 100%;
    height: auto;
    display: block;
}

.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Compare Slider ---------- */
.compare-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 24px;
    border-radius: var(--radius);
    overflow: hidden;
    user-select: none;
}

.compare-wrapper img {
    width: 100%;
    display: block;
}

.compare-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.compare-overlay img {
    height: 100%;
    object-fit: cover;
    display: block;
}

.compare-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 4px;
    background: #fff;
    cursor: ew-resize;
    transform: translateX(-50%);
    z-index: 2;
}

.compare-handle::before {
    content: '⟷';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.2rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ---------- Alert / Toast ---------- */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 16px;
    display: none;
}

.alert.error {
    display: block;
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.25);
    color: #fca5a5;
}

.alert.success {
    display: block;
    background: rgba(16,185,129,0.12);
    border: 1px solid rgba(16,185,129,0.25);
    color: #6ee7b7;
}

.alert.info {
    display: block;
    background: rgba(59,130,246,0.12);
    border: 1px solid rgba(59,130,246,0.25);
    color: #93c5fd;
}

/* ---------- Footer ---------- */
.footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---------- Key Status Badge ---------- */
.key-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 0.8rem;
    margin-top: 8px;
}

.key-status.valid {
    background: rgba(16,185,129,0.12);
    border: 1px solid rgba(16,185,129,0.25);
    color: #6ee7b7;
}

.key-status.invalid {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.25);
    color: #fca5a5;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease-out forwards;
}

/* ---------- History Section ---------- */
.history-section {
    margin-top: 60px;
}

.history-section h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.5rem;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.history-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: var(--transition);
}

.history-item:hover {
    transform: translateY(-4px);
    border-color: rgba(124,58,237,0.3);
}

.history-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.history-item .history-info {
    padding: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---------- Quality Selector ---------- */
.quality-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 12px 24px;
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    border-right: 1px solid var(--border-color);
}

.quality-option:last-child {
    border-right: none;
}

.quality-option:hover {
    background: rgba(124,58,237,0.08);
}

.quality-option.active {
    background: rgba(124,58,237,0.15);
    box-shadow: inset 0 0 0 1px rgba(124,58,237,0.4);
}

.quality-option .quality-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}

.quality-option:hover .quality-name {
    color: var(--text-primary);
}

.quality-option.active .quality-name {
    color: var(--accent-1);
}

.quality-option .quality-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: var(--transition);
}

.quality-option.active .quality-desc {
    color: rgba(124,58,237,0.7);
}
