/* ============================================================
   RRIDDL.com -- a cyberpunk scriptorium
   palette, type and motion drawn from DESIGN.md
   ============================================================ */

:root {
    --soot-vellum: #1a120b;
    --ember-slate: #2a1d12;
    --burnt-orange: #cc5803;
    --marigold: #f49b42;
    --phos-magenta: #e63991;
    --phos-cyan: #3ad6c4;
    --aged-paper: #f0e3cf;
    --faded-ink: #a08365;
    --mica-pale: #d9c4a3;
    --abyss: #0d0805;

    --font-display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
    --font-sc: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;

    --col-spine: 220px;
    --row-top: 220px;
    --row-mid: 480px;

    --line: rgba(204, 88, 3, 0.55);
    --line-faint: rgba(204, 88, 3, 0.22);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--soot-vellum);
    color: var(--aged-paper);
    font-family: var(--font-display);
    font-size: 16px;
    line-height: 1.55;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'><polygon points='10,1 19,10 10,19 1,10' fill='none' stroke='%23d9c4a3' stroke-width='1.2'/><circle cx='10' cy='10' r='1.2' fill='%23cc5803'/></svg>") 10 10, crosshair;
}

/* ---------- layered background ---------- */

.bg-vellum,
.bg-noise,
.bg-lattice,
.bg-vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.bg-vellum {
    background:
        radial-gradient(120% 80% at 50% 0%, #20160d 0%, var(--soot-vellum) 60%, var(--abyss) 100%);
}

.bg-noise {
    width: 100%;
    height: 100%;
    opacity: 0.08;
    mix-blend-mode: overlay;
}

.bg-lattice {
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='70' viewBox='0 0 80 70'><g fill='none' stroke='%23cc5803' stroke-width='0.6' opacity='0.55'><path d='M0 35 L20 0 L60 0 L80 35 L60 70 L20 70 Z'/><path d='M20 0 L40 35 L20 70'/><path d='M60 0 L40 35 L60 70'/><path d='M0 35 L80 35'/></g></svg>");
    background-size: 80px 70px;
    opacity: 0.06;
    animation: lattice-drift 8s linear infinite;
}

.bg-vignette {
    background:
        radial-gradient(120% 100% at 50% 50%, transparent 40%, rgba(13,8,5,0.55) 80%, var(--abyss) 100%);
}

@keyframes lattice-drift {
    0%   { background-position: 0 0; }
    100% { background-position: 80px 70px; }
}

/* ---------- glyph debris + cursor trail layers ---------- */

.glyph-debris,
.cursor-trail {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 60;
    overflow: hidden;
}

.glyph-debris span {
    position: absolute;
    font-family: var(--font-sc);
    font-size: 11px;
    color: var(--faded-ink);
    letter-spacing: 0.2em;
    opacity: 0;
    text-transform: uppercase;
    will-change: transform, opacity;
    animation: glyph-drift 14s linear forwards;
}

@keyframes glyph-drift {
    0%   { opacity: 0; transform: translateY(0) translateX(0); }
    15%  { opacity: 0.6; }
    50%  { opacity: 0.5; }
    85%  { opacity: 0.25; }
    100% { opacity: 0; transform: translateY(-90px) translateX(40px); }
}

.cursor-trail span {
    position: absolute;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 18px;
    color: var(--mica-pale);
    pointer-events: none;
    transform: translate(-50%, -50%);
    will-change: transform, opacity;
    animation: quill-fade 320ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes quill-fade {
    0%   { opacity: 0.7; transform: translate(-50%, -50%) translateY(0) rotate(-3deg); }
    100% { opacity: 0;   transform: translate(-50%, -50%) translateY(-12px) rotate(2deg); }
}

/* ---------- F-pattern frame ---------- */

.frame {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: var(--col-spine) 1fr 1fr;
    grid-template-rows: var(--row-top) var(--row-mid) auto auto;
    grid-template-areas:
        "spine beam-top  beam-top"
        "spine beam-mid  beam-mid"
        "spine cascade   ."
        "spine cipher    cipher";
    min-height: 100vh;
    border-left: 1px solid var(--line);
}

/* ---------- spine ---------- */

.spine {
    grid-area: spine;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    border-right: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(42,29,18,0.7) 0%, rgba(26,18,11,0.4) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 0 20px;
}

.spine-mark {
    width: 48px;
    height: 48px;
    margin-bottom: 36px;
}

.spine-sigil { width: 100%; height: 100%; display: block; }

.spine-list {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.spine-item {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--line-faint);
    cursor: pointer;
    transition: background 240ms ease, color 240ms ease;
}

.spine-item:last-child { border-bottom: 1px solid var(--line-faint); }

.spine-item span {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-family: var(--font-sc);
    font-size: 12px;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--mica-pale);
    transition: color 220ms ease, transform 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.spine-item::before {
    content: "";
    position: absolute;
    left: 100%;
    top: 50%;
    width: 0;
    height: 1px;
    background: var(--burnt-orange);
    transition: width 360ms cubic-bezier(0.65, 0, 0.35, 1);
    pointer-events: none;
    box-shadow: 0 0 10px rgba(204, 88, 3, 0.4);
}

.spine-item:hover span,
.spine-item.is-active span {
    color: var(--burnt-orange);
}

.spine-item:hover::before,
.spine-item.is-active::before {
    width: min(380px, 30vw);
}

.spine-foot {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--faded-ink);
}

.spine-time {
    color: var(--marigold);
}

/* ---------- top beam ---------- */

.beam-top {
    grid-area: beam-top;
    position: relative;
    border-bottom: 2px solid var(--burnt-orange);
    padding: 28px 60px 28px 36px;
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 24px;
    align-items: center;
    background:
        linear-gradient(180deg, rgba(42,29,18,0.45), rgba(26,18,11,0.0));
}

.beam-top::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 8px;
    height: 100%;
    background: linear-gradient(180deg, var(--burnt-orange), transparent 90%);
}

