/* ==========================================================================
   haskell.quest -- A journey through Haskell, drawn as a quest map.
   ========================================================================== */

:root {
    /* Palette from DESIGN.md */
    --parchment: #f8f5f0;
    --parchment-warm: #f5f0e5;
    --vellum: #efe9df;
    --dungeon: #1e1b2e;
    --quest-ink: #2d3142;
    --scroll: #e8e4ef;
    --traveler-gray: #7a7989;
    --quest-gold: #f0a830;
    --forest-emerald: #2d936c;
    --arcane-violet: #6c5ce7;
    --torch-red: #e17055;
    --trail-tan: #c4a882;

    /* Typography */
    --font-display: "Fredoka", "Nunito", system-ui, sans-serif;
    --font-body: "Nunito", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;
    --font-ui: "Space Mono", ui-monospace, monospace;

    /* Easing */
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --decel: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--parchment);
    color: var(--quest-ink);
    font-family: var(--font-body);
    line-height: 1.75;
    font-size: clamp(1rem, 1.15vw, 1.08rem);
    -webkit-font-smoothing: antialiased;
}

body {
    overflow-x: hidden;
    background:
        radial-gradient(circle at 18% 12%, rgba(196, 168, 130, 0.10), transparent 40%),
        radial-gradient(circle at 82% 88%, rgba(240, 168, 48, 0.08), transparent 45%),
        var(--parchment);
}

img { max-width: 100%; display: block; }

/* Typography ----------------------------------------------------------------*/

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.1;
    margin: 0 0 0.5em;
}

p { margin: 0 0 1em; }

code, pre {
    font-family: var(--font-mono);
    font-feature-settings: "liga" on, "calt" on;
}

em { font-style: italic; color: var(--quest-ink); }

/* Persistent quest log sidebar ---------------------------------------------*/

.quest-log {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 100vh;
    padding: 28px 22px;
    background: rgba(30, 27, 46, 0.96);
    color: var(--scroll);
    z-index: 50;
    display: none;
    flex-direction: column;
    border-right: 2px solid var(--trail-tan);
    backdrop-filter: blur(6px);
}

@media (min-width: 1200px) {
    .quest-log { display: flex; }
    main.quest { padding-left: 220px; }
}

.quest-log-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 16px;
    border-bottom: 1px dashed rgba(196, 168, 130, 0.5);
    color: var(--trail-tan);
}

.compass-icon { color: var(--quest-gold); display: inline-flex; }

.quest-log-title {
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.78rem;
    color: var(--trail-tan);
}

.quest-log-list {
    list-style: none;
    margin: 18px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.quest-log-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 0.78rem;
    color: var(--scroll);
    opacity: 0.62;
    transition: opacity 200ms var(--decel), transform 200ms var(--decel);
    position: relative;
    padding-left: 4px;
}

.quest-log-list li::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 18px;
    width: 1px;
    height: 14px;
    background: rgba(196, 168, 130, 0.4);
}

.quest-log-list li:last-child::before { display: none; }

.quest-log-list li .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--trail-tan);
    background: transparent;
    flex: 0 0 auto;
    transition: all 200ms var(--decel);
}

.quest-log-list li.completed { opacity: 1; color: var(--trail-tan); }
.quest-log-list li.completed .dot {
    background: var(--quest-gold);
    border-color: var(--quest-gold);
    box-shadow: 0 0 0 3px rgba(240, 168, 48, 0.18);
}

.quest-log-list li.current {
    opacity: 1;
    color: var(--parchment);
    transform: translateX(2px);
}
.quest-log-list li.current .dot {
    background: var(--quest-gold);
    border-color: var(--parchment);
    box-shadow: 0 0 0 4px rgba(240, 168, 48, 0.28);
    animation: pulseDot 2s ease-in-out infinite;
}

.quest-log-list li:hover { opacity: 1; }

@keyframes pulseDot {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 4px rgba(240, 168, 48, 0.18); }
    50%      { transform: scale(1.18); box-shadow: 0 0 0 7px rgba(240, 168, 48, 0.28); }
}

