/* ==========================================================================
   thefirst.quest — Retro-futuristic Hero's Journey
   Palette: #C4B8A0 #E8C547 #A89080 #9E4A4A #2A1F10 #6B9E7A #8B4A6B #4A7A9E
   Fonts: Press Start 2P, Chakra Petch, Share Tech Mono, Spectral
   ========================================================================== */

:root {
    --abyss: #1A1422;
    --dungeon: #2A1F10;
    --leather: #322818;
    --gold: #E8C547;
    --parchment: #C4B8A0;
    --aged-scroll: #A89080;
    --forest: #6B9E7A;
    --potion: #8B4A6B;
    --steel: #4A7A9E;
    --damage: #9E4A4A;

    --shadow-pixel: 3px 3px 0 #1A1422;
    --shadow-pixel-lg: 4px 4px 0 #1A1422;

    --diag-cut: clip-path: polygon(0 0, 100% 6vh, 100% 100%, 0 calc(100% - 6vh));
}

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

html {
    scroll-behavior: smooth;
    background: var(--abyss);
}

body {
    font-family: "Chakra Petch", system-ui, sans-serif;
    color: var(--parchment);
    background: var(--abyss);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    image-rendering: pixelated;
}

/* Force crisp pixels for SVG icons */
.pix-icon, .pix-icon-large, .torch-svg {
    shape-rendering: crispEdges;
}

/* ==========================================================================
   Star Field — twinkling background dots
   ========================================================================== */

