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

body {
    font-family: 'Arial', sans-serif;
    background-image: url('images/character-creation.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.character-creator-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
}

/* Character Section */
.character-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    height: 100%;
    padding: 1rem;
}

/* Character Container */
.character-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: relative;
    width: 100%;
    height: 100%;
    margin-top: 1rem;
}

.character-display {
    position: relative;
    width: 100%;
    max-width: 990px;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.character {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

    .character-layer {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        transform: translateY(7.5vh) scale(1.25);
    }

/* Unified character parts with reversed z-index layering */
.character-part {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.character-part img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    display: block;
    max-width: none !important;
    max-height: none !important;
    min-width: 100% !important;
    min-height: 100% !important;
}

.layer-1 { z-index: 13; }
.layer-2 { z-index: 12; }
.layer-3 { z-index: 11; }
.layer-4 { z-index: 10; } /* hair (moved from layer 5) */
.layer-5 { z-index: 9; }  /* eyes (moved from layer 4) */
.layer-6 { z-index: 8; }
.layer-7 { z-index: 7; }
.layer-8 { z-index: 6; }
.layer-9 { z-index: 5; }
.layer-10 { z-index: 4; }
.layer-11 { z-index: 3; }
.layer-12 { z-index: 2; }
.layer-13 { z-index: 1; }

/* Action Buttons Container */
.action-buttons {
    display: flex;
    gap: 1rem;
    align-items: stretch;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    z-index: 100;
}

/* Random Button */
.random-btn {
    background: linear-gradient(45deg, #9370DB, #8A2BE2);
    color: white;
    border: 4px solid #000;
    border-radius: 75px;
    padding: 1rem 2rem;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: baseline;
}

.random-btn::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: linear-gradient(45deg, #9370DB, #8A2BE2);
    border-radius: 50px;
    z-index: -1;
}

.random-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

/* Download Button */
.download-btn {
    background: linear-gradient(45deg, #228B22, #32CD32);
    color: white;
    border: 4px solid #000;
    border-radius: 75px;
    padding: 1rem 2rem;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    vertical-align: baseline;
}

.download-btn::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: linear-gradient(45deg, #228B22, #32CD32);
    border-radius: 50px;
    z-index: -1;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

/* Customization Panel */
.customization-panel {
    background: #F5C6E8;
    border: 3px solid #000;
    border-radius: 15px;
    padding: 2rem;
    width: 100%;
    height: fit-content;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 20;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    align-items: center;
}

.tab-btn {
    background: #FFB6C1;
    border: 3px solid #000;
    border-radius: 13px;
    padding: 0.7125rem 0.95rem;
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 25;
    pointer-events: auto;
}

.tab-btn:hover {
    background: #FFC0CB;
}

.tab-btn.active {
    background: #DC9FC9;
    border-color: #000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Options Container */
.options-container {
    position: relative;
    width: 100%;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
    justify-content: center;
    align-items: center;
    min-height: 160px;
    padding: 1.5rem;
    background: transparent;
    border-radius: 15px;
    border: none;
    box-shadow: none;
}

.option-item {
    width: 100%;
    aspect-ratio: 1;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #DC9FC9;
    transition: all 0.2s ease;
    position: relative;
}

.option-item:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.option-item.selected {
    border: 3px solid #000;
    background: #DC9FC9;
    box-shadow: 0 0 0 2px #000;
}

.option-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

/* Navigation Arrows */
.navigation-arrows {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding-bottom: 1rem;
}

.nav-arrow {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.nav-arrow img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: all 0.2s ease;
}

.nav-arrow:hover {
    transform: scale(1.1);
}

.nav-arrow:hover img {
    filter: brightness(1.2);
}

/* Back Button */
.back-button {
    position: fixed;
    top: calc(1rem + 2.5vh);
    left: 1rem;
    z-index: 1000;
    padding: 1rem;
    padding-left: calc(1rem + 1vw);
}

.back-link {
    background: rgba(139, 92, 246, 0.9);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    text-decoration: none;
    font-weight: bold;
    border: 2px solid #000;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 1.5rem;
}

.back-link:hover {
    background: rgba(139, 92, 246, 1);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Responsive Design */
/* Large Desktop */
@media (min-width: 1440px) {
    .character-creator-container {
        grid-template-columns: 1fr 1fr;
        gap: 3rem;
        max-width: 1800px;
        padding: 2rem;
    }
    
    .character-display {
        max-width: 1210px;
    }
    
    .customization-panel {
        padding: 2rem;
    }
    
    .options-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
        min-height: 150px;
    }
    
    .action-buttons {
        gap: 1.5rem;
    }
    
    .random-btn,
    .download-btn {
        font-size: 1.25rem;
        padding: 1rem 2rem;
        width: 160px;
        height: 56px;
    }
}

/* Desktop */
@media (min-width: 1024px) and (max-width: 1439px) {
    .character-creator-container {
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
        padding: 1.5rem;
    }
    
    .character-display {
        max-width: 800px;
    }
    
    .options-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 0.75rem;
        min-height: 120px;
    }
    
    .action-buttons {
        gap: 1rem;
    }
    
    .random-btn,
    .download-btn {
        font-size: 1.25rem;
        padding: 1rem 2rem;
        width: 160px;
        height: 56px;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    .character-creator-container {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
        padding: 1rem;
    }
    
    .character-display {
        max-width: 540px;
    }
    
    .options-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 0.5rem;
        min-height: 100px;
    }
    
    .tab-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .action-buttons {
        gap: 0.75rem;
    }
    
    .random-btn,
    .download-btn {
        font-size: 1rem;
        padding: 0.75rem 1.5rem;
        width: 140px;
        height: 48px;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .character-creator-container {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0.25rem;
        min-height: 100vh;
        height: 100vh;
    }
    
    .character-section {
        order: 1;
        gap: 0.5rem;
        height: 40vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        overflow: visible;
    }
    
    .customization-panel {
        order: 2;
        padding: 0.5rem;
        height: 50vh;
        width: 90%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin: 0 auto;
    }
    
    .character-display {
        max-width: 80vw;
        height: 80vw;
        position: relative;
        overflow: visible;
    }
    
    .character-layer {
        transform: translateY(-1.5vh) scale(1.25);
    }
    
    .options-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 0.5rem;
        min-height: auto;
        padding: 0.25rem;
        flex: 1;
        display: grid;
        place-items: center;
        justify-content: center;
        align-content: center;
    }
    
    .option-item {
        width: 35vw;
        height: 35vw;
        max-width: 35vw;
        max-height: 35vw;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .category-tabs {
        gap: 0.15rem;
        row-gap: 0.25rem;
        margin-bottom: 1.25rem;
        max-height: 12vh;
        overflow-x: auto;
        overflow-y: hidden;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0.25rem 0.5rem;
        scrollbar-width: thin;
        scrollbar-color: #DC9FC9 transparent;
    }
    
    /* Custom scrollbar for webkit browsers */
    .category-tabs::-webkit-scrollbar {
        height: 4px;
    }
    
    .category-tabs::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .category-tabs::-webkit-scrollbar-thumb {
        background: #DC9FC9;
        border-radius: 2px;
    }
    
    .category-tabs::-webkit-scrollbar-thumb:hover {
        background: #C88BB3;
    }
    
    .tab-btn {
        padding: 0.2rem 0.3rem;
        font-size: 0.6rem;
        min-width: 60px;
        margin: 0.5vw;
        flex-shrink: 0;
    }
    
    .action-buttons {
        gap: 0.5rem;
        order: 3;
        margin-top: -4vh;
        flex-direction: row;
        width: 100%;
        justify-content: center;
        align-items: center;
    }
    
    .random-btn,
    .download-btn {
        font-size: 1rem;
        padding: 12px 24px !important;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 140px;
        height: 48px;
        line-height: 1;
        box-sizing: border-box;
        margin: 0 !important;
    }
    
    /* Force exact same positioning */
    .action-buttons > * {
        flex: 0 0 140px;
        height: 48px;
    }
    
    .back-button {
        top: calc(0.25rem + 2.5vh);
        left: 0.25rem;
        padding: 0.5rem;
        padding-left: calc(0.5rem + 2.5vw);
    }
    
    .back-link {
        padding: 0.45rem 0.9rem;
        font-size: 1.05rem;
    }
}

/* Extra small mobile */
@media (max-width: 480px) {
    .character-display {
        max-width: 80vw;
        height: 80vw;
        position: relative;
        overflow: visible;
    }
    
    .character-layer {
        transform: translateY(-1.5vh) scale(1.25);
    }
    
    .options-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 0.4rem;
        padding: 0.1rem;
        min-height: auto;
        display: grid;
        place-items: center;
        justify-content: center;
        align-content: center;
    }
    
    .option-item {
        width: 30vw;
        height: 30vw;
        max-width: 30vw;
        max-height: 30vw;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .category-tabs {
        gap: 0.1rem;
        row-gap: 0.25rem;
        margin-bottom: 1rem;
        max-height: 10vh;
        overflow-x: auto;
        overflow-y: hidden;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0.2rem 0.8rem;
        scrollbar-width: thin;
        scrollbar-color: #DC9FC9 transparent;
    }
    
    .tab-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.5rem;
        min-width: 50px;
        margin: 0.5vw;
        flex-shrink: 0;
    }
    
    .random-btn,
    .download-btn {
        font-size: 1rem;
        padding: 12px 24px !important;
        margin: 0 !important;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 140px;
        height: 48px;
    }
}

/* Landscape mobile adjustments */
@media (max-width: 767px) and (orientation: landscape) {
    .character-creator-container {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        align-items: center;
    }
    
    .character-display {
        max-width: 200px;
    }
    
    .options-grid {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 0.4rem;
        padding: 0.4rem;
        min-height: 60px;
    }
    
    .customization-panel {
        padding: 0.75rem;
    }
    
    .category-tabs {
        gap: 0.2rem;
        margin-bottom: 0.5rem;
    }
    
    .tab-btn {
        padding: 0.3rem 0.4rem;
        font-size: 0.6rem;
        min-width: 45px;
    }
}
