/* ===========================================================
   RRIDDL.com — Japanese-minimal × Dopamine-neon
   =========================================================== */

:root {
    --void-black: #0a0a0f;
    --deep-indigo: #12101f;
    --cipher-mint: #00ffaa;
    --pulse-magenta: #ff2d7b;
    --signal-yellow: #f5e642;
    --moon-silver: #c8c8d0;
    --pure-white: #f0f0f5;
    --ghost-line: #1a1a2e;

    --sidebar-width: clamp(60px, 6vw, 90px);

    --font-display: 'Bebas Neue', 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Space Mono', monospace;

    --ease-hud: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
    background: var(--void-black);
    color: var(--moon-silver);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.75;
    letter-spacing: 0.01em;
    font-weight: 300;
    overflow-x: hidden;
    cursor: none;
}

body {
    min-height: 100vh;
    position: relative;
}

a { color: inherit; text-decoration: none; position: relative; }
a.text-link::after {
    content: '';
    position: absolute; left: 0; bottom: -2px;
    width: 0; height: 1px;
    background: var(--cipher-mint);
    transition: width 200ms ease;
}
a.text-link:hover::after { width: 100%; }

em { color: var(--pure-white); font-style: normal; border-bottom: 1px solid var(--cipher-mint); padding-bottom: 1px; }

/* Selection */
::selection { background: var(--pulse-magenta); color: var(--void-black); }

/* ===== Background kanji texture ===== */
.bg-kanji {
    position: fixed; inset: 0;
    z-index: 0;
    opacity: 0.15;
    pointer-events: none;
}
.bg-kanji svg { width: 100%; height: 100%; }

/* ===== Scanline overlay ===== */
.scanlines {
    position: fixed; inset: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        rgba(0, 255, 170, 0.03) 0px,
        rgba(0, 255, 170, 0.03) 1px,
        transparent 1px,
        transparent 4px
    );
    pointer-events: none;
    z-index: 1000;
    mix-blend-mode: screen;
}

/* ===== Custom reticle cursor ===== */
.reticle {
    position: fixed;
    top: 0; left: 0;
    width: 24px; height: 24px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2000;
    transition: opacity 200ms;
    will-change: transform;
}
.reticle svg { display: block; }

/* ===== Sidebar Spine ===== */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--void-black);
    border-right: 1px solid var(--ghost-line);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0 16px;
    overflow: hidden;
}

.sidebar-rules {
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 63px,
        rgba(0, 255, 170, 0.4) 63px,
        rgba(0, 255, 170, 0.4) 64px
    );
    pointer-events: none;
}

.sidebar-mark {
    font-family: var(--font-mono);
    color: var(--cipher-mint);
    font-size: 14px;
    letter-spacing: 0.1em;
    z-index: 1;
    margin-bottom: 24px;
    opacity: 0.7;
}

.glyph-stack {
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-items: center;
    z-index: 1;
    margin-top: 16px;
}

.glyph {
    position: relative;
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 16px;
    color: var(--ghost-line);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    transition: color 300ms ease, text-shadow 300ms ease, border-color 300ms ease;
    cursor: none;
}

.glyph::after {
    content: '';
    position: absolute;
    inset: 50%;
    border: 1px solid var(--cipher-mint);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
}

.glyph:hover::after {
    animation: pulseRing 500ms ease-out forwards;
}

@keyframes pulseRing {
    0% { inset: 50%; opacity: 0.8; }
    100% { inset: -22px; opacity: 0; }
}

.glyph.active {
    color: var(--cipher-mint);
    text-shadow: 0 0 12px rgba(0, 255, 170, 0.7);
    border-color: rgba(0, 255, 170, 0.3);
}

.glyph-tail { color: rgba(255, 45, 123, 0.4); }
.glyph-tail.active { color: var(--pulse-magenta); text-shadow: 0 0 12px rgba(255, 45, 123, 0.7); border-color: rgba(255, 45, 123, 0.4); }

.data-readout {
    margin-top: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(0, 255, 170, 0.5);
    text-align: center;
    line-height: 1.7;
    z-index: 1;
}
.data-line { white-space: nowrap; }

/* ===== Main Content ===== */
.content {
    margin-left: var(--sidebar-width);
    position: relative;
    z-index: 2;
}

