/* =============================================
   rriddl.net - Surreal Dreamscape Styles
   ============================================= */

/* --- CSS Custom Properties --- */
:root {
    --deep-indigo: #1b1340;
    --phantom-violet: #4a2f8a;
    --oracle-gold: #d4a843;
    --mist-silver: #c8c5d4;
    --cipher-green: #3dd68c;
    --paradox-rose: #b84c7e;
    --fog-white: #eee8f5;
    --obsidian: #0c0a14;

    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Outfit', 'Segoe UI', sans-serif;
    --font-accent: 'Caveat', cursive;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

    --spring-ease: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --golden-ratio: 1.618;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
    overflow-x: hidden;
}

body {
    background-color: var(--obsidian);
    color: var(--mist-silver);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.75;
    overflow-x: hidden;
}

/* --- Typography Classes --- */
.heading-display {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(3rem, 7vw, 7rem);
    letter-spacing: -0.03em;
    color: var(--fog-white);
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

.heading-display em {
    font-style: italic;
    color: var(--oracle-gold);
}

.text-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.75;
    color: var(--mist-silver);
    margin-bottom: 1.25rem;
    max-width: 620px;
}

.text-body.text-gold {
    color: var(--oracle-gold);
    font-weight: 500;
}

.caveat-text {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 1.5rem;
    transform: rotate(-1deg);
    color: var(--fog-white);
}

.text-cipher {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--cipher-green);
    letter-spacing: 0.05em;
}

/* --- Gradient Mesh Backgrounds --- */
.gradient-mesh-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.mesh-portal {
    background:
        radial-gradient(ellipse at 25% 45%, rgba(74, 47, 138, 0.45) 0%, transparent 58%),
        radial-gradient(ellipse at 75% 25%, rgba(27, 19, 64, 0.75) 0%, transparent 52%),
        radial-gradient(ellipse at 50% 85%, rgba(74, 47, 138, 0.28) 0%, transparent 55%),
        var(--obsidian);
    animation: portalMesh 30s ease-in-out infinite alternate;
}

.mesh-labyrinth-front {
    background:
        radial-gradient(ellipse at 35% 35%, rgba(74, 47, 138, 0.5) 0%, transparent 58%),
        radial-gradient(ellipse at 65% 75%, rgba(27, 19, 64, 0.6) 0%, transparent 52%),
        var(--deep-indigo);
}

.mesh-labyrinth-back {
    background:
        radial-gradient(ellipse at 55% 25%, rgba(74, 47, 138, 0.5) 0%, transparent 58%),
        radial-gradient(ellipse at 25% 75%, rgba(12, 10, 20, 0.65) 0%, transparent 52%),
        var(--deep-indigo);
}

.mesh-mirrors {
    background:
        radial-gradient(ellipse at 65% 35%, rgba(74, 47, 138, 0.38) 0%, transparent 55%),
        radial-gradient(ellipse at 25% 65%, rgba(27, 19, 64, 0.55) 0%, transparent 58%),
        radial-gradient(ellipse at 85% 85%, rgba(184, 76, 126, 0.12) 0%, transparent 42%),
        var(--obsidian);
    animation: mirrorMesh 30s ease-in-out infinite alternate;
}

.mesh-cipher {
    background:
        radial-gradient(ellipse at 45% 25%, rgba(74, 47, 138, 0.42) 0%, transparent 55%),
        radial-gradient(ellipse at 75% 65%, rgba(27, 19, 64, 0.48) 0%, transparent 52%),
        var(--deep-indigo);
}

.mesh-abyss {
    background:
        radial-gradient(ellipse at 50% 50%, rgba(74, 47, 138, 0.28) 0%, transparent 62%),
        radial-gradient(ellipse at 15% 15%, rgba(27, 19, 64, 0.68) 0%, transparent 52%),
        radial-gradient(ellipse at 85% 85%, rgba(12, 10, 20, 0.75) 0%, transparent 42%),
        var(--obsidian);
}

@keyframes portalMesh {
    0% { background-position: 0% 0%, 100% 0%, 50% 100%; }
    50% { background-position: 8% 12%, 88% 8%, 42% 88%; }
    100% { background-position: 4% 6%, 94% 4%, 56% 94%; }
}

@keyframes mirrorMesh {
    0% { background-position: 0% 0%, 100% 100%, 50% 50%; }
    100% { background-position: 12% 8%, 88% 92%, 58% 42%; }
}