/* Main quest container ------------------------------------------------------*/

main.quest {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* Quest map (Section 1) -----------------------------------------------------*/

.quest-map {
    min-height: 100vh;
    padding: 80px 5vw 40px;
    position: relative;
    background: linear-gradient(180deg, var(--parchment) 0%, var(--parchment-warm) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.map-header {
    text-align: center;
    margin-bottom: 28px;
}

.map-title {
    font-size: clamp(2.6rem, 6vw, 4.8rem);
    color: var(--quest-ink);
    margin-bottom: 0.2em;
    text-shadow: 0 1px 0 rgba(196, 168, 130, 0.25);
}

.map-subtitle {
    font-style: italic;
    color: var(--traveler-gray);
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    margin: 0;
}

.map-canvas {
    width: 100%;
    max-width: 920px;
    aspect-ratio: 800 / 560;
    position: relative;
    margin: 0 auto;
    background:
        repeating-linear-gradient(45deg, rgba(196, 168, 130, 0.04) 0 2px, transparent 2px 22px),
        repeating-linear-gradient(-45deg, rgba(196, 168, 130, 0.04) 0 2px, transparent 2px 22px);
    border: 1px dashed rgba(196, 168, 130, 0.5);
    border-radius: 14px;
}

.map-svg {
    width: 100%;
    height: 100%;
    display: block;
}

.map-path {
    fill: none;
    stroke: var(--trail-tan);
    stroke-width: 2.5;
    stroke-dasharray: 8 4;
    opacity: 0.7;
    stroke-linecap: round;
}

.map-svg.draw .map-path {
    stroke-dasharray: 1600;
    stroke-dashoffset: 1600;
    animation: drawPath 2.5s var(--decel) forwards;
}

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

.map-node {
    cursor: pointer;
    transform-box: fill-box;
    transform-origin: center;
}

.map-node .node-circle {
    fill: var(--vellum);
    stroke: var(--trail-tan);
    stroke-width: 2.5;
    transition: transform 220ms var(--decel), filter 220ms var(--decel);
    filter: drop-shadow(0 4px 6px rgba(45, 49, 66, 0.15));
}

.map-node .node-citadel {
    fill: var(--vellum);
    stroke: var(--quest-gold);
    stroke-width: 2.5;
    filter: drop-shadow(0 4px 8px rgba(240, 168, 48, 0.35));
}

.map-node .node-num {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    fill: var(--quest-ink);
    pointer-events: none;
}

.map-node .node-label {
    font-family: var(--font-ui);
    font-size: 12px;
    fill: var(--quest-ink);
    pointer-events: none;
    letter-spacing: 0.04em;
}

.map-node:hover .node-circle,
.map-node:hover .node-citadel {
    transform: scale(1.12);
    filter: drop-shadow(0 6px 14px rgba(240, 168, 48, 0.4));
}

.map-node.start .node-halo {
    fill: var(--quest-gold);
    opacity: 0.25;
    animation: haloPulse 2s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}

.map-node.start .node-circle {
    stroke: var(--quest-gold);
    stroke-width: 3;
    fill: var(--parchment);
    animation: nodePulse 2s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}

@keyframes nodePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.1); opacity: 0.85; }
}
@keyframes haloPulse {
    0%, 100% { transform: scale(1); opacity: 0.25; }
    50%      { transform: scale(1.5); opacity: 0; }
}

.map-node.completed .node-circle {
    fill: var(--quest-gold);
    stroke: var(--quest-gold);
}
.map-node.completed .node-num { fill: var(--parchment); }

.map-node.pop {
    animation: nodePop 600ms var(--spring) forwards;
    transform-box: fill-box;
    transform-origin: center;
}

@keyframes nodePop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.compass {
    pointer-events: none;
}
.compass-n {
    font-family: var(--font-ui);
    font-size: 11px;
    fill: var(--traveler-gray);
}