.panel {
    position: relative;
    min-height: 100vh;
    padding: clamp(48px, 8vh, 120px) clamp(32px, 6vw, 96px);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.panel + .panel { border-top: 1px solid var(--ghost-line); }

.panel-reveal { background: var(--deep-indigo); }
.panel-converge { background: var(--void-black); }

/* ===== Corner Brackets ===== */
.bracket {
    position: absolute;
    width: 16px; height: 16px;
    pointer-events: none;
}
.bracket-tl { top: 24px; left: 24px; border-top: 1px solid var(--cipher-mint); border-left: 1px solid var(--cipher-mint); }
.bracket-br { bottom: 24px; right: 24px; border-bottom: 1px solid var(--cipher-mint); border-right: 1px solid var(--cipher-mint); }

.panel:not(.in-view) .bracket { clip-path: inset(0 100% 100% 0); }
.panel.in-view .bracket {
    clip-path: inset(0 0 0 0);
    transition: clip-path 400ms var(--ease-hud);
}

/* ===== Typography ===== */
.kicker {
    color: var(--cipher-mint);
    font-size: 13px;
    font-family: var(--font-mono);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 32px;
    opacity: 0.85;
}

.mono { font-family: var(--font-mono); font-weight: 400; font-size: 13px; letter-spacing: 0.05em; }
.mono-large { font-size: 15px; color: var(--cipher-mint); }

.hero-headline,
.section-headline,
.converge-headline {
    font-family: var(--font-display);
    font-weight: 400;
    color: var(--pure-white);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 0.95;
}

.hero-headline {
    font-size: clamp(4rem, 12vw, 10rem);
    margin-bottom: 32px;
}

.section-headline {
    font-size: clamp(2.5rem, 6vw, 5.5rem);
    margin-bottom: 48px;
}

.converge-headline {
    font-size: clamp(3rem, 8vw, 7rem);
    margin: 24px 0 40px;
    color: var(--pure-white);
}

/* ===== Panel 1: Hero ===== */
.panel-hero { padding-top: 120px; }

.hero-grid {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: clamp(32px, 6vw, 96px);
    align-items: center;
    flex: 1;
}

.hero-cipher {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wireframe-r {
    position: relative;
    width: 70%;
    height: 70%;
    z-index: 2;
    filter: drop-shadow(0 0 16px rgba(0, 255, 170, 0.4));
}
.wireframe-r path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
}
.panel-hero.in-view .wireframe-r path {
    animation: drawR 2s var(--ease-hud) forwards;
}
.panel-hero.in-view .wireframe-r path:nth-child(2) { animation-delay: 400ms; }

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

.orbit-rings {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.ring {
    position: absolute;
    inset: -10%;
    transform-origin: center;
}
.ring-1 { animation: spin 20s linear infinite; }
.ring-2 { animation: spin 35s linear infinite reverse; }
.ring-3 { animation: spin 50s linear infinite; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hero-text { position: relative; }
.hero-tagline {
    font-family: var(--font-mono);
    color: var(--moon-silver);
    font-size: 16px;
    letter-spacing: 0.04em;
    margin-bottom: 32px;
    min-height: 1.75em;
    position: relative;
    display: inline-block;
}
.hero-tagline.typing::after,
.typewriter-active::after {
    content: '';
    display: inline-block;
    width: 0.6ch;
    height: 1em;
    background: var(--signal-yellow);
    margin-left: 4px;
    vertical-align: -2px;
    animation: blink 530ms steps(2) infinite;
    box-shadow: 0 0 8px rgba(245, 230, 66, 0.5);
}
.typewriter-done::after {
    content: '';
    display: inline-block;
    width: 0.6ch; height: 1em;
    background: var(--signal-yellow);
    margin-left: 4px;
    vertical-align: -2px;
    animation: blink 530ms steps(2) 3, fadeOut 600ms ease 1590ms forwards;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}
@keyframes fadeOut {
    to { opacity: 0; transform: scaleY(0); }
}

.hero-meta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: rgba(0, 255, 170, 0.7);
}

.dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.dot-mint { background: var(--cipher-mint); box-shadow: 0 0 8px var(--cipher-mint); animation: pulseDot 3s ease-in-out infinite; }
.dot-magenta { background: var(--pulse-magenta); box-shadow: 0 0 8px var(--pulse-magenta); animation: pulseDot 3s ease-in-out infinite 1s; }
.dot-yellow { background: var(--signal-yellow); box-shadow: 0 0 8px var(--signal-yellow); animation: pulseDot 3s ease-in-out infinite 0.5s; }

@keyframes pulseDot {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.3); }
}

