:root {
    --bgColor: #A0A5B1;
    --bgLight: #B8BDC9;
    --inkDark: #0F1218;
    --inkMuted: rgba(15, 18, 24, 0.68);
    --inkLight: #F5F7FA;
    --glassSurface: rgba(255, 255, 255, 0.44);
    --glassBorder: rgba(255, 255, 255, 0.65);

    /* Apple SF Clean Font Stack */
    --font-sf: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html, body {
    width: 100%;
    background-color: var(--bgColor);
    color: var(--inkDark);
    font-family: var(--font-sf);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    cursor: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.sf-mono {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#gl-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    display: block;
}

#debug-console {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    background: rgba(185, 28, 28, 0.94);
    color: #fff;
    padding: 14px 18px;
    border-radius: 12px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

/* 1. CSS KEYFRAME ASCII LOADER (:before content cycling) */
#ascii-loader {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bgColor);
    display: flex;
    padding: 2rem;
    transition: opacity 0.85s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.85s;
}

#ascii-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.ascii-frame {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(15, 18, 24, 0.16);
    border-radius: 20px;
    padding: 1.75rem;
}

.ascii-top, .ascii-bottom {
    display: flex;
    justify-content: space-between;
    color: var(--inkMuted);
}

.ascii-center {
    text-align: center;
    margin: auto;
}

.ascii-spinner {
    font-family: var(--font-mono);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.25em;
    color: var(--inkDark);
    margin-bottom: 1rem;
    height: 1.8rem;
}

.ascii-spinner::before {
    content: "---===+++";
    animation: asciiCycle 0.75s steps(1) infinite;
}

@keyframes asciiCycle {
    0%   { content: "---===+++"; }
    16%  { content: "--===+++="; }
    33%  { content: "-===+++=="; }
    50%  { content: "===+++==="; }
    66%  { content: "==+++===-"; }
    83%  { content: "=+++===--"; }
    100% { content: "+++===---"; }
}

.ascii-pct {
    font-size: 3.8rem;
    font-weight: 300;
    letter-spacing: -0.05em;
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.5rem;
}

.ascii-status {
    color: var(--inkMuted);
}

/* Top HUD */
.hud-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.35rem 2.5rem;
    pointer-events: none;
}

.brand, .nav-cluster, .hud-controls {
    pointer-events: auto;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--inkDark);
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.16em;
    cursor: none;
}

.brand-glyph {
    font-size: 1.1rem;
}

.nav-cluster {
    display: flex;
    gap: 0.25rem;
    padding: 0.3rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.36);
    border: 1px solid rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.nav-pill {
    background: transparent;
    border: none;
    color: var(--inkMuted);
    font-family: var(--font-sf);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.42rem 0.95rem;
    border-radius: 999px;
    cursor: none;
    transition: all 0.25s ease;
}

.nav-pill:hover { color: var(--inkDark); }
.nav-pill.active {
    background: var(--inkDark);
    color: var(--inkLight);
}

.hud-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.telemetry-chip {
    color: var(--inkMuted);
    background: rgba(255, 255, 255, 0.34);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 0.42rem 0.75rem;
    border-radius: 999px;
}

.audio-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.48);
    border: 1px solid rgba(255, 255, 255, 0.68);
    color: var(--inkDark);
    font-family: var(--font-sf);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.44rem 1rem;
    border-radius: 999px;
    cursor: none;
    backdrop-filter: blur(18px);
    transition: background 0.2s;
}

.audio-chip:hover { background: rgba(255, 255, 255, 0.8); }

.eq {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    height: 11px;
}

.eq i {
    display: block;
    width: 2px;
    height: 4px;
    background: var(--inkDark);
    border-radius: 2px;
}

.audio-chip.active .eq i {
    animation: eqAnim 0.75s infinite ease-in-out;
}
.audio-chip.active .eq i:nth-child(2) { animation-delay: 0.2s; }
.audio-chip.active .eq i:nth-child(3) { animation-delay: 0.4s; }