.map-legend {
    position: absolute;
    bottom: 14px;
    left: 14px;
    display: flex;
    gap: 16px;
    padding: 8px 14px;
    background: rgba(248, 245, 240, 0.85);
    border: 1px dashed rgba(196, 168, 130, 0.5);
    border-radius: 10px;
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: var(--traveler-gray);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid var(--trail-tan);
    background: var(--vellum);
}
.legend-dot.pulsing {
    background: var(--quest-gold);
    border-color: var(--quest-gold);
    animation: pulseDot 2s ease-in-out infinite;
}
.legend-dot.completed {
    background: var(--forest-emerald);
    border-color: var(--forest-emerald);
}

.scroll-cue {
    margin-top: 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--traveler-gray);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}
.cue-arrow {
    width: 12px; height: 12px;
    border-right: 2px solid var(--trail-tan);
    border-bottom: 2px solid var(--trail-tan);
    transform: rotate(45deg);
    animation: cueBob 1.6s ease-in-out infinite;
}
@keyframes cueBob {
    0%, 100% { transform: translateY(0) rotate(45deg); opacity: 0.6; }
    50%      { transform: translateY(6px) rotate(45deg); opacity: 1; }
}

/* Stage sections ------------------------------------------------------------*/

.stage {
    position: relative;
    padding: 96px 5vw 96px;
    min-height: 92vh;
    background: var(--parchment);
    border-top: 1px dashed rgba(196, 168, 130, 0.45);
    overflow: hidden;
}

.stage::before {
    /* Subtle isometric grid wash for the "map tile" feel */
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        repeating-linear-gradient(60deg, rgba(196, 168, 130, 0.05) 0 1px, transparent 1px 38px),
        repeating-linear-gradient(-60deg, rgba(196, 168, 130, 0.05) 0 1px, transparent 1px 38px);
    opacity: 0.6;
}

.stage-2 { background: linear-gradient(180deg, var(--parchment) 0%, var(--parchment-warm) 100%); }
.stage-3 { background: var(--parchment-warm); }
.stage-4 { background: var(--parchment); }
.stage-5 { background: var(--parchment-warm); }
.stage-6 { background: linear-gradient(180deg, var(--parchment-warm) 0%, var(--vellum) 100%); }

.progress-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    display: flex;
    gap: 2px;
    padding: 0 5vw;
    z-index: 5;
}

.progress-bar .seg {
    flex: 1 1 auto;
    height: 4px;
    background: transparent;
    border: 1px solid var(--trail-tan);
    border-radius: 2px;
    transition: background 300ms var(--decel), box-shadow 300ms var(--decel);
}

.progress-bar .seg.completed {
    background: var(--quest-gold);
    border-color: var(--quest-gold);
}
.progress-bar .seg.current {
    background: var(--quest-gold);
    border-color: var(--quest-gold);
    animation: pulseSeg 1.6s ease-in-out infinite;
}
@keyframes pulseSeg {
    0%, 100% { box-shadow: 0 0 0 0 rgba(240, 168, 48, 0.4); }
    50%      { box-shadow: 0 0 0 4px rgba(240, 168, 48, 0.15); }
}

.stage-inner {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
}

.stage-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--traveler-gray);
    font-size: 0.78rem;
}

.stage-counter::before {
    content: "";
    display: inline-block;
    width: 8px; height: 8px;
    background: var(--quest-gold);
    border-radius: 50%;
    margin-right: 8px;
    transform: translateY(-1px);
}
.stage-tag {
    color: var(--quest-ink);
    background: var(--vellum);
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px dashed var(--trail-tan);
}

.stage-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 56px;
    align-items: start;
}

@media (max-width: 900px) {
    .stage-grid { grid-template-columns: 1fr; gap: 36px; }
}

.stage-name {
    font-size: clamp(2.4rem, 5vw, 4rem);
    color: var(--quest-ink);
    margin-bottom: 0.4em;
    position: relative;
    display: inline-block;
}

.stage-name::after {
    content: "";
    position: absolute;
    left: 0; bottom: -10px;
    width: 60%;
    height: 4px;
    background: currentColor;
    opacity: 0.25;
    border-radius: 2px;
}