.scroll-cue {
    position: absolute;
    bottom: 32px; left: 50%;
    transform: translateX(-50%);
    color: rgba(200, 200, 208, 0.5);
    display: flex; flex-direction: column; align-items: center;
    gap: 6px;
    font-size: 11px;
    letter-spacing: 0.3em;
}
.scroll-arrow {
    animation: bob 2s ease-in-out infinite;
    color: var(--cipher-mint);
}
@keyframes bob {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* ===== Panel 2: Reveal ===== */
.reveal-grid {
    display: grid;
    grid-template-columns: 60% 40%;
    gap: clamp(40px, 5vw, 80px);
    align-items: start;
}

.reveal-left { padding-right: 24px; }

.text-block {
    margin-bottom: 48px;
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 600ms var(--ease-hud), transform 600ms var(--ease-hud);
}
.panel-reveal.in-view .text-block {
    opacity: 1;
    transform: translateX(0);
}
.panel-reveal.in-view .text-block:nth-child(1) { transition-delay: 80ms; }
.panel-reveal.in-view .text-block:nth-child(2) { transition-delay: 160ms; }
.panel-reveal.in-view .text-block:nth-child(3) { transition-delay: 240ms; }
.panel-reveal.in-view .text-block:nth-child(4) { transition-delay: 320ms; }
.panel-reveal.in-view .text-block:nth-child(5) { transition-delay: 400ms; }
.panel-reveal.in-view .text-block:nth-child(6) { transition-delay: 480ms; }

.text-block p { max-width: 55ch; }

.ledger {
    list-style: none;
    border-top: 1px solid var(--ghost-line);
    padding-top: 24px;
}
.ledger li {
    display: flex;
    align-items: baseline;
    gap: 24px;
    padding: 12px 0;
    border-bottom: 1px solid var(--ghost-line);
}
.ledger-key {
    color: var(--cipher-mint);
    font-size: 12px;
    letter-spacing: 0.15em;
    flex: 0 0 32px;
}
.ledger-val { color: var(--moon-silver); font-size: 17px; font-weight: 300; }
.ledger li:hover .ledger-val { color: var(--pure-white); }
.ledger li:hover .ledger-key { color: var(--pulse-magenta); transition: color 200ms; }

.reveal-right {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.rotating-shape {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
}
.rotating-shape svg { width: 100%; height: 100%; }
.rotating-shape .shape-group {
    transform-origin: 150px 150px;
    animation: spin 30s linear infinite;
}

.shape-caption {
    margin-top: 16px;
    color: rgba(0, 255, 170, 0.5);
    font-size: 11px;
    letter-spacing: 0.15em;
}

/* ===== Panel 3: Grid Fragment ===== */
.grid-header { margin-bottom: 56px; max-width: 720px; }
.grid-intro { color: var(--moon-silver); max-width: 60ch; }

.fragment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(180px, 1fr);
    gap: 2px;
    background: var(--ghost-line);
    border: 1px solid var(--ghost-line);
    max-width: 880px;
}

.cell {
    position: relative;
    background: var(--void-black);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: border-color 150ms ease;
    overflow: hidden;
    transform: scale(0);
    opacity: 0;
}

.panel-grid.in-view .cell { animation: cellIn 500ms var(--ease-pop) forwards; }
.panel-grid.in-view .cell[data-cell="4"] { animation-delay: 0ms; }
.panel-grid.in-view .cell[data-cell="1"] { animation-delay: 150ms; }
.panel-grid.in-view .cell[data-cell="3"] { animation-delay: 150ms; }
.panel-grid.in-view .cell[data-cell="5"] { animation-delay: 150ms; }
.panel-grid.in-view .cell[data-cell="7"] { animation-delay: 150ms; }
.panel-grid.in-view .cell[data-cell="0"] { animation-delay: 300ms; }
.panel-grid.in-view .cell[data-cell="2"] { animation-delay: 300ms; }
.panel-grid.in-view .cell[data-cell="6"] { animation-delay: 300ms; }
.panel-grid.in-view .cell[data-cell="8"] { animation-delay: 300ms; }

@keyframes cellIn {
    to { transform: scale(1); opacity: 1; }
}

.cell-filled:hover {
    outline: 1px solid var(--pulse-magenta);
    outline-offset: -1px;
}

.cell-index {
    color: var(--cipher-mint);
    font-size: 11px;
    letter-spacing: 0.2em;
    opacity: 0.7;
}

.cell-glyph {
    font-family: var(--font-display);
    font-size: clamp(3rem, 6vw, 5rem);
    color: var(--pure-white);
    text-align: center;
    line-height: 1;
    letter-spacing: 0;
}

.cell-center .cell-glyph { color: var(--signal-yellow); text-shadow: 0 0 24px rgba(245, 230, 66, 0.5); }

.cell-label {
    color: var(--moon-silver);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.7;
    text-align: right;
}

.cell-empty {
    background: var(--void-black);
    position: relative;
}
.empty-pulse {
    position: absolute;
    top: 50%; left: 50%;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--cipher-mint);
    transform: translate(-50%, -50%);
    opacity: 0.2;
    box-shadow: 0 0 12px rgba(0, 255, 170, 0.4);
    animation: pulseDim 3s ease-in-out infinite;
}
.cell-empty:nth-child(2) .empty-pulse { animation-delay: 0.5s; }
.cell-empty:nth-child(4) .empty-pulse { animation-delay: 1s; }
.cell-empty:nth-child(6) .empty-pulse { animation-delay: 1.5s; }
.cell-empty:nth-child(8) .empty-pulse { animation-delay: 2s; }

