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

html {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    font-family: 'Courier New', monospace;
    background: #000;
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    /* Prevent touch actions that could trigger scrolling */
    touch-action: none;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#bg {
    background: #111;
    z-index: 1;
    /* No transition - background color changes immediately while curtain is closed */
}

#curtain {
    background: #222;
    z-index: 250; /* Below sound icon (300), above menu (200) */
    transform-origin: left center;
    transition: transform 1.5s ease, background-color 0.8s ease;
    transform: scaleX(0);
    pointer-events: none;
}

#curtain.closed {
    transform: scaleX(1);
}

#curtain.open {
    transform: scaleX(0);
}

#experiment-container {
    position: absolute;
    z-index: 50; /* Below curtain so curtain can cover it */
    /* Prevent any scrolling within the container */
    overflow: hidden;
    /* Prevent touch scrolling */
    touch-action: none;
}

#experiment-container ruffle-embed,
#experiment-container ruffle-player {
    width: 100%;
    height: 100%;
    display: block;
}

#loading-bar {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 2px;
    background: rgba(255, 255, 255, 0.2);
    z-index: 260; /* Above curtain (250) so it's visible during loading */
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

#loading-bar.visible {
    opacity: 1;
}

#bar-fg {
    width: 0%;
    height: 100%;
    /* background color set dynamically in JS based on colorLoadingBar */
    transition: width 0.3s ease;
}

#menu-scrim {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Background color set dynamically based on experiment's colorCurtain */
    z-index: 150; /* Below menu (200), above message (120) */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#menu-scrim.visible {
    opacity: 1;
    pointer-events: all;
}

#menu {
    position: fixed;
    top: 32px;
    right: 32px;
    z-index: 200; /* Below curtain (250), above menu scrim (150) */
    opacity: 1; /* Always visible (curtain covers it during transitions) */
}

#menu-button {
    width: 12px;
    height: 12px;
    background: rgba(255, 255, 255, 0.7); /* Default, overridden per experiment */
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.3s ease, background 0.3s ease;
    user-select: none;
    /* Increase tappable area for mobile without changing visual size */
    position: relative;
    /* Allow touch interaction on menu button */
    touch-action: auto;
}

/* Larger invisible hit area for easier tapping on mobile */
#menu-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px; /* Larger touch target for easy mobile tapping */
    height: 80px;
    border-radius: 50%;
    /* Debug: uncomment to visualize the tap area */
    /* background: rgba(255, 0, 0, 0.2); */
}

#menu-button:hover {
    transform: scale(1.3);
    background: var(--hover-bg, rgba(255, 255, 255, 0.9)); /* Use CSS variable if set */
}

#menu-items {
    position: absolute;
    pointer-events: none;
}

.menu-item {
    position: absolute;
    cursor: pointer;
    pointer-events: all;
    white-space: nowrap;
    font-size: 14px;
    color: #fff; /* Default, overridden per experiment */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); /* Default, overridden per experiment */
    transition: transform 0.3s ease;
    transform-origin: center center;
    user-select: none;
    /* Allow touch interaction on menu items */
    touch-action: auto;
}

/* Larger text on mobile for better readability */
@media (max-width: 767px), (max-height: 767px) {
    .menu-item {
        font-size: 18px;
    }
}

.menu-item:hover {
    transform: scale(2) !important;
}

#sound-toggle {
    position: fixed;
    top: 32px;
    left: 32px;
    width: 8px;
    height: 8px;
    cursor: pointer !important;
    z-index: 300; /* Top of stack - always visible */
    /* Allow touch interaction on sound toggle */
    touch-action: auto;
    /* Hidden by default, only shown for experiments with hasSound: true */
    display: none;
    /* Increase tappable area for mobile without changing visual size */
    user-select: none;
}

/* Larger invisible hit area for easier tapping on mobile (same as menu button) */
#sound-toggle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px; /* Larger touch target for easy mobile tapping */
    height: 80px;
    border-radius: 50%;
    /* Debug: uncomment to visualize the tap area */
    /* background: rgba(255, 0, 0, 0.2); */
}

#sound-toggle svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    transition: fill 0.8s ease; /* Matches curtain transition timing */
    pointer-events: none;
}

#sound-toggle svg path {
    transition: fill 0.8s ease; /* Animate color changes */
}

#sound-toggle.sound-off #sound-on-icon {
    display: none;
}

#sound-toggle.sound-off #sound-off-icon {
    display: block;
}

#sound-toggle.sound-on #sound-on-icon {
    display: block;
}

#sound-toggle.sound-on #sound-off-icon {
    display: none;
}

/* Experiment message (bottom right) */
#experiment-message {
    position: fixed;
    bottom: 15px;
    right: 15px;
    z-index: 120; /* Below menu scrim (150), above experiment (50) */
    /* Color set dynamically based on experiment's messageColor or colorMenuItems */
    font-family: Arial, sans-serif;
    font-size: 12px;
    pointer-events: auto; /* Allow hover to work */
    user-select: none; /* Prevent text selection */
    opacity: 0;
    transition: opacity 1s ease, color 0.3s ease;
}

#experiment-message.visible {
    opacity: 1;
}

#experiment-message:hover {
    color: rgba(
        var(--message-color-r, 255),
        var(--message-color-g, 255),
        var(--message-color-b, 255),
        var(--message-alpha-hover, 0.5)
    ) !important;
}

