/* ============================================
   Design Tokens
   ============================================ */
:root {
    --bg: #06060e;
    --accent: #00ffd5;
    --accent-dim: #00ffd533;
    --accent-glow: #00ffd566;
    --text: #e0e8f0;
    --text-dim: #5a6a7a;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Outfit', sans-serif;
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: auto;
    overflow-x: hidden;
}

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

#scroll-spacer {
    height: 3000vh;
    pointer-events: none;
}

/* ============================================
   Canvas
   ============================================ */
#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

/* ============================================
   UI Overlay
   ============================================ */
#ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
}

#ui-overlay * {
    pointer-events: none;
}

/* Header */
#header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 28px 40px;
}

.logo {
    font-family: var(--sans);
    font-weight: 800;
    font-size: 20px;
    letter-spacing: 4px;
    color: var(--text);
}

.logo .accent {
    color: var(--accent);
}

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

#ui-overlay .view-btn {
    pointer-events: auto; /* Force enable clicks, overriding #ui-overlay * */
}

.view-controls {
    display: flex;
    gap: 8px;
}

.view-btn {
    background: transparent;
    border: 1px solid var(--text-dim);
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 1px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-btn:hover {
    border-color: var(--text);
    color: var(--text);
}

.view-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

#depth-label {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--accent);
    opacity: 0.8;
}

/* Floor Indicator */
#floor-indicator {
    position: absolute;
    bottom: 40px;
    left: 40px;
}

.floor-ring {
    position: relative;
    width: 100px;
    height: 100px;
}

.floor-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: var(--accent-dim);
    stroke-width: 2;
}

.ring-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.3s ease;
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.floor-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.floor-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 3px;
    color: var(--text-dim);
    margin-bottom: 2px;
}

#floor-number {
    font-family: var(--sans);
    font-weight: 700;
    font-size: 28px;
    color: var(--accent);
    line-height: 1;
}

/* Scroll Hint */
#scroll-hint {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    animation: fadeHint 3s ease-in-out infinite;
}

#scroll-hint span {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 4px;
    color: var(--text-dim);
}

.scroll-line {
    width: 1px;
    height: 40px;
    background: linear-gradient(to bottom, transparent, var(--accent), transparent);
    animation: scrollPulse 2s ease-in-out infinite;
}

@keyframes scrollPulse {
    0%, 100% { opacity: 0.3; transform: scaleY(0.6); }
    50% { opacity: 1; transform: scaleY(1); }
}

@keyframes fadeHint {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Progress Track */
#progress-track {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 200px;
    background: var(--accent-dim);
    border-radius: 1px;
}

#progress-thumb {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 12px var(--accent-glow), 0 0 4px var(--accent);
    transition: top 0.15s ease;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    #header { padding: 20px 24px; }
    #floor-indicator { bottom: 24px; left: 24px; }
    .floor-ring { width: 80px; height: 80px; }
    #floor-number { font-size: 22px; }
    #progress-track { right: 20px; height: 150px; }
    #scroll-hint { bottom: 24px; }
}

/* ============================================
   Transitions & Portals
   ============================================ */
#ending-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 3s ease-in-out;
}

#ending-screen.active {
    opacity: 1;
    pointer-events: all;
}

.ending-title {
    font-family: 'Outfit', sans-serif;
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: 0.5em;
    color: #111;
    margin: 0;
    transform: translateY(20px);
    transition: transform 3s ease-out;
}

.ending-subtitle {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 0.3em;
    color: #555;
    margin-top: 1rem;
    transform: translateY(20px);
    transition: transform 3s ease-out;
}

#ending-screen.active .ending-title,
#ending-screen.active .ending-subtitle {
    transform: translateY(0);
}

#whiteout {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.5); /* Darken the shader for text legibility */
    backdrop-filter: blur(8px); /* Blur the ripples to make text pop */
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 1.0s cubic-bezier(0.4, 0, 0.2, 1);
}

#whiteout.active {
    opacity: 1;
    pointer-events: all;
}

#map-title {
    font-family: var(--sans);
    font-weight: 300;
    font-size: 32px;
    letter-spacing: 12px;
    color: #ffffff;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1s ease, transform 1s ease;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); /* Add slight shadow for legibility */
}

#whiteout.active #map-title {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   Key Inventory UI
   ============================================ */
.key-inventory {
    position: fixed;
    top: 50%;
    right: 40px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 1000;
    pointer-events: none; /* Let clicks pass through */
    transition: opacity 0.5s ease;
}

.key-slot {
    width: 22px;
    height: 22px;
    background-color: rgba(255, 255, 255, 0.25);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M12.65 10A5.99 5.99 0 0 0 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6a5.99 5.99 0 0 0 5.65-4H17v4h4v-4h2v-4H12.65zM7 14c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M12.65 10A5.99 5.99 0 0 0 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6a5.99 5.99 0 0 0 5.65-4H17v4h4v-4h2v-4H12.65zM7 14c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
    transform: rotate(90deg); /* Hang the keys vertically */
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.key-slot.filled {
    background-color: #00ffff;
    filter: drop-shadow(0 0 8px rgba(0, 255, 255, 0.8));
    transform: rotate(90deg) scale(1.1);
}

@media (max-width: 768px) {
    .key-inventory {
        right: 20px;
        gap: 10px;
    }
    .key-slot {
        width: 10px;
        height: 10px;
    }
}
