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

:root {
    /* Warm earth-tone palette — no blue/purple */
    --bg-deep: #0e0c0a;
    --bg-main: #141210;
    --bg-surface: #1e1b17;
    --bg-card: #262220;
    --bg-card-hover: #302c28;

    --accent: #e8a33a;
    --accent-glow: rgba(232, 163, 58, 0.25);
    --accent-soft: #f5c97a;
    --coral: #d4634e;
    --coral-glow: rgba(212, 99, 78, 0.20);
    --green: #6dba5a;
    --green-glow: rgba(109, 186, 90, 0.15);

    --text: #f0ebe5;
    --text-secondary: #a39e96;
    --text-muted: #6e6860;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);

    --font: 'Outfit', -apple-system, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ===== Background Particles ===== */
.bg-particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    animation: particleFloat linear infinite;
}

@keyframes particleFloat {
    0% {
        opacity: 0;
        transform: translateY(100vh) scale(0);
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-20vh) scale(1);
    }
}

/* ===== Layout ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 20px 80px;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 48px;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 2.4rem;
    filter: drop-shadow(0 0 12px var(--accent-glow));
    animation: iconPulse 2.5s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.header h1 {
    font-size: 2.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--coral));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 300;
    letter-spacing: 4px;
}

/* ===== Upload Section ===== */
.upload-section {
    animation: fadeInUp 0.6s ease-out 0.15s both;
}

.upload-area {
    position: relative;
    border: 2px dashed var(--text-muted);
    border-radius: var(--radius);
    background: var(--bg-surface);
    padding: 64px 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.35s ease;
    overflow: hidden;
}

.upload-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, var(--accent-glow) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.35s;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--accent);
    background: var(--bg-card);
    transform: translateY(-2px);
    box-shadow: 0 12px 40px var(--accent-glow);
}

.upload-area:hover::before,
.upload-area.drag-over::before {
    opacity: 1;
}

.upload-icon {
    color: var(--accent);
    margin-bottom: 20px;
    transition: transform 0.35s;
    position: relative;
}

.upload-area:hover .upload-icon {
    transform: translateY(-6px);
}

.upload-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 8px;
    position: relative;
}

.upload-hint {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 12px;
    position: relative;
}

.upload-formats {
    color: var(--text-muted);
    font-size: 0.8rem;
    position: relative;
}

/* ===== Loading ===== */
.loading-section {
    animation: fadeIn 0.4s ease;
}

.loading-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 64px 40px;
    text-align: center;
    box-shadow: var(--shadow);
}

.loading-spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 28px;
}

.spinner-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
}

.spinner-ring:nth-child(1) {
    border-top-color: var(--accent);
    animation: spin 1.2s linear infinite;
}

.spinner-ring:nth-child(2) {
    inset: 8px;
    border-right-color: var(--coral);
    animation: spin 1.6s linear infinite reverse;
}

.spinner-ring:nth-child(3) {
    inset: 16px;
    border-bottom-color: var(--green);
    animation: spin 2s linear infinite;
}

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

.loading-text {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.progress-bar {
    width: 100%;
    max-width: 320px;
    height: 4px;
    background: var(--bg-card);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

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

/* ===== Results ===== */
.results-section {
    animation: fadeInUp 0.5s ease-out;
}

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

.results-stats {
    display: flex;
    gap: 16px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 24px;
    display: flex;
    align-items: baseline;
    gap: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-number {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.btn-new {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--accent), #c88520);
    color: var(--bg-deep);
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 24px;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-new:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.btn-new:active {
    transform: translateY(0);
}

/* Result Cards */
.result-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.image-wrapper {
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-wrapper img {
    max-width: 100%;
    max-height: 80vh;
    height: auto;
    display: block;
    object-fit: contain;
    cursor: zoom-in;
    transition: opacity 0.2s;
}

.image-wrapper img:hover {
    opacity: 0.92;
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ===== Lightbox ===== */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(10, 8, 6, 0.94);
    backdrop-filter: blur(12px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.lightbox.active {
    display: flex;
    animation: fadeIn 0.25s ease;
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 24px;
    z-index: 2001;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text);
    font-size: 2rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s;
    line-height: 1;
}

.lightbox-close:hover {
    background: var(--coral);
    color: #fff;
    transform: rotate(90deg);
}

.lightbox-viewport {
    width: 95vw;
    height: 88vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    position: relative;
    user-select: none;
}

.lightbox-viewport.dragging {
    cursor: grabbing;
}

.lightbox-viewport img {
    max-width: none;
    max-height: none;
    transform-origin: 0 0;
    will-change: transform;
    pointer-events: none;
}

.lightbox-hint {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--text-muted);
    font-size: 0.82rem;
    letter-spacing: 2px;
    background: rgba(0,0,0,0.5);
    padding: 6px 18px;
    border-radius: 20px;
}

/* Debug info */
.debug-info {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-top: 8px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.debug-info summary {
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 8px;
    user-select: none;
}

.debug-info pre {
    background: var(--bg-deep);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--accent-soft);
}

/* ===== Error ===== */
.error-section {
    animation: fadeIn 0.4s ease;
}

.error-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 64px 40px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid rgba(212, 99, 78, 0.15);
}

.error-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 16px;
}

.error-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--coral);
    margin-bottom: 12px;
}

.error-msg {
    color: var(--text-secondary);
    margin-bottom: 28px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.btn-retry {
    background: var(--coral);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 32px;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 20px var(--coral-glow);
}

.btn-retry:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--coral-glow);
}

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

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

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

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .app-container {
        padding: 24px 12px 60px;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .upload-area {
        padding: 44px 20px;
    }

    .comparison-grid {
        grid-template-columns: 1fr;
    }

    .results-header {
        flex-direction: column;
        align-items: stretch;
    }

    .results-stats {
        justify-content: center;
    }

    .btn-new {
        justify-content: center;
    }
}
