/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary: #110d14;
    --bg-foyer: #1a1118;
    --bg-secondary: #1e1726;
    --surface: #2a2233;
    --text-primary: #e8dcc4;
    --text-secondary: #9b8e7e;
    --aurora-green: #3dffa2;
    --aurora-violet: #9b5de5;
    --aurora-cyan: #00d4ff;
    --aurora-pink: #ff6b9d;
    --brass: #b8944a;
    --leather-dark: #2a1f18;
    --leather-mid: #3d2e22;
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

html { scroll-behavior: smooth; }

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* ===== NAVIGATION SPINE ===== */
#nav-spine {
    position: fixed;
    left: 0;
    top: 0;
    width: 48px;
    height: 100vh;
    background: linear-gradient(180deg, var(--leather-dark), var(--leather-mid), var(--leather-dark));
    box-shadow: inset 0 0 30px rgba(0,0,0,0.5), 2px 0 10px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0;
    z-index: 1000;
    transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#nav-spine:hover { width: 200px; }

.nav-item {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 12px 8px;
    cursor: pointer;
    transition: color 0.2s, text-shadow 0.2s;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-item:hover {
    color: var(--aurora-green);
    text-shadow: 0 0 8px rgba(61,255,162,0.4);
}

.nav-item.active { color: var(--aurora-green); }

.nav-label {
    opacity: 0;
    transition: opacity 0.3s 0.1s;
    font-size: 0.65rem;
}

#nav-spine:hover .nav-label { opacity: 1; }
#nav-spine:hover .nav-item { writing-mode: horizontal-tb; }

/* ===== PANELS (SECTIONS) ===== */
.panel {
    position: relative;
    min-height: 100vh;
    padding: 6rem 4rem 6rem calc(48px + 4rem);
    overflow: hidden;
}

/* Diagonal clip for sections 2-5 */
#reading-room,
#circuit-library,
#observatory,
#archive {
    clip-path: polygon(0 0, 100% 4vh, 100% 100%, 0 calc(100% - 4vh));
    margin-top: -4vh;
}

#circuit-library {
    clip-path: polygon(0 0, 100% 6vh, 100% 100%, 0 calc(100% - 6vh));
    margin-top: -6vh;
}

/* Section backgrounds */
#foyer { background: var(--bg-foyer); }
#reading-room { background: var(--bg-secondary); }
#circuit-library { background: linear-gradient(180deg, var(--bg-secondary), var(--bg-primary)); }
#observatory { background: var(--bg-primary); }
#archive { background: var(--bg-primary); }

/* ===== VIGNETTE ===== */
.vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.6) 100%);
    pointer-events: none;
    z-index: 1;
}

/* ===== CIRCUIT TRACES ===== */
.circuit-traces {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.trace {
    fill: none;
    stroke: var(--aurora-green);
    stroke-width: 1.5;
    opacity: 0.15;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 3s ease;
}

.trace.animated { stroke-dashoffset: 0; }

.via-dot {
    fill: var(--aurora-green);
    opacity: 0;
    transition: opacity 1s ease 1s;
}

.via-dot.animated {
    opacity: 0.3;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.5; }
}

/* ===== HERO (FOYER) ===== */
.hero-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    min-height: 80vh;
    padding-left: 5vw;
    transform: rotate(-3deg);
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(5rem, 15vw, 18rem);
    line-height: 0.95;
    letter-spacing: 0.02em;
    background: linear-gradient(135deg, var(--aurora-green) 0%, var(--aurora-cyan) 30%, var(--aurora-violet) 65%, var(--aurora-pink) 100%);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: gradient-shift 8s ease infinite;
}

