/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: #1A140E;
    color: #E8D5B5;
    font-family: 'Crimson Text', serif;
    font-size: clamp(1rem, 1.15vw, 1.15rem);
    line-height: 1.85;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3 {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    letter-spacing: 0.03em;
}

h1 {
    font-size: clamp(2.5rem, 5vw, 4.5rem);
}

h2 {
    font-size: clamp(2rem, 3.5vw, 3rem);
    margin-bottom: 1.5rem;
}

blockquote {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    font-weight: 400;
}

code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.875rem;
    background-color: rgba(201, 168, 76, 0.08);
    border: 1px solid rgba(201, 168, 76, 0.2);
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    color: #8B7B65;
}

/* Draw Underline Animation */
.draw-underline {
    position: relative;
    background-image: linear-gradient(#C9A84C, #C9A84C);
    background-size: 0% 2px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 800ms ease-out;
    padding-bottom: 2px;
}

.draw-underline.visible {
    background-size: 100% 2px;
}

/* Opening Frame */
.opening-frame {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4rem 8vw;
    position: relative;
    overflow: hidden;
    background-color: #1A140E;
}

.opening-content {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.opening-title {
    position: absolute;
    right: 8vw;
    top: 50%;
    transform: translateY(-50%);
    text-align: right;
    color: #E8D5B5;
    z-index: 10;
    max-width: 400px;
}

.opening-photo {
    position: absolute;
    left: 8vw;
    top: 50%;
    transform: translateY(-50%);
    width: 35vw;
    max-width: 500px;
    height: 60vh;
    max-height: 600px;
    position: relative;
}

.opening-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Sepia Photo Treatment */
.sepia-photo {
    filter: grayscale(100%) sepia(40%) contrast(1.1) brightness(0.9);
    position: relative;
}

.sepia-photo::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(201, 168, 76, 0.03) 0px,
            rgba(201, 168, 76, 0.03) 1px,
            transparent 1px,
            transparent 2px
        );
    pointer-events: none;
    opacity: 0.08;
}

.opening-photo,
.chapter-image {
    box-shadow: inset 0 0 80px rgba(13, 10, 7, 0.5);
}

/* HUD Reticle */
.hud-reticle {
    position: absolute;
    width: 120px;
    height: 120px;
    border: 1px solid rgba(201, 168, 76, 0.15);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    animation: slow-rotate 60s linear infinite, pulse-opacity 8s ease-in-out infinite;
}

.hud-reticle::before,
.hud-reticle::after {
    content: '';
    position: absolute;
    background-color: rgba(201, 168, 76, 0.15);
}

.hud-reticle::before {
    width: 2px;
    height: 16px;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
}

.hud-reticle::after {
    width: 16px;
    height: 2px;
    top: 50%;
    left: -8px;
    transform: translateY(-50%);
}

@keyframes slow-rotate {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

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

/* HUD Corner Brackets */
.hud-corner-bracket {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 2px solid rgba(201, 168, 76, 0.25);
    z-index: 4;
}

.top-left {
    top: 0;
    left: 0;
    border-right: none;
    border-bottom: none;
}

.top-right {
    top: 0;
    right: 0;
    border-left: none;
    border-bottom: none;
}

.bottom-left {
    bottom: 0;
    left: 0;
    border-right: none;
    border-top: none;
}

.bottom-right {
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: none;
}

/* Chapter Blocks */
.chapter-block {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 4rem 8vw;
    gap: 4rem;
    background-color: #1A140E;
    position: relative;
}

.block-left {
    flex-direction: row;
    justify-content: flex-start;
}

.block-right {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

.chapter-text {
    max-width: 500px;
    flex: 0 0 auto;
    z-index: 2;
}

.chapter-text h2 {
    color: #FFB347;
    margin-bottom: 1.5rem;
}

.chapter-text p {
    margin-bottom: 1.5rem;
    color: #E8D5B5;
}

.chapter-image {
    flex: 1;
    max-width: 40vw;
    height: 60vh;
    position: relative;
    overflow: hidden;
}

.chapter-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chapter-image .hud-reticle {
    top: 30%;
    left: 40%;
}

/* Koan Interlude */
.koan-interlude {
    min-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 8vw;
    background: linear-gradient(90deg, #1A140E 0%, #3D2B1A 30%, #3D2B1A 70%, #1A140E 100%);
    text-align: center;
    position: relative;
}

.koan-text {
    opacity: 0;
    letter-spacing: 0.2em;
    color: #E8D5B5;
    line-height: 1.6;
    transition: opacity 1200ms ease-out, letter-spacing 1200ms ease-out;
}

.koan-text.visible {
    opacity: 1;
    letter-spacing: 0.05em;
}

/* Terminal Horizon */
.terminal-horizon {
    min-height: 100vh;
    background: linear-gradient(180deg, #1A140E 0%, #0D0A07 100%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 4rem 8vw;
    position: relative;
    overflow: hidden;
}

.terminal-content {
    text-align: right;
    position: relative;
    z-index: 2;
}

.horizon-text {
    font-family: 'Playfair Display', serif;
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    color: #E8D5B5;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: repeating-linear-gradient(
        0deg,
        rgba(201, 168, 76, 0.03) 0px,
        rgba(201, 168, 76, 0.03) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .opening-frame {
        flex-direction: column;
        padding: 2rem 4vw;
    }

    .opening-title {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        text-align: center;
        margin-bottom: 2rem;
        width: 100%;
    }

    .opening-photo {
        position: relative;
        left: auto;
        top: auto;
        transform: none;
        width: 100%;
        max-width: none;
        height: 50vh;
        margin-bottom: 2rem;
    }

    .chapter-block {
        flex-direction: column !important;
        padding: 2rem 4vw;
        gap: 2rem;
    }

    .chapter-text {
        order: 1;
    }

    .chapter-image {
        order: 2;
        max-width: 100%;
        height: 40vh;
    }

    .koan-interlude {
        padding: 2rem 4vw;
        min-height: auto;
    }

    .koan-text {
        font-size: clamp(1rem, 2vw, 1.5rem);
    }

    .terminal-horizon {
        justify-content: center;
        padding: 2rem 4vw;
    }

    .horizon-text {
        font-size: clamp(1.5rem, 3vw, 2.5rem);
    }
}