/* Matrix Telemetry Rail */
.matrix-rail {
    position: fixed;
    left: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 25;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    color: var(--inkMuted);
}

.rail-bar {
    width: 2px;
    height: 105px;
    background: rgba(15, 18, 24, 0.16);
    overflow: hidden;
}

.rail-fill {
    width: 100%;
    height: 25%;
    background: var(--inkDark);
}

/* Scroll Chapters */
#scroll-container {
    position: relative;
    z-index: 10;
}

.chapter {
    min-height: 125vh;
    display: flex;
    align-items: center;
    padding: 6rem 8vw;
}

.chapter.align-right { justify-content: flex-end; }
.chapter.align-left { justify-content: flex-start; }
.chapter.align-center { justify-content: center; text-align: center; }

.content-wrap { max-width: 470px; }
.hero-wrap { max-width: 560px; }

.glass-card {
    background: var(--glassSurface);
    border: 1px solid var(--glassBorder);
    border-radius: 24px;
    padding: 2.6rem;
    backdrop-filter: blur(28px) saturate(165%);
    -webkit-backdrop-filter: blur(28px) saturate(165%);
    box-shadow: 0 24px 60px rgba(15, 18, 24, 0.1);
}

.center-box { max-width: 580px; }

.kicker {
    color: var(--inkMuted);
    margin-bottom: 0.85rem;
}

.hero-headline {
    font-size: clamp(3.1rem, 6.4vw, 5.4rem);
    font-weight: 600;
    line-height: 0.98;
    letter-spacing: -0.04em;
    color: var(--inkDark);
    margin-bottom: 1.35rem;
}

.card-headline {
    font-size: clamp(2rem, 3.6vw, 2.85rem);
    font-weight: 600;
    line-height: 1.04;
    letter-spacing: -0.03em;
    color: var(--inkDark);
    margin-bottom: 1.1rem;
}

.hero-lead, .card-body {
    font-size: 1.02rem;
    line-height: 1.6;
    color: var(--inkMuted);
    margin-bottom: 1.85rem;
}

.card-body code {
    font-family: var(--font-mono);
    font-size: 0.84rem;
    background: rgba(15, 18, 24, 0.08);
    padding: 2px 6px;
    border-radius: 5px;
}

.scroll-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.pulse-ring {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--inkDark);
    animation: pulse 1.8s infinite ease-in-out;
}

.stat-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(15, 18, 24, 0.12);
}

.stat-val {
    display: block;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.stat-lbl {
    font-size: 0.78rem;
    color: var(--inkMuted);
}

.btn-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-row.centered { justify-content: center; }

.btn-primary, .btn-secondary {
    font-family: var(--font-sf);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.82rem 1.45rem;
    border-radius: 999px;
    cursor: none;
    transition: transform 0.2s ease, background 0.2s ease;
}

.btn-primary {
    background: var(--inkDark);
    color: var(--inkLight);
    border: none;
}

.btn-primary:hover {
    transform: translateY(-1px);
    background: #000000;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.52);
    color: var(--inkDark);
    border: 1px solid rgba(15, 18, 24, 0.16);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.88);
}

/* Custom Cursor */
#cursor {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.cursor-dot {
    width: 6px;
    height: 6px;
    background: var(--inkDark);
    border-radius: 50%;
    position: absolute;
    top: -3px;
    left: -3px;
}

.cursor-circle {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(15, 18, 24, 0.45);
    border-radius: 50%;
    position: absolute;
    top: -16px;
    left: -16px;
    transition: transform 0.2s ease-out;
}

@keyframes eqAnim {
    0%, 100% { height: 3px; }
    50% { height: 11px; }
}

@keyframes pulse {
    0%, 100% { transform: scale(0.8); opacity: 0.45; }
    50% { transform: scale(1.35); opacity: 1; }
}

@media (max-width: 900px) {
    .nav-cluster, .matrix-rail, #cursor { display: none; }
    html, body, button, a { cursor: auto; }
    .chapter { padding: 5rem 1.5rem; }
}