/* ============================================
   RRIDDL.com - Styles
   Sepia-Cyberpunk Cryptography Archive
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-archive: #1c1a17;
    --parchment: #f5e6c8;
    --oxidized-copper: #8b6914;
    --decode-amber: #ffb627;
    --cipher-cyan: #00d4aa;
    --burnt-sepia: #3d2b1f;
    --faded-dossier: #a89070;
    --scan-line-blue: #7ecfc0;
    --scroll: 0;
    --grain-opacity: 0.07;
}

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

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

body {
    background: var(--deep-archive);
    color: var(--parchment);
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.8;
    letter-spacing: 0.02em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- SVG Filters (hidden) --- */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Film Grain Overlay --- */
.grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    z-index: 1000;
    pointer-events: none;
    opacity: var(--grain-opacity);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    animation: grainShift 0.5s steps(4) infinite;
}

@keyframes grainShift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-5%, -5%); }
    50% { transform: translate(5%, -10%); }
    75% { transform: translate(-10%, 5%); }
    100% { transform: translate(0, 0); }
}

/* --- Plane 0: Fixed Background --- */
.plane-0 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.bg-photo {
    position: absolute;
    top: -5%;
    left: -5%;
    width: 110%;
    height: 110%;
    background:
        radial-gradient(ellipse at 30% 40%, rgba(139, 105, 20, 0.15) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 60%, rgba(61, 43, 31, 0.3) 0%, transparent 50%),
        linear-gradient(135deg, #3d2b1f 0%, #1c1a17 40%, #2a1f15 60%, #1c1a17 100%);
    filter: sepia(0.6) contrast(1.1) brightness(0.9) saturate(0.7);
    animation: bgPan 30s ease-in-out infinite alternate;
    will-change: transform;
}

/* Subtle circuit board pattern overlay on background */
.bg-photo::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(90deg, rgba(139, 105, 20, 0.04) 1px, transparent 1px),
        linear-gradient(0deg, rgba(139, 105, 20, 0.04) 1px, transparent 1px);
    background-size: 60px 60px;
}

@keyframes bgPan {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.05) translate(-1%, -0.5%); }
}

.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 1px,
        rgba(0, 212, 170, 0.03) 1px,
        rgba(0, 212, 170, 0.03) 2px
    );
    pointer-events: none;
}

/* --- Sidebar Navigation --- */
.sidebar-nav {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px 0;
    background: rgba(28, 26, 23, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-right: 1px solid rgba(139, 105, 20, 0.3);
    border-radius: 0 4px 4px 0;
}

.nav-glyph {
    color: var(--faded-dossier);
    cursor: pointer;
    transition: color 0.3s ease, filter 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.nav-glyph:hover {
    color: var(--decode-amber);
    animation: decodeTremor 0.3s ease;
}

.nav-glyph.active {
    color: var(--decode-amber);
    filter: drop-shadow(0 0 6px rgba(255, 182, 39, 0.5));
    animation: glyphPulse 2s ease-in-out infinite;
}

@keyframes glyphPulse {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(255, 182, 39, 0.3)); }
    50% { filter: drop-shadow(0 0 10px rgba(255, 182, 39, 0.6)); }
}

@keyframes decodeTremor {
    0%, 100% { transform: translateX(0); }
    16% { transform: translateX(-2px); }
    33% { transform: translateX(2px); }
    50% { transform: translateX(-2px); }
    66% { transform: translateX(2px); }
    83% { transform: translateX(-1px); }
}

/* --- Decode Chambers (Sections) --- */
.decode-chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    perspective: 1200px;
    overflow: hidden;
}

/* --- Hero Section --- */
.chamber-hero {
    min-height: 100vh;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.chamber-hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        transparent 40%,
        rgba(28, 26, 23, 0.6) 70%,
        var(--deep-archive) 100%
    );
    z-index: 1;
    pointer-events: none;
}

/* Cipher Wheel */
.cipher-wheel-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    height: 400px;
    z-index: 0;
    opacity: 0.15;
}

.cipher-wheel {
    position: relative;
    width: 100%;
    height: 100%;
}

.cipher-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    border: 1px solid;
}

.ring-outer {
    width: 400px;
    height: 400px;
    margin-left: -200px;
    margin-top: -200px;
    border-color: var(--parchment);
    animation: rotateClockwise 60s linear infinite;
}

