/* =====================================================================
   glolos.com — A Haunted Cartography Studio
   Design tokens follow DESIGN.md exactly.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
    --parchment: #F2E8D5;
    --parchment-2: #D4C4A8;
    --iron-gall: #1A110B;
    --burgundy: #3B0A1A;
    --gilt: #8B6914;
    --dried-blood: #6B1528;
    --colophon-black: #0A0506;
    --faded-notation: #A8957A;
    --foxing: #C4A060;

    /* Text + bg variables modulated by JS during transition */
    --bg-r: 242;
    --bg-g: 232;
    --bg-b: 213;
    --text-color: var(--iron-gall);
    --text-secondary: var(--faded-notation);
    --rule-color: var(--parchment-2);
}

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

html {
    scroll-behavior: smooth;
    background: var(--parchment);
}

body {
    font-family: "Lora", Georgia, "Times New Roman", serif;
    font-weight: 400;
    color: var(--text-color);
    background-color: rgb(var(--bg-r), var(--bg-g), var(--bg-b));
    line-height: 1.75;
    overflow-x: hidden;
    filter: sepia(0.05) contrast(1.02);
    transition: color 600ms ease;
    min-height: 100vh;
}

/* ---------- Paper-grain noise overlay ---------- */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/></svg>");
    background-size: 256px 256px;
    mix-blend-mode: multiply;
    opacity: 0.55;
}

/* Vignette */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(26, 17, 11, 0.32) 100%);
}

/* ---------- Quill-stroke progress indicator ---------- */
.quill-progress {
    position: fixed;
    top: 0;
    left: 28px;
    height: 100vh;
    width: 30px;
    z-index: 1000;
    pointer-events: none;
}

.quill-line {
    position: absolute;
    top: 0;
    left: 14px;
    width: 2px;
    height: 0%;
    background: var(--gilt);
    transition: height 80ms linear;
    box-shadow: 0 0 4px rgba(139, 105, 20, 0.4);
}

.quill-flourish {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 60px;
    transform: translateY(-30px);
    transition: top 80ms linear;
}

@media (max-width: 720px) {
    .quill-progress {
        left: 12px;
    }
}

/* ---------- Section base ---------- */
.section {
    position: relative;
    width: 100%;
    padding: 8vh 8vw;
    overflow: hidden;
}

.section-heading-wrap {
    text-align: center;
    margin: 0 auto 6vh;
    max-width: 760px;
    position: relative;
}

.section-title {
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 600;
    font-size: clamp(1.6rem, 4vw, 2.8rem);
    letter-spacing: 0.06em;
    color: var(--text-color);
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.section-sub {
    font-family: "Cormorant Garamond", Georgia, serif;
    font-style: italic;
    font-weight: 500;
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.section-intro {
    max-width: 780px;
    margin: 0 auto 5vh;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.85;
    text-align: justify;
    hyphens: auto;
}

.heading-cartouche {
    width: min(560px, 82vw);
    height: 60px;
    display: block;
    margin: 0 auto 1.4rem;
}

/* Drop cap */
.dropcap {
    float: left;
    font-family: "Cormorant Garamond", Georgia, serif;
    font-weight: 600;
    color: var(--dried-blood);
    font-size: 4em;
    line-height: 0.86;
    padding: 0.05em 0.12em 0 0;
    margin-top: 0.1em;
}

/* ---------- Rhumb-line overlay ---------- */
.rhumb-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(22.5deg, rgba(26, 17, 11, 0.05) 0 1px, transparent 1px 90px),
        repeating-linear-gradient(67.5deg, rgba(26, 17, 11, 0.04) 0 1px, transparent 1px 110px),
        repeating-linear-gradient(-22.5deg, rgba(26, 17, 11, 0.04) 0 1px, transparent 1px 100px),
        repeating-linear-gradient(-67.5deg, rgba(26, 17, 11, 0.04) 0 1px, transparent 1px 130px);
    z-index: 0;
}

.rhumb-fade {
    opacity: 0.65;
}

.ruled-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 41px,
        rgba(212, 196, 168, 0.5) 41px,
        rgba(212, 196, 168, 0.5) 42px
    );
    z-index: 0;
}

/* ---------- Section 1: Hero / Cartographer's Desk ---------- */
.section-hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6vh 8vw;
}

.hero-inner {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 980px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4vh;
}

