:root {
    --primary-color: #6366f1;
    --primary-dark: #4338ca;
    --background: #0a0a0a;
    --surface: #1a1a1a;
    --surface-light: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a3a3a3;
    --border: #404040;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --border-radius: 12px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overscroll-behavior: none;
    overscroll-behavior-y: contain;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navigation */
.nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
}

.nav-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--surface-light);
}

.nav-btn svg {
    width: 24px;
    height: 24px;
}

.nav-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Screens */
.screen {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 20px;
    padding-bottom: 80px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.screen.active {
    display: flex;
}

/* Upload Area */
.upload-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border);
    border-radius: var(--border-radius);
    background: var(--surface);
    transition: all 0.3s ease;
    min-height: 400px;
    cursor: pointer;
}

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

.upload-content {
    text-align: center;
    padding: 40px 20px;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.upload-content h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.upload-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 16px;
}

.upload-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* Image Container */
.image-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#imageCanvas {
    max-width: 100%;
    max-height: 50vh;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* Color Info */
.color-info {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 400px;
}

.color-preview {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--border);
    flex-shrink: 0;
}

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

.color-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.color-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 14px;
}

.color-code {
    font-family: 'SF Mono', 'Monaco', monospace;
    background: var(--background);
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.color-code:hover {
    background: var(--surface-light);
    border-color: var(--primary-color);
}

/* Tools Panel */
.tools-panel {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 20px 0;
}

.tool-btn {
    width: 56px;
    height: 50px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

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

.tool-btn svg {
    width: 24px;
    height: 24px;
}

/* Saved Colors */
.saved-colors-container {
    flex: 1;
}

.saved-colors-container h2 {
    font-size: 24px;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.saved-colors-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.saved-color-item {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    cursor: pointer;
}

.saved-color-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.saved-color-preview {
    width: 100%;
    height: 80px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 2px solid var(--border);
}

.saved-color-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.saved-color-code {
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.delete-color-btn {
    width: 32px;
    height: 32px;
    background: var(--error);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.delete-color-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.delete-color-btn svg {
    width: 16px;
    height: 16px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Menu Overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: none;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 0;
}

.menu-overlay.active {
    display: flex;
}

.menu-content {
    background: var(--surface);
    width: 280px;
    height: 100vh;
    padding: 20px;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.menu-overlay.active .menu-content {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.menu-header h3 {
    font-size: 20px;
    color: var(--text-primary);
}

.close-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--surface-light);
}

.close-btn svg {
    width: 20px;
    height: 20px;
}

.menu-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.2s ease;
    text-align: left;
}

.menu-item:hover {
    background: var(--surface-light);
}

.menu-item svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--border-radius);
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn.primary {
    background: var(--primary-color);
    color: white;
}

.modal-btn.primary:hover {
    background: var(--primary-dark);
}

.modal-btn.secondary {
    background: var(--surface-light);
    color: var(--text-primary);
}

.modal-btn.secondary:hover {
    background: var(--border);
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
}

.loading-spinner.active {
    display: flex;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 96px;
    left: 20px;
    right: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

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

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

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

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

.footer a:hover {
    text-decoration: underline;
}

/* Touch indicator and magnifier */
.touch-indicator {
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.1s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.touch-indicator.active {
    opacity: 1;
}

.magnifier {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 120px;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    background: var(--surface);
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.magnifier.active {
    opacity: 1;
}

.magnifier-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.magnifier-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 50%;
    background: var(--primary-color);
    transform: translate(-50%, -50%);
    z-index: 1;
}

.magnifier-crosshair::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 2px;
    background: var(--primary-color);
    transform: translate(-50%, -50%);
}

.magnifier::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    border: 2px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    background: transparent;
}

/* Red dot in the center of the small circle */
.magnifier::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px; /* Diameter of the red dot */
    height: 6px; /* Diameter of the red dot */
    background: red;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 3; /* Ensure it's above the circle and crosshairs */
}

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

    .magnifier {
        bottom: 80px;
    }

    .saved-colors-list {
        grid-template-columns: 1fr;
    }

    .color-info {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 16px;
    }

    .color-preview {
         width: 50px;
         height: 50px;
         margin-bottom: 10px;
     }

    .color-values {
         width: 100%;
         gap: 4px;
     }

    .color-value {
         flex-direction: row;
         justify-content: space-between;
         align-items: center;
     }

    .color-label {
        font-size: 12px;
    }

    .color-code {
        font-size: 12px;
        padding: 4px 8px;
    }

    .tools-panel {
        flex-wrap: wrap;
    }

    .toast-container {
        bottom: 96px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen.active {
    animation: fadeIn 0.3s ease;
}

/* PWA Styles */
@media (display-mode: standalone) {
    .nav-bar {
        padding-top: env(safe-area-inset-top, 12px);
    }

    .magnifier {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }

     .toast-container {
        bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    }

     .footer {
         padding-bottom: env(safe-area-inset-bottom, 16px);
     }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--surface-light);
}