/* ── PhET Scaling Base ───────────────────────────────────── */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* PhET Stage — scalable container */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow-y: auto;
    background: #cbd5e1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

:root {
    --primary: #8b5cf6;
    /* Purple for modern physics */
    --primary-dark: #7c3aed;
    --bg-dark: #0f172a;
    --panel-bg: rgba(255, 255, 255, 0.9);
    --text: #1e293b;
    --text-muted: #64748b;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: #cbd5e1;
    color: var(--text);
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.simulation-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Nav Styles */
.sim-nav {
    flex-shrink: 0;
    height: 60px;
    background: #fff;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

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

.back-btn {
    color: var(--text);
    font-size: 1.2rem;
    text-decoration: none;
    transition: transform 0.2s;
}

.back-btn:hover {
    transform: translateX(-5px);
    color: var(--primary);
}

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--bg-dark);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.icon-btn:hover {
    color: var(--primary);
}

/* Layout */
.sim-viewport {
    flex: 1;
    display: flex;
    overflow: hidden;
    padding: 15px;
    gap: 15px;
    min-height: 0;
}

.canvas-section {
    flex: 1;
    background: var(--bg-dark);
    border-radius: 12px;
    position: relative;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

#main-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Floating Controls */
.phet-box {
    background: var(--panel-bg);
    border: 2px solid #94a3b8;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.lamp-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 220px;
    backdrop-filter: blur(8px);
    z-index: 10;
}

.control-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 5px;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
    margin-bottom: 10px;
}

.spectrum-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.spectrum-gradient {
    height: 12px;
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(to right,
            #a855f7,
            /* UV/Purple */
            #3b82f6,
            /* Blue */
            #22c55e,
            /* Green */
            #eab308,
            /* Yellow */
            #f97316,
            /* Orange */
            #ef4444,
            /* Red */
            #7f1d1d
            /* IR/Deep Red */
        );
    margin-top: 5px;
}

/* Ammeter Spliced into Wire */
.ammeter-wire-unit {
    position: absolute;
    bottom: 60px;
    /* Shifted up */
    left: calc(50% + 140px);
    /* Positioned on the right wire */
    background: #020617;
    border: 1px solid #334155;
    padding: 3px 12px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 0 5px rgba(74, 222, 128, 0.1);
    z-index: 15;
}

.ammeter-wire-unit .ammeter-label {
    font-size: 0.5rem;
    color: #4ade80;
    opacity: 0.7;
    font-weight: 800;
    letter-spacing: 1px;
    margin-bottom: 1px;
}

.ammeter-wire-unit .ammeter-value {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    font-weight: 700;
    color: #4ade80;
    text-shadow: 0 0 8px rgba(74, 222, 128, 0.3);
}

/* Side Panel */
.battery-system {
    position: absolute;
    bottom: 60px;
    /* Shifted up */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 20;
}

@media (max-width: 1024px) {
    .battery-system {
        bottom: 50px;
    }
}

.battery-container {
    position: relative;
    width: 180px;
    height: 45px;
}

.battery-hardware {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.battery-terminal {
    width: 15px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 0.8rem;
    background: linear-gradient(to right, #cbd5e1, #64748b, #cbd5e1);
    /* Brushed Aluminum */
    border: 1px solid rgba(0, 0, 0, 0.3);
    z-index: 5;
}

.battery-cylinder {
    width: 130px;
    height: 40px;
    /* Duracell-style copper/black scheme */
    background: linear-gradient(to bottom,
            #334155 0%,
            #0f172a 40%,
            #0f172a 60%,
            #334155 100%);
    box-shadow:
        inset 0 0 15px rgba(0, 0, 0, 0.8),
        0 8px 15px rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    margin: 0 -2px;
    position: relative;
    overflow: hidden;
}

/* Copper Shoulder */
.battery-cylinder::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 35%;
    background: linear-gradient(to bottom,
            #f59e0b 0%,
            #92400e 40%,
            #92400e 60%,
            #f59e0b 100%);
    border-left: 2px solid rgba(0, 0, 0, 0.3);
}

.battery-terminal.positive {
    background: linear-gradient(to right, #92400e, #d97706, #92400e);
}

.battery-cap {
    width: 10px;
    height: 25px;
    background: #475569;
    border-radius: 0 4px 4px 0;
    border: 1px solid #1e293b;
}

/* Control Layer (Stable Overlay) */
.battery-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.battery-title {
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 800;
    letter-spacing: 1.5px;
    margin-bottom: 3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.battery-controls input[type="range"] {
    width: 110px;
    margin: 0;
    cursor: pointer;
    accent-color: #f1f5f9;
}

.voltage-readout-digital {
    background: #020617;
    color: #4ade80;
    padding: 4px 18px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    font-weight: 700;
    border: 1px solid #334155;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.4),
        inset 0 0 8px rgba(74, 222, 128, 0.1);
    z-index: 25;
}

/* Polarity Flip Class */
.battery-hardware.reversed {
    transform: rotateY(180deg);
}

/* Side Panel */
.control-panel {
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.section-header {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.select-wrapper select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
}

.phet-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

.phet-checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.graph-box {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.graph-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.graph-btn {
    flex: 1;
    padding: 6px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.graph-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.embedded-graph-container {
    background: #020617;
    border: 1px solid #1e293b;
    border-radius: 6px;
    margin-bottom: 8px;
    padding: 5px;
    overflow: hidden;
}

#main-canvas {
    width: 100%;
    height: 100%;
}

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

#graph-title-label {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 1px;
}

.actions-group {
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: none;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #fff;
    color: var(--text);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

.reset-btn {
    background: #fecaca;
    color: #dc2626;
}

.reset-btn:hover {
    background: #f87171;
    color: white;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
}

.modal-content {
    background: white;
    width: 500px;
    margin: 100px auto;
    padding: 30px;
    border-radius: 15px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-bottom: 15px;
    color: var(--primary);
}

.modal-content li {
    margin-left: 20px;
    margin-bottom: 8px;
}

.close-modal {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

@keyframes glow {
    0% {
        filter: drop-shadow(0 0 5px currentColor);
    }

    100% {
        filter: drop-shadow(0 0 15px currentColor);
    }
}