.cartouche {
    position: relative;
    width: min(800px, 92vw);
    aspect-ratio: 800 / 320;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cartouche-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.hero-title {
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 600;
    font-size: clamp(3rem, 10vw, 7rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--iron-gall);
    line-height: 1;
    position: relative;
    z-index: 1;
    margin-bottom: 0.2em;
    text-shadow: 0 0 1px rgba(26, 17, 11, 0.3);
}

.hero-subtitle {
    font-family: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    font-weight: 500;
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--gilt);
    position: relative;
    z-index: 1;
    margin-top: 1.2rem;
}

.compass-rose-wrap {
    text-align: center;
}

.compass-rose {
    width: 180px;
    height: 180px;
    overflow: visible;
    animation: spin 120s linear infinite; /* 0.5 rpm */
    transform-origin: 50% 50%;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.compass-caption {
    margin-top: 0.8rem;
    font-family: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    font-size: 0.78rem;
    letter-spacing: 0.3em;
    color: var(--gilt);
    text-transform: uppercase;
}

.hero-tagline {
    max-width: 640px;
    text-align: center;
    font-style: italic;
    font-size: clamp(1rem, 1.7vw, 1.15rem);
    color: var(--iron-gall);
    line-height: 1.7;
}

@media (max-width: 720px) {
    .compass-rose { width: 120px; height: 120px; }
}

/* ---------- Section 2: Glyph Atlas ---------- */
.section-atlas {
    padding-top: 12vh;
    padding-bottom: 12vh;
}

.glyph-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    max-width: 1100px;
    margin: 0 auto;
    border-top: 1px solid var(--rule-color);
    border-left: 1px solid var(--rule-color);
    position: relative;
    z-index: 1;
}

@media (max-width: 768px) {
    .glyph-grid { grid-template-columns: 1fr; }
}

.glyph-cell {
    border-right: 1px solid var(--rule-color);
    border-bottom: 1px solid var(--rule-color);
    padding: 2.4rem 2rem;
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 1.6rem;
    align-items: start;
    position: relative;
    background-color: rgba(212, 196, 168, 0.08);
    transition: background-color 300ms ease;
}

.glyph-cell::after {
    content: "";
    position: absolute;
    inset: 8px;
    border: 1px solid rgba(168, 149, 122, 0.25);
    pointer-events: none;
}

.glyph-cell:hover {
    background-color: rgba(107, 21, 40, 0.04);
}

.glyph-mark {
    width: 100px;
    height: 100px;
    border: 1px solid var(--iron-gall);
    border-radius: 2px;
    background: rgba(242, 232, 213, 0.5);
    padding: 6px;
    box-shadow: inset 0 0 12px rgba(26, 17, 11, 0.06);
}

.glyph-mark svg {
    width: 100%;
    height: 100%;
}

.glyph-info {
    min-width: 0;
}

.glyph-class {
    font-family: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-size: clamp(0.78rem, 1.3vw, 0.92rem);
    color: var(--gilt);
    margin-bottom: 0.5rem;
}

.glyph-name {
    font-family: "Cormorant Garamond", Georgia, serif;
    font-weight: 600;
    font-style: italic;
    font-size: clamp(1.4rem, 2.4vw, 1.9rem);
    color: var(--iron-gall);
    letter-spacing: 0.04em;
    line-height: 1.2;
    margin-bottom: 0.6rem;
}

.glyph-desc {
    font-size: clamp(0.92rem, 1.5vw, 1rem);
    line-height: 1.7;
    color: var(--iron-gall);
}

/* ---------- Section 3: Marginalia Corridor ---------- */
.section-marginalia {
    padding: 14vh 6vw 14vh;
    position: relative;
}

.section-heading-typewriter {
    text-align: left;
    margin-left: max(8vw, 60px);
    margin-right: 0;
}

.typewriter-title {
    font-family: "IM Fell English", "Cormorant Garamond", Georgia, serif;
    font-weight: 400;
    color: var(--iron-gall);
    letter-spacing: 0.04em;
}

.typewriter-title .tw-char {
    opacity: 0;
    display: inline-block;
    transition: opacity 0ms;
}

.typewriter-title.is-typed .tw-char {
    opacity: 1;
}

.typewriter-title .tw-char.is-on {
    opacity: 1;
}

