:root {
    --accent-cyan: #06b6d4;
    --accent-glow: rgba(6, 182, 212, 0.4);
    --bg-dark: #0f172a;
    --card-bg: rgba(255, 255, 255, 0.05);
    --border-soft: rgba(255, 255, 255, 0.1);
}

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 {
    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;
}

body.binary-page {
    background-color: #020617;
    color: #e2e8f0;
}

#sim-app {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

.sim-container {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
    height: calc(100% - 100px);
}

.canvas-panel {
    flex: 1;
    background: radial-gradient(circle at top right, #1e293b, #020617);
    border-radius: 24px;
    border: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* Bulbs Row */
.bulb-row {
    display: flex;
    gap: 15px;
    margin-bottom: 40px;
}

.bulb {
    width: 60px;
    height: 80px;
    background: #1e293b;
    border-radius: 30px 30px 5px 5px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.05);
}

.bulb::after {
    content: '';
    position: absolute;
    top: 10%;
    left: 15%;
    width: 70%;
    height: 50%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

.bulb.active {
    background: var(--accent-cyan);
    box-shadow: 0 0 30px var(--accent-glow), inset 0 0 15px rgba(255, 255, 255, 0.5);
}

.bulb.active::after {
    background: rgba(255, 255, 255, 0.3);
}

/* Bit Board */
.bit-board {
    display: flex;
    gap: 15px;
    margin-bottom: 60px;
}

.bit-card {
    width: 80px;
    height: 120px;
    perspective: 1000px;
    cursor: pointer;
    position: relative;
}

/* Highlight the LSB (last block) as the primary trigger */
#card-0 {
    transform: scale(1.05);
    z-index: 10;
}

#card-0::after {
    content: 'CLICK TO COUNT';
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--accent-cyan);
    white-space: nowrap;
    opacity: 0.6;
}

.bit-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.bit-card.active .bit-inner {
    transform: rotateY(180deg);
}

.bit-front,
.bit-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    font-family: 'Space Grotesk', sans-serif;
}

.bit-front {
    background: #1e293b;
    color: #94a3b8;
}

.bit-back {
    background: var(--accent-cyan);
    color: white;
    transform: rotateY(180deg);
}

.bit-val {
    font-size: 3rem;
    font-weight: 800;
}

.bit-pos {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-bottom: 5px;
}

/* Math Ribbon */
.math-ribbon {
    background: rgba(255, 255, 255, 0.03);
    padding: 20px 40px;
    border-radius: 100px;
    border: 1px solid var(--border-soft);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
}

.equation {
    color: #94a3b8;
}

.equation .part.active {
    color: var(--accent-cyan);
    font-weight: 700;
}

.equation .total {
    font-size: 2rem;
    color: white;
    font-weight: 800;
    margin-left: 10px;
}

/* Sidebar */
.control-panel {
    width: 320px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 25px;
    border: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.section-title {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #64748b;
    margin-bottom: 12px;
}

.phet-box {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 15px;
    border: 1px solid var(--border-soft);
}

.display-selectors {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    text-align: left;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mode-btn.active {
    background: var(--accent-cyan);
    color: white;
    border-color: var(--accent-cyan);
}

.stats-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.stat-row .label {
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 500;
}

.stat-row .value {
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: monospace;
}

.btn-action {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    transition: 0.2s;
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-action.danger {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
    margin-top: auto;
}

.btn-action.danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

.speed-control {
    margin-top: 10px;
}

.speed-control label {
    font-size: 0.8rem;
    color: #64748b;
    display: block;
    margin-bottom: 5px;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent-cyan);
}

/* Nav refinements for experiments */
nav {
    position: relative !important;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    height: 65px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    flex-shrink: 0;
    z-index: 100;
}

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

.exp-label {
    color: var(--accent-cyan);
    font-weight: 800;
}