* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif;
}

:root {
    --bg: #fafafa;
    --text: #3a3a3a;
    --border: #3a3a3a;
    --hover-bg: #3a3a3a;
    --hover-text: #fafafa;
}

body.dark-mode {
    --bg: #1a1a1a;
    --text: #d0d0d0;
    --border: #d0d0d0;
    --hover-bg: #d0d0d0;
    --hover-text: #1a1a1a;
}

body {
    font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition:
        background 0.3s,
        color 0.3s;
}

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

header h1 {
    font-size: clamp(1.5rem, 5vw, 3rem);
    font-weight: 100;
    letter-spacing: -0.02em;
    text-transform: none;
}

#dark-mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

#dark-mode-toggle input[type="checkbox"] {
    display: none;
}

#dark-mode-toggle .toggle-slider {
    width: 58px;
    height: 36px;
    background: #3a3a3a;
    border-radius: 18px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

#dark-mode-toggle .toggle-slider::after {
    content: "☽";
    position: absolute;
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    top: 0;
    left: 0;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

#dark-mode-toggle input[type="checkbox"]:checked + .toggle-slider {
    background: #d0d0d0;
}

#dark-mode-toggle input[type="checkbox"]:checked + .toggle-slider::after {
    content: "☀";
    transform: translateX(22px);
}

main {
    flex: 1;
    padding: 40px 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.hidden {
    display: none !important;
}

#upload-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

#dropzone {
    width: 100%;
    max-width: 600px;
    height: 300px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    border-radius: 16px;
}

#dropzone span {
    font-size: 1.5rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

#dropzone .sub {
    font-size: 0.9rem;
    margin-top: 10px;
    opacity: 0.6;
}

#dropzone:hover,
#dropzone.dragover {
    background: var(--hover-bg);
    color: var(--hover-text);
}

#dropzone input {
    display: none;
}

#result-section {
    display: flex;
    flex-direction: column;
    gap: 40px;
    border-radius: 16px;
}

#preview-container {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 30px;
    align-items: start;
    border-radius: 16px;
}

#source-preview {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-radius: 16px;
}

#source-preview img,
#source-preview button {
    width: 150px;
}

#output-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-radius: 16px;
}

#output-canvas {
    width: 100%;
    max-width: 512px;
    height: auto;
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 16px;
}

#source-preview img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.label {
    font-size: 0.75rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.1em;
}

#palette-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.swatch {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    border-radius: 16px;
}

.swatch .hex {
    display: none;
    position: absolute;
    bottom: -25px;
    font-size: 1.65rem;
    white-space: nowrap;
    background: var(--hover-bg);
    color: var(--hover-text);
    padding: 2px 4px;
    z-index: 10;
    border-radius: 16px;
}

.swatch:hover .hex {
    display: block;
}

#controls {
    display: flex;
    justify-content: space-between;
    gap: 128px;
    flex-wrap: wrap;
    align-items: center;
}

#reversed-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

#controls button {
    flex: 1;
    font-size: 1rem;
    font-weight: 100;
    padding: 18px 30px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0.05em;
    transition: all 0.2s;
    border-radius: 16px;
    min-width: 120px;
}

#reversed-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

#reversed-toggle input[type="checkbox"] {
    display: none;
}

#reversed-toggle .toggle-slider {
    width: 88px;
    height: 48px;
    background: var(--text);
    border-radius: 24px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

#reversed-toggle .toggle-slider::after {
    content: "";
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--bg);
    border-radius: 50%;
    top: 4px;
    left: 4px;
    transition: transform 0.3s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

#reversed-toggle input[type="checkbox"]:checked + .toggle-slider::after {
    transform: translateX(40px);
}

#reversed-toggle .toggle-label {
    font-size: 1rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

#controls button {
    font-size: 1rem;
    font-weight: 100;
    padding: 18px 30px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0.05em;
    transition: all 0.2s;
    border-radius: 16px;
}

#controls button:hover {
    background: var(--hover-bg);
    color: var(--hover-text);
}

#controls button:active {
    transform: translate(2px, 2px);
}

#restart-btn {
    font-size: 1rem;
    font-weight: 100;
    padding: 18px 30px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0.05em;
    transition: all 0.2s;
    border-radius: 16px;
}

#restart-btn:hover {
    background: var(--hover-bg);
    color: var(--hover-text);
}

#restart-btn:active {
    transform: translate(2px, 2px);
}

footer {
    padding: 30px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

footer span {
    font-size: 0.8rem;
    font-weight: 100;
    text-transform: none;
    letter-spacing: 0.05em;
}

footer a {
    font-size: 0.8rem;
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 2px;
    transition: all 0.2s;
}

footer a:hover {
    background: var(--hover-bg);
    color: var(--hover-text);
}

@media (max-width: 600px) {
    header {
        padding: 25px 15px;
        flex-wrap: nowrap;
    }

    header h1 {
        margin-right: auto;
    }

    main {
        padding: 25px 15px;
    }

    #preview-container {
        grid-template-columns: 1fr;
    }

    #source-preview {
        flex-direction: row;
        align-items: center;
        gap: 15px;
    }

    #source-preview img {
        width: 80px;
        height: 80px;
    }

    #dropzone {
        height: 200px;
    }

    #dropzone span {
        font-size: 1.1rem;
    }

    #controls {
        flex-direction: column;
        gap: 48px;
    }

    #controls button {
        width: 100%;
    }

    .swatch {
        width: 44px;
        height: 44px;
    }

    #reversed-toggle .toggle-slider {
        width: 88px;
        height: 48px;
        background: var(--text);
        border-radius: 24px;
        position: relative;
        cursor: pointer;
        transition: background 0.3s;
    }

    #reversed-toggle .toggle-slider::after {
        content: "";
        position: absolute;
        width: 40px;
        height: 40px;
        background: var(--bg);
        border-radius: 50%;
        top: 4px;
        left: 4px;
        transition: transform 0.3s;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }

    #reversed-toggle input[type="checkbox"]:checked + .toggle-slider::after {
        transform: translateX(40px);
    }

    #reversed-toggle .toggle-label {
        font-size: 1rem;
        font-weight: 100;
        text-transform: none;
        letter-spacing: 0.05em;
    }

    footer {
        flex-direction: column;
        text-align: center;
    }
}