.hero-subtitle {
    font-family: var(--font-body);
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-top: 1.5rem;
    max-width: 50ch;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.hero-subtitle.visible { opacity: 1; }

@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ===== GLITCH ===== */
@keyframes glitch-in {
    0% { transform: translateX(-3px); text-shadow: -2px 0 var(--aurora-cyan), 2px 0 var(--aurora-pink); }
    30% { transform: translateX(2px); text-shadow: 2px 0 var(--aurora-cyan), -2px 0 var(--aurora-pink); }
    60% { transform: translateX(-1px); text-shadow: -1px 0 var(--aurora-cyan), 1px 0 var(--aurora-pink); }
    100% { transform: translateX(0); text-shadow: none; }
}

.glitch-active { animation: glitch-in 300ms ease; }

/* ===== BRASS ELEMENTS ===== */
.brass-rule {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--brass) 20%, var(--brass) 80%, transparent);
    margin: 1.5rem 0 2.5rem;
    max-width: 600px;
}

.brass-ornament {
    text-align: center;
    color: var(--brass);
    font-size: 1.5rem;
    margin: 3rem 0;
    opacity: 0.6;
    position: relative;
    z-index: 2;
}

/* ===== SECTION HEADERS ===== */
.section-header {
    position: relative;
    z-index: 2;
    margin-bottom: 3rem;
}

.section-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(3rem, 10vw, 12rem);
    line-height: 0.95;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.section-title.aurora-text {
    background: linear-gradient(135deg, var(--aurora-green) 0%, var(--aurora-cyan) 30%, var(--aurora-violet) 65%, var(--aurora-pink) 100%);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: gradient-shift 8s ease infinite;
}

/* ===== SLIDE-IN ANIMATIONS ===== */
.slide-in-left, .slide-in-right {
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.slide-in-left { transform: translateX(-30px); }
.slide-in-right { transform: translateX(30px); }
.slide-in-left.visible, .slide-in-right.visible { opacity: 1; transform: translateX(0); }

/* ===== READING ROOM ===== */
.reading-room-grid {
    display: grid;
    grid-template-columns: 61.8% 38.2%;
    gap: 3rem;
    position: relative;
    z-index: 2;
}

.main-column p {
    max-width: 62ch;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.margin-column {
    padding-top: 1rem;
}

.marginalia {
    font-family: var(--font-mono);
    font-size: 0.88em;
    line-height: 1.55;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(61,255,162,0.2);
}

.margin-label {
    display: block;
    color: var(--aurora-green);
    opacity: 0.6;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

/* ===== CIRCUIT LIBRARY ===== */
.book-shelf {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 4rem 0;
    perspective: 800px;
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
}

.book-spine {
    width: 80px;
    height: 320px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s ease;
    cursor: pointer;
}

.spine-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
}

.spine-front {
    background: linear-gradient(180deg, var(--leather-dark) 0%, var(--leather-mid) 40%, var(--leather-dark) 100%);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.5), 2px 2px 10px rgba(0,0,0,0.4);
    border: 1px solid rgba(184,148,74,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px 6px 6px 2px;
}

.spine-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--brass);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.spine-page {
    background: var(--text-primary);
    transform: rotateY(180deg);
    border-radius: 2px;
    overflow: hidden;
}

.circuit-page {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
    padding: 1rem;
}

.circuit-line {
    height: 2px;
    background: var(--aurora-green);
    opacity: 0.4;
    margin: 20px 0;
    width: 60%;
    border-radius: 1px;
}

.circuit-line:nth-child(2) { width: 80%; margin-left: 10%; }
.circuit-line:nth-child(3) { width: 40%; margin-left: 30%; }

.circuit-dot {
    width: 6px;
    height: 6px;
    background: var(--aurora-green);
    border-radius: 50%;
    opacity: 0.5;
    position: absolute;
}

.circuit-dot:nth-child(4) { top: 40%; left: 20%; }
.circuit-dot:nth-child(5) { top: 70%; left: 65%; }

.book-spine.flipped { transform: rotateY(180deg); }

.circuit-caption {
    text-align: center;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    position: relative;
    z-index: 2;
    max-width: 60ch;
    margin: 0 auto;
}

/* Section glitch shake */
@keyframes section-glitch {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(2px); }
    75% { transform: translateX(-2px); }
}

