:root {
    --bg-color-light: #f4f4f9;
    --text-color-light: #333;
    --header-bg-light: #fff;
    --footer-text-light: #666;
    --drop-zone-border-light: #ccc;
    --drop-zone-bg-hover-light: #e9e9e9;
    --button-bg-light: #007bff;
    --button-text-light: #fff;

    --bg-color-dark: #121212;
    --text-color-dark: #f1f1f1;
    --header-bg-dark: #1e1e1e;
    --footer-text-dark: #aaa;
    --drop-zone-border-dark: #555;
    --drop-zone-bg-hover-dark: #333;
    --button-bg-dark: #007bff;
    --button-text-dark: #fff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

body.light-mode {
    background-color: var(--bg-color-light);
    color: var(--text-color-light);
}

body.dark-mode {
    background-color: var(--bg-color-dark);
    color: var(--text-color-dark);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.25rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
header h1 { font-size: 1.25rem; margin: 0; }

body.light-mode header {
    background-color: var(--header-bg-light);
}

body.dark-mode header {
    background-color: var(--header-bg-dark);
}


#theme-toggle {
    padding: 0.5rem;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background-color: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s;
}

body.light-mode #theme-toggle:hover {
    background-color: var(--drop-zone-bg-hover-light);
}

body.dark-mode #theme-toggle:hover {
    background-color: var(--drop-zone-bg-hover-dark);
}

#theme-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: all 0.3s ease-in-out;
}

body.light-mode #theme-icon {
    background-color: transparent;
    box-shadow: inset 8px -8px 0 0 var(--text-color-light);
    transform: rotate(0deg);
}

body.dark-mode #theme-icon {
    background-color: var(--text-color-dark);
    transform: rotate(90deg);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem;
    gap: 1.25rem;
}

.upload-container {
    display: flex;
    gap: 1.25rem;
    width: 100%;
    max-width: 900px;
    justify-content: center;
}

.upload-area {
    text-align: center;
    width: 100%;
}

.drop-zone {
    border: 2px dashed;
    border-radius: 10px;
    padding: 2rem;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone .drop-zone-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.drop-zone p {
    margin: 0;
}

.upload-note {
    font-size: 0.8rem;
    opacity: 0.7;
    max-width: 80%;
}

body.light-mode .drop-zone {
    border-color: var(--drop-zone-border-light);
}

body.dark-mode .drop-zone {
    border-color: var(--drop-zone-border-dark);
}

body.light-mode .drop-zone:hover {
    background-color: var(--drop-zone-bg-hover-light);
}

body.dark-mode .drop-zone:hover {
    background-color: var(--drop-zone-bg-hover-dark);
}

.drop-zone.dragover {
    border-style: solid;
}

.preview {
    max-width: 100%;
    max-height: 300px;
    margin-top: 1rem;
    display: none;
    border-radius: 5px;
    position: relative;
}
.remove-btn {
    margin-top: 0.25rem;
    align-self: center;
    padding: 0.2rem 0.5rem;
    font-size: 0.9rem;
    line-height: 1;
    border-radius: 4px;
    border: 1px solid transparent;
    background: rgba(0,0,0,0.06);
    color: inherit;
    cursor: pointer;
    display: none;
}
.remove-btn:hover { background: rgba(0,0,0,0.1); }

#try-on-button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: var(--button-bg-light);
    color: var(--button-text-light);
}

.carousel-container-small {
    width: 100%;
    margin-top: 0.5rem;
}

.carousel-heading-small {
    font-size: 1rem;
    font-weight: normal;
    margin-bottom: 0.5rem;
}

.carousel-small {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 400px;
    margin: 0 auto;
}

.carousel-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    border: none;
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 30px;
    text-align: center;
    padding: 0;
}

.carousel-button:hover {
    background-color: rgba(0, 0, 0, 0.6);
}

.carousel-button.prev {
    left: 5px;
}

.carousel-button.next {
    right: 5px;
}

.carousel-track-container-small {
    overflow: hidden;
    width: 100%;
}

.carousel-track {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0;
}

.carousel-slide {
    flex: 0 0 90px;
    height: 90px;
    margin: 0 5px;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: border-color 0.2s;
}

.carousel-slide:hover {
    border-color: var(--button-bg-light);
}

.carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

#result-area {
    width: 100%;
    max-width: 500px;
    text-align: center;
    display: none;
}

#result-canvas {
    max-width: 100%;
    border-radius: 5px;
    margin-top: 1rem;
}

footer {
    text-align: center;
    padding: 0.6rem;
    font-size: 0.8rem;
}

body.light-mode footer {
    color: var(--footer-text-light);
}

body.dark-mode footer {
    color: var(--footer-text-dark);
}

footer a {
    color: inherit;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal.show { display: flex; }
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}
.modal-content {
    position: relative;
    max-width: min(90vw, 900px);
    max-height: 90vh;
    width: 100%;
    background: var(--header-bg-light);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
body.dark-mode .modal-content { background: var(--header-bg-dark); }
.modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
}
.modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 300px;
}
.spinner-hint {
    font-size: 0.95rem;
    opacity: 0.8;
    text-align: center;
}
#modal-image {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    display: none;
}
.modal-actions {
    display: none;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
}
.modal-actions .primary-btn,
.modal-actions .secondary-btn,
#copy-image,
#download-image {
    padding: 0.6rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
}
#copy-image {
    background: var(--button-bg-light);
    color: var(--button-text-light);
}
#download-image {
    background: transparent;
    color: inherit;
    border-color: currentColor;
    text-decoration: none;
}
body.dark-mode #download-image { color: var(--text-color-dark); }
body.light-mode #download-image { color: var(--text-color-light); }
#copy-image:hover { opacity: 0.9; }
#download-image:hover { background: rgba(0,0,0,0.06); }

/* Minimal spinner */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0,0,0,0.1);
    border-top-color: var(--button-bg-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
body.dark-mode .spinner { border-top-color: var(--button-bg-dark); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
    .upload-container {
        flex-direction: column;
        align-items: center;
    }
    .upload-area {
        width: 80%;
    }
}

.carousel-container-small.history {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.carousel-container-small.history .carousel-heading-small {
    margin: 0;
    flex: 0 0 auto;
}
.carousel-container-small.history .carousel-small {
    flex: 1 1 auto;
}