/* --- Question Mark Constellation --- */
.question-mark-field {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.question-mark-field::before {
    content: '? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?';
    position: absolute;
    inset: -50%;
    width: 200%;
    height: 200%;
    font-family: var(--font-body);
    font-size: 3px;
    color: var(--mist-silver);
    opacity: 0.07;
    word-spacing: 28px;
    line-height: 38px;
    letter-spacing: 24px;
    overflow: hidden;
    transform: rotate(12deg);
}

body.dreaming .question-mark-field::before {
    animation: constellationDrift 55s linear infinite;
}

@keyframes constellationDrift {
    from { transform: rotate(12deg); }
    to { transform: rotate(372deg); }
}

/* --- Scene Base --- */
.scene {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    transition: background-color 400ms ease-in-out;
}

/* Zoom-focus scroll effect */
.scene.zoom-active {
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.8s var(--spring-ease), transform 0.8s var(--spring-ease);
}

.scene.zoom-active.visible {
    opacity: 1;
    transform: scale(1);
}

/* =========================================
   Scene 1: Portal / Hero
   ========================================= */
.scene-portal {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--obsidian);
}

.portal-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Penrose triangle SVG */
.penrose-main {
    width: clamp(180px, 28vw, 340px);
    height: auto;
    margin-bottom: 2rem;
    animation: penroseSpin 60s linear infinite;
}

.penrose-small {
    width: clamp(100px, 14vw, 180px);
    animation-duration: 75s;
}

.penrose-stroke {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: strokeDraw 3s ease-out forwards;
    filter: drop-shadow(0 0 8px rgba(212, 168, 67, 0.3));
}

.ps-2 { animation-delay: 0.45s; }
.ps-3 { animation-delay: 0.9s; }
.ps-4 { animation-delay: 1.3s; }
.ps-5 { animation-delay: 1.6s; }
.ps-6 { animation-delay: 1.9s; }
.ps-7 { animation-delay: 2.3s; animation-name: dotFadeIn; }

.ps-a1 { animation-delay: 0s; }
.ps-a2 { animation-delay: 0.35s; }
.ps-a3 { animation-delay: 0.7s; }
.ps-a4 { animation-delay: 1.0s; }
.ps-a5 { animation-delay: 1.3s; }

@keyframes strokeDraw {
    to { stroke-dashoffset: 0; }
}

@keyframes dotFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; stroke-dashoffset: 0; }
}

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

/* Portal Title - Letter Reveal */
.portal-title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(4rem, 8vw, 10rem);
    letter-spacing: 0.1em;
    color: var(--fog-white);
    line-height: 1;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.title-letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(50px) rotateZ(8deg);
    animation: letterEmerge 0.65s var(--spring-ease) forwards;
    text-shadow: 0 0 35px rgba(238, 232, 245, 0.12);
    color: #ffffff;
}

.title-letter[data-idx="0"] { animation-delay: 3.3s; }
.title-letter[data-idx="1"] { animation-delay: 3.5s; }
.title-letter[data-idx="2"] { animation-delay: 3.7s; }
.title-letter[data-idx="3"] { animation-delay: 3.9s; }
.title-letter[data-idx="4"] { animation-delay: 4.1s; }
.title-letter[data-idx="5"] { animation-delay: 4.3s; }

@keyframes letterEmerge {
    to {
        opacity: 1;
        transform: translateY(0) rotateZ(0deg);
    }
}

/* Portal Tagline */
.portal-tagline {
    opacity: 0;
    animation: taglineFadeUp 1s ease-out 5.2s forwards;
}