.ring-middle {
    width: 300px;
    height: 300px;
    margin-left: -150px;
    margin-top: -150px;
    border-color: var(--oxidized-copper);
    animation: rotateCounterClockwise 45s linear infinite;
}

.ring-inner {
    width: 200px;
    height: 200px;
    margin-left: -100px;
    margin-top: -100px;
    border-color: var(--cipher-cyan);
    animation: rotateClockwise 30s linear infinite;
}

/* Generate characters around rings using box-shadows as dots */
.ring-outer::before,
.ring-middle::before,
.ring-inner::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 50%;
    top: -2px;
    left: 50%;
    margin-left: -2px;
    box-shadow:
        /* Place dots around the ring at intervals */
        0px 0px 0 0 currentColor;
}

.ring-outer::after {
    content: 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 380px;
    height: 380px;
    margin-left: -190px;
    margin-top: -190px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Special Elite', monospace;
    font-size: 10px;
    letter-spacing: 6px;
    color: var(--parchment);
    opacity: 0.4;
    border-radius: 50%;
    text-align: center;
    word-spacing: 2px;
}

.ring-middle::after {
    content: '0 1 2 3 4 5 6 7 8 9 A B C D E F';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 280px;
    height: 280px;
    margin-left: -140px;
    margin-top: -140px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Special Elite', monospace;
    font-size: 9px;
    letter-spacing: 5px;
    color: var(--oxidized-copper);
    opacity: 0.5;
    border-radius: 50%;
    text-align: center;
}

.ring-inner::after {
    content: '* + - / = % & #';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 180px;
    height: 180px;
    margin-left: -90px;
    margin-top: -90px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Special Elite', monospace;
    font-size: 11px;
    letter-spacing: 8px;
    color: var(--cipher-cyan);
    opacity: 0.5;
    border-radius: 50%;
    text-align: center;
}

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

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

/* Hero Content */
.hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 0 20px;
}

.hero-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(4rem, 12vw, 10rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--parchment);
    line-height: 1;
    margin-bottom: 0.1em;
    position: relative;
}

.hero-title .letter {
    display: inline-block;
    opacity: 0;
    animation: typewriterIn 0.4s ease forwards;
    animation-delay: calc(var(--delay) * 120ms + 0.5s);
}

@keyframes typewriterIn {
    0% {
        opacity: 0;
        transform: translateY(10px) translateX(-2px);
        color: var(--cipher-cyan);
    }
    30% {
        opacity: 1;
        transform: translateY(0) translateX(2px);
        color: var(--cipher-cyan);
    }
    50% {
        transform: translateX(-1px);
        color: var(--decode-amber);
    }
    70% {
        transform: translateX(1px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
        color: var(--parchment);
    }
}

.hero-subtitle {
    font-family: 'Special Elite', monospace;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--faded-dossier);
    letter-spacing: 0.3em;
    opacity: 0;
    animation: fadeIn 1s ease forwards;
    animation-delay: 1.5s;
}

.hero-tagline {
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    color: var(--faded-dossier);
    margin-top: 2rem;
    letter-spacing: 0.1em;
    opacity: 0;
    animation: fadeIn 1.2s ease forwards;
    animation-delay: 2s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Scan Sweep */
.scan-sweep {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--cipher-cyan) 20%, var(--cipher-cyan) 80%, transparent 100%);
    opacity: 0.6;
    z-index: 5;
    animation: scanSweep 4s ease-in-out infinite;
    animation-delay: 2.5s;
}

@keyframes scanSweep {
    0% { top: 0; opacity: 0; }
    5% { opacity: 0.6; }
    95% { opacity: 0.6; }
    100% { top: 100%; opacity: 0; }
}

/* --- Decode Matrices (corner accents) --- */
.decode-matrix {
    position: absolute;
    width: 80px;
    height: 60px;
    z-index: 3;
    font-family: 'Special Elite', monospace;
    font-size: 10px;
    color: var(--cipher-cyan);
    opacity: 0.3;
    overflow: hidden;
    letter-spacing: 2px;
    line-height: 1.6;
}

.decode-matrix::before {
    content: 'A7F 2K9\aB3D E8C\a4G1 H6J';
    white-space: pre-wrap;
}

.matrix-tl {
    top: 40px;
    left: 70px;
}