@keyframes pulseDim {
    0%, 100% { opacity: 0.15; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.7; transform: translate(-50%, -50%) scale(1.6); }
}

.grid-footnote {
    margin-top: 32px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: rgba(255, 45, 123, 0.7);
}

/* ===== Panel 4: Convergence ===== */
.panel-converge {
    align-items: center;
    text-align: center;
}

.converge-column {
    max-width: 540px;
    width: 100%;
    margin: 0 auto;
    opacity: 0;
    transition: opacity 1.2s ease;
}
.panel-converge.in-view .converge-column { opacity: 1; }

.converge-body {
    color: var(--moon-silver);
    margin-bottom: 32px;
    font-size: 18px;
}
.converge-body.mono-large { color: var(--cipher-mint); margin-top: 24px; }

.signoff {
    margin-top: 56px;
    color: rgba(245, 230, 66, 0.7);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    letter-spacing: 0.15em;
    font-size: 11px;
}

/* ===== Typewriter cursor on data-typewriter elements ===== */
[data-typewriter], [data-typewriter-2], [data-typewriter-3] {
    display: inline-block;
    min-height: 1.6em;
    word-break: break-word;
}
.tw-cursor::after {
    content: '';
    display: inline-block;
    width: 0.5ch;
    height: 1em;
    background: var(--signal-yellow);
    margin-left: 3px;
    vertical-align: -2px;
    box-shadow: 0 0 8px rgba(245, 230, 66, 0.6);
    animation: blink 530ms steps(2) infinite;
}
.tw-finishing::after {
    animation: blink 530ms steps(2) 3, fadeCursor 600ms ease 1590ms forwards;
}
@keyframes fadeCursor {
    to { opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .hero-grid, .reveal-grid {
        grid-template-columns: 1fr;
        gap: 48px;
    }
    .reveal-right { max-width: 320px; }
    .fragment-grid { grid-auto-rows: minmax(140px, 1fr); }
    .cell-glyph { font-size: 2.5rem; }
    .panel { padding: 64px 24px; }
}

@media (max-width: 600px) {
    :root { --sidebar-width: 56px; }
    html, body { cursor: auto; }
    .reticle { display: none; }
    .glyph { font-size: 14px; width: 28px; height: 28px; }
    .data-readout { font-size: 9px; }
    .bracket-tl { top: 12px; left: 12px; }
    .bracket-br { bottom: 12px; right: 12px; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .text-block { opacity: 1 !important; transform: none !important; }
    .cell { opacity: 1 !important; transform: scale(1) !important; }
    .converge-column { opacity: 1 !important; }
    .wireframe-r path { stroke-dashoffset: 0 !important; }
}