.beam-top-inner {
    min-width: 0;
}

.rotd-eyebrow {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--marigold);
}

.eyebrow-divider {
    font-family: var(--font-mono);
    color: var(--burnt-orange);
    font-size: 13px;
    letter-spacing: 0.04em;
}

.hero-riddle {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2.1rem, 4.4vw, 4rem);
    line-height: 1.05;
    margin: 0;
    letter-spacing: -0.01em;
    color: var(--aged-paper);
    min-height: 1.2em;
}

.hero-typewriter .ch {
    display: inline-block;
    white-space: pre;
    color: var(--phos-magenta);
    font-family: var(--font-mono);
    font-style: normal;
    font-size: 0.7em;
    letter-spacing: 0.04em;
    opacity: 0;
    transform: translateY(2px);
    transition:
        color 200ms ease,
        font-family 0ms 200ms,
        font-style 0ms 200ms,
        font-size 280ms cubic-bezier(0.65, 0, 0.35, 1),
        letter-spacing 280ms ease,
        opacity 220ms ease,
        transform 280ms cubic-bezier(0.65, 0, 0.35, 1);
}

.hero-typewriter .ch.is-shown {
    opacity: 1;
    transform: translateY(0);
}

.hero-typewriter .ch.is-resolved {
    color: var(--aged-paper);
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1em;
    letter-spacing: -0.01em;
}

.rotd-meta {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--faded-ink);
}

.ts-label {
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.ts {
    color: var(--mica-pale);
    text-shadow: -1px 0 var(--phos-magenta), 1px 0 var(--phos-cyan);
}

.rotd-crystal {
    width: 200px;
    height: 200px;
    perspective: 1000px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotd-crystal .crystal-svg {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: center;
    will-change: transform;
}

.rotd-rsigil {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 44px;
    height: 44px;
    opacity: 0.85;
}

.rotd-rsigil .rsigil { width: 100%; height: 100%; }

/* ---------- middle beam: triptych ---------- */

.beam-mid {
    grid-area: beam-mid;
    position: relative;
    border-bottom: 2px solid var(--burnt-orange);
    padding: 36px 48px 36px 36px;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(42,29,18,0.3), rgba(26,18,11,0.0));
}

.beam-mid::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, transparent, var(--burnt-orange) 50%, transparent);
}

.rsigil-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 260px;
    height: 260px;
    transform: translate(-50%, -50%);
    opacity: 0.08;
    pointer-events: none;
    transition: opacity 1.2s ease, filter 1.2s ease;
}

.rsigil-watermark svg { width: 100%; height: 100%; }

.rsigil-watermark.is-glowing {
    opacity: 0.42;
    filter: drop-shadow(0 0 18px var(--marigold)) drop-shadow(0 0 32px var(--burnt-orange));
}

.triptych {
    position: relative;
    z-index: 1;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 24px;
    align-items: stretch;
}

.triptych-cell {
    position: relative;
    padding: 14px 18px;
    border-left: 1px dashed var(--line-faint);
    display: flex;
    flex-direction: column;
}

.triptych-cell:first-child { border-left: none; }

.cell-tag {
    font-family: var(--font-sc);
    font-size: 11px;
    letter-spacing: 0.24em;
    color: var(--faded-ink);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.triptych-illus {
    align-items: center;
    justify-content: center;
}

.triptych-illus .crystal-svg {
    width: 100%;
    max-width: 240px;
    height: auto;
}

.triptych-text {
    justify-content: center;
}

.featured-riddle {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.6rem, 2.6vw, 2.4rem);
    line-height: 1.18;
    margin: 0 0 16px 0;
    color: var(--aged-paper);
}

