/* NEANDERTHAL PALETTE - Cave Parallax */
* { margin: 0; padding: 0; box-sizing: border-box; }

html,
body {
    background: #000;
    color: #ff69b4;
    font-family: 'Courier New', monospace;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

body {
    position: fixed;
    inset: 0;
    touch-action: none;
    overscroll-behavior: none;
}

#canvas-wrapper {
    /* Fixed 1920×1080 design frame — the scene is composed at this size and
       treated like a video: scaled to COVER the viewport (JS sets the scale
       factor in _updateStageScale) and cropped, instead of reflowing when the
       browser resizes. A transform here also re-bases position:fixed children
       (video player, mech HUD) onto this frame, so the whole composition
       scales as one. The corner HUD buttons live outside and stay fluid. */
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    overflow: hidden;
}

#frame-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    box-sizing: border-box;
    border: 4px solid #c0c0c0;
    border-top-color: #f0f0f0;
    border-left-color: #f0f0f0;
    border-right-color: #404040;
    border-bottom-color: #404040;
    box-shadow:
        inset 4px 4px 0 #000000,
        inset -4px -4px 0 #c0c0c0,
        12px 12px 28px rgba(0, 0, 0, 0.45);
}

#frameStack {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: visible;
    pointer-events: auto;
    transform-style: preserve-3d;
}

/* Neanderthal 3D canvas — sits on top of cave layers, behind overlay */
#neanderthalCanvas3D {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    background: transparent;
}
#neanderthalCanvas3D canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: transparent;
}

.scene-canvas-layer {
    position: absolute;
    pointer-events: none;
}

.scene-canvas {
    position: absolute;
    display: block;
    pointer-events: none;
}

/* Retro Buttons */
.retro-btn {
    position: fixed;
    z-index: 1000;
    padding: 6px 10px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 14px;
    color: lightgrey;
    background-color: #000000;
    border-top: 3px solid #ff69b4;
    border-left: 3px solid #ff69b4;
    border-right: 3px solid #8b3a62;
    border-bottom: 3px solid #8b3a62;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    text-transform: uppercase;
    outline: none;
    user-select: none;
    overflow: hidden;
    isolation: isolate;
    contain: paint;
}

.retro-btn span {
    position: relative;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(180deg,
            #f5e6a3 0%,
            #d4af37 25%,
            #b8860b 50%,
            #d4af37 75%,
            #f5e6a3 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.9)) drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.7));
    font-weight: bold;
}

/* The IR button's label swaps between IR:ON and IR:OFF — reserve the width of
   the longer text (6 monospace chars) so the button never resizes. */
#arduinoBtn span {
    display: inline-block;
    min-width: 6ch;
    text-align: center;
}

.retro-btn .btn-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.9;
    mix-blend-mode: screen;
    filter: brightness(1.2);
    pointer-events: none;
}

.retro-btn:active,
.retro-btn.active {
    border-top: 3px solid #000000;
    border-left: 3px solid #000000;
    border-right: 3px solid #ff69b4;
    border-bottom: 3px solid #ff69b4;
    box-shadow: inset 2px 2px 0px #000000;
}

.retro-btn.active .btn-canvas {
    filter: hue-rotate(-120deg) saturate(2) brightness(0.8) contrast(1.3);
}

/* Retro marble buttons reused inside the replay player control row: they must
   flow in the flex bar instead of being pinned to the viewport like the HUD
   buttons, so unset the fixed positioning and let them share the row width. */
.retro-btn.video-btn {
    position: relative;
    z-index: auto;
    flex: 1;
    margin: 0;
    padding: 5px 6px;
    font-size: 12px;
    text-align: center;
}

/* Replay playhead (scrub bar) — squared-off and styled to match the retro
   marble buttons: a see-through beveled groove with a raised gold, beveled handle.
   Overlaid on the BOTTOM of the video (inside the frame) so there's no black gap
   between the footage and the controls. */
