/* ================================================================
   PHOTOSYNTHESIS SIMULATOR — PhET-Style Scale-to-Fit Layout
   Desktop view is the "true" design. On mobile the entire
   #phet-stage is scaled down via JS transform: scale() to fit
   the screen — identical to how PhET simulations work.
   ================================================================ */

/* --- Root viewport: always fills the real screen exactly --- */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #020617;
    font-family: 'Outfit', sans-serif;
    overscroll-behavior: none;
    touch-action: none; /* Disable browser defaults for panning */
}

/* ----------------------------------------------------------------
   #phet-stage  — The fixed-size "design canvas"
   JS sets its width/height and transform: scale() dynamically.
   Think of it like a 1280×720 TV inside whatever-size room.
   ---------------------------------------------------------------- */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 1280px;
    height: 720px;
    background: #020617;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: 0 0; /* Updated for custom pan/zoom math */
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    touch-action: none;
}

/* ----------------------------------------------------------------
   Everything inside #phet-stage uses the SAME px values as desktop.
   Nothing below changes on mobile — JS handles the zoom.
   ---------------------------------------------------------------- */

nav {
    position: relative !important;
    z-index: 50;
    flex-shrink: 0;
}


:root {
    --bg-deep: #020617;
    --glass-surface: rgba(15, 23, 42, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-blue: #38bdf8;
    --accent-purple: #8b5cf6;
    --accent-orange: #f59e0b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --nav-height: 60px;
}

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

body.lab-theme {
    background: var(--bg-deep);
    font-family: 'Outfit', 'Inter', sans-serif;
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.glass-nav {
    height: var(--nav-height);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    padding: 0 40px;
    justify-content: space-between;
    flex-shrink: 0;
}

.lab-app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Important for nested flex scroll/overflow */
}

.simulation-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 80px 24px 24px 24px;
    gap: 24px;
    position: relative;
    background: radial-gradient(circle at center, #0f172a 0%, #020617 100%);
    min-height: 0;
}

#sim-container {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    min-height: 0;
}

#grid-container {
    display: flex;
    gap: 32px;
    width: 100%;
    max-width: 1400px;
    height: 100%;
    align-items: stretch;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.grid-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    min-height: 0;
}

/* Stats Display Integrated */
.stats-display {
    padding: 16px 24px;
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-shrink: 0;
}

.stat-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 130px;
}

.stat-icon {
    font-size: 1.2rem;
    opacity: 0.8;
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-blue);
}

.secondary .stat-value {
    color: var(--accent-purple);
}

.canvas-holder {
    flex: 1;
    position: relative;
    min-height: 0;
    cursor: crosshair;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Bottom Controls */
.bottom-controls {
    height: 90px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(15px);
    border-top: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
}

.control-group {
    display: flex;
    gap: 12px;
}

.option-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-left: 28px;
    position: relative;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
}

.checkbox-container:hover .checkmark {
    background: rgba(255, 255, 255, 0.1);
}

.checkbox-container input:checked~.checkmark {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.checkmark::after {
    content: '';
    position: absolute;
    left: 7px;
    top: 3px;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    display: none;
}

.checkbox-container input:checked~.checkmark::after {
    display: block;
}

.buckets-wrapper {
    display: flex;
    gap: 40px;
}

.bucket-container {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* 3D Bucket Refined */
.bucket {
    width: 120px;
    height: 50px;
    background: rgba(15, 23, 42, 0.6);
    border: 2px solid rgba(56, 189, 248, 0.3);
    border-top: none;
    border-radius: 0 0 40px 40px;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
    box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.6);
}

.bucket::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -2px;
    width: calc(100% + 4px);
    height: 8px;
    background: rgba(56, 189, 248, 0.3);
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-radius: 10px;
}

.bucket.secondary {
    border-color: rgba(168, 85, 247, 0.3);
}

.bucket.secondary::before {
    background: rgba(168, 85, 247, 0.3);
    border-color: rgba(168, 85, 247, 0.4);
}

.block-stack {
    width: 40px;
    height: 40px;
    background: var(--accent-orange);
    border-radius: 6px;
    cursor: grab;
    transform: translateY(-10px);
    box-shadow: 0 3px 0 #92400e, -4px 4px 0 rgba(245, 158, 11, 0.6), 0 8px 16px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bucket.secondary .block-stack {
    background: var(--accent-purple);
    box-shadow: 0 3px 0 #7e22ce, -4px 4px 0 rgba(168, 85, 247, 0.6), 0 8px 16px rgba(0, 0, 0, 0.4);
}

.block-stack:hover {
    transform: translateY(-14px) scale(1.1);
}

/* Global Tools */
.global-tools {
    display: flex;
    gap: 12px;
    align-items: center;
}

.mode-toggle {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.mode-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.mode-btn.active {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.refresh-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #f59e0b, #ea580c);
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(234, 88, 12, 0.4);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.refresh-btn:hover {
    transform: rotate(180deg) scale(1.1);
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

/* Drag Overlay */
#drag-proxy {
    position: fixed;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Animations & Transitions */
.single-mode #wrapper-2 {
    display: none !important;
}

.dual-mode #wrapper-1,
.dual-mode #wrapper-2 {
    flex: 1;
}

.dual-mode #grid-container {
    max-width: 1400px;
}