:root {
    --bg-color: #040405; 
    --primary-color: #08080a; 
    --text-color: #ffffff;
    --gold: #b38b4d;
    --grey-text: #6b6b6b;
    --red-dot: #ab2828;
    
    --success-color: #647d38; 
    --error-color: #7a2119; 
    
    --font-heading: 'Playfair Display', serif;
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Courier Prime', monospace;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100dvh; /* Dynamic viewpoint height adjusts to mobile browser bars */
    overflow: hidden;
    position: relative;
    user-select: none;
    background: radial-gradient(circle at center, #0a0e12 0%, #000000 100%);
}

body::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

.view {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100dvh; /* Dynamic viewpoint height adjusts to mobile browser bars */
    display: none; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.view.active {
    display: flex;
}

/* ---------------------------------
   INTRO & VIDEO VIEWS
-----------------------------------*/
.intro-content {
    text-align: center;
    animation: fadeIn 2s ease-in;
    width: 100%;
    max-width: 600px;
}

.intro-title {
    font-family: var(--font-heading);
    font-size: 6rem;
    font-weight: 900;
    letter-spacing: 15px;
    color: var(--text-color);
    margin-right: -15px;
    line-height: 1.1;
    margin-bottom: 2rem;
    text-shadow: 0 0 40px rgba(255,255,255,0.1);
}

.intro-subtitle {
    margin-bottom: 5rem;
}

.intro-actions {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
    width: 100%;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 1rem 2rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    letter-spacing: 5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    border-radius: 4px;
    min-width: 280px;
    position: relative;
    overflow: hidden;
}

.action-btn.primary {
    background: rgba(179, 139, 77, 0.05); 
    border-width: 1px;
    font-weight: 400;
    color: #fff;
    border-color: rgba(255,255,255,0.2);
}

.action-btn.secondary {
    border-color: rgba(179, 139, 77, 0.4);
}

.action-btn:hover {
    background: var(--gold);
    color: #000;
    transform: scale(1.02);
    box-shadow: 0 0 25px rgba(179, 139, 77, 0.2);
    border-color: var(--gold);
}

.action-btn:active {
    transform: scale(0.98);
}

#video-view {
    background: #000;
}
#intro-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.skip-btn {
    position: absolute;
    bottom: 90px; /* Moved up to avoid mobile navbar cutoffs */
    right: 30px;
    z-index: 10;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    border-color: rgba(255,255,255,0.3);
    color: #fff;
    min-width: auto;
    padding: 0.8rem 2rem;
}

/* Modals Text */
.text-modal {
    text-align: center;
    color: var(--text-color);
}
.text-modal p {
    font-family: var(--font-sans);
    font-weight: 300;
    line-height: 1.8;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #bbb;
    letter-spacing: 1px;
}
.text-modal h2.gold {
    color: var(--gold);
    letter-spacing: 8px;
    margin-bottom: 1rem;
    font-weight: normal;
    font-family: var(--font-heading);
}
.text-modal .warning {
    color: var(--gold);
    font-weight: normal;
    letter-spacing: 4px;
}

/* Minigame 1: Radio */
.radio-container {
    background: #020202;
    border: 1px solid rgba(179, 139, 77, 0.3) !important;
    border-radius: 4px;
    box-shadow: inset 0 0 80px rgba(0,0,0,1), 0 0 40px rgba(0,0,0,0.8);
}
.radio-controls {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    margin-top: 2rem;
    padding: 0 1rem;
}
.slider-group label {
    display: block;
    color: var(--gold);
    font-size: 0.65rem;
    letter-spacing: 4px;
    margin-bottom: 1.2rem;
    text-align: left;
    font-family: var(--font-mono);
}
.slider-group label span {
    color: var(--grey-text);
}
.vintage-slider {
    -webkit-appearance: none;
    appearance: auto;
    width: 100%;
    height: 3px;
    background: rgba(179, 139, 77, 0.2);
    outline: none;
    border-radius: 1px;
}
.vintage-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 35px;
    background: #111;
    border: 1px solid var(--gold);
    cursor: pointer;
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(179, 139, 77, 0.2);
    transition: all 0.2s;
}
.vintage-slider::-webkit-slider-thumb:active {
    background: rgba(179, 139, 77, 0.1);
    box-shadow: 0 0 15px rgba(179, 139, 77, 0.5);
}
.radio-status {
    background: rgba(171, 40, 40, 0.05);
    border: 1px solid rgba(171, 40, 40, 0.3);
    padding: 1.5rem;
    border-radius: 4px;
    margin-bottom: 2rem;
    transition: all 0.5s ease;
}