.video-scrub {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 5px;          /* small gap below the slider */
    width: 100%;
    height: 18px;
    margin: 0;
    display: block;
    background: transparent;
    cursor: pointer;
    z-index: 2;
}
.video-scrub::-webkit-slider-runnable-track {
    height: 8px;
    background: rgba(0, 0, 0, 0.32);   /* see-through so the footage shows behind */
    border-top: 2px solid #8b3a62;
    border-left: 2px solid #8b3a62;
    border-right: 2px solid #ff69b4;
    border-bottom: 2px solid #ff69b4;
}
.video-scrub::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 18px;
    margin-top: -8px;
    background: linear-gradient(180deg, #f5e6a3 0%, #d4af37 50%, #b8860b 100%);
    border-top: 2px solid #ff69b4;
    border-left: 2px solid #ff69b4;
    border-right: 2px solid #8b3a62;
    border-bottom: 2px solid #8b3a62;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6);
}
.video-scrub::-moz-range-track {
    height: 8px;
    background: rgba(0, 0, 0, 0.32);   /* see-through so the footage shows behind */
    border-top: 2px solid #8b3a62;
    border-left: 2px solid #8b3a62;
    border-right: 2px solid #ff69b4;
    border-bottom: 2px solid #ff69b4;
}
.video-scrub::-moz-range-thumb {
    width: 12px;
    height: 18px;
    border-radius: 0;
    background: linear-gradient(180deg, #f5e6a3 0%, #d4af37 50%, #b8860b 100%);
    border-top: 2px solid #ff69b4;
    border-left: 2px solid #ff69b4;
    border-right: 2px solid #8b3a62;
    border-bottom: 2px solid #8b3a62;
}

/* Countdown as a classic LED alarm-clock readout, in a solid black box at the
   bottom-left of the footage. Same beveled text as the retro buttons (AUTOPLAY /
   F) — same font, size and drop-shadow bevel — but red instead of gold, no glow.
   The ghost layer (always "-88:88", the widest) fixes the box width and shows all
   segments faintly lit so blank positions read as unlit. */
.replay-led {
    position: absolute;
    left: 6px;
    bottom: 26px;         /* sits ABOVE the playhead, not over it */
    z-index: 4;
    pointer-events: none;
    padding: 2px 6px;
    background: #000;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 14px;
    line-height: 1;
    text-transform: uppercase;
}
.replay-led-ghost,
.replay-led-live {
    display: block;
    text-align: right;
    white-space: pre;
}
.replay-led-ghost {
    position: relative;   /* in-flow → sets the box width from "-88:88" */
    color: rgba(150, 20, 0, 0.2);   /* unlit segments */
}
.replay-led-live {
    position: absolute;
    top: 2px;
    left: 6px;
    right: 6px;           /* overlay the ghost exactly (matches padding) */
    background: linear-gradient(180deg,
            #ff6b5a 0%,
            #e01e00 25%,
            #a00d00 50%,
            #e01e00 75%,
            #ff6b5a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.9)) drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.7));
}

#retroAutoplayBtn { bottom: 20px; left: 20px; }
#fullscreenBtn { top: 20px; right: 20px; }
#arduinoBtn { bottom: 20px; right: 20px; }

/* IR tint overlay — red pulse when Arduino IR sensor fires */
#irTintOverlay {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    background: rgba(255, 0, 0, 0);
    transition: background 0.15s ease;
}
#irTintOverlay.active {
    background: rgba(255, 0, 0, 0.22);
}

#fpsCounter {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    color: #ff69b4;
    background: rgba(0,0,0,0.75);
    border: 2px solid #ff69b4;
    padding: 4px 8px;
    pointer-events: none;
    user-select: none;
}

#rpmCounter {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 1000;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: bold;
    color: #ff3100;
    background: rgba(0,0,0,0.85);
    border: 2px solid #ff3100;
    padding: 4px 12px;
    pointer-events: none;
    user-select: none;
}

/* Loading Screen */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-in-out;
}

