/* =========================================================
   rust.quest — A Digital Monument to Compilation
   Palette:
     #0c0c0e Forge Black     | #0e0c0a Cooling Forge
     #1a1a1f Slag Gray       | #2a2a32 Anvil
     #e8e4d9 Phosphor White  | #7a7a6e Patina
     #ce4a1d Oxide Orange    | #4ec965 Compiler Green
     #5b8dd9 Lifetime Blue   | #d94040 Borrow Red
     #c9a84c Ferrous Gold
   Noise grain (canvas overlay):
     #3a2a1a warm rust grain | #2a2a3a cool gray grain
   ========================================================= */

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

html {
    scroll-behavior: smooth;
}

body {
    background: linear-gradient(180deg, #0c0c0e 0%, #0e0c0a 100%);
    color: #e8e4d9;
    font-family: "Source Serif 4", Georgia, serif;
    font-weight: 300;
    line-height: 1.8;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* ---------- Oxidation Canvas ---------- */
#oxidation-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
    opacity: 0.045;
    mix-blend-mode: screen;
}

main {
    position: relative;
    z-index: 2;
}

/* ---------- Vertical Title (left strip) ---------- */
.vertical-title {
    position: fixed;
    top: 0;
    left: 0;
    width: 64px;
    height: 100vh;
    border-right: 1px solid #2a2a32;
    background: rgba(12, 12, 14, 0.85);
    backdrop-filter: blur(6px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 28px 0;
}

.vt-text {
    font-family: "Bebas Neue", "Arial Narrow", sans-serif;
    font-size: 14px;
    letter-spacing: 0.55em;
    color: #e8e4d9;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    text-transform: uppercase;
}

.vt-meta {
    font-family: "JetBrains Mono", monospace;
    font-size: 9px;
    color: #7a7a6e;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    letter-spacing: 0.05em;
}

/* ---------- Progress Strip (right edge) ---------- */
.progress-strip {
    position: fixed;
    top: 0;
    right: 0;
    width: 140px;
    height: 100vh;
    z-index: 50;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    padding: 0 18px 0 0;
    gap: 6px;
    pointer-events: none;
}

.progress-segment {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 56px;
    width: 100%;
    justify-content: flex-end;
    opacity: 0.5;
    transition: opacity 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-segment.active {
    opacity: 1;
}

.seg-label {
    font-family: "Bebas Neue", "Arial Narrow", sans-serif;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: #7a7a6e;
    text-transform: uppercase;
    transition: color 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-segment.active .seg-label {
    color: #e8e4d9;
}

.seg-bar {
    width: 3px;
    height: 100%;
    background: #2a2a32;
    position: relative;
    overflow: hidden;
}

.seg-bar::after {
    content: "";
    position: absolute;
    inset: 0;
    background: #c9a84c;
    transform: scaleY(0);
    transform-origin: top center;
    transition: transform 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-segment.active .seg-bar::after,
.progress-segment.completed .seg-bar::after {
    transform: scaleY(1);
}

.progress-segment[data-stage="running"].active .seg-bar::after {
    background: #4ec965;
}

/* ---------- Sections (shared) ---------- */
.section {
    position: relative;
    min-height: 100vh;
    padding: 100px 180px 100px 120px;
    border-bottom: 1px solid rgba(42, 42, 50, 0.4);
}

.section-header {
    margin-bottom: 64px;
    max-width: 720px;
}

.section-header.centered {
    margin: 0 auto 80px;
    text-align: center;
}

.section-num {
    display: inline-block;
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    letter-spacing: 0.25em;
    color: #c9a84c;
    text-transform: uppercase;
    margin-bottom: 18px;
    border-left: 2px solid #c9a84c;
    padding-left: 10px;
}

.section-title {
    font-family: "Bebas Neue", "Arial Narrow", sans-serif;
    font-weight: 400;
    font-size: clamp(2.4rem, 6vw, 5.5rem);
    letter-spacing: 0.15em;
    line-height: 1;
    color: #e8e4d9;
    margin-bottom: 18px;
}

.section-sub {
    font-family: "Source Serif 4", Georgia, serif;
    font-size: clamp(1rem, 1.3vw, 1.15rem);
    color: #7a7a6e;
    font-style: italic;
    max-width: 540px;
}

/* ---------- Memory Address Labels ---------- */
.addr-label {
    position: absolute;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    letter-spacing: 0.05em;
    color: #7a7a6e;
    pointer-events: none;
}

.addr-tl { top: 36px; left: 120px; }
.addr-br { bottom: 36px; right: 180px; }

/* ========== SECTION 1: THE SOURCE ========== */
.section-source {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 140px;
}

.source-frame {
    position: relative;
    max-width: 1100px;
    margin-left: 40px;
}

.source-meta {
    display: flex;
    gap: 18px;
    margin-bottom: 28px;
}

.meta-tag {
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: #7a7a6e;
    text-transform: uppercase;
}

.meta-tag-accent {
    color: #ce4a1d;
    border-left: 2px solid #ce4a1d;
    padding-left: 10px;
}

.source-code {
    font-family: "JetBrains Mono", monospace;
    font-feature-settings: "liga" on, "calt" on;
    font-size: clamp(1rem, 2.6vw, 2.4rem);
    font-weight: 400;
    line-height: 1.5;
    color: #e8e4d9;
    white-space: pre-wrap;
    overflow: visible;
}

.source-code .line {
    display: block;
}

.tok {
    display: inline-block;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 380ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 380ms cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 600ms cubic-bezier(0.22, 1, 0.36, 1),
                color 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tok.parsed {
    opacity: 1;
    transform: translateY(0);
}

/* token colors — hand-crafted from palette */
.tok-kw   { color: #ce4a1d; }   /* keywords: orange */
.tok-fn   { color: #c9a84c; }   /* function names: gold */
.tok-type { color: #5b8dd9; }   /* types: lifetime blue */
.tok-ident { color: #e8e4d9; }  /* identifiers: phosphor white */
.tok-punct { color: #7a7a6e; }  /* punctuation: patina */
.tok-arrow { color: #d94040; }  /* the move arrow: borrow red */

.tok.kw    { color: #ce4a1d; }
.tok.fn    { color: #c9a84c; }
.tok.type  { color: #5b8dd9; }
.tok.ident { color: #e8e4d9; }
.tok.punct { color: #7a7a6e; }
.tok.arrow { color: #d94040; }

.tok.glow {
    text-shadow: 0 0 12px rgba(206, 74, 29, 0.55),
                 0 0 24px rgba(206, 74, 29, 0.25);
    box-shadow: inset 0 -2px 0 rgba(206, 74, 29, 0.4);
}

.source-annotations {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px dotted #2a2a32;
}

.anno {
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    letter-spacing: 0.05em;
    padding-left: 14px;
    position: relative;
}

.anno::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 8px;
    height: 1px;
    transform: translateY(-50%);
}

.anno-blue   { color: #5b8dd9; }
.anno-blue::before   { background: #5b8dd9; }
.anno-orange { color: #ce4a1d; }
.anno-orange::before { background: #ce4a1d; }
.anno-green  { color: #4ec965; }
.anno-green::before  { background: #4ec965; }

.bracket-svg {
    position: absolute;
    width: 40px;
    height: 220px;
    pointer-events: none;
}

.bracket-left {
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.55;
}

/* ========== SECTION 2: THE COMPILATION ========== */
.section-compilation {
    min-height: 140vh;
    overflow: hidden;
}

.ast-stage {
    position: relative;
    width: 100%;
    height: 90vh;
    min-height: 720px;
    margin-top: 24px;
}

.ast-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ast-card {
    position: absolute;
    left: var(--x);
    top: var(--y);
    transform: rotate(var(--r)) translateY(28px);
    width: clamp(180px, 18vw, 240px);
    background: #1a1a1f;
    border: 1px solid #2a2a32;
    padding: 18px 18px 14px;
    opacity: 0;
    transition: opacity 720ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 720ms cubic-bezier(0.34, 1.56, 0.64, 1),
                border-color 280ms cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 280ms cubic-bezier(0.22, 1, 0.36, 1);
    cursor: default;
    will-change: transform, opacity;
}

.ast-card.appear {
    opacity: 1;
    transform: rotate(var(--r)) translateY(0);
}

.ast-card:hover {
    border-color: #5b8dd9;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(91, 141, 217, 0.25);
    transform: rotate(0deg) translateY(-6px);
    z-index: 10;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-bottom: 10px;
}

.dot-orange { background: #ce4a1d; box-shadow: 0 0 8px rgba(206, 74, 29, 0.6); }
.dot-blue   { background: #5b8dd9; box-shadow: 0 0 8px rgba(91, 141, 217, 0.6); }
.dot-green  { background: #4ec965; box-shadow: 0 0 8px rgba(78, 201, 101, 0.6); }

.ast-code {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.95rem;
    font-weight: 500;
    color: #e8e4d9;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.ast-anno {
    font-family: "Source Serif 4", Georgia, serif;
    font-size: 0.82rem;
    line-height: 1.5;
    color: #7a7a6e;
    font-style: italic;
    margin-bottom: 10px;
}

.ast-addr {
    font-family: "JetBrains Mono", monospace;
    font-size: 9px;
    color: #2a2a32;
    letter-spacing: 0.05em;
    text-transform: lowercase;
}

.ast-card[data-type="ownership"] { border-top: 2px solid #ce4a1d; }
.ast-card[data-type="lifetime"]  { border-top: 2px solid #5b8dd9; }
.ast-card[data-type="borrow"]    { border-top: 2px solid #4ec965; }

/* Ferris fragments — abstract crab shapes */
.ferris-fragment {
    position: absolute;
    background: #ce4a1d;
    opacity: 0.45;
    pointer-events: none;
}

.ferris-1 {
    width: 18px;
    height: 18px;
    top: 14%;
    right: 10%;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.ferris-2 {
    width: 22px;
    height: 12px;
    bottom: 12%;
    left: 6%;
    clip-path: polygon(0% 0%, 100% 0%, 80% 100%, 20% 100%);
    opacity: 0.55;
}

.ferris-3 {
    width: 14px;
    height: 14px;
    top: 50%;
    right: 18%;
    border-radius: 50%;
    border: 2px solid #ce4a1d;
    background: transparent;
    opacity: 0.5;
}

/* ========== SECTION 3: THE OPTIMIZATION ========== */
.section-optimization {
    padding: 140px 240px 140px 240px;
    background: linear-gradient(180deg, #0c0c0e 0%, #0e0c0a 100%);
}

.opt-stack {
    max-width: 38rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 64px;
}

.opt-block {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 900ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 900ms cubic-bezier(0.22, 1, 0.36, 1);
    transition-delay: calc(var(--d, 0) * 200ms);
}

.opt-block.reveal {
    opacity: 1;
    transform: translateY(0);
}

.opt-paragraph {
    font-family: "Source Serif 4", Georgia, serif;
    font-weight: 300;
    font-size: clamp(1.05rem, 1.3vw, 1.2rem);
    line-height: 1.85;
    color: #e8e4d9;
    text-align: justify;
    hyphens: auto;
}

.opt-paragraph em {
    font-style: italic;
    color: #c9a84c;
    font-weight: 400;
}

.dropcap {
    font-family: "Playfair Display", Georgia, serif;
    font-weight: 900;
    font-size: 4.5rem;
    line-height: 0.85;
    color: #c9a84c;
    float: left;
    padding-right: 14px;
    padding-top: 6px;
    margin-bottom: -8px;
}

.opt-rule {
    display: block;
    width: 200px;
    height: 4px;
    margin: 80px auto 0;
    opacity: 0.6;
}

/* ========== SECTION 4: THE BINARY ========== */
.section-binary {
    padding-bottom: 140px;
}

.hex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1px;
    background: #2a2a32;
    border: 1px solid #2a2a32;
    margin-top: 24px;
}

.hex-cell {
    aspect-ratio: 1 / 1;
    background: #0c0c0e;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: background 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.hex-cell.alt {
    background: #1a1a1f;
}

.hex-cell:hover {
    background: #2a2a32;
}

.hex-cell::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid transparent;
    pointer-events: none;
    animation: cell-pulse 4.5s ease-in-out infinite;
}

@keyframes cell-pulse {
    0%, 100% { border-color: transparent; }
    50% { border-color: rgba(122, 122, 110, 0.18); }
}

.hex-keyword {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.95rem;
    font-weight: 500;
    color: #e8e4d9;
    letter-spacing: 0.02em;
}

.hex-keyword.kw-orange { color: #ce4a1d; }
.hex-keyword.kw-blue   { color: #5b8dd9; }
.hex-keyword.kw-green  { color: #4ec965; }
.hex-keyword.kw-gold   { color: #c9a84c; }

.hex-addr {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.7rem;
    color: #7a7a6e;
    letter-spacing: 0.04em;
}

.hex-shape {
    width: 32px;
    height: 32px;
}

.shape-square { background: #ce4a1d; opacity: 0.5; }
.shape-circle { background: #5b8dd9; border-radius: 50%; opacity: 0.5; }
.shape-tri    { width: 0; height: 0;
                border-left: 16px solid transparent;
                border-right: 16px solid transparent;
                border-bottom: 28px solid #4ec965;
                opacity: 0.5; background: transparent; }
.shape-rhomb  { background: #c9a84c; opacity: 0.5;
                clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.shape-bar    { width: 32px; height: 6px; background: #d94040; opacity: 0.6; }

.hex-cell.empty {
    background: #0c0c0e;
}

/* ========== SECTION 5: THE EXECUTION ========== */
.section-execution {
    background: #0c0c0e;
    padding: 0 180px 0 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    border-bottom: none;
}

.terminal-frame {
    width: 100%;
    max-width: 920px;
    border: 1px solid #2a2a32;
    background: #0c0c0e;
    padding: 32px 40px;
    position: relative;
}

.terminal-frame::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, #4ec965, transparent);
    opacity: 0.4;
}

.terminal-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px dotted #2a2a32;
}

.t-meta {
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: #4ec965;
    text-transform: uppercase;
}

.t-meta-dim {
    color: #7a7a6e;
    text-transform: none;
    letter-spacing: 0.05em;
}

.terminal-output {
    font-family: "JetBrains Mono", monospace;
    font-size: clamp(0.95rem, 1.3vw, 1.2rem);
    line-height: 1.85;
    color: #4ec965;
    min-height: 280px;
    white-space: pre-wrap;
    word-break: break-word;
}

.terminal-text {
    color: #4ec965;
}

.terminal-cursor {
    display: inline-block;
    color: #4ec965;
    animation: blink 530ms steps(2, end) infinite;
    margin-left: 2px;
    line-height: 1;
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.terminal-foot {
    margin-top: 28px;
    padding-top: 14px;
    border-top: 1px dotted #2a2a32;
}

/* ---------- Footer ---------- */
.site-foot {
    padding: 40px 180px 60px 120px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 18px;
    border-top: 1px solid #2a2a32;
    background: #0c0c0e;
}

.foot-cell {
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    color: #7a7a6e;
    letter-spacing: 0.05em;
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 1024px) {
    .section { padding: 80px 100px 80px 90px; }
    .section-optimization { padding: 100px 60px; }
    .section-execution { padding: 0 100px 0 90px; }
    .site-foot { padding: 40px 100px 60px 90px; }
    .progress-strip { width: 100px; padding-right: 10px; }
    .ast-card { width: clamp(160px, 22vw, 220px); }
    .addr-tl { left: 90px; }
    .addr-br { right: 100px; }
}

@media (max-width: 720px) {
    .vertical-title { width: 44px; }
    .progress-strip { display: none; }
    .section { padding: 70px 30px 70px 64px; }
    .section-optimization { padding: 80px 30px; }
    .section-execution { padding: 0 30px 0 64px; }
    .site-foot { padding: 30px 30px 50px 64px; flex-direction: column; }
    .ast-stage { height: auto; min-height: 0; display: flex; flex-direction: column; gap: 20px; }
    .ast-card { position: relative; left: 0 !important; top: 0 !important; transform: none !important; width: 100%; }
    .ast-card.appear { transform: none !important; }
    .ast-lines { display: none; }
    .source-code { font-size: 1.1rem; }
    .addr-tl, .addr-br { display: none; }
}
