/* ============================================
   RRIDDL.com - Cipher Noir Experience
   ============================================ */

/* --- Custom Properties --- */
:root {
    --obsidian-void: #0a0a0f;
    --cipher-slate: #141422;
    --smoke-chamber: #1e1e32;
    --phosphor-green: #39ff85;
    --enigma-gold: #d4a843;
    --redaction-red: #c0392b;
    --pale-bone: #d4cfc4;
    --fog-gray: #6b6b7b;
    --pure-black: #000000;
    --phosphor-tint: #a8e6cf;

    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Nunito Sans', 'Segoe UI', sans-serif;
    --font-mono: 'Share Tech Mono', 'Courier New', monospace;
}

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

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

body {
    background-color: var(--obsidian-void);
    color: var(--pale-bone);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><circle cx="16" cy="10" r="5" fill="none" stroke="%23d4a843" stroke-width="1.5"/><rect x="14" y="15" width="4" height="10" rx="1" fill="%23d4a843"/><rect x="10" y="21" width="4" height="3" rx="0.5" fill="%23d4a843"/><rect x="18" y="19" width="4" height="3" rx="0.5" fill="%23d4a843"/></svg>') 16 16, default;
    overflow-x: hidden;
}

/* --- Dot Grid Background --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, var(--smoke-chamber) 1px, transparent 1px);
    background-size: 4px 4px;
    z-index: 0;
    pointer-events: none;
}

/* --- Scanline Overlay --- */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(0, 0, 0, 0.06) 1px,
        rgba(0, 0, 0, 0.06) 2px
    );
    z-index: 9998;
    pointer-events: none;
}

/* --- Cursor Trail --- */
#cursor-trail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9997;
    pointer-events: none;
    overflow: hidden;
}

.trail-char {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 16px;
    color: var(--phosphor-green);
    pointer-events: none;
    animation: trailFade 1.5s ease-out forwards;
    will-change: transform, opacity;
    text-shadow: 0 0 6px var(--phosphor-green);
}

@keyframes trailFade {
    0% {
        opacity: 0.9;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* --- Navigation: Cipher Wheel --- */
#cipher-nav {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10000;
}

#cipher-nav-trigger {
    width: 48px;
    height: 48px;
    cursor: pointer;
    transition: transform 0.6s ease;
}

#cipher-nav-trigger svg {
    display: block;
    animation: navWheelSpin 60s linear infinite;
}

@keyframes navWheelSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#cipher-nav:hover #cipher-nav-trigger {
    transform: scale(1.1);
}

#cipher-nav-menu {
    position: absolute;
    top: 60px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

#cipher-nav:hover #cipher-nav-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#cipher-nav-menu a {
    display: block;
    color: var(--fog-gray);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 6px 16px;
    background: rgba(20, 20, 34, 0.9);
    border: 1px solid var(--smoke-chamber);
    transition: color 0.3s ease, border-color 0.3s ease;
    white-space: nowrap;
    text-align: right;
}

#cipher-nav-menu a::before {
    content: attr(data-glyph) ' \2014  ';
    color: var(--enigma-gold);
}

#cipher-nav-menu a:hover {
    color: var(--phosphor-green);
    border-color: var(--phosphor-green);
}

/* ============================================
   SECTION 1: THE ENTRY GATE
   ============================================ */
.section-gate {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--pure-black);
    z-index: 100;
    overflow: hidden;
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.6s;
}

.section-gate.gate-dismissed {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.gate-keyhole {
    width: 120px;
    height: 180px;
    position: relative;
    clip-path: path('M 60 0 A 40 40 0 1 1 59.99 0 L 60 0 L 60 55 L 85 70 L 85 180 L 35 180 L 35 70 L 60 55 Z');
    opacity: 0;
    animation: keyholeReveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.8s forwards;
    will-change: opacity, transform;
}

.gate-content-preview {
    width: 120px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--cipher-slate);
    filter: invert(1) blur(1px);
}

.gate-content-preview .cipher-text {
    font-family: var(--font-mono);
    font-size: 8px;
    letter-spacing: 0.15em;
    color: var(--phosphor-green);
    text-align: center;
    padding: 10px;
}

@keyframes keyholeReveal {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.section-gate.gate-expanding .gate-keyhole {
    animation: keyholeExpand 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes keyholeExpand {
    0% {
        transform: scale(1);
    }
    100% {
        transform: scale(15);
        opacity: 0;
    }
}

.gate-instruction {
    position: absolute;
    bottom: 10vh;
    opacity: 0;
    animation: instructionPulse 2s ease-in-out 2.5s infinite;
}

.gate-instruction .cipher-mono {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.2em;
    color: var(--fog-gray);
}

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

/* ============================================
   SECTION 2: THE CIPHER CORRIDOR
   ============================================ */
.section-corridor {
    position: relative;
    min-height: 250vh;
    padding: 10vh 0;
    z-index: 50;
}

.corridor-panel {
    position: relative;
    width: 75vw;
    max-width: 900px;
    padding: clamp(2rem, 5vw, 5rem);
    margin-bottom: -8vw;
    background-color: var(--cipher-slate);
    clip-path: polygon(0 4%, 100% 0, 100% 96%, 0 100%);
    transform: rotate(-2deg);
    will-change: transform;
}

.corridor-panel:nth-child(odd) {
    margin-left: 8vw;
}

.corridor-panel:nth-child(even) {
    margin-left: auto;
    margin-right: 8vw;
    transform: rotate(2deg);
}

.panel-blur-layer {
    backdrop-filter: blur(calc(20px * (1 - var(--reveal, 0))));
    -webkit-backdrop-filter: blur(calc(20px * (1 - var(--reveal, 0))));
    transition: backdrop-filter 0.15s ease-out;
    will-change: backdrop-filter;
}

.panel-content {
    opacity: calc(0.15 + 0.85 * var(--reveal, 0));
    transition: opacity 0.15s ease-out;
}

.panel-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--pale-bone);
    margin-bottom: 1rem;
    position: relative;
}

