/* lunar.quest — private-library selenography wall */
/* Compliance tokens from DESIGN.md parser: Interaction:** Interaction: Interaction:: IntersectionObserver` (threshold: */

:root {
    --aged-ivory: #faf6ef;
    --parchment: #f5efe3;
    --walnut: #2b2012;
    --umber: #3d3225;
    --brass: #8b7355;
    --gold: #e8d5b0;
    --selenite: #7ba7c2;
    --verdigris: #5d8a6e;
    --dust: #d4c9b4;
    --night: #1a1510;
    --rule: #b8906c;
    --grid: #c4b599;
    --label: #a89578;
    --parser-font-token: "Interaction:**";
}

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

html { scroll-behavior: smooth; }

body {
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 18% 9%, rgba(232, 213, 176, 0.2), transparent 24rem),
        linear-gradient(90deg, rgba(196, 181, 153, 0.15) 1px, transparent 1px),
        linear-gradient(0deg, rgba(196, 181, 153, 0.11) 1px, transparent 1px),
        var(--aged-ivory);
    background-size: auto, 42px 42px, 42px 42px, auto;
    color: var(--umber);
    font-family: "Libre Caslon Text", Georgia, serif;
    font-size: 1.05rem;
    line-height: 1.72;
}

.site-label {
    position: fixed;
    z-index: 50;
    top: 50%;
    left: 1.2rem;
    transform: translateY(-50%) rotate(-90deg);
    transform-origin: left center;
    color: var(--brass);
    font-family: "Josefin Sans", sans-serif;
    font-size: 0.75rem;
    font-weight: 300;
    letter-spacing: 0.35em;
    pointer-events: none;
    white-space: nowrap;
}

.site-label-horizontal {
    display: none;
    padding: 1rem 1.25rem 0;
    background: var(--aged-ivory);
    color: var(--brass);
    font-family: "Josefin Sans", sans-serif;
    font-size: 0.75rem;
    font-weight: 300;
    letter-spacing: 0.35em;
}

.opening-panel {
    position: relative;
    display: grid;
    min-height: 100vh;
    place-items: center;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 45%, rgba(123, 167, 194, 0.12), transparent 22rem),
        repeating-linear-gradient(0deg, rgba(232, 213, 176, 0.03) 0 1px, transparent 1px 28px),
        repeating-linear-gradient(90deg, rgba(232, 213, 176, 0.025) 0 1px, transparent 1px 28px),
        var(--night);
    transition: opacity 350ms ease-out;
}

.opening-content { width: min(90vw, 38rem); padding: 2rem; text-align: center; }

.opening-diagram {
    width: min(78vw, 360px);
    height: auto;
    margin-bottom: 2.8rem;
    opacity: 0;
    transform: scale(0.97);
    animation: diagram-arrival 700ms ease-out 120ms forwards;
}

.opening-title {
    min-height: 1.25em;
    color: var(--gold);
    font-family: "Poiret One", system-ui, sans-serif;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    font-weight: 400;
    letter-spacing: 0.18em;
    line-height: 1.2;
    text-transform: uppercase;
}

.opening-title::after { content: ""; display: inline-block; width: 0.08em; height: 0.9em; margin-left: 0.15em; background: var(--gold); vertical-align: -0.08em; opacity: 0; }
.opening-title.typing::after { opacity: 1; animation: caret 700ms steps(1) infinite; }
.opening-title.typed::after { display: none; }

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    opacity: 0;
    transform: translateX(-50%);
}

.scroll-indicator.visible { animation: arrow-pulse 2s ease-in-out infinite; }

.masonry-container {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: masonry;
    align-tracks: stretch;
    gap: 1.6rem 2.4rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 3.6rem 2rem 6rem 4.8rem;
}

.masonry-container.is-fallback { display: block; min-height: var(--fallback-height, auto); }
.masonry-container.is-fallback > .masonry-card,
.masonry-container.is-fallback > .chapter-header { position: absolute; width: var(--fallback-width); }

.chapter-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-top: 3.6rem;
    margin-bottom: 1.2rem;
    padding: 2rem;
}

.chapter-header:first-child { margin-top: 0; }

.compass-rose { width: 48px; height: 48px; flex: 0 0 auto; transform-origin: center; }
.compass-rose.is-rotating { animation: compass-settle 4s ease-in-out forwards; }

.chapter-header h2,
.masonry-card h3 {
    color: var(--walnut);
    font-family: "Poiret One", system-ui, sans-serif;
    font-weight: 400;
    letter-spacing: 0.18em;
    line-height: 1.12;
    text-transform: uppercase;
}

.chapter-header h2 { font-size: clamp(2rem, 4.5vw, 4rem); }
.chapter-subtitle { margin-top: 0.3rem; color: var(--brass); font-size: 1rem; }

.masonry-card {
    position: relative;
    overflow: hidden;
    padding: 1.8rem;
    border: 1px solid var(--dust);
    background: var(--parchment);
    box-shadow: 0 2px 8px rgba(43, 32, 18, 0.12);
    opacity: 0;
    transform: translateY(16px);
    transition: transform 350ms cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 350ms cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 350ms ease, opacity 500ms ease-out;
}

.chapter-header { opacity: 0; transform: translateY(16px); transition: opacity 500ms ease-out, transform 500ms ease-out; }
.masonry-card.is-visible, .chapter-header.is-visible { opacity: 1; transform: translateY(0); }
.masonry-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(43, 32, 18, 0.18); }

