:root {
    --bg-dark: #09090b;
    --bg-panel: rgba(24, 24, 27, 0.95);
    /* Slightly more opaque for better contrast */
    --header-bg: #000000;
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    --border: rgba(255, 255, 255, 0.15);
    --radius: 8px;
    --blur: 20px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    background-image: radial-gradient(circle at 60% -20%, #2e1065 0%, #000 60%);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    /* Dynamic Viewport Height for mobile browsers */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- PROFESSIONAL HEADER --- */
.main-header {
    height: 60px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 50;
    flex-shrink: 0;
    /* Never shrink the header */
}

.brand-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    height: 28px;
    width: auto;
    border-radius: 4px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-name {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.brand-tag {
    font-size: 0.6rem;
    color: #888;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.text-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.2s;
}

.text-link:hover {
    color: #fff;
}

.shop-btn {
    text-decoration: none;
    background: transparent;
    border: 1px solid var(--border);
    color: #fff;
    padding: 6px 14px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
}

.shop-btn:hover {
    background: #fff;
    color: #000;
}

/* --- WORKSPACE LAYOUT --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
}

#viewer {
    flex: 1;
    cursor: grab;
    background: transparent;
    min-width: 0;
    /* Prevent flex overflow */
}

#viewer:active {
    cursor: grabbing;
}

/* --- CONTROLS SIDEBAR --- */
#controls-area {
    width: 380px;
    background: var(--bg-panel);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    height: 100%;
}

/* CRITICAL FIX: min-height: 0 allows this flex child to scroll properly */
.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 0;
}

/* SECTION STYLING */
.section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 12px;
    display: block;
}

/* INPUTS */
.input-group {
    margin-bottom: 12px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.full-width {
    grid-column: span 2;
}

label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 6px;
    color: #e4e4e7;
    font-weight: 500;
}

.sub-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

input[type="file"] {
    width: 100%;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: 0.85rem;
}

input[type="number"] {
    padding-right: 4px;
}

.range-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

input[type="range"] {
    flex: 1;
    height: 4px;
    background: #333;
    border-radius: 2px;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    border: 2px solid #fff;
    cursor: pointer;
}

.color-picker {
    width: 30px;
    height: 30px;
    border: none;
    padding: 0;
    background: none;
    cursor: pointer;
}

/* Checkboxes */
.checkbox-group {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* FOOTER - CRITICAL FIX */
.controls-footer {
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.6);
    /* Darker background to separate from content */
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    /* PREVENTS FOOTER FROM DISAPPEARING */
    z-index: 20;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    /* iPhone Home Bar Support */
}

.stats-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stats-bar b {
    color: #fff;
}

.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    width: 100%;
    background: #10b981;
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    display: none;
}

.btn-secondary:hover {
    background: #059669;
}

/* LOADING */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #333;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#status {
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* --- SCROLLABLE MODAL --- */
.modal {
    display: none;
    position: fixed;
    z-index: 200;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #18181b;
    border: 1px solid var(--border);
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    border-radius: 12px;
    color: #eee;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #202023;
    border-radius: 12px 12px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
}

.close-btn {
    font-size: 28px;
    cursor: pointer;
    color: #aaa;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-section {
    margin-bottom: 30px;
}

.modal-section h3 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1rem;
}

.modal-section p {
    line-height: 1.5;
    color: #ccc;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.tech-list {
    margin: 10px 0;
    padding-left: 20px;
    color: #ccc;
    font-size: 0.9rem;
}

.tech-list li {
    margin-bottom: 5px;
}

.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.step-card {
    background: #27272a;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid #333;
}

.step-card b {
    display: block;
    color: #fff;
    margin-bottom: 5px;
}

.step-card p {
    font-size: 0.8rem;
    margin: 0;
    color: #aaa;
}

/* --- MOBILE OPTIMIZATIONS --- */
/* --- MOBILE OPTIMIZATIONS --- */
@media (max-width: 800px) {
    .workspace {
        flex-direction: column;
    }

    #viewer {
        height: 35%;
        flex: none;
    }

    #controls-area {
        width: 100%;
        height: 65%;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.5);
    }

    /* HEADER ADJUSTMENTS FOR MOBILE */
    .main-header {
        padding: 0 12px;
        /* Reduce padding to fit content */
    }

    .brand-tag {
        display: block;
        /* Force show */
        font-size: 0.55rem;
        /* Make slightly smaller */
        margin-top: 2px;
    }

    .text-link {
        display: block;
        /* Force show */
        font-size: 0.75rem;
        margin-right: 5px;
        /* Add small spacing */
    }

    .header-actions {
        gap: 8px;
        /* Reduce gap between buttons */
    }

    .brand-name {
        font-size: 0.9rem;
        /* Slightly smaller title */
    }

    .shop-btn {
        padding: 6px 10px;
        /* Compact button */
        font-size: 0.75rem;
    }
}