body {
    background: linear-gradient(135deg, #4B0082, #663399); /* Changed to dark violet shades */
    font-family: 'Comic Sans MS', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
}

#game {
    background: #F4EDE4; /* Soft sepia color */
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
    display: flex;
    gap: 20px;
    position: relative;
}

.custom-dolls-header {
    background: #F4EDE4; /* Sepia color matching the game background */
    padding: 15px;
    border-radius: 15px;
    margin-bottom: 15px;
    text-align: center;
    font-family: 'Comic Sans MS', cursive;
    color: #ff7eb6; /* Pink color matching the theme */
    font-size: 20px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.name-input {
    display: none; /* Hide the name input section */
}

.doll-container {
    width: 400px;
    height: 600px;
    position: relative;
    margin-right: 180px; /* Add margin to make room for controls */
}

#uploadContainer {
    background: rgba(255, 255, 255, 0.1);
    border: 3px dashed #ffb6e6;
    border-radius: 20px;
    padding: 20px;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Updated control panel styles */
.control-panel {
    background: rgba(244, 237, 228, 0.8);
    padding: 8px; /* Decreased padding */
    border-radius: 10px; /* Decreased border radius */
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

/* Update position controls size */
.doll-position-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px; /* Decreased gap */
    margin-top: 10px;
}

.position-btn {
    padding: 4px 8px; /* Decreased padding */
    background: #ffb6e6;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px; /* Decreased font size */
    min-width: 30px; /* Decreased min-width */
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Update upload controls position */
.upload-controls {
    position: static; /* Change from fixed to static */
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
    margin-bottom: 15px;
}

#dollImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
    display: none;
    transition: transform 0.2s ease;
}

.clothes-menu {
    width: 200px;
    background: #F9F6F2; /* Slightly lighter sepia for contrast */
    padding: 15px;
    border-radius: 15px;
    max-height: 600px;
    overflow-y: auto;
}

.clothing-item {
    cursor: pointer;
    padding: 10px;
    margin: 5px;
    background: transparent;
    border-radius: 10px;
    transition: transform 0.2s;
    border: 2px solid #ffb6e6;
    color: #ff7eb6;
    text-align: center;
}

.clothing-item:hover {
    transform: scale(1.05);
    background: rgba(255, 240, 247, 0.5);
}

.clothing-item[onclick="deleteDoll()"] {
    background: rgba(255, 139, 139, 0.1); /* Very light transparent red */
    border-color: #ff8b8b;
}

.clothing-item[onclick="deleteAllAccessories()"] {
    background: rgba(255, 139, 139, 0.2) !important; /* Slightly more visible red */
    border-color: #ff8b8b !important;
    color: #ff6b6b !important;
    margin-top: 15px;
    font-weight: bold;
}

.clothing-item[onclick="deleteAllAccessories()"]:hover {
    background: rgba(255, 139, 139, 0.4) !important;
    transform: scale(1.05);
}

.worn {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: all;
    cursor: move;
    user-select: none;
    z-index: 1; /* Base z-index */
}

.worn[data-category="hair"] { z-index: 6; } /* Hair should be above faceplates */
.worn[data-category="eyes"] { z-index: 7; } /* Eyes should be above hair */
.worn[data-category="faceplate"] { z-index: 5; } /* Faceplates above doll but below hair/eyes */
.worn[data-category="dress"] { z-index: 2; }
.worn[data-category="top"] { z-index: 3; }
.worn[data-category="bottom"] { z-index: 3; }
.worn[data-category="accessories"] { z-index: 8; }
.worn[data-category="footwear"] { z-index: 10; } /* Shoes/boots above special outfits */
.worn[data-category="special-outfit"] { 
    z-index: 4; /* Above bottoms/tops but below shoes & accessories */
}
.worn[data-category="pets"] { z-index: 4; } /* Make pets appear above most items */

.worn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none; /* Changed to none to prevent image interference */
    position: absolute;
    top: 0;
    left: 0;
}

.worn[data-category="hair"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 6; /* Ensure hair is on top of faceplates */
    cursor: move;
    pointer-events: all;  /* Change this */
}

.worn[data-category="hair"] img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;  /* Add this */
    transform: scale(0.95); /* Slightly reduce size */
}

.worn[data-category="top"],
.worn[data-category="bottom"],
.worn[data-category="footwear"],
.worn[data-category="earrings"],
.worn[data-category="septum"],
.worn[data-category="lipPiercing"] {
    z-index: 3;  /* Ensure these items appear above the doll */
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
}

.tab {
    padding: 8px 15px;
    background: #ffb6e6;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-family: 'Comic Sans MS', cursive;
    transition: all 0.3s;
}

.tab:hover {
    background: #ff9ecd;
}

.tab.active {
    background: #ff7eb6;
    color: white;
}

.clothing-category {
    display: none;
}

.clothing-category.active {
    display: block;
}

.doll-menu-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 8px 15px;
    background: #ffb6e6;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-family: 'Comic Sans MS', cursive;
    transition: all 0.3s;
    z-index: 100;
}

.doll-menu-btn:hover {
    background: #ff9ecd;
}

.doll-menu {
    position: absolute;
    top: 60px;
    right: 20px;
    background: #F4EDE4; /* Match the sepia background */
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    display: none;
    z-index: 100;
}

.doll-menu.active {
    display: block;
}