@keyframes taglineFadeUp {
    from {
        opacity: 0;
        transform: translateY(22px) rotate(-1deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotate(-1deg);
    }
}

/* --- Hidden Riddle Fragments --- */
.hidden-fragment {
    position: absolute;
    z-index: 5;
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 1.15rem;
    color: var(--fog-white);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    text-shadow: 0 0 14px rgba(238, 232, 245, 0.45);
    white-space: nowrap;
}

.hidden-fragment.revealed {
    opacity: 0.85;
}

/* =========================================
   Scene 2: Labyrinth / Card Flip
   ========================================= */
.scene-labyrinth {
    min-height: 100vh;
    perspective: 1200px;
}

.card-flip-wrapper {
    width: 100%;
    height: 100vh;
    position: relative;
}

.card-flip-body {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 1.2s var(--spring-ease);
    transform-style: preserve-3d;
}

.card-flip-body.flipped {
    transform: rotateX(180deg);
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-face-front {
    background-color: var(--deep-indigo);
}

.card-face-back {
    background-color: var(--deep-indigo);
    transform: rotateX(180deg);
}

.card-face-content {
    position: relative;
    z-index: 2;
    padding: 2rem;
    text-align: center;
    max-width: 820px;
}

.card-face-front .heading-display {
    font-size: clamp(2.5rem, 6vw, 5rem);
}

.card-face-back .heading-display {
    margin-bottom: 2rem;
}

/* =========================================
   Scene 3: Mirrors / Diagonal Slide
   ========================================= */
.scene-mirrors {
    min-height: 100vh;
    display: flex;
    align-items: center;
    background-color: var(--obsidian);
}

.mirrors-layout {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 4rem;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 4rem 3rem;
    align-items: center;
    opacity: 0;
    transform: translate(40px, 40px);
    transition: opacity 0.9s var(--spring-ease), transform 0.9s var(--spring-ease);
}

.scene-mirrors.visible .mirrors-layout {
    opacity: 1;
    transform: translate(0, 0);
}

.mirrors-visual {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Concentric Rotating Hexagons (Optical Illusion) */
.hex-vortex {
    position: relative;
    width: clamp(240px, 28vw, 400px);
    height: clamp(240px, 28vw, 400px);
}

.hex-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 1.5px solid var(--oracle-gold);
    clip-path: polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%);
    animation: hexSpin 24s linear infinite;
    filter: drop-shadow(0 0 4px rgba(212, 168, 67, 0.18));
}

.hex-1 { width: 100%; height: 100%; margin-top: -50%; margin-left: -50%; animation-delay: 0s; }
.hex-2 { width: 86%; height: 86%; margin-top: -43%; margin-left: -43%; animation-delay: -3.4s; animation-direction: reverse; }
.hex-3 { width: 74%; height: 74%; margin-top: -37%; margin-left: -37%; animation-delay: -6.8s; }
.hex-4 { width: 63%; height: 63%; margin-top: -31.5%; margin-left: -31.5%; animation-delay: -10.2s; animation-direction: reverse; }
.hex-5 { width: 54%; height: 54%; margin-top: -27%; margin-left: -27%; animation-delay: -13.6s; }
.hex-6 { width: 46%; height: 46%; margin-top: -23%; margin-left: -23%; animation-delay: -17s; animation-direction: reverse; }
.hex-7 { width: 39%; height: 39%; margin-top: -19.5%; margin-left: -19.5%; animation-delay: -20.4s; }

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

.mirrors-text {
    position: relative;
}

.mirrors-text .heading-display {
    font-size: clamp(2rem, 5vw, 4.5rem);
}

/* Lens Flare */
.lens-flare {
    position: absolute;
    width: 75px;
    height: 75px;
    border-radius: 50%;
    pointer-events: none;
    background:
        radial-gradient(circle, rgba(212, 168, 67, 0.22) 0%, transparent 58%),
        radial-gradient(circle at 35% 35%, rgba(61, 214, 140, 0.12) 0%, transparent 42%);
    animation: flareBreath 3s ease-in-out infinite;
}

.flare-mirrors {
    top: -25px;
    right: -35px;
}

@keyframes flareBreath {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* =========================================
   Scene 4: Interactive Cipher
   ========================================= */
.scene-cipher {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--deep-indigo);
}

.cipher-container {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 3rem;
    max-width: 820px;
}

.cipher-hint {
    margin-bottom: 3rem;
    font-size: 1.6rem;
    color: var(--mist-silver);
}

.cipher-grid {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    padding: 2.5rem 3rem;
    background: rgba(12, 10, 20, 0.5);
    border: 1px solid rgba(212, 168, 67, 0.2);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.4s ease;
}

.cipher-grid:hover {
    border-color: var(--oracle-gold);
}

.glyph {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-weight: 400;
    color: var(--paradox-rose);
    transition: color 0.5s ease, transform 0.5s var(--spring-ease);
    min-width: 0.7em;
    text-align: center;
}

.glyph.spacer {
    min-width: 0.4em;
}

.cipher-grid.decoded .glyph {
    color: var(--cipher-green);
    text-shadow: 0 0 10px rgba(61, 214, 140, 0.4);
}

.cipher-result {
    margin-top: 2rem;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s ease, transform 0.6s var(--spring-ease);
    position: relative;
}

.cipher-result.shown {
    opacity: 1;
    transform: translateY(0);
}

.solved-msg {
    font-size: 1.1rem;
}

/* Particle burst */
.particle-field {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.q-particle {
    position: absolute;
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--oracle-gold);
    opacity: 0;
    animation: particleExplode 1.5s var(--spring-ease) forwards;
}

@keyframes particleExplode {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--px), var(--py)) scale(0.3) rotate(360deg);
    }
}

/* Decorative Penrose */
.deco-penrose {
    position: absolute;
    z-index: 1;
    opacity: 0.14;
    animation: penroseSpin 75s linear infinite;
}

.deco-left {
    bottom: 10%;
    left: 5%;
    width: 115px;
}