.stage-1 .stage-name { color: var(--quest-ink); }
.stage-1 .stage-name::after { background: var(--quest-gold); opacity: 0.7; }
.stage-2 .stage-name::after { background: var(--forest-emerald); opacity: 0.7; }
.stage-3 .stage-name::after { background: var(--arcane-violet); opacity: 0.7; }
.stage-4 .stage-name::after { background: var(--torch-red); opacity: 0.7; }
.stage-5 .stage-name::after { background: var(--forest-emerald); opacity: 0.7; }
.stage-6 .stage-name::after { background: var(--arcane-violet); opacity: 0.7; }

.stage-prose {
    color: var(--quest-ink);
    font-size: clamp(1rem, 1.2vw, 1.12rem);
    max-width: 36em;
}

.stage-prose code {
    background: rgba(30, 27, 46, 0.06);
    color: var(--arcane-violet);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.92em;
}

/* Loot card -----------------------------------------------------------------*/

.loot-card {
    margin-top: 32px;
    background: var(--vellum);
    border: 2px solid var(--quest-gold);
    border-radius: 10px;
    padding: 18px 22px 18px 56px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    position: relative;
    transition: transform 240ms var(--spring), box-shadow 240ms var(--decel);
    max-width: 36em;
}

.loot-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(196, 168, 130, 0.35);
}

.loot-icon {
    position: absolute;
    left: 18px;
    top: 18px;
    width: 24px;
    height: 24px;
    display: inline-block;
    background: var(--icon-color, var(--quest-gold));
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    filter: drop-shadow(0 1px 1px rgba(45, 49, 66, 0.2));
}

.loot-body { flex: 1; }

.loot-label {
    display: block;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.7rem;
    color: var(--quest-gold);
    margin-bottom: 4px;
    font-weight: 700;
}

.loot-text {
    margin: 0;
    color: var(--quest-ink);
    font-size: 0.96rem;
    line-height: 1.55;
}

/* Isometric structures ------------------------------------------------------*/

.iso-stage {
    position: relative;
    width: 100%;
    height: 220px;
    margin-bottom: 28px;
    perspective: 800px;
}

.iso {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotateX(55deg) rotateZ(-45deg);
    transform-style: preserve-3d;
    width: 140px;
    height: 140px;
}

.iso .face {
    position: absolute;
    inset: 0;
    transition: transform 700ms var(--spring), opacity 500ms var(--decel);
}

