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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --success: #22c55e;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* App Container */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 30px 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Upload Section */
.upload-section {
    width: 100%;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface);
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

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

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--primary-color);
}

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

.upload-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Canvas Section */
.canvas-section {
    display: none;
}

.canvas-section.visible {
    display: block;
}

.canvas-container {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    overflow: hidden;
}

#imageCanvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    cursor: crosshair;
    border-radius: var(--radius-sm);
}

.zoom-indicator {
    display: none;
    position: absolute;
    width: 110px;
    height: 110px;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    overflow: hidden;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
    background: var(--surface);
}

.zoom-indicator.visible {
    display: block;
}

#zoomCanvas {
    width: 100px;
    height: 100px;
    margin: 2px;
    border-radius: 50%;
    image-rendering: pixelated;
}

.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    transform: translate(-50%, -50%);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.canvas-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 12px;
}

/* Color Display Section */
.color-display-section {
    display: none;
}

.color-display-section.visible {
    display: block;
}

.picked-color-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    gap: 20px;
    box-shadow: var(--shadow);
}

.color-preview {
    width: 100px;
    height: 100px;
    border-radius: var(--radius-sm);
    background: #6366f1;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.color-info {
    flex: 1;
    min-width: 0;
}

.color-info h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.color-values {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.color-value-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-value-item label {
    width: 40px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.value-copy {
    flex: 1;
    display: flex;
    gap: 8px;
}

.value-copy input {
    flex: 1;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
}

.copy-btn {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.copy-btn svg {
    width: 16px;
    height: 16px;
    color: var(--text-primary);
}

/* Palette Section */
.palette-section {
    display: none;
}

.palette-section.visible {
    display: block;
}

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

.palette-header h3,
.saved-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.extract-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.extract-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
}

.palette-item {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.palette-item:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.palette-item .hex-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.625rem;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    padding: 4px;
    text-align: center;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    opacity: 0;
    transition: var(--transition);
}

.palette-item:hover .hex-label {
    opacity: 1;
}

/* Saved Colors Section */
.saved-section {
    display: none;
}

.saved-section.visible {
    display: block;
}

.clear-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.clear-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}

.saved-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.saved-color-item {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.saved-color-item:hover {
    transform: scale(1.1);
}

.saved-color-item .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.saved-color-item:hover .remove-btn {
    opacity: 1;
}

.empty-message {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    padding: 20px;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 0;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    border: 1px solid var(--border-color);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    header {
        padding: 20px 0;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .upload-area {
        padding: 30px 16px;
    }

    .picked-color-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .color-preview {
        width: 80px;
        height: 80px;
    }

    .color-value-item {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .color-value-item label {
        width: auto;
    }

    .palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }

    .palette-header,
    .saved-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .extract-btn,
    .clear-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    .upload-icon {
        width: 36px;
        height: 36px;
    }

    .palette-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .saved-color-item {
        width: 40px;
        height: 40px;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus states for accessibility */
button:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
