/* ============================================
   LITHOPHANE STUDIO — Design System
   ============================================ */

:root {
    /* Color palette */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a26;
    --bg-elevated: #1e1e2e;
    --bg-glass: rgba(22, 22, 35, 0.85);

    --text-primary: #e8e8f0;
    --text-secondary: #9898b0;
    --text-tertiary: #686880;
    --text-accent: #c4b5fd;

    --accent-primary: #8b5cf6;
    --accent-secondary: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.3);
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #6d28d9);

    --warm-glow: #fbbf24;
    --warm-glow-soft: rgba(251, 191, 36, 0.15);

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.1);

    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;

    /* Sizing */
    --panel-width: 320px;
    --header-height: 56px;
    --mobile-header-height: 48px;
    --mobile-viewport-height: 42vh;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 150ms var(--ease-out);
    --transition-normal: 250ms var(--ease-out);
    --transition-slow: 400ms var(--ease-out);
}

/* ============================================
   Reset & Base
   ============================================ */

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

html, body {
    height: 100%;
    height: 100dvh; /* Use dynamic viewport height for mobile browsers */
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   App Layout
   ============================================ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile address bar */
}

/* ============================================
   Header
   ============================================ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-xl);
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-secondary);
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.logo h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.header-btn svg {
    width: 16px;
    height: 16px;
}

.header-btn:hover:not(:disabled) {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.header-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.header-btn.primary {
    background: var(--accent-gradient);
    border-color: transparent;
    color: white;
}

.header-btn.primary:hover:not(:disabled) {
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: translateY(-1px);
}

.header-btn.active {
    background: var(--warm-glow-soft);
    border-color: var(--warm-glow);
    color: var(--warm-glow);
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   Control Panel
   ============================================ */

.control-panel {
    width: var(--panel-width);
    min-width: var(--panel-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.control-panel::-webkit-scrollbar {
    width: 5px;
}

.control-panel::-webkit-scrollbar-track {
    background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 10px;
}

.panel-section {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-subtle);
}

.section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

/* ============================================
   Upload Zone
   ============================================ */

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.upload-zone:hover {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.upload-zone.drag-over {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.1);
    transform: scale(1.02);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl) var(--space-lg);
    text-align: center;
}

.upload-placeholder svg {
    width: 40px;
    height: 40px;
    color: var(--text-tertiary);
    margin-bottom: var(--space-md);
    transition: color var(--transition-fast);
}

.upload-zone:hover .upload-placeholder svg {
    color: var(--accent-secondary);
}

.upload-placeholder p {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.upload-placeholder span {
    font-size: 11px;
    color: var(--text-tertiary);
}

.upload-preview {
    position: relative;
    aspect-ratio: 16/10;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.remove-image-btn {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
}

.remove-image-btn:hover {
    background: var(--error);
    transform: scale(1.1);
}

/* ============================================
   Multi-Panel Upload (flat-sided shapes)
   ============================================ */

.panel-uploads {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
}

.panel-upload-zone {
    position: relative;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    overflow: hidden;
    aspect-ratio: 1;
    transition: all var(--transition-fast);
}

.panel-upload-zone:hover {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.panel-upload-zone.drag-over {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.1);
}

.panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-sm);
    gap: 2px;
}

.panel-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
}

.panel-hint {
    font-size: 10px;
    color: var(--text-tertiary);
}

.panel-direction {
    font-size: 10px;
    font-weight: 500;
    color: var(--accent-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panel-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.panel-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.panel-remove-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 9px;
    cursor: pointer;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
}

.panel-remove-btn:hover {
    background: var(--error);
    transform: scale(1.1);
}

.panel-preview-label {
    position: absolute;
    bottom: 3px;
    left: 3px;
    padding: 1px 6px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 3px;
    color: var(--accent-secondary);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    pointer-events: none;
    backdrop-filter: blur(4px);
}

/* ============================================
   Controls
   ============================================ */

.control-group {
    margin-bottom: var(--space-lg);
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
    font-size: 12px;
    color: var(--text-secondary);
}

.value-input-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
}

.value-input-wrapper:focus-within {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.number-input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 11px;
    font-family: inherit;
    width: 36px;
    text-align: right;
    outline: none;
    padding: 0;
}

