/* Variables & Base styling */
:root {
    --bg-primary: #0a0a0f;
    --bg-panel: rgba(20, 20, 30, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --accent-color: #ec4899;
    --accent-hover: #db2777;

    --success-color: #10b981;

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    --glass-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(236, 72, 153, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(56, 189, 248, 0.08) 0%, transparent 40%);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.hidden {
    display: none !important;
}

/* Container */
.app-container {
    width: 100%;
    max-width: 1000px;
    background: var(--bg-panel);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 700px;
}

/* Header */
header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo i {
    width: 36px;
    height: 36px;
    color: var(--accent-color);
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.settings-group {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
}

.settings-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    margin-top: -6px;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(236, 72, 153, 0.5);
}

#colorCountVal {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    width: 2ch;
    text-align: right;
}

/* Main Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Drop Zone */
.drop-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    border: 2px dashed var(--border-color);
    margin: 32px;
    border-radius: 16px;
    transition: var(--transition);
    cursor: pointer;
    background: rgba(0, 0, 0, 0.2);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent-color);
    background: rgba(236, 72, 153, 0.05);
}

.drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    pointer-events: none;
}

.drop-content i {
    width: 64px;
    height: 64px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    transition: var(--transition);
}

.drop-zone:hover i,
.drop-zone.dragover i {
    color: var(--accent-color);
    transform: translateY(-5px);
}

.drop-content h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
}

.drop-content p {
    color: var(--text-secondary);
}

.supported-formats {
    display: inline-block;
    margin-top: 16px;
    font-size: 0.75rem;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 999px;
    color: var(--text-secondary);
}

/* Loading State */
.loading-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
}

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

.loading-state h2 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
}

.loading-state p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Result Area */
.result-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
}

.image-preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(0, 0, 0, 0.3);
    overflow: hidden;
    min-height: 300px;
}

#imagePreview {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    object-fit: contain;
}

.palette-panel {
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    padding: 24px 32px;
}

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

.palette-header h2 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
}

.palette-actions {
    display: flex;
    gap: 12px;
}

.btn {
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-icon i {
    width: 18px;
    height: 18px;
}

/* Palette Swatches */
.palette-container {
    display: flex;
    height: 120px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.swatch {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 16px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.swatch:hover {
    flex: 1.5;
}

.swatch-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 50%);
    opacity: 0;
    transition: var(--transition);
}

.swatch:hover .swatch-overlay {
    opacity: 1;
}

.swatch-hex {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    z-index: 1;
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition);
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.swatch:hover .swatch-hex {
    opacity: 1;
    transform: translateY(0);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: rgba(20, 20, 30, 0.9);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    padding: 12px 24px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: var(--transition);
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.toast i {
    color: var(--success-color);
    width: 20px;
    height: 20px;
}

/* Export Wrapper (Offscreen) */
.export-wrapper {
    position: fixed;
    left: -9999px;
    top: 0;
}

.export-content {
    width: 800px;
    height: 600px;
    background: #111;
    display: flex;
    flex-direction: column;
    padding: 40px;
    font-family: 'Outfit', sans-serif;
    color: #fff;
}

.export-content .export-image {
    flex: 1;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 16px;
    margin-bottom: 24px;
}

.export-content .export-palette {
    display: flex;
    height: 100px;
    border-radius: 12px;
    overflow: hidden;
}

.export-content .export-swatch {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
}

.export-content .export-hex {
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    text-transform: uppercase;
}

/* Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .app-container {
        min-height: auto;
        border-radius: 16px;
    }

    .palette-container {
        height: 100px;
    }

    .swatch:hover {
        flex: 1;
        /* Disable expansion on mobile */
    }

    .swatch .swatch-hex {
        opacity: 1;
        transform: none;
        font-size: 0.7rem;
    }
}