/* Background menu button and panel inside clothes menu */
.background-menu-btn {
    width: 100%;
    padding: 6px 12px;
    margin-bottom: 8px;
    background: #ffb6e6;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Comic Sans MS', cursive;
    font-size: 14px;
    transition: background 0.2s;
}

.background-menu-btn:hover {
    background: #ff9ecd;
}

/* Background gallery button */
.background-gallery-btn {
    width: 100%;
    padding: 6px 12px;
    margin-bottom: 10px;
    background: #ffe0f3;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Comic Sans MS', cursive;
    font-size: 14px;
    transition: background 0.2s;
}

.background-gallery-btn:hover {
    background: #ffcfec;
}

/* Background gallery modal */
.background-gallery-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.background-gallery-modal.active {
    display: flex;
}

.background-gallery-content {
    background: #F9F6F2;
    border-radius: 15px;
    padding: 15px;
    width: 260px;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.25);
    position: relative;
}

.background-gallery-content h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #ff7eb6;
    text-align: center;
}

.background-gallery-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #ff8b8b;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.background-gallery-close:hover {
    background: #ff6b6b;
}

.background-menu {
    display: none;
    margin-bottom: 10px;
}

.background-menu.active {
    display: block;
}

.doll-list {
    max-height: 200px;
    overflow-y: auto;
}

.doll-item {
    padding: 8px;
    margin: 5px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.doll-name {
    cursor: pointer;
    flex: 1;
    margin-right: 10px;
}

.doll-item:hover {
    background: #fff5f9;
}

.remove-doll-btn {
    background: #ff8b8b;
    border: none;
    border-radius: 5px;
    padding: 3px 8px;
    color: white;
    cursor: pointer;
    font-size: 12px;
}

.remove-doll-btn:hover {
    background: #ff6b6b !important;
}

.hair-submenu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hair-submenu .clothing-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
}

.hair-submenu .clothing-item img {
    border-radius: 5px;
}

.hair-submenu .clothing-item span {
    flex: 1;
}

.worn.active-draggable {
    outline: none;
    cursor: move;
}

/* Visual marker for selected menu items */
.clothing-item.selected {
    background: #ff7eb6 !important;
    color: white !important;
    border-color: #ff7eb6 !important;
    transform: none !important;
}

.worn {
    transition: transform 0.1s ease-out;
}

.doll-position-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px; /* Updated for better spacing */
    margin-top: 15px; /* Added margin for better layout */
}

.position-btn {
    padding: 8px 15px;
    background: #ffb6e6;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    min-width: 40px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.position-btn:hover {
    background: #ff9ecd;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.position-btn:active {
    transform: scale(0.95);
}

.upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffb6e6 !important;
    color: white !important;
    margin-bottom: 15px;
    cursor: pointer;
}

.upload-label:hover {
    background: #ff9ecd !important;
}

.custom-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin: 5px 0;
    border: 2px solid #ffb6e6;
    border-radius: 10px;
}

.custom-item img {
    border: 2px solid transparent;
    transition: border-color 0.3s;
    border-radius: 5px;
}

.custom-item img:hover {
    border-color: #ffb6e6;
}

.text-menu {
    position: absolute;
    bottom: 10px;
    left: 20%;
    transform: translateX(-20%);
    background: rgba(244, 237, 228, 0.9);
    padding: 8px; /* Reduced from 10px */
    border-radius: 10px; /* Reduced from 12px */
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    width: 60%; /* Reduced from 70% */
    display: flex;
    flex-direction: column;
    gap: 6px; /* Reduced from 8px */
    z-index: 5;
}

.text-controls {
    display: flex;
    gap: 6px; /* Reduced from 8px */
    align-items: center;
    flex-wrap: wrap;
}

.text-input {
    padding: 4px; /* Reduced from 6px */
    border: 1px solid #ffb6e6; /* Reduced from 2px */
    border-radius: 6px; /* Reduced from 8px */
    font-family: 'Comic Sans MS', cursive;
    width: 120px; /* Reduced from 150px */
    font-size: 11px; /* Reduced from 12px */
}

.font-select,
.color-select {
    padding: 4px; /* Reduced from 6px */
    border: 1px solid #ffb6e6; /* Reduced from 2px */
    border-radius: 6px; /* Reduced from 8px */
    font-family: 'Comic Sans MS', cursive;
    cursor: pointer;
    font-size: 11px; /* Reduced from 12px */
}

.size-control {
    display: flex;
    align-items: center;
    gap: 3px; /* Reduced from 4px */
    font-size: 11px; /* Reduced from 12px */
}

.size-slider {
    width: 70px; /* Reduced from 80px */
}

.text-btn {
    padding: 4px 8px; /* Reduced from 6px 10px */
    font-size: 11px; /* Reduced from 12px */
    border-radius: 6px; /* Reduced from 8px */
}

.custom-text {
    cursor: move;
    z-index: 1000;
    padding: 4px 18px 4px 4px;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.1);
    transition: background-color 0.2s;
    position: absolute;
}

.custom-text:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.custom-text-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: none;
    background: #ff7eb6;
    color: #ffffff;
    font-size: 12px;
    line-height: 14px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-text-close:hover {
    background: #ff4f9c;
}

#backgroundLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
}

.doll-container {
    position: relative;
}

#uploadContainer {
    position: relative;
    z-index: 1;
}