/* ============================================================
   HHUDDL.com — Luminous Scholarship
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --void: #0e0d20;
    --spine: #0c0b1e;
    --ruled: #1a1940;
    --neon-magenta: #ff2d78;
    --neon-cyan: #00e5ff;
    --pale-lavender: #d4d0e6;
    --dusty-violet: #6b6590;
    --ember-amber: #ffb347;
    --ghost-white: #f0eef8;

    --sidebar-width: 280px;
    --glow-y: 50%;
    --glow-x: 50%;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--void);
    color: var(--pale-lavender);
    font-family: 'Lora', Georgia, serif;
    font-size: 18px;
    line-height: 1.75;
    font-weight: 400;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Reading Lamp Glow --- */
.reading-lamp {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background: radial-gradient(
        circle 600px at var(--glow-x) var(--glow-y),
        rgba(255, 45, 120, 0.06) 0%,
        transparent 70%
    );
    pointer-events: none;
    z-index: 1;
    transition: background 0.3s ease;
}

/* --- Sidebar / Book Spine --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--spine);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    opacity: 0;
    transform: translateX(-280px);
    animation: sidebarEnter 800ms ease-out 500ms forwards;
}

@keyframes sidebarEnter {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Ruled lines overlay in sidebar */
.sidebar-ruled-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 31px,
        rgba(26, 25, 64, 0.3) 31px,
        rgba(26, 25, 64, 0.3) 32px
    );
    pointer-events: none;
    mask-image: linear-gradient(to bottom, transparent, black);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black);
    animation: ruledLinesDraw 800ms ease-out 500ms forwards;
    opacity: 0;
}

@keyframes ruledLinesDraw {
    0% {
        opacity: 0;
        mask-image: linear-gradient(to bottom, black 0%, transparent 0%);
        -webkit-mask-image: linear-gradient(to bottom, black 0%, transparent 0%);
    }
    100% {
        opacity: 1;
        mask-image: linear-gradient(to bottom, black 100%, transparent 100%);
        -webkit-mask-image: linear-gradient(to bottom, black 100%, transparent 100%);
    }
}

/* Progress Indicator / Bookmark Ribbon */
.sidebar-progress {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: rgba(26, 25, 64, 0.4);
}

.sidebar-progress-fill {
    width: 100%;
    height: 0%;
    background: linear-gradient(to bottom, var(--neon-magenta), var(--neon-cyan));
    transition: height 0.15s ease-out;
}

/* Sidebar Navigation */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 48px;
    padding: 0 32px;
}

.sidebar-link {
    display: block;
    text-decoration: none;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--dusty-violet);
    opacity: 0.4;
    transition: opacity 0.4s ease, color 0.4s ease;
    position: relative;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
}

.sidebar-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 1px;
    background-color: var(--neon-cyan);
    transition: width 200ms ease;
}

.sidebar-link:hover::after {
    width: 100%;
}

.sidebar-link:hover {
    opacity: 0.7;
}

.sidebar-link.active {
    color: var(--neon-magenta);
    opacity: 1;
    animation: pulseAttention 3s ease-in-out infinite;
}

@keyframes pulseAttention {
    0%, 100% {
        opacity: 0.6;
        text-shadow: 0 0 10px rgba(255, 45, 120, 0.2);
    }
    50% {
        opacity: 1;
        text-shadow: 0 0 20px rgba(255, 45, 120, 0.5), 0 0 40px rgba(255, 45, 120, 0.2);
    }
}

/* --- Main Content Area --- */
.main-content {
    margin-left: var(--sidebar-width);
    position: relative;
    z-index: 2;
}

/* --- Chapter Sections --- */
.chapter {
    min-height: 100vh;
    position: relative;
    padding: 120px 48px;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 400ms ease, transform 400ms ease;
}

.chapter.visible {
    opacity: 1;
    transform: translateY(0);
}

.chapter.fading {
    opacity: 0.3;
    transform: translateY(-10px);
}

