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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

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

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 40px 20px;
}

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

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

/* Main content */
main {
    flex: 1;
}

/* Input Section */
.input-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.color-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.hex-input-group {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0 16px;
    flex: 1;
    min-width: 200px;
    transition: border-color 0.2s;
}

.hex-input-group:focus-within {
    border-color: var(--primary-color);
}

.hash-symbol {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 600;
}

#hexInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 8px;
    font-size: 1rem;
    outline: none;
    text-transform: uppercase;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

#hexInput::placeholder {
    text-transform: none;
    color: var(--text-secondary);
}

#colorPicker {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    overflow: hidden;
}

#colorPicker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#colorPicker::-webkit-color-swatch {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

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

.primary-btn:active {
    transform: scale(0.98);
}

/* Color Preview */
.color-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.preview-box {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    background: #FF5733;
    box-shadow: var(--shadow);
    border: 3px solid white;
}

.preview-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.preview-info span {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.95rem;
}

#previewHex {
    font-weight: 600;
    color: var(--text-primary);
}

#previewRgb {
    color: var(--text-secondary);
}

/* Palette Filter */
.palette-filter {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.palette-filter h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

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

.palette-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-color);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.palette-checkbox:hover {
    background: #e2e8f0;
}

.palette-checkbox input {
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
}

/* Results Section */
.results-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.results-section h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

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

/* Result Card */
.result-card {
    background: var(--bg-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.result-color-bar {
    height: 60px;
    position: relative;
}

.result-palette-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-info {
    padding: 16px;
}

.result-name {
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.result-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

.result-distance {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.distance-bar {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.distance-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
    border-radius: 3px;
    transition: width 0.3s;
}

.distance-value {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 45px;
    text-align: right;
}

/* Copy Button */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
}

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

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    z-index: 1000;
}

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

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

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

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

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

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

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 1rem;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    header {
        padding: 30px 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .input-section {
        padding: 16px;
    }

    .color-input-wrapper {
        flex-direction: column;
        align-items: stretch;
    }

    .hex-input-group {
        min-width: 100%;
    }

    .color-input-wrapper > * {
        width: 100%;
    }

    #colorPicker {
        height: 50px;
    }

    .color-preview {
        flex-direction: column;
        text-align: center;
    }

    .preview-box {
        width: 100%;
        height: 60px;
    }

    .palette-options {
        gap: 8px;
    }

    .palette-checkbox {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .result-card {
        margin-bottom: 8px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .palette-checkbox {
        flex: 1 1 calc(50% - 8px);
        justify-content: center;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --card-bg: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }

    .hex-input-group {
        background: #0f172a;
    }

    #colorPicker::-webkit-color-swatch {
        border-color: #475569;
    }

    .palette-checkbox {
        background: #0f172a;
    }

    .palette-checkbox:hover {
        background: #334155;
    }

    .result-card {
        background: #0f172a;
    }

    .distance-bar {
        background: #334155;
    }
}