.featured-clue {
    font-family: var(--font-display);
    font-size: 19px;
    line-height: 1.7;
    color: var(--mica-pale);
    margin: 0 0 18px 0;
}

.featured-byline {
    font-family: var(--font-sc);
    font-size: 12px;
    letter-spacing: 0.22em;
    color: var(--faded-ink);
    margin: 0;
}

.featured-byline em { font-style: italic; }

.triptych-input {
    justify-content: center;
}

.input-label {
    font-family: var(--font-sc);
    font-size: 12px;
    letter-spacing: 0.22em;
    color: var(--marigold);
    text-transform: uppercase;
    display: block;
    margin-bottom: 12px;
}

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    padding: 6px 0;
}

.input-prompt {
    font-family: var(--font-mono);
    color: var(--burnt-orange);
    font-size: 16px;
}

.featured-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--aged-paper);
    font-size: 18px;
    padding: 4px 0;
}

.featured-input::placeholder {
    color: var(--faded-ink);
    opacity: 0.7;
    font-style: italic;
}

.input-caret {
    width: 1px;
    height: 18px;
    background: var(--marigold);
    animation: caret-blink 1.05s steps(2) infinite;
}

@keyframes caret-blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

.input-hint {
    margin: 14px 0 0 0;
    font-family: var(--font-sc);
    font-size: 11px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--faded-ink);
}

.input-bracket {
    position: absolute;
    right: 12px;
    top: 30px;
    width: 34px;
    height: 80px;
    opacity: 0.6;
}

.input-bracket svg { width: 100%; height: 100%; }

/* ---------- cascade ---------- */

.cascade {
    grid-area: cascade;
    padding: 56px 24px 56px 36px;
    max-width: 720px;
    width: 100%;
    border-right: 1px dashed var(--line-faint);
}

.cascade-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 36px;
}

.riddle-block {
    position: relative;
    padding: 28px 32px 28px 0;
    border-bottom: 1px solid var(--line-faint);
    display: grid;
    grid-template-columns: 1fr 96px;
    column-gap: 24px;
    align-items: start;
}

.riddle-block-head {
    grid-column: 1 / 2;
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 10px;
}

.riddle-num {
    font-family: var(--font-sc);
    font-size: 12px;
    color: var(--burnt-orange);
    letter-spacing: 0.22em;
}

.riddle-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(1.4rem, 2.2vw, 1.9rem);
    margin: 0;
    color: var(--aged-paper);
    line-height: 1.18;
}

.riddle-clue {
    grid-column: 1 / 2;
    font-family: var(--font-display);
    font-size: 18px;
    line-height: 1.7;
    color: var(--mica-pale);
    margin: 0;
}

.riddle-sigil {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    width: 96px;
    height: 96px;
    align-self: center;
}

.riddle-sigil .crystal-svg { width: 100%; height: 100%; }

.riddle-margin-mark {
    position: absolute;
    left: -28px;
    top: 30px;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--faded-ink);
    font-size: 22px;
    transform: rotate(-8deg);
    opacity: 0.7;
}

/* ---------- cipher footer ---------- */

.cipher {
    grid-area: cipher;
    padding: 60px 36px 80px;
    border-top: 2px solid var(--burnt-orange);
    background: linear-gradient(180deg, rgba(42,29,18,0.0), rgba(13,8,5,0.6));
}

.cipher-inner {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cipher-line {
    margin: 0;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 22px;
    line-height: 1.6;
    color: var(--faded-ink);
    letter-spacing: 0.02em;
}

.cipher-text .cl {
    display: inline-block;
    transition: color 220ms ease, transform 220ms ease;
    white-space: pre;
}

.cipher-text .cl.is-flash {
    color: var(--burnt-orange);
    text-shadow: 0 0 12px rgba(204, 88, 3, 0.45);
    transform: translateY(-1px);
}

.cipher-text .cl.is-resolved {
    color: var(--aged-paper);
}

.cipher-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    border-top: 1px solid var(--line-faint);
    padding-top: 18px;
}

.cipher-label {
    font-family: var(--font-mono);
    color: var(--burnt-orange);
    font-size: 14px;
    letter-spacing: 0.06em;
}

.cipher-input {
    flex: 0 1 240px;
    background: transparent;
    border: none;
    border-bottom: 1px dashed var(--line);
    outline: none;
    font-family: var(--font-mono);
    color: var(--aged-paper);
    font-size: 16px;
    letter-spacing: 0.08em;
    padding: 4px 6px;
    text-transform: uppercase;
}

