:root {
    --primary-color: #5d4fec;
    --secondary-color: #7361ff;
    --light-color: #f5f7fa;
    --dark-color: #2c3e50;
    --border-color: #e0e5ec;
    --accent-color: #a991ff;
    --bg-dark: #1e1e1e;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: white;
    color: var(--dark-color);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

header {
    text-align: center;
    padding: 1rem 0;
    position: relative;
}

h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--dark-color);
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.image-container {
    width: 100%;
    height: auto;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.upload-area {
    background-color: rgba(0, 0, 0, 0.05);
    border: 2px dashed rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    min-height: 250px;
    flex-grow: 1;
    color: var(--dark-color);
}

.upload-area svg {
    stroke: var(--dark-color);
    margin-bottom: 1rem;
}

.upload-area p {
    color: var(--dark-color);
    margin-bottom: 0.5rem;
}

.upload-area p:last-child {
    margin-bottom: 0;
}

.upload-area:hover {
    border-color: var(--primary-color);
}

.drag-over {
    border-color: var(--accent-color) !important;
    background-color: rgba(169, 145, 255, 0.1) !important;
}

.palette-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.palette-view {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 1.5rem;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.palette-container {
    width: 100%;
}

.palette-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-panel {
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: 600;
    min-width: 80px;
    flex-shrink: 0;
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    flex-wrap: wrap;
}

.filter-selector {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: white;
    min-width: 120px;
    flex-grow: 1;
    max-width: 200px;
}

.filter-strength-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 200px;
}

.filter-strength-slider {
    flex: 1;
    max-width: 200px;
    cursor: pointer;
}

.title-edit-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls-container {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.mode-toggle-container {
    display: none;
}

#palette-title {
    font-weight: 700;
    font-size: 1.5rem;
    margin: 0;
    display: inline;
    cursor: pointer;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#palette-title-input {
    display: none;
    font-size: 1.5rem;
    font-weight: 700;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 5px;
    width: 200px;
    background-color: rgba(255, 255, 255, 0.8);
    color: var(--dark-color);
}

.pencil-icon {
    width: 16px;
    height: 16px;
    cursor: pointer;
    color: #777;
    vertical-align: middle;
}

.pencil-icon:hover {
    color: var(--primary-color);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

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

.slider-container label {
    font-weight: 600;
}

.color-count-display {
    min-width: 25px;
    text-align: center;
    font-weight: 600;
}

.color-filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.color-filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background-color: #eee;
    color: var(--dark-color);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.color-filter-btn:hover {
    background-color: #ddd;
}

.color-filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.color-filter-btn.active:hover {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.palette-display {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 0;
    margin-top: 1rem;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.color-item {
    overflow: hidden;
    background-color: white; 
    position: relative; 
    aspect-ratio: 1 / 1;
    margin: 0;
    padding: 0;
    cursor: pointer; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

.color-item .hex-display {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.5); 
    color: white; 
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    pointer-events: none; 
    opacity: 1;
    transition: opacity 0.5s ease-out 1s; 
    z-index: 10;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
}

.color-item .hex-display.fade-out {
    opacity: 0;
}

.color-sample {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

.empty-color-slot {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.05),
        rgba(0, 0, 0, 0.05) 5px,
        rgba(0, 0, 0, 0.08) 5px,
        rgba(0, 0, 0, 0.08) 10px
    );
    border-radius: 2px;
}

.color-info {
    display: none;
}

.empty-palette-message {
    text-align: center;
    padding: 2rem;
    color: #777;
    display: none;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    margin-top: 1rem;
}

.actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.actions button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
}

.actions button:hover {
    background-color: var(--secondary-color);
}

.actions button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.upload-button {
    margin-top: 10px;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
    width: auto;
    display: block;
    min-width: 150px;
}

.upload-button:hover {
    background-color: var(--secondary-color);
}

.loading-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    grid-column: 1 / -1;
    min-height: 100px;
}

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

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

.image-placeholder {
    width: 100%;
    height: 100%;
    max-height: 400px;
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.02);
    border: 2px dashed transparent;
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.image-placeholder img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.image-placeholder.drag-over {
    border-color: var(--accent-color);
    background-color: rgba(169, 145, 255, 0.1);
}

.image-overlay {
    display: none;
}

.copy-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
    font-size: 0.9rem;
}

.copy-message.show {
    opacity: 1;
    visibility: visible;
}

footer {
    margin-top: auto;
    text-align: center;
    padding: 1rem 0;
    color: #777;
    font-size: 0.8rem;
}

.preset-library-section {
    margin-top: 1rem;
    margin-bottom: 2rem;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 10px;
    padding: 1rem;
}

.preset-library-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.preset-tabs {
    display: flex;
    flex-wrap: wrap; 
    gap: 8px;
    padding-bottom: 1rem; 
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.preset-tab {
    padding: 8px 16px;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s;
    border: 1px solid transparent;
    font-size: 0.9rem;
}

.preset-tab:hover {
    background-color: rgba(255, 255, 255, 0.8);
    border-color: var(--border-color);
}

.preset-tab.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    border-color: var(--primary-color);
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.preset-card {
    background-color: white;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border-color);
}

.preset-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.12);
}

.preset-title {
    font-weight: 600;
    margin-bottom: 8px;
    text-align: center;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preset-swatches {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 1px;
    aspect-ratio: 6/5;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.1);
}

.mini-swatch {
    height: 100%;
    width: 100%;
}

.info-icon-container {
    position: relative; 
    display: inline-flex; 
    align-items: center;
    margin-left: 8px; 
}

.info-icon {
    width: 20px;
    height: 20px;
    fill: #888; 
    cursor: help; 
    transition: fill 0.2s ease;
}

.info-icon:hover {
    fill: var(--primary-color); 
}

.tooltip-text {
    visibility: hidden; 
    opacity: 0;
    width: 250px; 
    background-color: rgba(44, 62, 80, 0.9); 
    color: #fff; 
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 10;
    bottom: 125%; 
    left: 50%;
    margin-left: -125px; 
    transition: opacity 0.3s ease, visibility 0.3s ease;
    font-size: 0.85rem;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%; 
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: rgba(44, 62, 80, 0.9) transparent transparent transparent; 
}

.info-icon-container:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .image-container {
        max-height: 300px;
    }

    .upload-area {
        min-height: 200px;
    }

    .palette-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .controls-container {
        width: 100%;
        justify-content: flex-start;
    }

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

    .filter-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-controls {
        gap: 10px;
    }

    .filter-strength-container {
        min-width: 100%;
    }

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

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

    .image-container {
        max-height: 250px;
    }

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

    .actions button {
        font-size: 0.9rem;
        padding: 0.4rem 0.8rem;
    }

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