.loader-marble {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.9;
    mix-blend-mode: screen;
    pointer-events: none;
}

.retro-window {
    background-color: #000000;
    border-top: 3px solid #ff69b4;
    border-left: 3px solid #ff69b4;
    border-right: 3px solid #8b3a62;
    border-bottom: 3px solid #8b3a62;
    padding: 8px;
    width: 600px;
    box-sizing: border-box;
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.5);
    text-align: center;
    position: relative;
    overflow: hidden;
}

@media (max-width: 600px) {
    .retro-window { width: 85%; }
}

.retro-header {
    font-weight: bold;
    margin-bottom: 6px;
    text-align: left;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    position: relative;
    z-index: 2;
    background: linear-gradient(180deg,
            #f5e6a3 0%,
            #d4af37 25%,
            #b8860b 50%,
            #d4af37 75%,
            #f5e6a3 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.9)) drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.7));
}

/* Intro sensor prompt: blink the text while "…LISTENING" to read as an active
   sensor waiting for input (removed once it flips to "FIRE DETECTED"). */
@keyframes introListenBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
.intro-status.listening .retro-header { animation: introListenBlink 1.05s ease-in-out infinite; }

.retro-bar-container {
    height: 20px;
    background-color: #000000;
    border: 2px solid #ff69b4;
    padding: 2px;
    text-align: left;
    position: relative;
    z-index: 2;
}

.retro-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(180deg, #ff69b4 0%, #ff1493 50%, #ff69b4 100%);
    transition: width 0.1s linear;
}

/* Controls Panel */
#controls-panel {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(0,0,0,0.96);
    border: 2px solid #ff69b4;
    padding: 12px;
    width: 360px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 4px 4px 10px rgba(0,0,0,0.6);
    font-size: 11px;
    color: #ccc;
}

/* Post FX Panel */
#postfx-panel {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 1000;
    background: rgba(0,0,0,0.96);
    border: 2px solid #ff69b4;
    padding: 12px;
    width: 280px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 4px 4px 10px rgba(0,0,0,0.6);
    font-size: 11px;
    color: #ccc;
}
#postfx-panel h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    text-transform: uppercase;
    color: #f5e6a3;
    border-bottom: 1px solid #444;
    padding-bottom: 6px;
}

/* Vignette overlay (driven by Post FX panel) */
#postfxVignette {
    position: absolute;
    inset: 0;
    z-index: 19;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0) 40%, rgba(0,0,0,1) 100%);
}

#controls-panel h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    text-transform: uppercase;
    color: #f5e6a3;
    border-bottom: 1px solid #444;
    padding-bottom: 6px;
}

.panel-section { margin-bottom: 14px; }
.panel-section-title {
    font-size: 11px;
    color: #888;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.slider-row { margin-bottom: 10px; }
.slider-row label {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 11px;
    color: #ccc;
    margin-bottom: 4px;
}
.slider-row input[type=range] { width: 100%; cursor: pointer; }

.two { display: flex; gap: 6px; }
.two button {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #555;
    color: #d4af37;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    text-transform: uppercase;
    padding: 4px 8px;
    cursor: pointer;
}
.two button:hover { background: #2a2a2a; }
.two button.active { border-color: #ff69b4; color: #ff69b4; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #d4af37;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    cursor: pointer;
    text-transform: uppercase;
}
.checkbox-label input[type=checkbox] {
    accent-color: #ff69b4;
    cursor: pointer;
}

@media (hover: none) and (pointer: coarse) {
    .retro-btn { padding: 8px 11px; font-size: 12px; }
    #retroAutoplayBtn { bottom: 14px; left: 14px; }
    #fullscreenBtn { top: 14px; right: 14px; }
    #frame-overlay {
        border-width: 3px;
        box-shadow:
            inset 3px 3px 0 #000000,
            inset -3px -3px 0 #c0c0c0,
            8px 8px 18px rgba(0, 0, 0, 0.38);
    }
}