.deco-right {
    top: 10%;
    right: 5%;
    width: 95px;
    animation-direction: reverse;
}

/* =========================================
   Scene 5: Abyss / Closing
   ========================================= */
.scene-abyss {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--obsidian);
}

.abyss-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 3rem;
}

.abyss-heading {
    font-size: clamp(2.5rem, 6vw, 6rem);
    margin-bottom: 1.5rem;
}

.abyss-quote {
    font-size: 2rem;
    color: var(--oracle-gold);
    margin-bottom: 3rem;
    opacity: 0.9;
}

.abyss-penrose {
    margin: 3rem auto;
}

.site-footer {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(200, 197, 212, 0.15);
}

.footer-text {
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--mist-silver);
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.footer-cipher-text {
    font-size: 0.8rem;
    opacity: 0.4;
}

/* --- Mobius Strip Divider --- */
.mobius-line {
    width: clamp(200px, 40vw, 420px);
    height: auto;
    margin-bottom: 2rem;
}

.mobius-stroke {
    stroke-dasharray: 650;
    stroke-dashoffset: 650;
    filter: drop-shadow(0 0 12px rgba(212, 168, 67, 0.4));
}

.mobius-line.drawn .mobius-stroke {
    animation: mobiusDraw 2s ease-out forwards;
}

@keyframes mobiusDraw {
    to { stroke-dashoffset: 0; }
}

/* --- Radial Navigation --- */
.radial-nav {
    position: fixed;
    top: 30px;
    left: 30px;
    z-index: 100;
}

.nav-trigger {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    z-index: 101;
}

.nav-circles {
    position: relative;
    width: 28px;
    height: 28px;
}

.circle {
    position: absolute;
    border-radius: 50%;
    border: 1.5px solid var(--oracle-gold);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: border-color 0.3s ease, transform 0.3s ease;
}

.circle-outer {
    width: 28px;
    height: 28px;
}

.circle-mid {
    width: 18px;
    height: 18px;
}

.circle-inner {
    width: 8px;
    height: 8px;
    background-color: var(--oracle-gold);
}

.nav-trigger:hover .circle-outer { transform: translate(-50%, -50%) scale(1.15); }
.nav-trigger:hover .circle-mid { transform: translate(-50%, -50%) scale(1.1); }

.nav-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 200px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.radial-nav.open .nav-menu {
    pointer-events: auto;
    opacity: 1;
}

.nav-item {
    position: absolute;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--fog-white);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid rgba(212, 168, 67, 0.3);
    border-radius: 20px;
    background: rgba(12, 10, 20, 0.85);
    backdrop-filter: blur(8px);
    white-space: nowrap;
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
    transition: all 0.4s var(--spring-ease);
}

.radial-nav.open .nav-item {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.nav-item:hover {
    background: var(--oracle-gold);
    color: var(--obsidian);
    border-color: var(--oracle-gold);
}

/* Nav orbital positions */
.nav-item[data-angle="0"]   { top: -55px; left: 22px;  transition-delay: 0s; }
.nav-item[data-angle="72"]  { top: 0px;   left: 120px; transition-delay: 0.05s; }
.nav-item[data-angle="144"] { top: 70px;  left: 105px; transition-delay: 0.1s; }
.nav-item[data-angle="216"] { top: 70px;  left: -50px; transition-delay: 0.15s; }
.nav-item[data-angle="288"] { top: 0px;   left: -70px; transition-delay: 0.2s; }

/* --- Flashlight Overlay --- */
.flashlight-overlay {
    position: fixed;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    background: radial-gradient(circle 300px at var(--fl-x, 50%) var(--fl-y, 50%), rgba(238, 232, 245, 0.025) 0%, transparent 100%);
}

.flashlight-overlay.active {
    opacity: 1;
}

/* --- Dreaming State --- */
body.dreaming .gradient-mesh-bg {
    animation-duration: 10s !important;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .mirrors-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 3rem 1.5rem;
    }

    .mirrors-visual {
        order: -1;
    }

    .hex-vortex {
        width: 220px;
        height: 220px;
    }

    .cipher-grid {
        padding: 1.5rem 2rem;
    }

    .glyph {
        font-size: 1.5rem;
    }
}

@media (max-width: 600px) {
    .portal-title {
        font-size: clamp(3rem, 12vw, 5rem);
    }

    .heading-display {
        font-size: clamp(2rem, 8vw, 3.5rem);
    }

    .radial-nav {
        top: 15px;
        left: 15px;
    }

    .mirrors-layout {
        padding: 2rem 1rem;
    }

    .cipher-container {
        padding: 2rem 1rem;
    }

    .abyss-content {
        padding: 2rem 1rem;
    }
}