/* Cottage (Stage 1) */
.iso-cottage .face.top    { background: var(--quest-gold); transform: translateZ(60px); }
.iso-cottage .face.left   { background: #d8902a; width: 140px; height: 60px; transform: rotateX(90deg) translateZ(70px) translateY(80px); transform-origin: top; }
.iso-cottage .face.right  { background: #b87718; width: 60px; height: 140px; transform: rotateY(-90deg) translateZ(70px) translateX(-80px); transform-origin: right; }
.iso-cottage .face.roof-l { background: var(--torch-red); width: 100px; height: 70px; top: -40px; left: 20px; transform: rotateX(35deg) translateZ(30px); }
.iso-cottage .face.roof-r { background: #b54e36; width: 100px; height: 70px; top: -40px; left: 20px; transform: rotateX(-35deg) translateZ(30px); opacity: 0.85; }
.iso-cottage .face.door   { background: var(--dungeon); width: 28px; height: 36px; top: 80px; left: 56px; transform: translateZ(61px); border-radius: 14px 14px 2px 2px; }

/* Workshop (Stage 2) */
.iso-workshop .face.top   { background: var(--forest-emerald); transform: translateZ(70px); }
.iso-workshop .face.left  { background: #237757; width: 140px; height: 70px; transform: rotateX(90deg) translateZ(70px) translateY(70px); transform-origin: top; }
.iso-workshop .face.right { background: #1c5d44; width: 70px; height: 140px; transform: rotateY(-90deg) translateZ(70px) translateX(-70px); transform-origin: right; }
.iso-workshop .chimney {
    position: absolute;
    top: -50px; left: 90px;
    width: 22px; height: 60px;
    background: var(--trail-tan);
    transform: translateZ(70px);
    border-radius: 4px 4px 0 0;
}
.iso-workshop .chimney span {
    position: absolute;
    top: -8px; left: -3px;
    width: 28px; height: 8px;
    background: #a48a66;
    border-radius: 3px;
}
.iso-workshop .smoke {
    position: absolute;
    top: -90px; left: 92px;
    width: 16px; height: 16px;
    background: rgba(196, 168, 130, 0.5);
    border-radius: 50%;
    transform: translateZ(70px);
    animation: smokeRise 4s ease-in-out infinite;
    box-shadow:
        12px -16px 0 -2px rgba(196, 168, 130, 0.4),
        -8px -32px 0 -4px rgba(196, 168, 130, 0.3);
}

@keyframes smokeRise {
    0%, 100% { transform: translateZ(70px) translateY(0); opacity: 0.6; }
    50%      { transform: translateZ(70px) translateY(-8px); opacity: 0.9; }
}

/* Fortress (Stage 3) */
.iso-fortress { width: 160px; height: 160px; }
.iso-fortress .face.top   { background: var(--arcane-violet); transform: translateZ(50px); }
.iso-fortress .face.left  { background: #5749b8; width: 160px; height: 50px; transform: rotateX(90deg) translateZ(80px) translateY(80px); transform-origin: top; }
.iso-fortress .face.right { background: #463a94; width: 50px; height: 160px; transform: rotateY(-90deg) translateZ(80px) translateX(-80px); transform-origin: right; }
.iso-fortress .turret {
    position: absolute;
    width: 28px; height: 50px;
    background: var(--arcane-violet);
    border: 2px solid var(--trail-tan);
    transform: translateZ(80px);
}
.iso-fortress .turret span {
    position: absolute;
    top: -10px; left: -2px;
    width: 32px; height: 10px;
    background: var(--torch-red);
    clip-path: polygon(0% 100%, 12% 0%, 25% 100%, 37% 0%, 50% 100%, 62% 0%, 75% 100%, 87% 0%, 100% 100%);
}
.iso-fortress .turret.t1 { top: -36px; left: 4px; }
.iso-fortress .turret.t2 { top: -36px; left: 128px; }
.iso-fortress .gate {
    position: absolute;
    bottom: 12px; left: 60px;
    width: 40px; height: 50px;
    background: var(--dungeon);
    border-radius: 20px 20px 2px 2px;
    transform: translateZ(51px);
    border: 2px solid var(--trail-tan);
}

/* Tower (Stage 4) */
.iso-tower .face.top   { background: var(--torch-red); transform: translateZ(140px); width: 80px; height: 80px; left: 30px; top: 30px; }
.iso-tower .face.left  { background: #b54e36; width: 80px; height: 140px; left: 30px; top: 30px; transform: rotateX(90deg) translateZ(70px) translateY(110px); transform-origin: top; }
.iso-tower .face.right { background: #93412a; width: 140px; height: 80px; left: 30px; top: 30px; transform: rotateY(-90deg) translateZ(70px) translateX(-110px); transform-origin: right; }
.iso-tower .ring {
    position: absolute;
    width: 80px; height: 8px;
    background: var(--trail-tan);
    left: 30px;
    border-radius: 2px;
}
.iso-tower .ring.r1 { top: 60px; transform: translateZ(140px); }
.iso-tower .ring.r2 { top: 90px; transform: translateZ(140px); opacity: 0.85; }
.iso-tower .ring.r3 { top: 120px; transform: translateZ(140px); opacity: 0.7; }
.iso-tower .flag {
    position: absolute;
    top: -28px; left: 64px;
    width: 12px; height: 28px;
    background: var(--quest-gold);
    transform: translateZ(140px);
    clip-path: polygon(0 0, 100% 0, 60% 50%, 100% 100%, 0 100%);
}

/* Guild Hall (Stage 5) */
.iso-guild .face.top   { background: var(--forest-emerald); transform: translateZ(60px); }
.iso-guild .face.left  { background: #237757; width: 140px; height: 60px; transform: rotateX(90deg) translateZ(70px) translateY(80px); transform-origin: top; }
.iso-guild .face.right { background: #1c5d44; width: 60px; height: 140px; transform: rotateY(-90deg) translateZ(70px) translateX(-80px); transform-origin: right; }
.iso-guild .banner {
    position: absolute;
    width: 18px; height: 36px;
    transform: translateZ(61px);
}
.iso-guild .banner.b1 { background: var(--quest-gold); top: 10px; left: 14px; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); }
.iso-guild .banner.b2 { background: var(--torch-red); top: 10px; left: 60px; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); }
.iso-guild .banner.b3 { background: var(--arcane-violet); top: 10px; left: 106px; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); }

/* Citadel iso (Stage 6) */
.iso-citadel { width: 170px; height: 170px; }
.iso-citadel .face.top   { background: var(--arcane-violet); transform: translateZ(50px); }
.iso-citadel .face.left  { background: #5749b8; width: 170px; height: 50px; transform: rotateX(90deg) translateZ(85px) translateY(85px); transform-origin: top; }
.iso-citadel .face.right { background: #463a94; width: 50px; height: 170px; transform: rotateY(-90deg) translateZ(85px) translateX(-85px); transform-origin: right; }
.iso-citadel .inner-wall {
    position: absolute;
    top: 30px; left: 30px;
    width: 110px; height: 110px;
    background: var(--quest-gold);
    border: 2px solid var(--trail-tan);
    transform: translateZ(75px);
}
.iso-citadel .keep {
    position: absolute;
    top: 55px; left: 65px;
    width: 40px; height: 60px;
    background: var(--torch-red);
    transform: translateZ(110px);
    border: 2px solid var(--trail-tan);
}
.iso-citadel .keep span {
    position: absolute;
    top: -14px; left: 6px;
    width: 28px; height: 14px;
    background: var(--quest-gold);
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

/* Iso build-in animation: faces hidden until stage active */
.stage:not(.in-view) .iso .face,
.stage:not(.in-view) .iso .chimney,
.stage:not(.in-view) .iso .smoke,
.stage:not(.in-view) .iso .turret,
.stage:not(.in-view) .iso .gate,
.stage:not(.in-view) .iso .ring,
.stage:not(.in-view) .iso .flag,
.stage:not(.in-view) .iso .banner,
.stage:not(.in-view) .iso .inner-wall,
.stage:not(.in-view) .iso .keep {
    opacity: 0;
}

.stage.in-view .iso .face,
.stage.in-view .iso .chimney,
.stage.in-view .iso .smoke,
.stage.in-view .iso .turret,
.stage.in-view .iso .gate,
.stage.in-view .iso .ring,
.stage.in-view .iso .flag,
.stage.in-view .iso .banner,
.stage.in-view .iso .inner-wall,
.stage.in-view .iso .keep {
    animation: faceIn 600ms var(--spring) forwards;
}

@keyframes faceIn {
    from { opacity: 0; transform-origin: center; }
    to   { opacity: 1; }
}

.stage.in-view .iso .face.left   { animation-delay: 0ms; }
.stage.in-view .iso .face.right  { animation-delay: 100ms; }
.stage.in-view .iso .face.top    { animation-delay: 200ms; }
.stage.in-view .iso .face.roof-l { animation-delay: 300ms; }
.stage.in-view .iso .face.roof-r { animation-delay: 350ms; }
.stage.in-view .iso .face.door   { animation-delay: 400ms; }
.stage.in-view .iso .chimney     { animation-delay: 300ms; }
.stage.in-view .iso .smoke       { animation-delay: 500ms; }
.stage.in-view .iso .turret      { animation-delay: 280ms; }
.stage.in-view .iso .gate        { animation-delay: 380ms; }
.stage.in-view .iso .ring        { animation-delay: 320ms; }
.stage.in-view .iso .flag        { animation-delay: 480ms; }
.stage.in-view .iso .banner      { animation-delay: 320ms; }
.stage.in-view .iso .inner-wall  { animation-delay: 320ms; }
.stage.in-view .iso .keep        { animation-delay: 460ms; }

/* Code blocks ---------------------------------------------------------------*/

.code-block {
    background: var(--dungeon);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 14px 30px rgba(30, 27, 46, 0.18);
    border: 1px solid rgba(196, 168, 130, 0.18);
}

.code-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.code-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: rgba(232, 228, 239, 0.18);
}
.code-dot:nth-child(1) { background: var(--torch-red); }
.code-dot:nth-child(2) { background: var(--quest-gold); }
.code-dot:nth-child(3) { background: var(--forest-emerald); }

.code-title {
    margin-left: 12px;
    font-family: var(--font-ui);
    font-size: 0.78rem;
    color: var(--traveler-gray);
    letter-spacing: 0.04em;
}

.code-block pre {
    margin: 0;
    padding: 20px 22px;
    font-size: clamp(0.82rem, 1vw, 0.95rem);
    line-height: 1.6;
    color: var(--scroll);
    overflow-x: auto;
    white-space: pre;
}

/* Syntax highlighting */
.code-block .cm { color: var(--traveler-gray); font-style: italic; }
.code-block .kw { color: var(--forest-emerald); font-weight: 500; }
.code-block .vn { color: var(--scroll); }
.code-block .ty { color: var(--quest-gold); }
.code-block .st { color: var(--arcane-violet); }
.code-block .nm { color: var(--torch-red); }
.code-block .op { color: var(--trail-tan); }

/* Stage entry animations ----------------------------------------------------*/

.stage .stage-meta,
.stage .stage-name,
.stage .stage-prose,
.stage .loot-card,
.stage .code-block {
    opacity: 0;
    transform: translateY(0);
    transition: opacity 400ms var(--decel), transform 500ms var(--decel);
}

.stage.in-view .stage-meta { opacity: 1; transition-delay: 50ms; }
.stage.in-view .stage-name {
    opacity: 1;
    animation: slideInLeft 400ms var(--decel) 100ms forwards;
}
.stage.in-view .stage-prose { opacity: 1; transition-delay: 250ms; }
.stage.in-view .code-block {
    opacity: 1;
    animation: slideUp 400ms var(--decel) 350ms forwards;
}
.stage.in-view .loot-card {
    opacity: 1;
    animation: bounceIn 500ms var(--spring) 500ms forwards;
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(15px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes bounceIn {
    0%   { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Citadel section -----------------------------------------------------------*/

.citadel {
    position: relative;
    background: linear-gradient(180deg, var(--vellum) 0%, var(--parchment-warm) 100%);
    padding: 110px 5vw 130px;
    min-height: 100vh;
    border-top: 1px dashed rgba(196, 168, 130, 0.45);
}

.citadel::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 0%, rgba(240, 168, 48, 0.16), transparent 50%),
        repeating-linear-gradient(60deg, rgba(196, 168, 130, 0.06) 0 1px, transparent 1px 38px),
        repeating-linear-gradient(-60deg, rgba(196, 168, 130, 0.06) 0 1px, transparent 1px 38px);
    pointer-events: none;
}

.progress-final .seg { background: var(--quest-gold); border-color: var(--quest-gold); }

.citadel-header {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 48rem;
    margin: 0 auto 48px;
}

.citadel-eyebrow {
    display: inline-block;
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--quest-gold);
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.citadel-title {
    font-size: clamp(2.6rem, 6vw, 4.4rem);
    color: var(--quest-ink);
    margin-bottom: 0.4em;
}

.citadel-sub {
    font-style: italic;
    color: var(--traveler-gray);
    font-size: 1.05rem;
}

.citadel-code {
    position: relative;
    z-index: 1;
    max-width: 48rem;
    margin: 0 auto;
}

.citadel-code .code-block {
    border-radius: 12px;
}

.citadel-code pre code.annotated {
    display: block;
    counter-reset: line;
}

.citadel-code .line {
    display: block;
    padding-left: 12px;
    border-left: 3px solid transparent;
    transition: background 200ms var(--decel), border-color 200ms var(--decel);
    cursor: default;
    position: relative;
}

.citadel-code .line .ln {
    display: inline-block;
    width: 28px;
    color: var(--traveler-gray);
    font-size: 0.78em;
    margin-right: 12px;
    text-align: right;
    user-select: none;
}

.citadel-code .line[data-stage="1"] { border-left-color: var(--quest-gold); }
.citadel-code .line[data-stage="2"] { border-left-color: var(--forest-emerald); }
.citadel-code .line[data-stage="3"] { border-left-color: var(--arcane-violet); }
.citadel-code .line[data-stage="4"] { border-left-color: var(--torch-red); }
.citadel-code .line[data-stage="5"] { border-left-color: var(--forest-emerald); }
.citadel-code .line[data-stage="6"] { border-left-color: var(--arcane-violet); }
.citadel-code .line[data-stage="0"] { border-left-color: transparent; }

.citadel-code .line:hover {
    background: rgba(240, 168, 48, 0.08);
}
.citadel-code .line.line-active {
    background: rgba(240, 168, 48, 0.14);
    border-left-width: 5px;
}

.annotation-key {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
    justify-content: center;
}

.ann-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--vellum);
    border: 1px solid var(--trail-tan);
    border-radius: 999px;
    font-family: var(--font-ui);
    font-size: 0.74rem;
    color: var(--quest-ink);
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: transform 200ms var(--decel), background 200ms var(--decel);
}
.ann-chip:hover { transform: translateY(-2px); }
.ann-chip.active { background: var(--parchment); border-color: var(--quest-gold); box-shadow: 0 0 0 3px rgba(240, 168, 48, 0.18); }

.ann-chip .chip-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.ann-chip[data-stage="1"] .chip-dot { background: var(--quest-gold); }
.ann-chip[data-stage="2"] .chip-dot { background: var(--forest-emerald); }
.ann-chip[data-stage="3"] .chip-dot { background: var(--arcane-violet); }
.ann-chip[data-stage="4"] .chip-dot { background: var(--torch-red); }
.ann-chip[data-stage="5"] .chip-dot { background: var(--forest-emerald); }
.ann-chip[data-stage="6"] .chip-dot { background: var(--arcane-violet); }

.hover-hint {
    text-align: center;
    color: var(--traveler-gray);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    margin-top: 18px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.line-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--dungeon);
    color: var(--scroll);
    padding: 8px 14px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    opacity: 0;
    transform: translate(-50%, -120%);
    transition: opacity 160ms var(--decel);
    z-index: 100;
    border: 1px solid var(--quest-gold);
    box-shadow: 0 8px 22px rgba(30, 27, 46, 0.35);
}
.line-tooltip.show { opacity: 1; }

.citadel-footer {
    position: relative;
    z-index: 1;
    max-width: 48rem;
    margin: 64px auto 0;
    text-align: center;
}

.closing-line {
    font-style: italic;
    color: var(--quest-ink);
    font-size: 1.1rem;
    line-height: 1.7;
}

.closing-eyebrow {
    font-family: var(--font-display);
    font-weight: 600;
    font-style: normal;
    color: var(--quest-gold);
    margin-right: 6px;
}

.restart-btn {
    margin-top: 28px;
    padding: 14px 28px;
    background: var(--quest-gold);
    color: var(--dungeon);
    border: none;
    border-radius: 999px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: transform 240ms var(--spring), box-shadow 240ms var(--decel);
    box-shadow: 0 6px 18px rgba(240, 168, 48, 0.32);
}
.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(240, 168, 48, 0.4);
}

/* Reduced motion ------------------------------------------------------------*/

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .map-svg.draw .map-path { animation: none; stroke-dashoffset: 0; }
}

/* Small-screen polish -------------------------------------------------------*/

@media (max-width: 600px) {
    .stage { padding: 64px 5vw 64px; }
    .stage-meta { flex-direction: column; gap: 8px; align-items: flex-start; }
    .iso-stage { height: 180px; }
    .map-canvas { aspect-ratio: 4 / 3; }
    .map-legend { font-size: 0.62rem; }
    .citadel { padding: 80px 5vw 100px; }
}
