/* Spring Composition 2 - Clean Scaffold */
* { margin: 0; padding: 0; box-sizing: border-box; }

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

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

#canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#frame-overlay {
    position: absolute;
    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;
    /* Viewport-sized wrapper. The actual oversized render surface is the
       .scene-canvas inside this wrapper, centered by JS. Keeping the wrapper
       viewport-sized is what makes the final 3D transform rotate around the
       screen center instead of around the giant offscreen canvas bounds. */
}

#rotate-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: #fff;
    z-index: 3000;
    display: none;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
    box-sizing: border-box;
    text-transform: uppercase;
}

#rotate-overlay.visible {
    display: flex;
}

.rotate-window {
    background: #000000;
    border-top: 3px solid #ff69b4;
    border-left: 3px solid #ff69b4;
    border-right: 3px solid #8b3a62;
    border-bottom: 3px solid #8b3a62;
    box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.5);
    max-width: 320px;
    position: relative;
    overflow: hidden;
}

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

.rotate-content {
    padding: 30px 40px;
    position: relative;
    z-index: 2;
}

.rotate-msg {
    font-size: 14px;
    line-height: 1.8;
    letter-spacing: 1px;
}

.rotate-msg span {
    font-weight: bold;
    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));
}

.frame-layer {
    position: absolute;
    inset: -10%;
    transform-origin: 50% 50%;
    transform-style: preserve-3d;
    backface-visibility: visible;
    pointer-events: none;
}

.frame-layer.protected-visibility {
    /* No forced compositor promotion per layer. The whole scene now renders
       into one canvas, so per-layer GPU promotion is unnecessary and was the
       original source of layers blinking on/off under memory pressure. */
}

.scene-canvas {
    position: absolute;
    display: block;
    pointer-events: none;
    /* Sized + positioned by JS. Do not force inset/width/height here or the
       renderer will drift back toward the top-left and expose black edges. */
}

.frame-layer img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
    user-select: none;
    pointer-events: none;
}

.frame-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.frame-layer.fit-contain img {
    object-fit: contain;
}

#threeCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    outline: none;
    pointer-events: none;
    display: 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;
}

.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);
}

/* Marble canvas for loading window */
.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;
}

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

/* iPhone-only video fallback. Lives behind #frame-overlay so the grey beveled
   border still frames it. Uses object-fit: contain so the aspect ratio of the
   source mp4 is preserved (letterboxed if viewport differs). */
#iphone-video-wrapper {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #000;
    overflow: hidden;
    pointer-events: none;
}

#iphone-video-wrapper video {
    width: 100%;
    height: 100%;
    /* Fill the full width of the iPhone screen; crop any overflow top/bottom
       instead of letterboxing. This keeps the original aspect ratio (no
       stretch) while eliminating black bars on the sides. */
    object-fit: cover;
    object-position: center center;
    background: #000;
    display: block;
    /* Allow taps for unmute. */
    pointer-events: auto;
}

/* Portrait rotate overlay (iPhone only). Same visual language as landscape
   overlay but triggered when the device is horizontal. */
#rotate-overlay-portrait {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: #fff;
    z-index: 3000;
    display: none;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
    box-sizing: border-box;
    text-transform: uppercase;
}

#rotate-overlay-portrait.visible {
    display: flex;
}

@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);
    }
}

/* Coordinate UI Panel */
/* 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;
}

.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));
}

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

#coords-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);
    display: none; /* shown after GLB load */
}

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

.coord-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 11px;
    color: #ccc;
}

.coord-row label { width: 70px; flex-shrink: 0; }
.coord-row input,
.coord-row select {
    flex: 1;
    background: #111;
    border: 1px solid #444;
    color: #ff69b4;
    padding: 2px 4px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    margin-right: 6px;
}

.coord-row select {
    min-width: 0;
}

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

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

.split-row {
    gap: 6px;
}

.split-row > * {
    flex: 1;
}

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

#gizmo-modes {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.gizmo-btn {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #555;
    color: #ccc;
    padding: 4px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 10px;
}
.gizmo-btn.active {
    border-color: #ff69b4;
    color: #ff69b4;
}