/* Chapter Number Watermark */
.chapter-number {
    position: absolute;
    top: 60px;
    right: 60px;
    pointer-events: none;
}

.chapter-numeral {
    font-family: 'Bungee Shade', cursive;
    font-size: 200px;
    color: transparent;
    -webkit-text-stroke: 2px rgba(255, 45, 120, 0.15);
    line-height: 1;
    user-select: none;
}

/* Page Curl Corner */
.page-curl {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 20px;
    height: 20px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.page-curl::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 20px 20px 0;
    border-color: transparent var(--ruled) transparent transparent;
    box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.3);
}

.page-curl::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 18px 18px 0;
    border-color: transparent var(--neon-cyan) transparent transparent;
    opacity: 0;
    transition: opacity 200ms ease;
}

.page-curl:hover {
    transform: scale(1.4);
}

.page-curl:hover::after {
    opacity: 0.6;
}

/* Chapter Grid */
.chapter-grid {
    display: grid;
    grid-template-columns: 4fr 2fr;
    gap: 24px;
    max-width: 1200px;
    width: 100%;
}

/* Chapter Content */
.chapter-content {
    position: relative;
}

.chapter-title {
    font-family: 'Righteous', cursive;
    font-size: 72px;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: var(--neon-magenta);
    text-shadow: 0 0 40px rgba(255, 45, 120, 0.4), 0 0 80px rgba(255, 45, 120, 0.15);
    margin-bottom: 16px;
    line-height: 1.1;
}

.chapter-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--dusty-violet);
    margin-bottom: 48px;
}

.chapter-body {
    font-family: 'Lora', Georgia, serif;
    font-size: 18px;
    line-height: 1.75;
    color: var(--pale-lavender);
    margin-bottom: 24px;
    max-width: 640px;
}

/* Pull Quotes */
.pull-quote {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-size: 22px;
    line-height: 1.6;
    color: var(--ghost-white);
    padding: 32px 0;
    margin: 32px 0;
    border-left: 3px solid var(--neon-magenta);
    padding-left: 24px;
    position: relative;
}

.pull-quote-mark {
    font-family: 'Righteous', cursive;
    font-size: 36px;
    color: var(--neon-magenta);
    opacity: 0.6;
    vertical-align: -4px;
}

/* Bookmark Ribbon */
.bookmark-ribbon {
    position: absolute;
    left: -24px;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--neon-magenta);
    transition: width 300ms cubic-bezier(0.34, 1.56, 0.64, 1), left 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bookmark-ribbon:hover {
    width: 5px;
    left: -28px;
}

/* Chapter Margin */
.chapter-margin {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 40px;
    padding-left: 24px;
}

/* Marginalia */
.marginalia {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--dusty-violet);
    line-height: 1.5;
    padding: 8px 0;
    border-bottom: 1px solid rgba(26, 25, 64, 0.5);
}

.marginalia-highlight {
    color: var(--ember-amber);
}

/* --- Isometric Icon System --- */
.iso-icon {
    width: 120px;
    height: 120px;
    perspective: 600px;
    margin: 20px auto;
}

.iso-scene {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(55deg) rotateZ(-45deg);
    animation: isoBreathing 3s ease-in-out infinite;
}

@keyframes isoBreathing {
    0%, 100% { transform: rotateX(55deg) rotateZ(-45deg) scale(1); }
    50% { transform: rotateX(55deg) rotateZ(-45deg) scale(1.03); }
}