.marginalia-grid {
    display: grid;
    grid-template-columns: 55% 45%;
    gap: 3rem;
    max-width: 1300px;
    margin: 0 auto;
    margin-left: max(8vw, 60px);
}

@media (max-width: 880px) {
    .marginalia-grid {
        grid-template-columns: 1fr;
        margin-left: max(8vw, 40px);
    }
}

.main-column p {
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.85;
    margin-bottom: 1.6rem;
    text-align: justify;
    hyphens: auto;
}

.margin-column {
    position: relative;
    will-change: transform;
    font-family: "IM Fell English", "Lora", Georgia, serif;
    color: var(--faded-notation);
}

.margin-note {
    position: relative;
    margin-bottom: 1.6rem;
    padding: 0.4rem 0.6rem;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    line-height: 1.5;
    color: var(--faded-notation);
    font-style: italic;
}

.margin-note p { margin-bottom: 0.2rem; }

.margin-note svg {
    width: 36px;
    height: 36px;
    display: block;
    margin-bottom: 0.4rem;
}

.margin-note-1 { transform: rotate(-2deg); margin-left: 0.5rem; }
.margin-note-2 { transform: rotate(1.5deg); margin-left: 2.5rem; }
.margin-note-3 { transform: rotate(-1deg); margin-left: 4rem; }
.margin-note-4 { transform: rotate(2deg); margin-left: 1rem; font-size: 0.72rem; line-height: 1.3; }
.margin-note-5 { transform: rotate(-2.5deg); margin-left: 3rem; }
.margin-note-6 { transform: rotate(0.8deg); margin-left: 0.8rem; }
.margin-note-7 { transform: rotate(-1.6deg); margin-left: 5rem; }
.margin-note-8 { transform: rotate(2.4deg); margin-left: 1.4rem; }
.margin-note-9 { transform: rotate(-1.2deg); margin-left: 3.4rem; font-family: "Cormorant SC", serif; letter-spacing: 0.15em; font-size: 0.7rem; }
.margin-note-10 { transform: rotate(1.8deg); margin-left: 0.6rem; }

.strikethrough p {
    color: var(--faded-notation);
}

.strikethrough s {
    text-decoration: line-through;
    text-decoration-color: var(--dried-blood);
    text-decoration-thickness: 1.5px;
    color: rgba(168, 149, 122, 0.55);
}

/* ---------- Transition zone ---------- */
.transition-zone {
    height: 20vh;
    width: 100%;
    position: relative;
    z-index: 0;
}

/* ---------- Section 4: Palimpsest Chamber ---------- */
.section-palimpsest {
    background-color: var(--burgundy);
    color: var(--parchment);
    padding: 14vh 8vw 14vh;
    min-height: 100vh;
    --text-color: var(--parchment);
    --text-secondary: var(--gilt);
    --rule-color: rgba(139, 105, 20, 0.3);
}

.palimpsest-heading {
    color: var(--parchment);
}

.section-title-light {
    color: var(--parchment);
    font-family: "Cormorant Garamond", Georgia, serif;
    font-weight: 600;
}

.section-sub-light { color: var(--gilt); }

/* Palimpsest layered text effect */
.palimpsest-text {
    position: relative;
    display: inline;
}

.palimpsest-text::before {
    content: attr(data-text);
    position: absolute;
    left: 2px;
    top: 1px;
    color: var(--gilt);
    opacity: 0.15;
    pointer-events: none;
    z-index: -1;
    white-space: pre-wrap;
}

.palimpsest-paragraph {
    max-width: 720px;
    margin: 0 auto 4vh;
    font-size: clamp(1rem, 1.8vw, 1.18rem);
    line-height: 1.85;
    color: var(--parchment);
    position: relative;
    text-align: justify;
    hyphens: auto;
}

.palimpsest-paragraph .palimpsest-text {
    position: relative;
    display: inline-block;
}

.palimpsest-paragraph .palimpsest-text::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(242, 232, 213, 0.04);
    transform: translate(2px, 1px);
    pointer-events: none;
}

.map-wrap {
    text-align: center;
    margin: 6vh auto;
    max-width: 460px;
}

.fictional-map {
    width: 100%;
    max-width: 400px;
    height: auto;
    aspect-ratio: 400 / 600;
    display: block;
    margin: 0 auto;
}