.starfield {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-color: transparent;
    background-image:
        radial-gradient(1px 1px at 12% 18%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 28% 62%, #C4B8A0 50%, transparent 51%),
        radial-gradient(1px 1px at 47% 8%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 63% 41%, #A89080 50%, transparent 51%),
        radial-gradient(2px 2px at 78% 82%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 88% 23%, #C4B8A0 50%, transparent 51%),
        radial-gradient(1px 1px at 33% 91%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 7% 78%, #A89080 50%, transparent 51%),
        radial-gradient(2px 2px at 56% 76%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 91% 56%, #C4B8A0 50%, transparent 51%),
        radial-gradient(1px 1px at 19% 39%, #E8C547 50%, transparent 51%),
        radial-gradient(1px 1px at 73% 14%, #A89080 50%, transparent 51%);
    background-size: 100% 100%;
    animation: twinkle 4s ease-in-out infinite;
    opacity: 0.55;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 0.85; }
}

/* ==========================================================================
   Quest Sidebar
   ========================================================================== */

.quest-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 64px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.sidebar-rail,
.sidebar-rail-fill {
    position: absolute;
    left: 50%;
    top: 12%;
    bottom: 12%;
    width: 2px;
    transform: translateX(-50%);
}

.sidebar-rail {
    background: var(--steel);
    opacity: 0.35;
}

.sidebar-rail-fill {
    background: var(--gold);
    height: 0%;
    box-shadow: 0 0 6px var(--gold), 0 0 14px rgba(232, 197, 71, 0.3);
    transition: height 250ms ease-out;
    bottom: auto;
    top: 12%;
}

.quest-icons {
    list-style: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 76%;
    position: relative;
    z-index: 2;
}

.quest-icon {
    width: 40px;
    height: 40px;
    background: var(--abyss);
    border: 2px solid var(--steel);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--steel);
    pointer-events: auto;
    cursor: pointer;
    position: relative;
    transition: border-color 400ms ease, background-color 400ms ease, transform 250ms ease;
}

.quest-icon .pix-icon {
    width: 22px;
    height: 22px;
    fill: var(--steel);
    transition: fill 400ms ease, filter 400ms ease;
}

.quest-icon .pix-icon .inner {
    fill: var(--abyss);
}

.quest-icon .icon-label {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-family: "Share Tech Mono", monospace;
    font-size: 10px;
    color: var(--steel);
    letter-spacing: 1px;
    transition: color 400ms ease;
}

.quest-icon.active {
    border-color: var(--gold);
    background: #2a1f10;
    transform: scale(1.08);
    filter: drop-shadow(0 0 6px rgba(232, 197, 71, 0.5));
}

.quest-icon.active .pix-icon {
    fill: var(--gold);
}

.quest-icon.active .icon-label {
    color: var(--gold);
}

.quest-icon:hover {
    transform: scale(1.12);
}

/* ==========================================================================
   Main scroll container & generic stage
   ========================================================================== */

.quest-scroll {
    position: relative;
    z-index: 1;
    padding-left: 64px;
}

.stage {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.stage-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.stage-content {
    position: relative;
    z-index: 3;
    max-width: 1100px;
    margin: 0 auto;
    padding: 14vh 6vw;
}

/* Stage marker (Share Tech Mono labels) */
.stage-marker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: "Share Tech Mono", "Courier New", monospace;
    color: var(--forest);
    font-size: 13px;
    line-height: 1.5;
    letter-spacing: 2px;
    margin-bottom: 32px;
}

.stage-marker .stage-number {
    color: var(--forest);
    text-transform: uppercase;
}

.stage-marker .stage-name {
    color: var(--parchment);
    font-size: 13px;
    letter-spacing: 3px;
}

.stage-marker-light .stage-name {
    color: var(--gold);
}

/* Headings */
.hero-heading,
.stage-heading,
.trial-heading,
.abyss-heading,
.return-heading {
    font-family: "Press Start 2P", "Courier New", monospace;
    font-weight: 400;
    color: var(--gold);
    text-shadow: var(--shadow-pixel);
    line-height: 1.4;
    letter-spacing: 2px;
}

.hero-heading {
    font-size: clamp(28px, 4.6vw, 56px);
    margin-bottom: 32px;
    text-shadow: var(--shadow-pixel-lg);
}

.stage-heading,
.trial-heading,
.abyss-heading,
.return-heading {
    font-size: clamp(24px, 3.4vw, 38px);
    margin-bottom: 28px;
}

.lore-text {
    font-family: "Spectral", "Georgia", serif;
    font-style: italic;
    font-weight: 400;
    color: var(--aged-scroll);
    font-size: clamp(15px, 1.4vw, 18px);
    line-height: 1.7;
    margin-bottom: 24px;
    max-width: 64ch;
}

.col-label,
.status-label,
.ending-label {
    font-family: "Share Tech Mono", monospace;
    color: var(--forest);
    font-size: 13px;
    letter-spacing: 2px;
}

.status-value {
    font-family: "Share Tech Mono", monospace;
    color: var(--gold);
    font-size: 13px;
    letter-spacing: 2px;
}

/* ==========================================================================
   Word reveal mechanic
   ========================================================================== */

.word {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    margin-right: 0.32em;
}

.word.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   Stage 0: The Call
   ========================================================================== */

.stage-call {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.stage-call-bg {
    background:
        radial-gradient(ellipse at center, #2a2238 0%, #1A1422 65%, #0d0816 100%);
}

.stage-call-content {
    text-align: center;
    max-width: 900px;
    padding: 14vh 6vw;
}

.status-block {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid var(--forest);
    padding: 12px 20px;
    margin-top: 32px;
    background: rgba(26, 20, 34, 0.6);
}

.chevron-pulse {
    position: absolute;
    bottom: 4vh;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    animation: chevronPulse 1.6s ease-in-out infinite;
}

.chevron-pulse .pix-icon {
    width: 32px;
    height: 32px;
    fill: var(--gold);
}

@keyframes chevronPulse {
    0%, 100% { transform: translate(-50%, 0); opacity: 0.6; }
    50% { transform: translate(-50%, 8px); opacity: 1; }
}

/* Torches */
.torch {
    position: absolute;
    top: 16vh;
    width: 80px;
    height: 160px;
    z-index: 4;
}

.torch-left { left: clamp(80px, 10vw, 14vw); }
.torch-right { right: clamp(20px, 6vw, 10vw); }

.torch-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
    filter: drop-shadow(0 0 18px rgba(232, 197, 71, 0.4));
}

/* CSS-only sprite cycle: 4 frames at ~8fps (480ms total) */
.flame {
    opacity: 0;
    animation: flicker 0.48s steps(1) infinite;
}

.flame-1 { animation-delay: 0s; }
.flame-2 { animation-delay: 0.12s; }
.flame-3 { animation-delay: 0.24s; }
.flame-4 { animation-delay: 0.36s; }

@keyframes flicker {
    0%   { opacity: 1; }
    24.9%{ opacity: 1; }
    25%  { opacity: 0; }
    100% { opacity: 0; }
}

/* Terrain layers */
.terrain {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    pointer-events: none;
    z-index: 1;
    will-change: transform;
}

.terrain svg {
    display: block;
    width: 100%;
}

.terrain-back  { height: 32vh; opacity: 0.7; }
.terrain-mid   { height: 22vh; opacity: 0.85; }
.terrain-front { height: 14vh; opacity: 1; }

/* ==========================================================================
   Stage 1: The Threshold (diagonal split)
   ========================================================================== */

.stage-threshold {
    min-height: 100vh;
    margin-top: -6vh;
    clip-path: polygon(0 6vh, 100% 0, 100% calc(100% - 6vh), 0 100%);
    padding: 6vh 0;
}

.threshold-dark {
    background: linear-gradient(115deg, #1A1422 0%, #1A1422 49%, transparent 49.5%, transparent 100%);
    z-index: 0;
}

.threshold-amber {
    background: linear-gradient(115deg, transparent 0%, transparent 49.5%, #2A1F10 50%, #322818 100%);
    z-index: 1;
}

.stage-threshold-content {
    position: relative;
    z-index: 3;
    padding: 18vh 6vw 14vh;
}

.dual-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin: 32px 0;
    border-top: 1px solid var(--forest);
    border-bottom: 1px solid var(--forest);
    padding: 28px 0;
}

.dual-col {
    padding: 16px 20px;
    border-left: 2px solid;
}

.col-dark {
    border-color: var(--steel);
}

.col-dark .col-label { color: var(--steel); }

.col-amber {
    border-color: var(--gold);
}

.col-amber .col-label { color: var(--gold); }

.threshold-prose {
    margin-top: 32px;
    max-width: 70ch;
}

.terrain-castle {
    position: absolute;
    bottom: 6vh;
    left: 0;
    right: 0;
    height: 22vh;
    z-index: 2;
    opacity: 0.85;
}

/* ==========================================================================
   Stage 2: The Trials (zigzag — alternating diagonals)
   ========================================================================== */

.stage-trials {
    margin-top: -6vh;
    position: relative;
}

.trial {
    position: relative;
    min-height: 80vh;
    overflow: hidden;
    padding: 14vh 0;
}

.trial:nth-child(1) {
    clip-path: polygon(0 0, 100% 6vh, 100% 100%, 0 calc(100% - 6vh));
    margin-bottom: -6vh;
}

.trial:nth-child(2) {
    clip-path: polygon(0 6vh, 100% 0, 100% calc(100% - 6vh), 0 100%);
    margin-bottom: -6vh;
}

.trial:nth-child(3) {
    clip-path: polygon(0 0, 100% 6vh, 100% 100%, 0 calc(100% - 6vh));
    margin-bottom: -6vh;
}

.trial-purple-bg {
    background:
        radial-gradient(ellipse at 30% 40%, #3a2240 0%, #2a1830 60%, #1A1422 100%);
}

.trial-purple .trial-heading,
.trial-purple .stage-marker .stage-name {
    color: var(--potion);
    text-shadow: 3px 3px 0 #1A1422;
}

.trial-purple .stage-marker .stage-number {
    color: var(--potion);
}

.trial-green-bg {
    background:
        radial-gradient(ellipse at 70% 50%, #1a3a2a 0%, #102218 60%, #0a1810 100%);
}

.trial-green .trial-heading,
.trial-green .stage-marker .stage-name {
    color: var(--forest);
    text-shadow: 3px 3px 0 #0a1810;
}

.trial-green .stage-marker .stage-number {
    color: var(--forest);
}

.trial-gold-bg {
    background:
        linear-gradient(160deg, #322818 0%, #2A1F10 50%, #1a1208 100%);
}

.trial-gold .trial-heading,
.trial-gold .stage-marker .stage-name {
    color: var(--gold);
}

.trial-content {
    position: relative;
    z-index: 3;
    max-width: 720px;
    margin-left: 8vw;
    padding: 4vh 0;
}

.trial-content-right {
    margin-left: auto;
    margin-right: 8vw;
    text-align: right;
}

.trial-content-right .lore-text {
    margin-left: auto;
}

.trial-content-right .trial-body {
    flex-direction: row-reverse;
}

.trial-body {
    display: flex;
    align-items: flex-start;
    gap: 32px;
    margin-top: 16px;
}

.trial-icon {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    fill: var(--gold);
    filter: drop-shadow(0 0 6px rgba(232, 197, 71, 0.35));
}

.trial-purple .trial-icon { fill: var(--potion); }
.trial-purple .trial-icon .inner { fill: #1A1422; }
.trial-green .trial-icon { fill: var(--forest); }
.trial-green .trial-icon .inner { fill: #0a1810; }
.trial-gold .trial-icon { fill: var(--gold); }
.trial-gold .trial-icon .inner { fill: #1a1208; }

/* ==========================================================================
   Stage 3: The Abyss
   ========================================================================== */

.stage-abyss {
    margin-top: -6vh;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24vh 0;
    position: relative;
}

.stage-abyss-bg {
    background:
        radial-gradient(ellipse at center, #0d0816 0%, #050208 100%);
}

.abyss-band {
    position: relative;
    z-index: 3;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 4vh 6vw;
    text-align: center;
    border-top: 1px solid var(--damage);
    border-bottom: 1px solid var(--damage);
    background: rgba(20, 8, 22, 0.5);
}

.abyss-heading {
    color: var(--damage);
    text-shadow: 3px 3px 0 #050208;
    margin-bottom: 24px;
    letter-spacing: 8px;
}

.abyss-lore {
    color: var(--aged-scroll);
    margin: 0 auto 24px;
    max-width: 56ch;
}

.abyss-glyph {
    width: 48px;
    height: 48px;
    margin: 16px auto 0;
}

.abyss-glyph .pix-icon {
    width: 100%;
    height: 100%;
    fill: var(--damage);
    animation: glyphPulse 2.4s ease-in-out infinite;
}

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

/* ==========================================================================
   Stage 4: The Return
   ========================================================================== */

.stage-return {
    margin-top: -6vh;
    min-height: 110vh;
    clip-path: polygon(0 6vh, 100% 0, 100% 100%, 0 100%);
    position: relative;
    padding: 12vh 0;
    display: flex;
    align-items: center;
}

.stage-return-bg {
    background:
        radial-gradient(ellipse at 50% 80%, #E8C547 0%, #c79835 18%, #6e4a18 38%, #322818 60%, #1A1422 100%);
}

.terrain-sunrise {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 22vh;
    z-index: 2;
    opacity: 0.95;
}

.stage-return-content {
    position: relative;
    z-index: 3;
    max-width: 900px;
    margin: 0 auto;
    padding: 10vh 6vw 6vh;
    text-align: center;
}

.return-heading {
    margin-bottom: 24px;
    letter-spacing: 4px;
}

.return-lore {
    color: var(--parchment);
    margin: 0 auto 32px;
    max-width: 60ch;
}

.return-status {
    display: inline-flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    border: 1px solid var(--gold);
    padding: 16px 24px;
    margin-bottom: 36px;
    background: rgba(26, 20, 34, 0.55);
}

.status-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 16px;
    align-items: center;
}

.return-sigil {
    width: 96px;
    height: 96px;
    margin: 24px auto;
    animation: sigilSpin 18s linear infinite;
}

.return-sigil .pix-icon-large {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 12px rgba(232, 197, 71, 0.7));
}

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

.ending-glyph {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--gold);
}

.ending-mark {
    font-family: "Press Start 2P", monospace;
    font-size: 12px;
    color: var(--gold);
    letter-spacing: 3px;
    text-shadow: var(--shadow-pixel);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .quest-sidebar { width: 48px; }
    .quest-scroll { padding-left: 48px; }
    .quest-icon { width: 32px; height: 32px; }
    .quest-icon .pix-icon { width: 18px; height: 18px; }

    .torch { width: 56px; height: 110px; }
    .torch-left { left: clamp(54px, 6vw, 60px); }

    .dual-column {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .trial-content,
    .trial-content-right {
        margin-left: 6vw;
        margin-right: 6vw;
        text-align: left;
    }

    .trial-content-right .lore-text { margin-left: 0; }

    .trial-content-right .trial-body {
        flex-direction: row;
    }

    .status-row {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .stage-content { padding: 12vh 6vw; }
}

@media (max-width: 480px) {
    .hero-heading { font-size: 22px; }
    .stage-heading,
    .trial-heading,
    .abyss-heading,
    .return-heading {
        font-size: 18px;
    }
    .torch { display: none; }
}
