:root {
    --bg-dark: #020617;
    --panel-bg: rgba(15, 23, 42, 0.7);
    --primary: #f43f5e;
    --primary-glow: rgba(244, 63, 94, 0.3);
    --secondary: #10b981;
    --accent: #3b82f6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
}

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

body.experiment-page {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 1280px;
    height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
    transform-origin: top left;
}

#bgCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    background: radial-gradient(circle at 50% 50%, #0f172a 0%, #020617 100%);
}

/* Nav */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 1000;
}

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

.chapter-label { color: var(--text-muted); font-size: 0.9rem; }
.exp-label { font-weight: 700; color: var(--primary); }
.divider { color: var(--border); }

.btn-back {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

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

/* Main Layout */
main {
    flex: 1;
    width: 100%;
    padding-top: 80px;
}

.sim-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    height: 100%;
}

/* Controls Panel */
.controls-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    overflow-y: auto;
}

@media (max-width: 1024px) {
    .sim-layout {
        grid-template-columns: 1fr 240px;
    }
    .controls-panel {
        padding: 15px;
        gap: 20px;
    }
    .math-formula {
        font-size: 2rem !important;
        gap: 15px !important;
    }
    .math-formula .equals {
        font-size: 1.8rem !important;
    }
    #f-rho {
        font-size: 1.8rem !important;
    }
    .fraction {
        margin-left: 10px !important;
    }
    .f-top, .f-bottom {
        height: 40px !important;
        min-width: 40px !important;
    }
}

.panel-section h2 {
    font-size: 1.2rem;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.panel-section h2 i { color: var(--primary); }

.control-group {
    margin-bottom: 30px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 12px;
}

.control-header label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-header .value {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
}

select {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    outline: none;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

select:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

select option {
    background-color: #0f172a; /* Force dark background for dropdown list */
    color: white;
}

input[type="range"] {
    width: 100%;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: -7px;
    box-shadow: 0 0 10px var(--primary-glow);
    cursor: pointer;
}

/* Formula Box */
.formula-box {
    background: rgba(244, 63, 94, 0.05);
    border: 1px solid var(--primary-glow);
    border-radius: 20px;
    padding: 25px;
}

.formula-box h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 15px;
}

/* Formula Overlay */
.formula-overlay {
    position: absolute;
    top: 40px;
    left: 40px;
    z-index: 10;
    pointer-events: none;
}

.math-formula {
    font-family: 'Space Grotesk', serif;
    font-size: 3.5rem; /* Bigger for main area */
    display: flex;
    align-items: center;
    gap: 30px;
    color: var(--text-main);
}

.math-formula span {
    display: inline-block;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#f-res { color: #ef4444; } /* Red */
#f-rho { color: #3b82f6; } /* Blue */
#f-len { color: #fbbf24; } /* Yellow */
#f-area { color: #10b981; } /* Green */

.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin-left: 20px;
}

.f-top {
    height: 60px;
    display: flex;
    align-items: flex-end; /* Keep L close to bar */
    justify-content: center;
    min-width: 60px;
}

.f-bottom {
    height: 60px;
    display: flex;
    align-items: flex-start; /* Keep A close to bar */
    justify-content: center;
    min-width: 60px;
}

.f-bar {
    width: 100%;
    height: 4px;
    background: var(--text-main);
    border-radius: 2px;
    margin: 2px 0;
}

#f-len, #f-area { transform-origin: center; }
#f-rho { margin: 0 15px; font-size: 3rem; }
.math-formula .equals { font-size: 3rem; margin: 0 10px; }

.result-display {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    text-align: center;
}

.result-display .label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.result-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary);
    font-family: 'Space Grotesk', sans-serif;
    text-shadow: 0 0 20px var(--primary-glow);
}

/* Visualization Area */
.viz-area {
    position: relative;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.viz-container {
    width: 100%;
    max-width: 900px;
    height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.wire-outer {
    position: relative;
    width: 50%; /* Variable Length */
    height: 60px; /* Variable Area */
    background: #475569;
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transition: width 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wire-inner {
    position: absolute;
    inset: 4px;
    background: linear-gradient(to right, #64748b, #475569);
    border-radius: 6px;
    overflow: hidden;
}

/* Atomic obstacles */
#atom-layer {
    position: absolute;
    inset: 0;
}

.atom {
    position: absolute;
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

/* Electron particles */
.electron {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fbbf24;
    border-radius: 50%;
    box-shadow: 0 0 8px #fbbf24;
}

/* Labels & Indicators */
.wire-labels {
    position: absolute;
    inset: -60px;
    pointer-events: none;
}

.length-indicator {
    position: absolute;
    bottom: 40px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.length-indicator .line {
    flex-grow: 1;
    height: 2px;
    background: rgba(255, 255, 255, 0.2);
}

.length-indicator span {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    color: var(--text-muted);
}

.area-indicator {
    position: absolute;
    right: -50px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.area-indicator .circle {
    width: 30px;
    height: 30px;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 50%;
}

.area-indicator span {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    color: var(--text-muted);
}

/* Info Card */
.info-overlay {
    position: absolute;
    bottom: 40px;
    right: 40px;
    width: 300px;
}

.info-card {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    gap: 15px;
}

.info-card i { color: var(--accent); font-size: 1.2rem; }
.info-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }
