:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #8b5cf6;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    background-image: radial-gradient(circle at top right, rgba(139, 92, 246, 0.15), transparent 40%),
                      radial-gradient(circle at bottom left, rgba(59, 130, 246, 0.15), transparent 40%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.app-container {
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* Header */
.header {
    padding: 1.5rem 2rem;
    margin-bottom: 2rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header .logo {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #fff 0%, #a5a5a5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex: 1;
    text-align: left;
}

.subtitle-author {
    font-size: 0.4em;
    font-weight: 400;
    opacity: 0.6;
    vertical-align: middle;
    margin-left: 0.5rem;
    -webkit-text-fill-color: var(--text-muted);
}

.gender-toggle {
    display: inline-flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    padding: 4px;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex: 0 0 auto;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(59, 130, 246, 0.15); /* var(--primary-color) with opacity */
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.6, 0.1, 0.4, 0.9) infinite;
}

.gender-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1.5rem;
    border-radius: 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.gender-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header .title {
    color: var(--text-muted);
    font-size: 1.1rem;
    flex: 1;
    text-align: right;
    margin: 0;
    font-weight: 400;
}

/* Workspace */
.workspace {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0; /* Important for nested scrolling */
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    position: relative;
    overflow: hidden;
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #ffffff; /* User requested white background */
    border-radius: 12px;
    overflow: hidden;
    padding: 2rem; /* Creates equal gaps on top, bottom, and sides */
    position: relative;
    min-height: 400px;
    width: 100%;
}

/* Loading Animation */
#loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    z-index: 10;
}

.loader-text {
    font-weight: 500;
    color: #64748b;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    animation: pulse 1.5s ease-in-out infinite;
}

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

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

#svg-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.canvas-wrapper svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.2); /* Reduced scale so hair/clothes stay in frame */
    transform-origin: center center;
    transition: transform 0.3s ease;
}

.loading-spinner {
    font-size: 1.2rem;
    color: var(--primary-color);
    animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Controls Panel */
.controls-panel {
    width: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tabs-header {
    display: flex;
    overflow-x: auto;
    padding: 1rem;
    gap: 0.5rem;
    border-bottom: 1px solid var(--panel-border);
    scrollbar-width: none;
}

.tabs-header::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

.tabs-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.tabs-content::-webkit-scrollbar {
    width: 6px;
}
.tabs-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.tab-pane {
    display: none;
    flex-direction: column;
    gap: 1.5rem;
}

.tab-pane.active {
    display: flex;
}

.color-control {
    position: sticky;
    top: -1px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: rgba(20, 20, 25, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.color-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.color-control label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
}

.custom-color-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}

.custom-color-btn:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.8);
}

#color-picker-popup {
    position: fixed;
    z-index: 1000;
    background: rgba(30, 30, 35, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 1.5rem;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    /* Pop animation */
    transform: scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#color-picker-popup.visible {
    transform: scale(1);
    opacity: 1;
    pointer-events: auto;
}

#color-picker-popup.hidden {
    display: none;
}

.hex-input-container {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hex-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    text-align: center;
    letter-spacing: 1px;
    text-transform: uppercase;
    outline: none;
    transition: border-color 0.2s;
}

.hex-input:focus {
    border-color: rgba(255, 255, 255, 0.8);
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.swatch:hover {
    transform: scale(1.15);
    border-color: rgba(255, 255, 255, 0.8);
}

.swatch.active {
    transform: scale(1.15);
    border-color: #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 1rem;
}

/* Option Buttons */
.option-btn {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    transition: all 0.2s ease;
    padding: 8px;
}

.option-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.option-btn.selected {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3) inset;
}

.option-btn svg {
    max-width: 100%;
    max-height: 100%;
    pointer-events: none;
}

.option-btn .option-label {
    position: absolute;
    bottom: 4px;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
}

#pane-nose .option-btn,
#pane-eyes .option-btn {
    background: #ebb99e;
}

#pane-nose .option-btn:hover,
#pane-eyes .option-btn:hover {
    background: #dca78c;
}

#pane-nose .option-btn.selected,
#pane-eyes .option-btn.selected {
    background: #e2a88a;
    border-color: #ffffff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5) inset;
}

/* Footer */
.controls-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--panel-border);
    display: flex;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--accent));
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    width: 100%;
    justify-content: center;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 1024px) {
    /* iPad / Tablet */
    .app-container {
        width: 100%;
        height: 100vh;
        gap: 0.5rem;
        border-radius: 0;
        border-radius: 0;
        gap: 0;
    }
    .glass-panel {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
    }
    .header {
        border-radius: 0;
        margin-bottom: 0;
        border-bottom: 1px solid var(--panel-border);
    }
    .header-content {
        flex-wrap: wrap;
    }
    .gender-toggle {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 1rem;
    }
    .gender-btn {
        padding: 0.4rem 1rem;
        font-size: 0.85rem;
        flex: 1; /* Make buttons stretch evenly */
        text-align: center;
    }
    .canvas-wrapper {
        aspect-ratio: 16/9;
        height: auto;
        max-width: 100%;
        margin: 0 auto;
        flex: none;
    }
    .controls-panel {
        width: 320px;
    }
}

@media (max-width: 767px) {
    /* Phone */
    .header {
        padding: 0.5rem 1rem; /* Reduce header height */
    }
    .header .title {
        display: none; /* Hide subtitle on phone */
    }
    .header .logo {
        text-align: center;
        width: 100%;
        font-size: 1rem; /* Make titles more smaller */
    }
    
    /* Make toggle smaller to shift character up */
    .gender-toggle {
        padding: 2px;
    }
    .gender-btn {
        padding: 0.25rem 0.75rem;
        font-size: 0.8rem;
    }

    .workspace {
        flex-direction: column;
        gap: 0;
    }
    .preview-panel {
        flex: 0 0 45vh; /* Take up less height to leave room for controls */
        padding: 0.5rem;
    }
    .canvas-wrapper {
        aspect-ratio: auto;
        width: 100%;
        height: 100%;
        flex: 1;
        min-height: 200px; /* Override global 400px to allow fitting on screen */
        padding: 0.25rem; /* Make character full visible */
    }
    
    .controls-panel {
        flex: 1; /* Bottom half */
        width: 100%;
        border-top: 1px solid var(--panel-border);
        display: flex;
        flex-direction: column;
    }
    
    /* Decrease sizes of customization */
    .tabs-header {
        padding: 0.25rem 0.5rem;
        gap: 0.25rem;
    }
    .tab-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
    .tabs-content {
        padding: 0.5rem;
        flex: 1;
        overflow-y: auto;
    }
    .options-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); /* Smaller option cards */
        gap: 0.5rem;
    }
    .option-btn {
        padding: 4px;
    }
    .color-control {
        padding: 0.25rem;
    }
    
    .controls-footer {
        padding: 0.5rem;
    }
    .btn-primary {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}