.number-input::-webkit-inner-spin-button,
.number-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.unit {
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* Custom Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--accent-glow);
    transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 12px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* Custom Select */
.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '▾';
    position: absolute;
    right: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
    font-size: 11px;
}

select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    padding-right: var(--space-2xl);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    transition: all var(--transition-fast);
}

select:hover {
    border-color: var(--border-medium);
}

select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Toggle Switch */
.toggle-label {
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-track::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: all var(--transition-fast);
}

.toggle-switch input:checked + .toggle-track {
    background: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(16px);
    background: white;
}

/* Sample Gallery */
.sample-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.sample-tile {
    aspect-ratio: 1;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary);
    padding: 0;
    transition: all var(--transition-fast);
}

.sample-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.sample-tile:hover {
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.sample-tile.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Range Wrapper */
.range-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* Control Hint */
.control-hint {
    display: block;
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: var(--space-xs);
    font-style: italic;
}

/* ============================================
   Info Section
   ============================================ */

.info-section {
    background: var(--bg-tertiary);
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.info-item:last-child {
    grid-column: 1 / -1;
}

.info-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
}

.info-value {
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

/* ============================================
   Viewport
   ============================================ */

.viewport {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

#render-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.viewport-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 2;
    background: radial-gradient(ellipse at center, transparent 0%, var(--bg-primary) 100%);
}

.viewport-overlay[hidden] {
    display: none;
}

.empty-state {
    text-align: center;
    animation: fadeInUp 0.8s var(--ease-out);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    color: var(--text-tertiary);
    opacity: 0.3;
    margin-bottom: var(--space-xl);
}

.empty-state h2 {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.empty-state p {
    font-size: 13px;
    color: var(--text-tertiary);
}

/* ============================================
   Status Bar
   ============================================ */

.viewport-status {
    position: absolute;
    bottom: var(--space-xl);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    z-index: 5;
    animation: fadeInUp 0.4s var(--ease-out);
}

.viewport-status[hidden] {
    display: none;
}

#status-text {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.progress-bar {
    width: 100px;
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ============================================
   Responsive Designs
   ============================================ */

@media (max-width: 768px) {
    body {
        font-size: 14px; /* Slightly larger text for mobile readability */
    }

    .app-header {
        height: var(--mobile-header-height);
        padding: 0 var(--space-lg);
    }

    .logo-icon {
        width: 20px;
        height: 20px;
    }

    .logo h1 {
        font-size: 14px;
    }

    .header-btn span {
        display: none; /* Hide button text to save space */
    }

    .header-btn {
        padding: var(--space-sm);
        aspect-ratio: 1;
    }

    /* THE MOBILE STACK: Viewer on TOP, Controls on BOTTOM */
    .main-content {
        flex-direction: column-reverse;
        overflow: hidden;
    }

    .viewport {
        height: var(--mobile-viewport-height);
        min-height: 220px; /* Lower min-height to prevent squeezing controls */
        flex: none;
        position: relative;
    }

    .control-panel {
        width: 100%;
        min-width: 0;
        flex: 1;
        border-right: none;
        border-top: 1px solid var(--border-subtle);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        padding-bottom: 80px; /* Extra space so last controls are reachable */
    }

    .panel-section {
        padding: var(--space-lg);
    }

    /* TOUCH OPTIMIZATION: LARGER TARGETS */
    .control-group label {
        margin-bottom: var(--space-md);
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    input[type="range"] {
        height: 32px; /* Thicker slider for easier drag */
    }

    .number-input {
        width: 48px;
        height: 32px;
        font-size: 14px;
    }

    .toggle-switch {
        width: 44px;
        height: 24px;
    }

    .toggle-track::after {
        width: 20px;
        height: 20px;
    }

    .toggle-switch input:checked + .toggle-track::after {
        transform: translateX(20px);
    }

    /* Fixed status overlay fix */
    .viewport-status {
        bottom: var(--space-md);
        font-size: 11px;
    }

    .empty-state svg {
        width: 48px;
        height: 48px;
    }

    .empty-state h2 {
        font-size: 14px;
    }

    .empty-state p {
        font-size: 11px;
    }
}