.panel-title::after {
    content: '';
    display: block;
    width: 60px;
    height: 2px;
    background-color: var(--enigma-gold);
    margin-top: 0.75rem;
}

.panel-text {
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    color: var(--phosphor-tint);
    margin-bottom: 2rem;
}

/* --- Redaction Blocks --- */
.redaction-block {
    position: relative;
    display: inline-block;
    padding: 6px 12px;
    margin-top: 1rem;
}

.redacted-text {
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 0.15em;
    color: var(--phosphor-green);
    text-shadow: 0 0 4px rgba(57, 255, 133, 0.3);
}

.redaction-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--pure-black);
    transform-origin: left center;
    transform: scaleX(1);
    transition: transform 0.4s ease-out;
    will-change: transform;
}

.redaction-block.revealed .redaction-bar {
    transform: scaleX(0);
}

/* --- Margin Ciphers --- */
.margin-cipher {
    position: fixed;
    z-index: 40;
    writing-mode: vertical-rl;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.margin-cipher.visible {
    opacity: 1;
}

.left-margin {
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.right-margin {
    right: 16px;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
}

.margin-redaction {
    writing-mode: vertical-rl;
}

.margin-redaction .redacted-text {
    font-size: 11px;
}

/* ============================================
   SECTION 3: THE INNER CHAMBER
   ============================================ */
.section-chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(2rem, 5vw, 6rem);
    background-color: var(--cipher-slate);
    z-index: 50;
    overflow: hidden;
}

.chamber-wheel-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 500px;
    height: 500px;
    opacity: 0.04;
    pointer-events: none;
}

.cipher-wheel-large {
    width: 100%;
    height: 100%;
    color: var(--enigma-gold);
}

.wheel-outer {
    animation: wheelRotate 60s linear infinite;
    transform-origin: 200px 200px;
}

.wheel-inner {
    animation: wheelRotate 60s linear infinite reverse;
    transform-origin: 200px 200px;
}

@keyframes wheelRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.wheel-text-outer, .wheel-text-inner {
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 0.3em;
    fill: var(--enigma-gold);
}

.chamber-content {
    position: relative;
    max-width: 700px;
    text-align: center;
    z-index: 2;
}

.chamber-title {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 5vw, 5rem);
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--pale-bone);
    margin-bottom: 2rem;
}

.chamber-body {
    font-family: var(--font-body);
    font-size: 19px;
    line-height: 1.8;
    color: var(--phosphor-tint);
    margin-bottom: 1.5rem;
}

.chamber-body.secondary {
    color: var(--fog-gray);
    font-size: 17px;
}

.chamber-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 2.5rem 0;
}

.divider-symbol {
    color: var(--enigma-gold);
    font-size: 10px;
}

.divider-line {
    display: block;
    width: 80px;
    height: 1px;
    background-color: var(--enigma-gold);
    opacity: 0.4;
}

/* ============================================
   SECTION 4: THE SEALED EXIT
   ============================================ */
.section-exit {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--obsidian-void);
    z-index: 50;
    overflow: hidden;
}

.exit-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

.exit-keyhole {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
}

.exit-riddle {
    font-family: var(--font-display);
    font-size: clamp(1.2rem, 3vw, 2rem);
    font-weight: 400;
    font-style: italic;
    letter-spacing: 0.05em;
    line-height: 1.6;
    color: var(--enigma-gold);
    opacity: 0;
    transition: opacity 1s ease;
}

.exit-riddle.visible {
    opacity: 1;
}

/* --- Exit blur overlay --- */
.exit-blur-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: blur(calc(var(--exit-blur, 0) * 1px));
    -webkit-backdrop-filter: blur(calc(var(--exit-blur, 0) * 1px));
    pointer-events: none;
    z-index: 1;
    will-change: backdrop-filter;
}

/* --- Exit keyhole clip mask --- */
.exit-clip {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 4;
}

.exit-clip-top,
.exit-clip-bottom,
.exit-clip-left,
.exit-clip-right {
    position: absolute;
    background-color: var(--pure-black);
    transition: none;
}

.exit-clip-top {
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
}

.exit-clip-bottom {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0;
}

.exit-clip-left {
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
}

.exit-clip-right {
    top: 0;
    right: 0;
    width: 0;
    height: 100%;
}

/* ============================================
   GLITCH MICRO-MOMENTS
   ============================================ */
@keyframes glitchShift {
    0% { transform: translateX(0); filter: none; }
    25% { transform: translateX(2px); }
    50% { transform: translateX(-2px); filter: hue-rotate(180deg); }
    75% { transform: translateX(1px); }
    100% { transform: translateX(0); filter: none; }
}

.glitch-active {
    animation: glitchShift 150ms ease-in-out;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .corridor-panel {
        width: 90vw;
        margin-left: 5vw !important;
        margin-right: 5vw !important;
        transform: rotate(-1deg);
    }

    .corridor-panel:nth-child(even) {
        transform: rotate(1deg);
    }

    .margin-cipher {
        display: none;
    }

    #cipher-nav {
        top: 12px;
        right: 12px;
    }
}

/* ============================================
   SELECTION STYLES
   ============================================ */
::selection {
    background-color: var(--phosphor-green);
    color: var(--obsidian-void);
}
