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

:root {
    --header-height: 60px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --accent: #6c63ff;
    --accent-hover: #5a52d5;
    --border: rgba(255,255,255,0.1);
    --shadow: 0 8px 32px rgba(0,0,0,0.3);
    --radius: 10px;
    --transition: 0.2s ease;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background: var(--bg-dark);
    color: var(--text-primary);
}

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

/* Header */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: var(--header-height);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
}

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

.header-left h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

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

kbd {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-family: var(--font-family);
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.harmony-select {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.harmony-select label {
    color: var(--text-secondary);
    font-weight: 500;
}

.harmony-select select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

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

.btn-secondary {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.14);
    transform: translateY(-1px);
}

/* Palette */
#palette {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.color-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 40px;
    position: relative;
    cursor: pointer;
    transition: flex var(--transition);
    min-width: 0;
}

.color-bar:hover {
    flex: 1.15;
}

.color-bar:hover .color-controls {
    opacity: 1;
    transform: translateY(0);
}

.color-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    z-index: 10;
    pointer-events: none;
}

.color-hex {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    pointer-events: auto;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 6px;
    transition: background var(--transition);
}

.color-hex:hover {
    background: rgba(0,0,0,0.2);
}

.color-rgb {
    font-size: 0.8rem;
    opacity: 0.8;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    pointer-events: auto;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}

.color-rgb:hover {
    background: rgba(0,0,0,0.2);
}

.color-name {
    font-size: 0.75rem;
    opacity: 0.6;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Lock button */
.lock-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    z-index: 10;
    opacity: 0;
    backdrop-filter: blur(4px);
}

.color-bar:hover .lock-btn {
    opacity: 1;
}

.lock-btn:hover {
    background: rgba(0,0,0,0.4);
    transform: scale(1.1);
}

.lock-btn.locked {
    opacity: 1;
    background: rgba(0,0,0,0.5);
}

.lock-btn svg {
    width: 18px;
    height: 18px;
}

/* Color Controls (HSL Sliders) */
.color-controls {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(16px);
    border-radius: var(--radius);
    padding: 16px;
    width: 220px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 20;
    pointer-events: auto;
}

.color-bar:hover .color-controls {
    transform: translateX(-50%) translateY(0);
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider-row label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    width: 14px;
    color: rgba(255,255,255,0.7);
}

.slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.slider-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.slider-value {
    font-size: 0.7rem;
    width: 32px;
    text-align: right;
    color: rgba(255,255,255,0.7);
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-close:hover {
    background: rgba(255,255,255,0.15);
    color: white;
}

.modal-body {
    padding: 24px;
}

/* Export */
.export-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.export-tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.export-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.export-tab:hover:not(.active) {
    background: rgba(255,255,255,0.06);
}

.export-output {
    background: rgba(0,0,0,0.3);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    overflow-x: auto;
}

.export-output pre {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: #e0e0e0;
    white-space: pre;
}

.export-image-container {
    margin-bottom: 16px;
    text-align: center;
}

.export-image-container canvas {
    border-radius: var(--radius);
    max-width: 100%;
}

.export-actions {
    display: flex;
    gap: 8px;
}

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255,255,255,0.04);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.history-item:hover {
    background: rgba(255,255,255,0.1);
}

.history-colors {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.history-swatch {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-mode {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
}

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(12px);
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    border: 1px solid rgba(255,255,255,0.1);
}

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

.toast.hidden {
    display: block;
}

/* Responsive */
@media (max-width: 900px) {
    #header {
        flex-direction: column;
        height: auto;
        padding: 12px 16px;
        gap: 10px;
    }

    .header-left, .header-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .hint {
        display: none;
    }

    .btn span {
        display: none;
    }

    .color-controls {
        width: 180px;
        padding: 12px;
    }

    .color-hex {
        font-size: 1.1rem;
    }
}

@media (max-width: 600px) {
    #palette {
        flex-direction: column;
    }

    .color-bar {
        flex-direction: row;
        justify-content: center;
        padding: 0;
        min-height: 0;
    }

    .color-bar:hover {
        flex: 1.3;
    }

    .color-info {
        flex-direction: row;
        gap: 12px;
    }

    .lock-btn {
        top: 50%;
        right: 12px;
        transform: translateY(-50%);
        opacity: 0.7;
    }

    .color-controls {
        display: none;
    }

    .color-name {
        display: none;
    }
}