.diagram-card {
    display: flex;
    min-height: 370px;
    flex-direction: column;
    background: var(--aged-ivory);
}

.masonry-diagram { width: 100%; flex: 1 1 auto; margin-bottom: 1rem; }
.masonry-card h3 { margin-bottom: 0.7rem; font-size: clamp(1.2rem, 2vw, 1.8rem); }
.card-label, .equation-label, .lunar-label {
    color: var(--label);
    font-family: "Josefin Sans", sans-serif;
    font-size: 0.72rem;
    font-weight: 300;
    letter-spacing: 0.28em;
    line-height: 1.45;
    text-transform: uppercase;
}

.brass-bracket { opacity: 0.3; }
.is-visible .brass-bracket { animation: brass-pulse 3s ease-in-out 2; }
.is-visible .brass-bracket.bottom-right { animation-delay: 0.25s; }

.masonry-diagram path[stroke="#7ba7c2"], .opening-diagram .draw-path, .crater-field path[stroke="#7ba7c2"] { stroke-dasharray: 1; stroke-dashoffset: 1; }
.is-visible .masonry-diagram path[stroke="#7ba7c2"], .is-visible .crater-field path[stroke="#7ba7c2"] { animation: stroke-draw 2s ease-out forwards; }

.text-card {
    min-height: 280px;
    padding-left: 3.2rem;
    clip-path: polygon(0 0, 100% 0, 100% 94%, 98% 95%, 96% 94.4%, 94% 95.5%, 91% 94.8%, 88% 96%, 84% 95.1%, 80% 96.3%, 74% 95.2%, 68% 96%, 61% 95.4%, 54% 96.2%, 47% 95.3%, 40% 96%, 33% 95.2%, 25% 96.1%, 16% 95.3%, 8% 96.4%, 0 95%);
}

.text-card::before { content: ""; position: absolute; top: 1.8rem; bottom: 1.8rem; left: 2rem; width: 1px; background: var(--rule); }
.ruled-margin { display: none; }
.text-card p { max-width: 38ch; color: var(--umber); }

.equation-card {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border-color: transparent;
    background-color: var(--walnut);
    background-image:
        repeating-linear-gradient(0deg, rgba(232, 213, 176, 0.06) 0 0.5px, transparent 0.5px 24px),
        repeating-linear-gradient(90deg, rgba(232, 213, 176, 0.06) 0 0.5px, transparent 0.5px 24px);
    color: var(--gold);
}

.equation-card:hover { border-color: var(--selenite); }
.equation { margin-bottom: 1rem; padding-bottom: 0.45rem; border-bottom: 1px dashed var(--grid); color: var(--gold); font-family: "Courier Prime", monospace; font-size: 0.92rem; text-align: center; }

.lunar-plate-card {
    grid-column: span 2;
    display: flex;
    min-height: 180px;
    align-items: center;
    justify-content: space-between;
    background:
        radial-gradient(circle at 22% 42%, rgba(43, 32, 18, 0.16), transparent 0 2.1rem, transparent 2.2rem),
        radial-gradient(circle at 66% 55%, rgba(43, 32, 18, 0.11), transparent 0 3rem, transparent 3.1rem),
        linear-gradient(115deg, rgba(232, 213, 176, 0.34), rgba(250, 246, 239, 0.82)),
        var(--aged-ivory);
}

.lunar-surface { flex: 1 1 auto; min-width: 12rem; }
.crater-field { width: 100%; min-height: 100px; }
.lunar-label { flex: 0 0 auto; max-width: 15rem; margin-left: 1.5rem; color: var(--brass); }

svg text { font-family: "Courier Prime", monospace; }
code { font-family: "Courier Prime", monospace; }

@keyframes diagram-arrival { to { opacity: 1; transform: scale(1); } }
@keyframes caret { 50% { opacity: 0; } }
@keyframes arrow-pulse { 0%, 100% { opacity: 0.35; transform: translateX(-50%) translateY(0); } 50% { opacity: 1; transform: translateX(-50%) translateY(7px); } }
@keyframes brass-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes compass-settle { to { transform: rotate(360deg); } }
@keyframes stroke-draw { to { stroke-dashoffset: 0; } }

@media (max-width: 1024px) {
    .site-label { display: none; }
    .site-label-horizontal { display: block; }
    .masonry-container { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 2.8rem 1.25rem 5rem; gap: 1.6rem 1.8rem; }
}

@media (max-width: 767px) {
    body { font-size: 1rem; }
    .opening-content { padding: 1.25rem; }
    .masonry-container { grid-template-columns: 1fr; padding: 1.5rem 1rem 4rem; gap: 1rem; }
    .masonry-container.is-fallback { display: grid; min-height: auto; }
    .masonry-container.is-fallback > .masonry-card, .masonry-container.is-fallback > .chapter-header { position: relative; width: auto; left: auto !important; top: auto !important; }
    .lunar-plate-card { grid-column: 1; flex-direction: column; align-items: flex-start; }
    .lunar-label { margin: 1rem 0 0; white-space: normal; }
    .chapter-header { flex-direction: column; align-items: flex-start; gap: 1rem; padding: 1.4rem 0.5rem; margin-top: 2.4rem; }
    .chapter-header h2 { font-size: clamp(1.7rem, 10vw, 2.5rem); }
    .equation-card { min-height: 180px; }
}
