/* ========================================================================
   Image Color Quantizer — Styles
   ======================================================================== */

:root {
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --bg: #0B0D17;
    --bg-secondary: #111427;
    --bg-card: rgba(17, 20, 39, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.04);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(108, 99, 255, 0.5);
    --text: #F0F0F5;
    --text-secondary: #8B8FA3;
    --text-muted: #5A5E72;
    --accent: #6C63FF;
    --accent2: #00D4AA;
    --accent3: #FFB547;
    --accent4: #FF5C8A;
    --gradient: linear-gradient(135deg, #6C63FF, #00D4AA);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.3);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg: #F5F6FA;
    --bg-secondary: #FFF;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.6);
    --bg-glass-hover: rgba(0, 0, 0, 0.04);
    --bg-input: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.08);
    --text: #1A1D2E;
    --text-secondary: #5A5E72;
    --text-muted: #8B8FA3;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.08);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

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

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -30%;
    width: 80%;
    height: 80%;
    background: radial-gradient(ellipse, rgba(108, 99, 255, 0.07) 0%, transparent 70%);
    pointer-events: none;
}

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-content {
    max-width: 960px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-title {
    font-size: 1.125rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 0.375rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: all var(--transition);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--gradient);
    color: #fff;
    padding: 0.625rem 1.5rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(108, 99, 255, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem;
    border: 1px solid transparent;
}

.btn-ghost:hover {
    background: var(--bg-glass-hover);
    color: var(--text);
    border-color: var(--border);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    border-radius: var(--radius-md);
    width: 100%;
}

/* Main */
.main {
    flex: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

/* Upload Section */
.upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    animation: fadeInUp 0.5s ease-out;
}

.section-header {
    text-align: center;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.drop-zone {
    width: 100%;
    max-width: 600px;
    padding: 3rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    cursor: pointer;
    text-align: center;
    transition: all var(--transition);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--bg-glass-hover);
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.drop-zone-content svg {
    color: var(--text-muted);
}

.drop-text {
    font-size: 1rem;
    font-weight: 500;
}

.drop-link {
    color: var(--accent);
    font-weight: 600;
}

.drop-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Editor */
.editor-section {
    animation: fadeInUp 0.5s ease-out;
}

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

.controls-card {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.control-label {
    font-size: 0.875rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.control-value {
    display: inline-block;
    min-width: 28px;
    text-align: center;
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    background: rgba(108, 99, 255, 0.15);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
}

.range-input {
    flex: 1;
    max-width: 300px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-input);
    border-radius: 2px;
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.4);
}

.select-input {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
    min-width: 160px;
}

.select-input:focus {
    border-color: var(--border-focus);
}

.select-input option {
    background: var(--bg-secondary);
    color: var(--text);
}

/* Processing */
.processing-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

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

.processing-text {
    font-weight: 500;
    color: var(--text-secondary);
}

/* Compare */
.compare-section {
    animation: fadeInUp 0.5s ease-out;
}

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

.compare-title {
    font-size: 1.125rem;
    font-weight: 700;
}

.compare-actions {
    display: flex;
    gap: 0.375rem;
}

.compare-container {
    position: relative;
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    cursor: col-resize;
    user-select: none;
    background: repeating-conic-gradient(#1a1a2e 0% 25%, #15152a 0% 50%) 50% / 20px 20px;
}

.compare-canvas {
    display: block;
    width: 100%;
    height: auto;
}

#quantizedCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    clip-path: inset(0 50% 0 0);
}

.compare-slider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 4px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.slider-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
}

.slider-handle {
    position: relative;
    z-index: 2;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    cursor: col-resize;
}

.slider-handle svg {
    width: 10px;
    height: 10px;
}

.compare-label {
    position: absolute;
    top: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    backdrop-filter: blur(4px);
}

.label-before {
    left: 0.75rem;
}

.label-after {
    right: 0.75rem;
}

/* Palette */
.palette-card {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    margin-top: 1rem;
}

.palette-title {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.palette-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.palette-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: transform var(--transition);
}

.palette-swatch:hover {
    transform: scale(1.1);
}

.swatch-color {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.swatch-hex {
    font-size: 0.625rem;
    font-family: 'SF Mono', monospace;
    color: var(--text-muted);
    font-weight: 500;
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@media (max-width: 640px) {
    .header-content {
        padding: 0.625rem 1rem;
    }

    .main {
        padding: 1.5rem 1rem;
    }

    .section-title {
        font-size: 1.25rem;
    }

    .control-row {
        flex-direction: column;
        align-items: stretch;
    }

    .range-input {
        max-width: 100%;
    }

    .select-input {
        min-width: 0;
        width: 100%;
    }

    .logo-subtitle {
        display: none;
    }
}