/* Minigame 2: Flashlight */
.flashlight-container {
    position: relative;
    width: 90vw;
    height: 80vh;
    max-width: 800px;
    padding: 0;
    overflow: hidden;
    background: #000;
    border: 2px solid rgba(179, 139, 77, 0.3) !important;
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0,0,0,0.9);
}
#flashlight-bg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 1;
    filter: sepia(0.5) contrast(1.2) brightness(0.6);
}
#flashlight-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 2;
    cursor: crosshair;
    touch-action: none;
}
.hud-text {
    position: absolute;
    bottom: 20px;
    left: 0; right: 0;
    text-align: center;
    color: rgba(179, 139, 77, 0.8);
    font-size: 0.7rem;
    letter-spacing: 4px;
    z-index: 3;
    pointer-events: none;
    font-family: var(--font-mono);
    text-shadow: 0 2px 4px #000;
}

/* Minigame 3: Gyroscope */
.gyro-container {
    background: #000;
    border: 1px solid rgba(179, 139, 77, 0.3) !important;
    overflow: hidden;
}
.gyro-hud {
    border: 1px solid rgba(179, 139, 77, 0.2);
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 2rem;
    transition: all 0.5s ease;
    background: rgba(179, 139, 77, 0.05);
}
.gyro-viewport {
    width: 250px;
    height: 250px;
    margin: 0 auto;
    perspective: 800px;
    border: 1px dashed rgba(179, 139, 77, 0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, rgba(179, 139, 77, 0.05) 0%, transparent 70%);
}
.gyro-world {
    width: 200px;
    height: 200px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.1s linear;
}
.layer {
    position: absolute;
    top: 0; left: 0;
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    transform-style: preserve-3d;
}
.gyro-world.aligned .layer svg path,
.gyro-world.aligned .layer svg circle {
    filter: drop-shadow(0 0 10px var(--gold));
    stroke: var(--success-color) !important;
    transition: stroke 0.5s ease, filter 0.5s ease;
}
.layer-1 { transform: translateZ(90px) scale(0.6); } 
.layer-2 { transform: translateZ(0px) scale(1); }
.layer-3 { transform: translateZ(-90px) scale(1.4); } 


