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

html {
    scroll-behavior: smooth;
}

body {
    font-family: "Space Grotesk", sans-serif;
    color: #2a2a22;
    background: #e8e4dc;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.grain {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px;
}

/* ───── BOOK CONTAINER ───── */
.journal-container {
    position: relative;
    width: min(860px, calc(100vw - 2.4rem));
    margin: 2rem auto;
    height: calc(100vh - 4rem);
    perspective: 2200px;
}

/* ───── PAGE (shared between entries & detail) ───── */
.journal-page {
    position: absolute;
    inset: 0;
    height: 100%;
    padding: 2.4rem 2.2rem 2rem 4.2rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(42, 42, 34, 0.1);
    border-radius: 10px;
    background:
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent 35px,
            rgba(102, 138, 189, 0.16) 35px,
            rgba(102, 138, 189, 0.16) 36px
        ),
        #f6f3eb;
    box-shadow: 0 18px 50px rgba(42, 42, 34, 0.08);
    transform-origin: left center;
    backface-visibility: hidden;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.journal-page::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2.1rem;
    width: 1px;
    background: rgba(190, 89, 79, 0.55);
}

/* Active page (visible, interactable) */
.journal-page.active {
    position: relative;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    overflow-y: auto;
}

/* ───── FLIP ANIMATIONS ───── */
.journal-page.flip-out {
    visibility: visible;
    opacity: 1;
    pointer-events: none;
    animation: pageFlipOut 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.journal-page.flip-in {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    animation: pageFlipIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pageFlipOut {
    0% {
        transform: perspective(2200px) rotateY(0deg);
        opacity: 1;
    }
    100% {
        transform: perspective(2200px) rotateY(-90deg);
        opacity: 0;
    }
}

@keyframes pageFlipIn {
    0% {
        transform: perspective(2200px) rotateY(90deg);
        opacity: 0;
    }
    100% {
        transform: perspective(2200px) rotateY(0deg);
        opacity: 1;
    }
}

/* ───── HEADER ───── */
.journal-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 2rem;
    padding-bottom: 0.8rem;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(42, 42, 34, 0.05);
    color: #2a2a22;
    text-decoration: none;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.2s ease, background 0.2s ease;
}

.back-btn:hover {
    background: rgba(42, 42, 34, 0.1);
    transform: translateX(-2px);
}

.journal-header h1 {
    font-family: "Instrument Serif", serif;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    font-weight: 400;
    letter-spacing: -0.02em;
}

/* ───── MAIN ───── */
.journal-main {
    flex: 1;
}

.journal-intro {
    margin-bottom: 2rem;
}

.journal-intro h2 {
    font-family: "Instrument Serif", serif;
    font-size: clamp(1.3rem, 2.2vw, 1.7rem);
    font-weight: 400;
    margin-bottom: 0.4rem;
}

.journal-intro p {
    color: #6e695e;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* ───── ENTRIES ───── */
.journal-entries {
    display: flex;
    flex-direction: column;
    gap: 1.3rem;
}

.journal-entry {
    border: 1px solid rgba(42, 42, 34, 0.1);
    background: rgba(255, 255, 255, 0.56);
    border-radius: 8px;
    padding: 1rem 1.1rem 1.1rem;
    cursor: pointer;
    transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.journal-entry:hover {
    transform: translateY(-2px);
    border-color: rgba(42, 42, 34, 0.2);
    background: rgba(255, 255, 255, 0.74);
}

.entry-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.35rem;
}

.entry-date {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9a9488;
}

.entry-title {
    font-family: "Instrument Serif", serif;
    font-size: 1.26rem;
    font-weight: 400;
    margin-bottom: 0.35rem;
}

.entry-text {
    color: #5f5a50;
    font-size: 0.95rem;
    line-height: 1.75;
}

/* ───── DETAIL PAGE ───── */
.detail-content {
    padding-top: 0.5rem;
}

.detail-date {
    display: block;
    color: #9a9488;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.7rem;
}

.detail-title {
    font-family: "Instrument Serif", serif;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    font-weight: 400;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.detail-summary {
    color: #5f5a50;
    font-size: 1rem;
    line-height: 1.85;
    margin-bottom: 1.35rem;
}

.detail-subsection {
    border-top: 1px solid rgba(42, 42, 34, 0.12);
    padding-top: 1rem;
}

.detail-subtitle {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8f887b;
    margin-bottom: 0.85rem;
}

.detail-sections {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.detail-section {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(42, 42, 34, 0.1);
    border-radius: 8px;
    padding: 0.85rem 0.95rem;
}

.detail-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #504b43;
    margin-bottom: 0.45rem;
}

.detail-section p {
    color: #5f5a50;
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-wrap;
}

.detail-section a {
    color: #3f617f;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
}

.detail-section a:hover {
    color: #2a2a22;
}

.detail-section code {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.88em;
    background: rgba(42, 42, 34, 0.08);
    border: 1px solid rgba(42, 42, 34, 0.08);
    border-radius: 4px;
    padding: 0.08rem 0.35rem;
}

.detail-section pre {
    margin-top: 0.8rem;
    padding: 0.8rem 0.9rem;
    background: rgba(42, 42, 34, 0.06);
    border: 1px solid rgba(42, 42, 34, 0.08);
    border-radius: 8px;
    overflow-x: auto;
}

.detail-section pre code {
    display: block;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    line-height: 1.7;
}

/* ───── FOOTER ───── */
.journal-footer {
    margin-top: 1.8rem;
    padding-top: 0.9rem;
    text-align: center;
}

.journal-footer p {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: #9a9488;
    text-transform: uppercase;
}

/* ───── MOBILE ───── */
@media (max-width: 768px) {
    .journal-container {
        width: calc(100vw - 1.2rem);
        margin: 0.6rem auto;
        height: calc(100vh - 1.2rem);
    }

    .journal-page {
        padding: 1.3rem 0.95rem 1.1rem 2.1rem;
        border-radius: 8px;
    }

    .journal-page::before {
        left: 1.1rem;
    }

    .journal-header {
        margin-bottom: 1.2rem;
        padding-bottom: 0.3rem;
    }

    .journal-intro {
        margin-bottom: 1.2rem;
    }

    .journal-entry {
        padding: 0.85rem 0.85rem 0.95rem;
    }

    .entry-title {
        font-size: 1.12rem;
    }

    .entry-text {
        font-size: 0.9rem;
        line-height: 1.7;
    }

    .detail-title {
        margin-bottom: 0.8rem;
    }

    .detail-summary {
        font-size: 0.94rem;
        line-height: 1.8;
    }

    .detail-section {
        padding: 0.75rem 0.8rem;
    }

    .detail-section p {
        font-size: 0.9rem;
    }
}
