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

:root {
    --bg-primary: #fafafa;
    --bg-card: #ffffff;
    --bg-input: #f5f5f5;
    --border-color: #e5e5e5;
    --text-primary: #1a1a1a;
    --text-secondary: #737373;
    --accent: #525252;
    --dot-color: #d4d4d4;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --border-color: #262626;
    --text-primary: #ededed;
    --text-secondary: #a3a3a3;
    --accent: #d4d4d4;
    --dot-color: #262626;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
}

header {
    margin-bottom: 2.5rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@media (max-width: 600px) {
    h1 {
        font-size: 1.4rem;
    }
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.8rem;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}

.icon-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--text-primary);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.icon-btn:hover {
    border-color: var(--accent);
    background: var(--bg-input);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.icon-btn:active {
    transform: translateY(0);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    position: relative;
    z-index: 1;
}

[data-theme="dark"] .sun-icon {
    display: block;
}

[data-theme="dark"] .moon-icon {
    display: none;
}

[data-theme="light"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: block;
}

.controls-section {
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    animation: slideIn 0.4s ease 0.1s both;
}

@media (max-width: 600px) {
    .controls-section {
        padding: 0.75rem;
    }
}

.control-group-title h2 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
}

.control-group-title:first-child h2 {
    margin-top: 0;
}

.slider-row {
    display: grid;
    grid-template-columns: 45px 1fr 40px;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.4rem;
}

@media (max-width: 600px) {
    .slider-row {
        grid-template-columns: 40px 1fr 35px;
        gap: 0.4rem;
    }
}

.slider-row label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-input);
    outline: none;
    position: relative;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.slider-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.35rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 35px;
    transition: all 0.2s ease;
}

.slider-value.updated {
    background: var(--text-primary);
    color: var(--bg-card);
}

.actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 600px) {
    .actions-row {
        flex-direction: column;
        align-items: stretch;
    }

    .actions-row button {
        width: 100%;
    }
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-primary);
    transition: opacity 0.2s ease;
}

.checkbox-label:hover {
    opacity: 0.8;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    cursor: pointer;
    accent-color: var(--text-primary);
}

button {
    padding: 0.875rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

button:hover::before {
    left: 100%;
}

button:hover {
    border-color: var(--accent);
    background: var(--bg-input);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

button:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-card);
    border-color: var(--text-primary);
}

.btn-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-card);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}

.racks-section {
    margin-bottom: 1.5rem;
}

.racks-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rack {
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    animation: rackSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes rackSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.rack.removing {
    animation: rackSlideOut 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes rackSlideOut {
    to {
        opacity: 0;
        transform: translateX(20px) scale(0.95);
    }
}

.rack-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.rack-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.rack-delete {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.rack-delete:hover {
    border-color: #ef4444;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    transform: rotate(90deg);
}

.rack-palette {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.25rem;
    scroll-behavior: smooth;
}

.rack-palette::-webkit-scrollbar {
    height: 6px;
}

.rack-palette::-webkit-scrollbar-track {
    background: var(--bg-input);
    border-radius: 3px;
}

.rack-palette::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
    transition: background 0.2s ease;
}

.rack-palette::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.swatch {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.swatch::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.swatch:hover {
    transform: scale(1.2);
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.swatch:hover::after {
    opacity: 1;
}

.swatch:active {
    transform: scale(1.1);
}

.swatch.color-updating {
    animation: colorPulse 0.3s ease;
}

@keyframes colorPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
        filter: brightness(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.color-picker-wrapper {
    position: relative;
}

.color-picker-wrapper::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: calc(var(--radius-sm) + 4px);
    border: 2px dashed var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.color-picker-wrapper:hover::after {
    opacity: 0.5;
}

.color-picker {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: var(--radius-sm);
    border: 2px dashed var(--border-color);
    cursor: pointer;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    background: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.color-picker:hover {
    border-color: var(--accent);
    transform: scale(1.05);
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.color-picker::-moz-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.swatch-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 0.35rem 0.6rem;
    background: var(--text-primary);
    color: var(--bg-card);
    font-size: 0.7rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.swatch:hover .swatch-tooltip,
.color-picker-wrapper:hover .swatch-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.export-section {
    padding: 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    animation: slideIn 0.4s ease 0.2s both;
}

@media (max-width: 600px) {
    .export-section {
        padding: 1rem;
    }
}

.export-row {
    display: flex;
    gap: 1rem;
    align-items: center;
}

@media (max-width: 600px) {
    .export-row {
        flex-direction: column;
        align-items: stretch;
    }

    .export-row button,
    .export-row select {
        width: 100%;
    }
}

.export-select {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.export-select:hover {
    border-color: var(--accent);
    background: var(--bg-card);
}

.export-select:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(128, 128, 128, 0.1);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

.modal.active {
    display: block;
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    animation: overlayFadeIn 0.25s ease;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

.modal-card {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    max-width: 400px;
    width: 90%;
    padding: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active .modal-card {
    transform: translate(-50%, -50%) scale(1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-input);
    transform: rotate(90deg);
}

.modal-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.modal-card p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

@media (max-width: 400px) {
    .modal-actions {
        flex-direction: column;
    }

    .modal-actions button {
        width: 100%;
    }
}