.iso-plane {
    position: absolute;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.iso-icon.assembled .iso-plane {
    opacity: 1;
    transform: translateY(0);
}

.iso-icon.assembled .iso-plane:nth-child(2) { transition-delay: 100ms; }
.iso-icon.assembled .iso-plane:nth-child(3) { transition-delay: 200ms; }
.iso-icon.assembled .iso-plane:nth-child(4) { transition-delay: 300ms; }
.iso-icon.assembled .iso-plane:nth-child(5) { transition-delay: 400ms; }
.iso-icon.assembled .iso-plane:nth-child(6) { transition-delay: 500ms; }

/* --- Isometric Book Icon --- */
.iso-book-left {
    width: 50px;
    height: 60px;
    background-color: var(--neon-magenta);
    bottom: 20px;
    left: 10px;
    transform-origin: right center;
    transform: translateY(30px) rotateY(-15deg);
}

.iso-icon.assembled .iso-book-left {
    transform: translateY(0) rotateY(-15deg);
}

.iso-book-right {
    width: 50px;
    height: 60px;
    background-color: var(--neon-cyan);
    bottom: 20px;
    right: 10px;
    transform-origin: left center;
    transform: translateY(30px) rotateY(15deg);
}

.iso-icon.assembled .iso-book-right {
    transform: translateY(0) rotateY(15deg);
}

.iso-book-spine {
    width: 8px;
    height: 60px;
    background-color: var(--ruled);
    bottom: 20px;
    left: 50%;
    margin-left: -4px;
}

.iso-book-page1 {
    width: 40px;
    height: 2px;
    background-color: rgba(208, 212, 230, 0.3);
    bottom: 45px;
    left: 16px;
}

.iso-book-page2 {
    width: 40px;
    height: 2px;
    background-color: rgba(208, 212, 230, 0.2);
    bottom: 50px;
    right: 16px;
}

.iso-book-page3 {
    width: 40px;
    height: 2px;
    background-color: rgba(208, 212, 230, 0.15);
    bottom: 55px;
    left: 20px;
}

/* --- Isometric Magnifying Glass Icon --- */
.iso-magnify-lens {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 4px solid var(--neon-cyan);
    background-color: rgba(0, 229, 255, 0.08);
    top: 10px;
    left: 15px;
}

.iso-magnify-handle {
    width: 6px;
    height: 35px;
    background-color: var(--neon-magenta);
    bottom: 10px;
    right: 25px;
    transform-origin: top center;
    transform: translateY(30px) rotate(30deg);
}

.iso-icon.assembled .iso-magnify-handle {
    transform: translateY(0) rotate(30deg);
}

.iso-magnify-glass {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: rgba(0, 229, 255, 0.04);
    top: 20px;
    left: 25px;
}

/* --- Isometric Hourglass Icon --- */
.iso-hg-top {
    width: 44px;
    height: 24px;
    background-color: var(--neon-cyan);
    top: 10px;
    left: 50%;
    margin-left: -22px;
    clip-path: polygon(10% 0%, 90% 0%, 50% 100%);
}

.iso-hg-bottom {
    width: 44px;
    height: 24px;
    background-color: var(--neon-magenta);
    bottom: 20px;
    left: 50%;
    margin-left: -22px;
    clip-path: polygon(50% 0%, 90% 100%, 10% 100%);
}

.iso-hg-neck {
    width: 4px;
    height: 10px;
    background-color: var(--pale-lavender);
    top: 50%;
    left: 50%;
    margin-left: -2px;
    margin-top: -5px;
}

.iso-hg-sand {
    width: 20px;
    height: 12px;
    background-color: var(--ember-amber);
    bottom: 22px;
    left: 50%;
    margin-left: -10px;
    clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
    opacity: 0.7;
}

.iso-hg-base-top {
    width: 54px;
    height: 4px;
    background-color: var(--ruled);
    top: 8px;
    left: 50%;
    margin-left: -27px;
}

.iso-hg-base-bottom {
    width: 54px;
    height: 4px;
    background-color: var(--ruled);
    bottom: 16px;
    left: 50%;
    margin-left: -27px;
}

/* --- Isometric Book Stack Icon --- */
.iso-stack-book1 {
    width: 60px;
    height: 14px;
    background-color: var(--neon-magenta);
    bottom: 20px;
    left: 50%;
    margin-left: -30px;
}

.iso-stack-book2 {
    width: 55px;
    height: 14px;
    background-color: var(--neon-cyan);
    bottom: 38px;
    left: 50%;
    margin-left: -25px;
}

.iso-stack-book3 {
    width: 58px;
    height: 14px;
    background-color: var(--neon-magenta);
    opacity: 0.7;
    bottom: 56px;
    left: 50%;
    margin-left: -32px;
}

.iso-stack-book1-side {
    width: 8px;
    height: 14px;
    background-color: var(--ruled);
    bottom: 20px;
    left: 50%;
    margin-left: 30px;
}

.iso-stack-book2-side {
    width: 8px;
    height: 14px;
    background-color: rgba(26, 25, 64, 0.8);
    bottom: 38px;
    left: 50%;
    margin-left: 27px;
}

.iso-stack-book3-side {
    width: 8px;
    height: 14px;
    background-color: var(--ruled);
    bottom: 56px;
    left: 50%;
    margin-left: 26px;
}

/* --- Isometric Scroll Icon --- */
.iso-scroll-body {
    width: 50px;
    height: 60px;
    background-color: rgba(26, 25, 64, 0.6);
    border: 1px solid var(--ruled);
    top: 20px;
    left: 50%;
    margin-left: -25px;
}

.iso-scroll-roll-top {
    width: 58px;
    height: 10px;
    background-color: var(--neon-cyan);
    border-radius: 5px;
    top: 16px;
    left: 50%;
    margin-left: -29px;
}

.iso-scroll-roll-bottom {
    width: 58px;
    height: 10px;
    background-color: var(--neon-cyan);
    border-radius: 5px;
    bottom: 14px;
    left: 50%;
    margin-left: -29px;
}

.iso-scroll-text1 {
    width: 30px;
    height: 2px;
    background-color: var(--dusty-violet);
    top: 40px;
    left: 50%;
    margin-left: -15px;
}

.iso-scroll-text2 {
    width: 24px;
    height: 2px;
    background-color: var(--dusty-violet);
    top: 50px;
    left: 50%;
    margin-left: -15px;
}

/* --- Body Links --- */
a {
    color: var(--pale-lavender);
    text-decoration: underline;
    text-decoration-color: var(--dusty-violet);
    transition: text-decoration-color 200ms ease, text-shadow 200ms ease;
}

a:hover {
    text-decoration-color: var(--neon-magenta);
    text-shadow: 0 2px 4px rgba(255, 45, 120, 0.3);
}

/* --- Horizontal Rule Motif --- */
.chapter + .chapter::before {
    content: '';
    position: absolute;
    top: 0;
    left: 48px;
    right: 48px;
    height: 1px;
    background-color: var(--ruled);
}

/* --- Opening Sequence: Hero Title Typewriter --- */
.chapter-title.typewriter {
    overflow: hidden;
    border-right: 2px solid var(--neon-magenta);
    white-space: nowrap;
    width: 0;
    animation: typewriter 600ms steps(6) 1300ms forwards, blinkCaret 600ms step-end 1300ms 5;
}

@keyframes typewriter {
    to { width: 100%; }
}

@keyframes blinkCaret {
    50% { border-color: transparent; }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-snap-type: none;
    }

    .sidebar {
        opacity: 1;
        transform: translateX(0);
    }

    .sidebar-ruled-lines {
        opacity: 1;
    }

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

    .iso-plane {
        opacity: 1;
        transform: translateY(0);
    }

    .chapter-title.typewriter {
        width: 100%;
        border-right: none;
    }
}

/* --- Responsive (sidebar collapses on small screens) --- */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 60px;
    }

    .sidebar-link-text {
        display: none;
    }

    .sidebar-nav {
        padding: 0 8px;
    }

    .chapter-grid {
        grid-template-columns: 1fr;
    }

    .chapter-margin {
        padding-left: 0;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .chapter-numeral {
        font-size: 100px;
    }

    .chapter-title {
        font-size: 48px;
    }

    .chapter {
        padding: 80px 24px;
    }
}

@media (max-width: 600px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        display: none;
    }

    .reading-lamp {
        left: 0;
    }
}