/* Minigame 4: Heartbeat */
.heartbeat-container {
    background: #000;
    border: 1px solid rgba(179, 139, 77, 0.3) !important;
    text-align: center;
}
.pulse-area {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 2rem auto;
    display: flex;
    justify-content: center;
    align-items: center;
}
.pulse-ring {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 2px solid var(--red-dot);
    opacity: 0.2;
    pointer-events: none;
    transition: transform 0.1s cubic-bezier(0.1, 0.8, 0.1, 1), box-shadow 0.1s ease-out, opacity 0.1s ease-out;
    z-index: 1;
}
.pulse-btn {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(171, 40, 40, 0.8);
    border: 2px solid var(--gold);
    cursor: pointer;
    z-index: 2;
    transition: transform 0.1s;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.pulse-btn:active, .pulse-btn:focus {
    background: var(--gold);
}
.sync-bars {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 2rem;
}
.sync-bar {
    width: 35px;
    height: 6px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(179, 139, 77, 0.2);
    border-radius: 2px;
    transition: all 0.3s ease;
}
.sync-bar.active {
    background: var(--success-color);
    border-color: var(--success-color);
    box-shadow: 0 0 10px rgba(100, 125, 56, 0.6);
}


/* Minigame 5: Cryptex */
.cryptex-container {
    background: #000;
    border: 1px solid rgba(179, 139, 77, 0.3) !important;
}
.cryptex-viewport {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto;
    border-radius: 50%;
    touch-action: none; /* Block default scroll to allow tactile smooth spin */
}
.cryptex-line {
    position: absolute;
    top: 0; left: 50%;
    margin-left: -2px; /* Center 4px width */
    width: 4px;
    height: 140px;
    background: rgba(171, 40, 40, 0.4);
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(171, 40, 40, 0.8);
    border-radius: 2px;
}
.cryptex-ring {
    position: absolute;
    border-radius: 50%;
    top: 50%; left: 50%;
    pointer-events: none; /* Viewport entirely manages math capturing */
    border: 1px solid rgba(179, 139, 77, 0.3);
    background: radial-gradient(circle at center, transparent 0%, rgba(179, 139, 77, 0.03) 100%);
}
.ring-outer {
    width: 280px; height: 280px;
    margin: -140px 0 0 -140px;
}
.ring-mid {
    width: 210px; height: 210px;
    margin: -105px 0 0 -105px;
    background: radial-gradient(circle at center, transparent 0%, rgba(179, 139, 77, 0.05) 100%);
    border-color: rgba(179, 139, 77, 0.5);
}
.ring-inner {
    width: 140px; height: 140px;
    margin: -70px 0 0 -70px;
    background: radial-gradient(circle at center, transparent 0%, rgba(179, 139, 77, 0.08) 100%);
    border-color: rgba(179, 139, 77, 0.7);
}
.cryptex-core {
    position: absolute;
    width: 60px; height: 60px;
    margin: -30px 0 0 -30px;
    top: 50%; left: 50%;
    border-radius: 50%;
    background: #040405;
    border: 2px solid var(--gold);
    pointer-events: none;
    box-shadow: inset 0 0 15px rgba(179, 139, 77, 0.2), 0 0 20px rgba(0,0,0,0.8);
    z-index: 5;
}
.cryptex-ring span {
    position: absolute;
    top: 50%; left: 50%;
    margin: -10px 0 0 -10px; 
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
    font-family: var(--font-heading);
    color: var(--gold);
    font-size: 1.1rem;
    pointer-events: none;
}


/* ---------------------------------
   MAIN APP DASHBOARD
-----------------------------------*/
#main-view {
    margin-top: -2vh;
}

#timer-container {
    position: absolute;
    top: 5vh;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 2rem;
    color: var(--red-dot);
    text-shadow: 0 0 10px rgba(171, 40, 40, 0.5);
    font-weight: 400;
    letter-spacing: 6px;
    z-index: 50;
    padding: 8px 25px;
    border: 1px solid rgba(171, 40, 40, 0.3);
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
}

#timer-container.danger {
    color: #ff3333;
    animation: flash 1s infinite alternate;
}

@keyframes flash {
    0% { opacity: 1; text-shadow: 0 0 20px #ff0000; border-color: #ff0000; }
    100% { opacity: 0.5; text-shadow: none; border-color: rgba(171, 40, 40, 0.3); }
}

header {
    text-align: center;
    margin-bottom: 4rem;
    width: 100%;
}

.subtitle {
    font-size: 0.70rem;
    letter-spacing: 4px;
    font-weight: 400;
}

.subtitle.gold {
    color: var(--gold);
    margin-bottom: 1.5rem;
}

.subtitle.grey {
    color: var(--grey-text);
    margin-top: 2rem;
}

header h1 {
    font-family: var(--font-heading);
    font-size: 5rem;
    font-weight: 900;
    letter-spacing: 14px;
    text-transform: uppercase;
    color: #ffffff;
    line-height: 1.1;
    margin-right: -14px; 
}

/* Stormy Flickering animations */
.flicker-1 { animation: flicker 5s infinite; }
.flicker-2 { animation: flicker 7s infinite; animation-delay: 1.2s; }
.flicker-3 { animation: flicker 4.5s infinite; animation-delay: 0.7s; }
.flicker-4 { animation: flicker 6.5s infinite; animation-delay: 2.1s; }

@keyframes flicker {
    0%, 19.9%, 22%, 62.9%, 64%, 64.9%, 70%, 100% {
        opacity: 1;
    }
    20%, 21.9%, 63%, 63.9%, 65%, 69.9% {
        opacity: 0.3;
    }
}

.separator {
    width: 120px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 3.5rem auto 0 auto;
    opacity: 0.6;
}

.tools-container {
    display: flex;
    gap: 3.5rem;
    justify-content: center;
}

.tool-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.tool-btn {
    background: rgba(179, 139, 77, 0.03); 
    border: 1px solid rgba(179, 139, 77, 0.3); 
    border-radius: 6px; 
    width: 95px;
    height: 95px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--gold); 
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    position: relative;
    overflow: hidden;
}

