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

body {
    min-height: 100vh;
    background-color: #1d1d1d;
    overflow: hidden;
}

/* Room light: fades in depending on how many bulbs are on (--lit is set from JS) */
.ambient {
    position: fixed;
    inset: 0;
    background: radial-gradient(#555, #111);
    opacity: var(--lit, 0);
    transition: opacity 0.6s ease;
    pointer-events: none;
    z-index: 0;
}

.container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1;
}

.scene {
    position: relative;
    display: flex;
    width: 100%;
    height: 100%;
}

.light {
    position: relative;
    flex: 1;
    height: 100%;
}

/* Wire + bulb swing together from the ceiling */
.pendulum {
    position: absolute;
    top: 0;
    left: 50%;
    width: 80px;
    margin-left: -40px;
    height: calc(var(--drop) + 40px);
    transform-origin: 50% 0;
    will-change: transform;
}

.wire {
    position: absolute;
    top: 0;
    bottom: 40px;
    left: calc(50% - 2px);
    width: 4px;
    background: #000;
    border-radius: 10px;
    z-index: 1;
}

.bulb {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 80px;
    height: 80px;
    background: #444;
    border-radius: 50%;
    z-index: 2;
    transition: background 0.3s, box-shadow 0.3s;
}

.bulb::before {
    content: '';
    position: absolute;
    top: -50px;
    left: 22.5px;
    width: 35px;
    height: 80px;
    background: #444;
    border-top: 30px solid #000;
    border-radius: 10px;
    transition: background 0.3s;
}

.bulb span:nth-child(1) {
    position: absolute;
    display: block;
    top: -16px;
    left: -4px;
    width: 30px;
    height: 30px;
    background: transparent;
    transform: rotate(342deg);
    border-bottom-right-radius: 40px;
    box-shadow: 20px 20px 0 10px #444;
}

.bulb span:nth-child(2) {
    position: absolute;
    display: block;
    top: -16px;
    right: -4px;
    width: 30px;
    height: 30px;
    background: transparent;
    transform: rotate(18deg);
    border-bottom-left-radius: 40px;
    box-shadow: -20px 20px 0 10px #444;
}

/* ---------- On state ---------- */

.light.on .bulb {
    background: #fff;
    box-shadow: 0 0 50px #fff,
        0 0 100px #fff,
        0 0 150px #fff,
        0 0 200px #fff,
        0 0 250px #fff,
        0 0 300px #fff,
        0 0 350px #fff;
}

.light.on .bulb::before {
    background: #fff;
}

.light.on .bulb::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, #fff);
    border-radius: 50%;
    filter: blur(40px);
}

.light.on .bulb span:nth-child(1) {
    box-shadow: 20px 20px 0 10px #fff;
}

.light.on .bulb span:nth-child(2) {
    box-shadow: -20px 20px 0 10px #fff;
}

/* Filament flicker when a bulb turns on */
.light.flicker .bulb {
    animation: flicker 0.4s steps(1, end);
}

@keyframes flicker {
    0% { filter: brightness(0.3); }
    20% { filter: brightness(1.3); }
    35% { filter: brightness(0.5); }
    55% { filter: brightness(1.15); }
    70% { filter: brightness(0.8); }
    100% { filter: brightness(1); }
}

/* ---------- Switch ---------- */

.switch {
    position: absolute;
    bottom: 50px;
    left: 50%;
    width: 80px;
    height: 80px;
    border: none;
    padding: 0;
    background: linear-gradient(#eee, #ccc, #eee);
    border-radius: 22px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transform: translateX(-50%);
    transition: transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    z-index: 3;
}

.switch:active {
    transform: translateX(-50%) scale(0.92);
}

.switch:focus-visible {
    outline: 3px solid #ffd27a;
    outline-offset: 4px;
}

.switch .btn {
    position: relative;
    width: 25px;
    height: 40px;
    background: linear-gradient(#777, #fff, #777);
    border-radius: 8px;
    border: 2px solid #000;
}

.switch .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 85%;
    background: linear-gradient(#fff, #fff);
    border-radius: 5px;
    transition: top 0.08s ease;
}

.light.on .switch .btn::before {
    top: 15%;
}

/* ---------- Flies ---------- */

#flies {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

#switchSound {
    display: none;
}

/* ---------- Responsive: 3 bulbs desktop, 2 tablet, 1 phone ---------- */

@media (max-width: 1024px) {
    .light:nth-child(3) {
        display: none;
    }
}

@media (max-width: 600px) {
    .light:nth-child(2) {
        display: none;
    }
}