.matrix-br {
    bottom: 80px;
    right: 40px;
}

/* --- Waveforms --- */
.waveform {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 200%;
    height: 40px;
    z-index: 4;
    overflow: hidden;
}

.wave-line {
    fill: none;
    stroke: var(--cipher-cyan);
    stroke-width: 1;
    opacity: 0.4;
    animation: waveScroll 20s linear infinite;
}

@keyframes waveScroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

.waveform-section {
    opacity: 0.3;
}

/* --- Content Panels (Plane 1) --- */
.chamber-panel {
    position: relative;
    background: rgba(28, 26, 23, 0.88);
    border: 1px solid var(--oxidized-copper);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    padding: clamp(2rem, 4vw, 4rem);
    max-width: 680px;
    width: 90%;
    z-index: 2;
    overflow: hidden;
    /* Decode transition initial state */
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s ease, transform 0.8s ease, border-color 1s ease;
}

.chamber-panel.decoded {
    opacity: 1;
    transform: translateY(0);
    border-color: var(--oxidized-copper);
}

.panel-left {
    margin-right: auto;
    margin-left: 80px;
}

.panel-right {
    margin-left: auto;
    margin-right: 80px;
}

.panel-center {
    margin: 0 auto;
}

/* Panel scan-line sweep */
.panel-scanline {
    position: absolute;
    top: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--cipher-cyan);
    opacity: 0;
    z-index: 10;
    transform: translateY(0);
    pointer-events: none;
}

.chamber-panel.decoding .panel-scanline {
    opacity: 0.6;
    animation: panelScan 0.6s ease-out forwards;
}

@keyframes panelScan {
    from { transform: translateY(0); }
    to { transform: translateY(calc(100% + 4px)); }
}

/* Panel border glow */
.panel-border-glow {
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 1px solid var(--cipher-cyan);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.chamber-panel.decoding .panel-border-glow {
    opacity: 0.5;
    animation: borderDecay 1.2s ease forwards;
}

@keyframes borderDecay {
    0% { border-color: var(--cipher-cyan); opacity: 0.5; }
    100% { border-color: var(--oxidized-copper); opacity: 0; }
}

/* --- Section Titles --- */
.section-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--parchment);
    line-height: 1.1;
    margin-bottom: 1.5rem;
    position: relative;
}

.section-title.decoded-text {
    color: var(--decode-amber);
}

