:root {
    --bg-deep: #07080c;
    --bg-main: #0c0e16;
    --bg-surface: #12151f;
    --bg-card: #181c28;
    --bg-elevated: #1f2433;
    --red-primary: #e63946;
    --red-dim: #b52d38;
    --orange: #fb8500;
    --yellow: #ffb703;
    --white-hot: #f8f9fc;
    --cyan: #00e5ff;
    --text-primary: #eaecf2;
    --text-secondary: #7c8297;
    --text-muted: #4a5068;
    --gradient-primary: linear-gradient(135deg, var(--red-primary), var(--orange));
    --gradient-warm: linear-gradient(135deg, var(--orange), var(--yellow));
    --gradient-success: linear-gradient(135deg, #0dca7a, var(--cyan));
    --gradient-stroke: linear-gradient(135deg, #6366f1, #a855f7);
    --border-subtle: rgba(230, 57, 70, 0.12);
    --glow-red: 0 0 30px rgba(230, 57, 70, 0.25);
    --glow-cyan: 0 0 30px rgba(0, 229, 255, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: 'IBM Plex Sans', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 15% 0%, rgba(230, 57, 70, 0.06) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 100%, rgba(0, 229, 255, 0.04) 0%, transparent 55%);
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

/* Header */
#header {
    text-align: center;
    padding: 24px 0 28px;
}

#title {
    font-size: 2.1rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.accent-icon {
    -webkit-text-fill-color: initial;
    background: none;
    display: inline;
}

#subtitle {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
}

.badge-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: rgba(230, 57, 70, 0.1);
    color: var(--red-primary);
    border: 1px solid rgba(230, 57, 70, 0.2);
    font-family: 'IBM Plex Mono', monospace;
}

.badge:nth-child(2) {
    background: rgba(0, 229, 255, 0.08);
    color: var(--cyan);
    border-color: rgba(0, 229, 255, 0.2);
}

.badge:nth-child(3) {
    background: rgba(99, 102, 241, 0.1);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.2);
}

/* Upload Zone */
.upload-zone {
    position: relative;
    border: 2.5px dashed rgba(230, 57, 70, 0.35);
    border-radius: 20px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-surface);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-border 3s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: rgba(230, 57, 70, 0.25); box-shadow: none; }
    50% { border-color: rgba(0, 229, 255, 0.4); box-shadow: inset 0 0 40px rgba(0, 229, 255, 0.03); }
}

.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--cyan);
    background: rgba(0, 229, 255, 0.03);
    box-shadow: var(--glow-cyan);
    animation: none;
}

.upload-zone.has-image {
    animation: none;
    border-color: #0dca7a;
    padding: 16px;
}

.upload-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.upload-hint {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-preview img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    border: 2px solid var(--border-subtle);
    image-rendering: pixelated;
}

.upload-preview p {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

/* Canvas Section */
.canvas-section {
    margin-top: 28px;
}

.canvas-pair {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.canvas-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    position: relative;
}

.canvas-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-align: center;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.canvas-wrap {
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
}

.checker-bg {
    background-image:
        linear-gradient(45deg, #151825 25%, transparent 25%),
        linear-gradient(-45deg, #151825 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #151825 75%),
        linear-gradient(-45deg, transparent 75%, #151825 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-color: #0e1018;
}

.canvas-wrap canvas {
    max-width: 100%;
    max-height: 400px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

/* Processing Overlay */
.processing-overlay {
    position: absolute;
    inset: 0;
    background: rgba(7, 8, 12, 0.88);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(230, 57, 70, 0.2);
    border-top-color: var(--red-primary);
    border-right-color: var(--orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.processing-overlay p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Controls */
.controls-section {
    margin-top: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.controls-group {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-subtle);
}

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

.slider-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

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

.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-min, .slider-max {
    font-size: 0.7rem;
    font-family: 'IBM Plex Mono', monospace;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 32px;
}

.slider-max { text-align: right; }

.slider-value {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--red-primary);
    min-width: 28px;
    text-align: center;
}

/* Custom Slider */
.custom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.slider-primary {
    background: var(--gradient-primary);
}

.slider-stroke {
    background: var(--gradient-stroke);
}

.slider-alpha {
    background: linear-gradient(90deg, #1a1a2e, var(--white-hot));
}

.slider-speck {
    background: var(--gradient-warm);
}

.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 3px solid var(--red-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.slider-stroke::-webkit-slider-thumb {
    border-color: #6366f1;
}

.slider-alpha::-webkit-slider-thumb {
    border-color: var(--text-secondary);
}

.slider-speck::-webkit-slider-thumb {
    border-color: var(--orange);
}

.custom-slider::-webkit-slider-thumb:active {
    transform: scale(1.2);
}

.custom-slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 3px solid var(--red-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    cursor: pointer;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 60px;
    padding: 16px 24px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 20px rgba(230, 57, 70, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 30px rgba(230, 57, 70, 0.5);
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--gradient-warm);
    color: white;
    box-shadow: 0 4px 20px rgba(251, 133, 0, 0.25);
}

.btn-secondary:hover {
    box-shadow: 0 4px 30px rgba(251, 133, 0, 0.45);
    filter: brightness(1.1);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid rgba(124, 130, 151, 0.3);
}

.btn-ghost:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
    background: rgba(255,255,255,0.03);
}

.btn-download {
    background: var(--gradient-success);
    color: white;
    box-shadow: 0 4px 20px rgba(13, 202, 122, 0.3);
}

.btn-download:hover {
    box-shadow: 0 4px 30px rgba(13, 202, 122, 0.5);
    filter: brightness(1.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.3);
}

.controls-actions {
    display: flex;
    gap: 12px;
    background: none;
    border: none;
    padding: 0;
    flex-direction: row;
}

.controls-actions .btn {
    flex: 1;
}

/* Footer */
#footer {
    margin-top: 48px;
    text-align: center;
    padding: 24px 0;
    border-top: 1px solid var(--border-subtle);
}

#footer p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

#footer a {
    color: var(--red-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.2s;
}

#footer a:hover {
    color: var(--cyan);
}

/* Responsive */
@media (min-width: 640px) {
    #app {
        padding: 32px 24px 48px;
    }

    #title {
        font-size: 2.6rem;
    }

    .canvas-pair {
        flex-direction: row;
    }

    .canvas-card {
        flex: 1;
    }

    .controls-section {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .controls-group {
        flex: 1;
        min-width: 280px;
    }

    .controls-actions {
        flex-basis: 100%;
    }
}

@media (min-width: 1024px) {
    .canvas-wrap canvas {
        max-height: 500px;
    }
}

/* Fade in animation */
.fade-in {
    animation: fadeIn 0.4s ease forwards;
}

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