.status-dot {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 6px;
    height: 6px;
    background-color: var(--red-dot);
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(171, 40, 40, 0.8);
}

.tool-icon {
    width: 38px;
    height: 38px;
    opacity: 0.8;
    transition: all 0.4s ease;
}

.tool-btn:hover {
    background: var(--gold);
    color: #000;
    transform: scale(1.03);
    box-shadow: 0 0 25px rgba(179, 139, 77, 0.3);
    border-color: var(--gold);
}

.tool-btn:active {
    transform: scale(0.96);
}

.tool-label {
    font-size: 0.65rem;
    color: var(--grey-text);
    letter-spacing: 4px;
    margin-right: -4px; 
    font-family: var(--font-sans);
}

.reset-btn {
    position: absolute;
    bottom: 90px; /* Moved up to avoid mobile navbar cutoffs */
    border: none;
    background: transparent;
    color: var(--grey-text);
    font-family: var(--font-sans);
    font-weight: 300;
    font-size: 0.65rem;
    letter-spacing: 4px;
    z-index: 10;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.5;
    transition: all 0.3s;
}

.reset-btn:hover {
    color: var(--red-dot);
    opacity: 1;
}

/* ---------------------------------
   MODALS & KEYPAD
-----------------------------------*/

.modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 2, 4, 0.98);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: transparent;
    border: 1px solid rgba(179, 139, 77, 0.3);
    border-radius: 4px;
    padding: 3.5rem 2.5rem;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.8);
    transform: scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
    transform: scale(0.98) translateY(20px);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    color: var(--gold);
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s;
    opacity: 0.6;
}

.close-btn:hover {
    opacity: 1;
    transform: rotate(90deg);
}

.keypad-container h2 {
    text-align: center;
    margin-bottom: 2.5rem;
    font-size: 0.9rem;
    letter-spacing: 6px;
    font-weight: 300;
    color: var(--gold);
    text-transform: uppercase;
}

.display {
    background: transparent;
    border-bottom: 1px solid rgba(179, 139, 77, 0.3);
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: 2.5rem;
    letter-spacing: 12px;
    margin-bottom: 3rem;
    font-family: var(--font-mono);
    color: #fff;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.display.error {
    color: var(--error-color);
    border-color: var(--error-color);
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

.display.success {
    color: var(--gold);
    border-color: var(--gold);
    text-shadow: 0 0 20px rgba(179, 139, 77, 0.4);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 250px;
    margin: 0 auto;
}

.key {
    background: transparent;
    border: 1px solid rgba(179, 139, 77, 0.2);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.4rem;
    font-family: var(--font-sans);
    font-weight: 300;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.key:hover {
    background: rgba(179, 139, 77, 0.1);
    border-color: var(--gold);
    color: var(--gold);
    transform: scale(1.1);
}

.key:active {
    transform: scale(0.95);
    background: var(--gold);
    color: #000;
}

.key.action {
    border: none;
    color: var(--grey-text);
    font-size: 1.2rem;
}

.key.action.submit {
    color: var(--gold);
}

.key.action.clear {
    color: #8f4040;
}

.key.action:hover {
    transform: scale(1.1);
    background: transparent;
}

.message {
    text-align: center;
    margin-top: 2.5rem;
    height: 20px;
    font-size: 0.7rem;
    letter-spacing: 4px;
    font-weight: 300;
    text-transform: uppercase;
}

#camera-modal .modal-content {
    background: #000;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