.cipher-input::placeholder {
    color: var(--faded-ink);
    text-transform: lowercase;
    letter-spacing: 0.04em;
    opacity: 0.6;
}

.cipher-status {
    font-family: var(--font-sc);
    font-size: 11px;
    letter-spacing: 0.24em;
    color: var(--marigold);
    text-transform: uppercase;
}

.cipher-foot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 26px;
    color: var(--faded-ink);
}

.cipher-credit {
    font-family: var(--font-sc);
    font-size: 11px;
    letter-spacing: 0.3em;
    color: var(--faded-ink);
    text-transform: uppercase;
}

/* ---------- chromatic glitch on headings ---------- */

.glitch {
    position: relative;
    text-shadow:
        -1px 0 var(--phos-magenta),
        1px 0 var(--phos-cyan);
    animation: glitch-jitter 7s infinite;
}

@keyframes glitch-jitter {
    0%, 96% {
        text-shadow:
            -1px 0 var(--phos-magenta),
            1px 0 var(--phos-cyan);
        transform: translateX(0);
    }
    96.5% {
        text-shadow:
            -3px 0 var(--phos-magenta),
            3px 0 var(--phos-cyan);
        transform: translateX(-1px);
    }
    97% {
        text-shadow:
            2px 0 var(--phos-magenta),
            -2px 0 var(--phos-cyan);
        transform: translateX(1px);
    }
    98% {
        text-shadow:
            -4px 0 var(--phos-magenta),
            4px 0 var(--phos-cyan);
        transform: translateX(-2px);
    }
    100% {
        text-shadow:
            -1px 0 var(--phos-magenta),
            1px 0 var(--phos-cyan);
        transform: translateX(0);
    }
}

/* slice glitch overlay */

.glitch.is-slice::before,
.glitch.is-slice::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    color: var(--aged-paper);
    pointer-events: none;
    background: var(--soot-vellum);
}

.glitch.is-slice::before {
    clip-path: polygon(0 12%, 100% 12%, 100% 22%, 0 22%);
    transform: translateX(-10px);
    color: var(--phos-magenta);
    background: transparent;
}

.glitch.is-slice::after {
    clip-path: polygon(0 64%, 100% 64%, 100% 72%, 0 72%);
    transform: translateX(8px);
    color: var(--phos-cyan);
    background: transparent;
}

/* ---------- crystal stroke draw-on ---------- */

.crystal-svg path,
.crystal-svg polygon,
.crystal-svg rect {
    stroke-dasharray: var(--len, 800);
    stroke-dashoffset: var(--len, 800);
    transition: stroke-dashoffset 1800ms cubic-bezier(0.65, 0, 0.35, 1);
}

.crystal-svg.is-drawing path,
.crystal-svg.is-drawing polygon,
.crystal-svg.is-drawing rect {
    stroke-dashoffset: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
    .frame {
        grid-template-columns: 56px 1fr;
        grid-template-areas:
            "spine beam-top"
            "spine beam-mid"
            "spine cascade"
            "spine cipher";
        grid-template-rows: auto auto auto auto;
    }
    .spine { padding: 18px 0 12px; }
    .spine-mark { width: 32px; height: 32px; margin-bottom: 18px; }
    .spine-item span { font-size: 10px; letter-spacing: 0.24em; }
    .spine-foot { font-size: 9px; }

    .beam-top { grid-template-columns: 1fr 140px; padding: 22px 22px; }
    .rotd-crystal { width: 130px; height: 130px; }

    .beam-mid { padding: 24px 18px; }
    .triptych { grid-template-columns: 1fr; gap: 18px; }
    .triptych-cell { border-left: none; border-top: 1px dashed var(--line-faint); padding-top: 14px; }
    .triptych-cell:first-child { border-top: none; }

    .cascade { padding: 36px 20px; }
    .riddle-block { grid-template-columns: 1fr 72px; }
    .riddle-sigil { width: 72px; height: 72px; }
    .riddle-margin-mark { left: -14px; }

    .cipher { padding: 36px 20px 60px; }
    .cipher-line { font-size: 18px; }
}

@media (max-width: 600px) {
    .frame {
        grid-template-columns: 44px 1fr;
    }
    .hero-riddle { font-size: clamp(1.6rem, 7vw, 2.4rem); }
    .featured-riddle { font-size: 1.5rem; }
    .rotd-rsigil { width: 32px; height: 32px; top: 10px; right: 10px; }
    .rotd-crystal { display: none; }
    .beam-top { grid-template-columns: 1fr; }
    .cipher-input { flex: 1 1 100%; }
}