/* --- Section Body --- */
.section-body {
    color: var(--d4c5a9, #d4c5a9);
    margin-bottom: 1.5rem;
    max-width: 580px;
}

.typewriter-text {
    font-family: 'Special Elite', monospace;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 2;
    letter-spacing: 0.03em;
}

/* Cleartext section: cleaner styling */
.cleartext-body {
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    color: var(--parchment);
}

/* --- Circuit Patterns --- */
.circuit-pattern {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0.06;
    z-index: 0;
}

.circuit-pattern::before {
    content: '';
    position: absolute;
    top: 10%;
    right: 5%;
    width: 60%;
    height: 80%;
    background-image:
        linear-gradient(90deg, var(--oxidized-copper) 1px, transparent 1px),
        linear-gradient(0deg, var(--oxidized-copper) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
}

/* --- Small Cipher Wheel (Section accent) --- */
.cipher-wheel-small {
    position: absolute;
    bottom: -20px;
    right: -20px;
    width: 100px;
    height: 100px;
    opacity: 0.15;
}

.ring-sm-outer {
    width: 100px;
    height: 100px;
    margin-left: -50px;
    margin-top: -50px;
    border-color: var(--oxidized-copper);
    animation: rotateClockwise 30s linear infinite;
}

.ring-sm-inner {
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    border-color: var(--cipher-cyan);
    animation: rotateCounterClockwise 20s linear infinite;
}

/* --- Decode Counter --- */
.decode-counter {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 2rem;
    padding: 1.2rem 1.5rem;
    border: 1px solid rgba(139, 105, 20, 0.3);
    background: rgba(28, 26, 23, 0.6);
}

.counter-label {
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    color: var(--faded-dossier);
    text-transform: uppercase;
}

.counter-value {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(2rem, 4vw, 3.5rem);
    letter-spacing: 0.1em;
    color: var(--decode-amber);
    line-height: 1;
}

/* --- Final Emblem --- */
.final-emblem {
    display: flex;
    justify-content: center;
    margin-top: 2.5rem;
    animation: emblemPulse 3s ease-in-out infinite;
}

@keyframes emblemPulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* --- Plane 2: Foreground Accents --- */
.plane-2-accents {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 800;
}

.accent-glyph {
    position: absolute;
    font-size: 1.5rem;
    color: var(--cipher-cyan);
    opacity: 0.12;
    will-change: transform;
}

.accent-1 {
    top: 15%;
    right: 8%;
}

.accent-2 {
    top: 45%;
    right: 4%;
}

.accent-3 {
    top: 70%;
    left: 6%;
}

.accent-4 {
    top: 88%;
    right: 12%;
}

/* --- Section-specific Visual Progression --- */

/* Top sections: heavy grain, more sepia, typewriter feel */
.chamber-archive {
    /* More grain in early sections */
}

.chamber-archive .section-title {
    color: var(--parchment);
}

/* Middle sections: transitional */
.chamber-cipher .section-title {
    color: var(--parchment);
}

.chamber-cipher .chamber-panel.decoded .section-title {
    color: var(--decode-amber);
}

/* Decode section: cipher cyan intensifies */
.chamber-decode .section-title {
    color: var(--parchment);
}

.chamber-decode .chamber-panel.decoded .section-title {
    color: var(--decode-amber);
}

.chamber-decode .wave-line {
    opacity: 0.5;
    stroke: var(--decode-amber);
}

/* Final section: clean, clear, illuminated */
.chamber-cleartext {
    /* Near-zero grain effect handled by JS */
}

.chamber-cleartext .section-title {
    color: var(--decode-amber);
}

.chamber-cleartext .chamber-panel {
    border-color: var(--decode-amber);
    box-shadow: 0 8px 32px rgba(255, 182, 39, 0.1), 0 0 60px rgba(255, 182, 39, 0.05);
}

.chamber-cleartext .wave-line {
    stroke: var(--decode-amber);
    opacity: 0.3;
}

/* --- Heading Ambient Vibration --- */
.section-title {
    animation: ambientVibration 0.15s ease-in-out infinite;
    animation-play-state: running;
}

.chamber-panel.decoded .section-title {
    animation-play-state: paused;
}

@keyframes ambientVibration {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-0.5px); }
    75% { transform: translateX(0.5px); }
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .sidebar-nav {
        width: 36px;
        gap: 16px;
    }

    .nav-glyph {
        width: 24px;
        height: 24px;
    }

    .nav-glyph svg {
        width: 16px;
        height: 16px;
    }

    .panel-left,
    .panel-right {
        margin-left: 50px;
        margin-right: 16px;
    }

    .cipher-wheel-container {
        width: 250px;
        height: 250px;
    }

    .ring-outer {
        width: 250px;
        height: 250px;
        margin-left: -125px;
        margin-top: -125px;
    }

    .ring-middle {
        width: 190px;
        height: 190px;
        margin-left: -95px;
        margin-top: -95px;
    }

    .ring-inner {
        width: 130px;
        height: 130px;
        margin-left: -65px;
        margin-top: -65px;
    }

    .ring-outer::after {
        width: 230px;
        height: 230px;
        margin-left: -115px;
        margin-top: -115px;
        font-size: 7px;
        letter-spacing: 3px;
    }

    .ring-middle::after {
        width: 170px;
        height: 170px;
        margin-left: -85px;
        margin-top: -85px;
        font-size: 7px;
    }

    .ring-inner::after {
        width: 110px;
        height: 110px;
        margin-left: -55px;
        margin-top: -55px;
        font-size: 8px;
    }

    .decode-matrix {
        display: none;
    }

    .plane-2-accents {
        display: none;
    }
}

@media (max-width: 480px) {
    .panel-left,
    .panel-right,
    .panel-center {
        margin-left: 44px;
        margin-right: 8px;
        padding: 1.5rem;
    }

    .hero-title {
        font-size: clamp(3rem, 15vw, 5rem);
    }
}

/* --- Decode Text Scramble State --- */
.decode-text.scrambled {
    color: var(--cipher-cyan);
}

.decode-text.resolving {
    transition: color 0.4s ease;
}

.decode-text.resolved {
    color: var(--decode-amber);
}