#circuit-library.glitch-shake { animation: section-glitch 100ms ease; }

/* ===== OBSERVATORY ===== */
#observatory { overflow: hidden; }

.aurora-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.aurora-layer {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    mix-blend-mode: screen;
}

.aurora-1 {
    width: 60vw; height: 60vw;
    background: radial-gradient(circle, rgba(61,255,162,0.08) 0%, transparent 70%);
    top: -20%; left: -10%;
    animation: aurora-move-1 12s ease-in-out infinite;
}

.aurora-2 {
    width: 50vw; height: 50vw;
    background: radial-gradient(circle, rgba(155,93,229,0.06) 0%, transparent 70%);
    top: 20%; right: -15%;
    animation: aurora-move-2 15s ease-in-out infinite;
}

.aurora-3 {
    width: 45vw; height: 45vw;
    background: radial-gradient(circle, rgba(0,212,255,0.05) 0%, transparent 70%);
    bottom: -10%; left: 30%;
    animation: aurora-move-3 10s ease-in-out infinite;
}

@keyframes aurora-move-1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(10vw, 5vh); }
}

@keyframes aurora-move-2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-8vw, 8vh); }
}

@keyframes aurora-move-3 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(5vw, -10vh); }
}

.observatory-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    position: relative;
    z-index: 2;
    max-width: 1000px;
    margin: 0 auto;
}

.glass-panel {
    background: rgba(42, 34, 51, 0.4);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    border: 1px solid rgba(61, 255, 162, 0.15);
    border-radius: 16px;
    padding: 2.5rem;
}

.glass-panel h3 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 2rem;
    background: linear-gradient(135deg, var(--aurora-green), var(--aurora-cyan), var(--aurora-violet));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: gradient-shift 8s ease infinite;
    margin-bottom: 1rem;
}

.glass-panel p {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.7;
}

.glass-1 { grid-column: 1; }
.glass-2 { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.glass-3 { grid-column: 1; }

/* ===== ARCHIVE INDEX ===== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    position: relative;
    z-index: 2;
    max-width: 1200px;
}

.catalog-card {
    border: 1px solid var(--brass);
    padding: 1.5rem 2rem;
    background: rgba(30, 23, 38, 0.6);
    transition: border-color 0.3s, background 0.3s;
    cursor: pointer;
}

.catalog-card:hover {
    border-image: linear-gradient(135deg, var(--aurora-green), var(--aurora-cyan), var(--aurora-violet), var(--aurora-pink)) 1;
    background: rgba(42, 34, 51, 0.6);
}

.card-category {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--aurora-green);
    letter-spacing: 0.15em;
    opacity: 0.7;
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.6rem;
    margin: 0.5rem 0;
    color: var(--text-primary);
}

.card-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===== COLOPHON ===== */
.colophon {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2rem 0 3rem;
}

.colophon p {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.5;
    max-width: 70ch;
    margin: 0 auto;
    line-height: 1.6;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
    .panel { padding: 4rem 1.5rem 4rem calc(16px + 1.5rem); }

    #nav-spine {
        left: 0; top: auto; bottom: 0;
        width: 100%; height: 48px;
        flex-direction: row;
        gap: 0;
    }
    #nav-spine:hover { width: 100%; height: 48px; }
    .nav-item { writing-mode: horizontal-tb; font-size: 0.6rem; padding: 8px; }
    .nav-label { display: none; }
    #nav-spine:hover .nav-item { writing-mode: horizontal-tb; }

    .reading-room-grid { grid-template-columns: 1fr; }

    .observatory-grid { grid-template-columns: 1fr; }
    .glass-2 { grid-column: 1; grid-row: auto; }

    .hero-title { font-size: clamp(3rem, 12vw, 8rem); }
    .section-title { font-size: clamp(2rem, 8vw, 6rem); }

    .book-shelf { gap: 1rem; }
    .book-spine { width: 60px; height: 240px; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