.map-caption {
    margin-top: 1rem;
    font-family: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    font-size: 0.78rem;
    letter-spacing: 0.28em;
    color: var(--gilt);
    text-transform: uppercase;
}

/* ---------- Section 5: Colophon ---------- */
.section-colophon {
    background-color: var(--colophon-black);
    padding: 12vh 8vw;
    min-height: 60vh;
    text-align: center;
    color: rgba(242, 232, 213, 0.7);
    position: relative;
}

.colophon-rule {
    border: none;
    height: 1px;
    width: 40%;
    margin: 0 auto;
    background-color: var(--gilt);
    opacity: 0.5;
}

.colophon-rule-bottom {
    margin-top: 8vh;
    width: 24%;
}

.colophon-inner {
    margin: 6vh auto;
    max-width: 600px;
}

.printers-mark {
    width: 90px;
    height: 90px;
    display: block;
    margin: 0 auto 2.4rem;
}

.colophon-name {
    font-family: "Cormorant Garamond", Georgia, serif;
    font-weight: 600;
    font-size: 1.3rem;
    letter-spacing: 0.45em;
    text-transform: uppercase;
    color: rgba(242, 232, 213, 0.7);
    margin-bottom: 1.5rem;
}

.colophon-line,
.colophon-roman,
.colophon-imprint,
.colophon-tag {
    font-family: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
    font-size: 0.75rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: rgba(242, 232, 213, 0.7);
    margin-bottom: 0.9rem;
    line-height: 1.7;
}

.colophon-line {
    color: var(--gilt);
}

.colophon-tag {
    font-style: italic;
    text-transform: none;
    letter-spacing: 0.18em;
    font-size: 0.78rem;
}

/* ---------- Foxing spots (decorative pseudo-elements simulated as spans) ---------- */
.foxing-spot {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(196, 160, 96, 0.55) 0%, rgba(196, 160, 96, 0) 70%);
    pointer-events: none;
    z-index: 1;
}

.fox-1 { top: 12%; left: 9%; width: 18px; height: 18px; }
.fox-2 { top: 70%; right: 11%; width: 12px; height: 12px; }
.fox-3 { bottom: 8%; left: 22%; width: 22px; height: 22px; }
.fox-4 { top: 18%; right: 7%; width: 14px; height: 14px; }
.fox-5 { bottom: 14%; left: 6%; width: 20px; height: 20px; }
.fox-6 { top: 25%; left: 8%; width: 16px; height: 16px; }
.fox-7 { bottom: 10%; right: 12%; width: 18px; height: 18px; }
.fox-8 { top: 40%; left: 8%; width: 14px; height: 14px; opacity: 0.4; }
.fox-light { background: radial-gradient(circle, rgba(196, 160, 96, 0.3) 0%, rgba(196, 160, 96, 0) 70%); }

/* ---------- Animation states ---------- */
[data-anim="blur-focus"] {
    filter: blur(8px);
    opacity: 0;
    transition: filter 800ms cubic-bezier(0.22, 1, 0.36, 1),
                opacity 800ms cubic-bezier(0.22, 1, 0.36, 1);
    will-change: filter, opacity;
}

[data-anim="blur-focus"].is-visible {
    filter: blur(0);
    opacity: 1;
}

[data-anim="fade-reveal"] {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 600ms ease, transform 600ms ease;
}

[data-anim="fade-reveal"].is-visible {
    opacity: 0.6;
    transform: translateY(0);
}

/* Path-draw animation */
.draw-path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 1200ms ease-in-out;
}

[data-anim="path-draw"].is-visible .draw-path {
    stroke-dashoffset: 0;
}

.map-path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 2000ms ease-in-out;
}

[data-anim="path-draw-map"].is-visible .map-path {
    stroke-dashoffset: 0;
}

/* Margin notes — fade-reveal pattern (capped at 0.6) */
.margin-note {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 700ms ease, transform 700ms ease;
}

.margin-note.is-visible {
    opacity: 0.6;
    transform: translateY(0);
}

/* Cartouche-frame draw paths */
.heading-cartouche .draw-path,
.cartouche-svg .draw-path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 1800ms ease-in-out;
}

.section-heading-wrap.is-visible .draw-path,
.cartouche.is-visible .draw-path {
    stroke-dashoffset: 0;
}

/* On hero, since cartouche is in immediate viewport, animate after a small delay */
.cartouche .draw-path { transition-duration: 2200ms; }
