/* ============================================================
   gur.al — a scholar's reading room submerged in watercolor light
   ============================================================ */

@property --border-angle {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}
@property --border-hue {
    syntax: "<color>";
    inherits: false;
    initial-value: #4a6670;
}
@property --wash-hue {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

:root {
    /* Palette */
    --ink-indigo: #2d2545;
    --wash-indigo: #3d3560;
    --wash-ochre: #8a7d62;
    --wash-teal: #5a7a80;
    --accent-teal: #4a6670;
    --accent-ochre: #9b8a6e;
    --accent-violet: #7c6f9b;
    --accent-amber: #c4a96a;
    --text-ivory: #f0e8d8;
    --text-lavender: #9b8fad;
    --card-bg: rgba(255, 248, 240, 0.07);
    --card-bg-hover: rgba(255, 248, 240, 0.12);
    --card-bg-dim: rgba(255, 248, 240, 0.06);

    /* Type */
    --font-mono: "Share Tech Mono", "Courier New", ui-monospace, monospace;
    --font-body: "Source Sans 3", "Inter", system-ui, sans-serif;

    /* Motion */
    --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);

    --wash-shift: 0;
}

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

html, body {
    background: var(--ink-indigo);
    color: var(--text-ivory);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.7;
    letter-spacing: 0.005em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    position: relative;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ============================================================
   Watercolor backdrop (fixed, parallax-free depth illusion)
   ============================================================ */

.watercolor-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background: var(--ink-indigo);
}

.wash {
    position: absolute;
    inset: -20%;
    mix-blend-mode: screen;
    filter: url(#watercolor-distort);
    opacity: 0;
    animation: wash-fade-in 800ms var(--ease-out-quint) forwards;
}

.wash-1 {
    background: radial-gradient(ellipse 80vw 70vh at 18% 22%, rgba(61, 53, 96, 0.95) 0%, rgba(61, 53, 96, 0.55) 35%, transparent 70%);
    animation-delay: 0ms;
}

.wash-2 {
    background: radial-gradient(ellipse 90vw 80vh at 78% 38%, rgba(90, 122, 128, 0.78) 0%, rgba(90, 122, 128, 0.4) 40%, transparent 75%);
    animation-delay: 200ms;
}

.wash-3 {
    background: radial-gradient(ellipse 110vw 90vh at 38% 82%, rgba(138, 125, 98, 0.72) 0%, rgba(138, 125, 98, 0.35) 40%, transparent 70%);
    animation-delay: 400ms;
}

.wash-4 {
    background: radial-gradient(ellipse 70vw 60vh at 85% 88%, rgba(124, 111, 155, 0.55) 0%, rgba(124, 111, 155, 0.25) 45%, transparent 75%);
    animation-delay: 600ms;
    mix-blend-mode: multiply;
    opacity: 0;
}

@keyframes wash-fade-in {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

/* Scroll-driven color temperature hue rotation via custom property */
.watercolor-backdrop {
    filter: hue-rotate(calc(var(--wash-shift) * 1deg));
    transition: filter 600ms linear;
}

/* Grain / pigment granulation overlay */
.grain-overlay {
    position: absolute;
    inset: 0;
    background-image:
        repeating-radial-gradient(circle at 25% 30%, rgba(240, 232, 216, 0.015) 0, rgba(240, 232, 216, 0.015) 1px, transparent 1px, transparent 2px),
        repeating-radial-gradient(circle at 75% 70%, rgba(45, 37, 69, 0.02) 0, rgba(45, 37, 69, 0.02) 1px, transparent 1px, transparent 3px);
    mix-blend-mode: overlay;
    opacity: 0.5;
    pointer-events: none;
}

.grain-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.95  0 0 0 0 0.91  0 0 0 0 0.84  0 0 0 0.4 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)' opacity='0.25'/></svg>");
    mix-blend-mode: overlay;
    opacity: 0.35;
}

/* ============================================================
   Ambient ink splashes
   ============================================================ */

.ink-splashes {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.ink-splash {
    position: absolute;
    opacity: 0.55;
    animation: splash-rotate 120s linear infinite, splash-drift 24s ease-in-out infinite alternate;
    mix-blend-mode: screen;
}

.splash-a { top: 8vh;  left: 4vw;  animation-delay: 0s, 0s; }
.splash-b { top: 42vh; left: 72vw; animation-delay: -24s, -5s; }
.splash-c { top: 78vh; left: 12vw; animation-delay: -48s, -10s; }
.splash-d { top: 138vh; left: 88vw; animation-delay: -72s, -7s; }
.splash-e { top: 220vh; left: 22vw; animation-delay: -96s, -3s; }

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

@keyframes splash-drift {
    from { translate: 0 0; }
    to   { translate: 2vw -1vh; }
}

/* ============================================================
   Title band (glassmorphic top strip, 15vh)
   ============================================================ */

.title-band {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 15vh;
    min-height: 76px;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(1.25rem, 4vw, 3rem);
    background: rgba(45, 37, 69, 0.35);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    backdrop-filter: blur(20px) saturate(1.2);
    border-bottom: 1px solid transparent;
    background-image:
        linear-gradient(rgba(45, 37, 69, 0.35), rgba(45, 37, 69, 0.35)),
        linear-gradient(90deg, var(--border-hue), var(--accent-amber), var(--accent-violet));
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
    animation: band-border-cycle 6s linear infinite;
}

@keyframes band-border-cycle {
    0%   { --border-hue: #7c6f9b; }
    50%  { --border-hue: #4a6670; }
    100% { --border-hue: #7c6f9b; }
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    font-family: var(--font-mono);
}

.brand-mark {
    font-size: clamp(1.2rem, 1.6vw, 1.5rem);
    letter-spacing: 0.04em;
    color: var(--text-ivory);
    text-shadow: 0 0 18px rgba(240, 232, 216, 0.15);
}

.brand-meta {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-lavender);
}

.nav-cluster {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: lowercase;
}

.nav-link {
    position: relative;
    color: var(--text-ivory);
    text-decoration: none;
    padding: 0.45rem 0.7rem;
    letter-spacing: 0.08em;
    transition: color 400ms var(--ease-out-quint);
}

.nav-link::before,
.nav-link::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 1px solid transparent;
    opacity: 0;
    transition: opacity 200ms;
}

.nav-link::before {
    border-image: conic-gradient(from var(--border-angle), var(--accent-teal), var(--accent-violet), var(--accent-amber), var(--accent-teal)) 1;
    animation: border-spin 6s linear infinite;
}

.nav-link:hover {
    color: var(--accent-amber);
}

.nav-link:hover::before {
    opacity: 1;
    animation: border-draw 400ms var(--ease-out-quint) forwards, border-spin 6s linear infinite 400ms;
}

@keyframes border-spin {
    from { --border-angle: 0deg; }
    to   { --border-angle: 360deg; }
}

@keyframes border-draw {
    0%   { clip-path: inset(0 100% 100% 0); }
    25%  { clip-path: inset(0 0 100% 0); }
    50%  { clip-path: inset(0 0 0 0); }
    100% { clip-path: inset(0 0 0 0); }
}

.nav-pipe {
    color: var(--text-lavender);
    font-family: var(--font-mono);
    opacity: 0.6;
    display: inline-block;
    animation: pipe-breathe 3s ease-in-out infinite;
}

.nav-cluster .nav-pipe:nth-of-type(2) { animation-delay: 0.5s; }
.nav-cluster .nav-pipe:nth-of-type(3) { animation-delay: 1s; }

@keyframes pipe-breathe {
    0%, 100% { transform: scaleY(1);    opacity: 0.5; }
    50%      { transform: scaleY(1.15); opacity: 0.85; }
}

/* ============================================================
   Scroll container + z-sections
   ============================================================ */

.scroll-container {
    position: relative;
    z-index: 10;
    padding-top: 15vh;
}

.z-section {
    position: relative;
    min-height: 100vh;
    padding: 6vh clamp(1.5rem, 5vw, 5rem);
    display: block;
}

.z-one   { --section-wash: -10; }
.z-two   { --section-wash: 14; }
.z-three { --section-wash: -20; }
.z-four  { --section-wash: 4; }

.section-marker {
    position: absolute;
    top: 3vh;
    left: clamp(1.5rem, 5vw, 5rem);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-lavender);
    opacity: 0.75;
}

.section-marker.align-right {
    left: auto;
    right: clamp(1.5rem, 5vw, 5rem);
    text-align: right;
}

/* Bleed-line separators */
.bleed-line {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    pointer-events: none;
    opacity: 0.85;
    mix-blend-mode: multiply;
}

/* ============================================================
   Glassmorphic cards
   ============================================================ */

.glass-card {
    position: relative;
    background: var(--card-bg);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid transparent;
    border-radius: 12px;
    padding: clamp(1.75rem, 3.2vw, 3rem);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 248, 240, 0.1);
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity 500ms var(--ease-out-quint),
        transform 500ms var(--ease-out-quint),
        box-shadow 500ms var(--ease-out-quint),
        backdrop-filter 500ms var(--ease-out-quint),
        background 500ms var(--ease-out-quint);
    --proximity: 0;
    overflow: hidden;
    isolation: isolate;
}

.glass-card.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* Animated border using gradient & conic rotation */
.glass-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 12px;
    padding: 1px;
    background: conic-gradient(from var(--border-angle),
        var(--accent-teal) 0deg,
        var(--accent-violet) 120deg,
        var(--accent-amber) 240deg,
        var(--accent-teal) 360deg);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    opacity: 0;
    pointer-events: none;
    z-index: 2;
    animation: border-spin 12s linear infinite;
    transition: opacity 600ms var(--ease-out-quint);
}

.glass-card.in-view::before {
    opacity: calc(0.3 + var(--proximity) * 0.4);
    animation: border-spin 12s linear infinite, border-reveal 600ms var(--ease-out-quint) forwards;
}

@keyframes border-reveal {
    0%   { clip-path: inset(0 100% 100% 0 round 12px); }
    25%  { clip-path: inset(0 0 100% 0 round 12px); }
    50%  { clip-path: inset(0 0 0 0 round 12px); }
    100% { clip-path: inset(0 0 0 0 round 12px); }
}

/* Ruled lines inside cards */
.glass-card .ruled-block {
    position: relative;
    margin: 1.25rem 0;
    padding: 1rem 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent calc(1.7em - 1px),
        rgba(74, 102, 112, 0.3) calc(1.7em - 1px),
        rgba(74, 102, 112, 0.3) 1.7em
    );
    background-size: 100% 1.7em;
    background-repeat: repeat-y;
    background-position: 0 0.2em;
}

.glass-card.in-view .ruled-block {
    animation: ruled-fade-in 600ms linear forwards;
}

@keyframes ruled-fade-in {
    from { background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 100%); }
    to   { background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(1.7em - 1px), rgba(74, 102, 112, 0.3) calc(1.7em - 1px), rgba(74, 102, 112, 0.3) 1.7em); }
}

.glass-card:hover {
    background: var(--card-bg-hover);
    -webkit-backdrop-filter: blur(28px) saturate(1.3);
    backdrop-filter: blur(28px) saturate(1.3);
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 248, 240, 0.15);
}

/* Proximity focus zone applied via JS */
.glass-card.near {
    background: var(--card-bg-hover);
    -webkit-backdrop-filter: blur(32px) saturate(1.3);
    backdrop-filter: blur(32px) saturate(1.3);
}

/* ============================================================
   Card placement (z-pattern)
   ============================================================ */

/* Section one: hero on the right */
.z-one {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    justify-items: end;
}

.card-hero {
    width: min(65vw, 720px);
    margin-top: 4vh;
    margin-right: 0;
    margin-left: auto;
}

/* Section two: left-card + right-card, offset vertically */
.z-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 4vh 3vw;
    align-items: start;
    padding-top: 10vh;
    padding-bottom: 12vh;
}

.card-left {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    width: min(35vw, 520px);
    justify-self: start;
    margin-top: 0;
}

.card-right {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    width: min(40vw, 580px);
    justify-self: end;
    margin-top: 8vh;
}

/* Section three: smaller cards, diminishing */
.z-three {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 4vh 3vw;
    padding-top: 10vh;
    padding-bottom: 10vh;
}

.card-small-left {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    width: min(32vw, 440px);
    justify-self: start;
}

.card-small-right {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    width: min(36vw, 500px);
    justify-self: end;
    margin-top: 6vh;
}

.card-wide {
    grid-column: 1 / 3;
    grid-row: 3 / 4;
    width: min(78vw, 1000px);
    justify-self: center;
    margin-top: 6vh;
}

/* Colophon */
.z-four {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: end;
    padding-top: 12vh;
    padding-bottom: 14vh;
}

.card-colophon {
    width: min(58vw, 640px);
    justify-self: end;
}

/* Mobile fallback */
@media (max-width: 820px) {
    .z-one, .z-two, .z-three, .z-four {
        display: block;
        padding-top: 18vh;
        padding-bottom: 8vh;
    }
    .card-hero,
    .card-left,
    .card-right,
    .card-small-left,
    .card-small-right,
    .card-wide,
    .card-colophon {
        width: 100%;
        max-width: 560px;
        margin: 4vh auto;
        float: none;
    }
    .title-band {
        padding: 0 1rem;
    }
    .brand-meta { display: none; }
    .nav-cluster { font-size: 0.72rem; gap: 0.25rem; }
    .nav-link { padding: 0.35rem 0.3rem; }
}

/* ============================================================
   Typography
   ============================================================ */

h1, h2 {
    font-family: var(--font-mono);
    font-weight: 400;
    letter-spacing: 0.04em;
    line-height: 1.25;
    color: var(--text-ivory);
    margin-bottom: 1rem;
    text-wrap: balance;
}

h1 {
    font-size: clamp(1.8rem, 4vw, 3.5rem);
}

h2 {
    font-size: clamp(1.2rem, 2.5vw, 2rem);
}

p {
    max-width: 62ch;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    font-weight: 400;
    color: var(--text-ivory);
    margin-bottom: 1rem;
}

p.lede {
    font-weight: 300;
    font-size: clamp(1rem, 1.3vw, 1.18rem);
    color: rgba(240, 232, 216, 0.9);
}

.kicker {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent-amber);
    margin-bottom: 1.1rem;
    padding: 0.2rem 0.6rem 0.2rem 0;
    border-left: 2px solid var(--accent-amber);
    padding-left: 0.75rem;
}

.meta-line {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-lavender);
    margin-top: 1rem;
    line-height: 1.8;
    max-width: none;
}

.meta-line-colophon { word-spacing: 0.2em; }

.meta-label {
    color: var(--accent-teal);
    margin-right: 0.35rem;
}

.meta-val {
    color: var(--text-ivory);
    opacity: 0.85;
    margin-right: 1rem;
}

.meta-sep { color: var(--text-lavender); opacity: 0.5; margin: 0 0.35rem; }

/* Marginalia - absolute positioned annotations */
.marginalia {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-lavender);
    opacity: 0.5;
    animation: margin-pulse 3s ease-in-out infinite;
    pointer-events: none;
}

.margin-top {
    top: 0.85rem;
    right: 1rem;
}

.margin-bottom {
    bottom: 0.85rem;
    left: 1rem;
}

@keyframes margin-pulse {
    0%, 100% { opacity: 0.5; }
    50%      { opacity: 0.8; }
}

/* Typewriter character reveal */
.typewriter {
    overflow-wrap: break-word;
}

.typewriter .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(2px);
}

.typewriter.typing .char {
    animation: char-reveal 120ms var(--ease-out-quint) forwards;
}

@keyframes char-reveal {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Catalog list (treatise i) */
.catalog-list {
    list-style: none;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin: 1.1rem 0;
    border-top: 1px solid rgba(74, 102, 112, 0.3);
}

.catalog-list li {
    display: grid;
    grid-template-columns: 2ch 1fr auto;
    gap: 0.9rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(74, 102, 112, 0.3);
    align-items: baseline;
    color: var(--text-ivory);
    letter-spacing: 0.04em;
}

.cat-idx {
    color: var(--accent-violet);
    text-align: right;
}

.cat-title {
    color: var(--text-ivory);
}

.cat-ref {
    color: var(--text-lavender);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

/* Palette strip */
.palette-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 1.2rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(74, 102, 112, 0.3);
}

.swatch {
    position: relative;
    flex: 1 1 80px;
    min-width: 64px;
    height: 48px;
    background: var(--sw);
    border-radius: 4px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.3rem;
    box-shadow: inset 0 1px 0 rgba(255, 248, 240, 0.15);
}

.swatch em {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    color: rgba(240, 232, 216, 0.75);
    font-style: normal;
    background: rgba(45, 37, 69, 0.65);
    padding: 1px 5px;
    border-radius: 2px;
}

/* ============================================================
   Chapter markers (book icons at z-turn points)
   ============================================================ */

.chapter-marker {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 600ms var(--ease-out-quint);
}

.chapter-marker.visible {
    opacity: 0.75;
}

.marker-one   { top: 52vh; left: 8vw; }
.marker-two   { bottom: 6vh; right: 8vw; }
.marker-three { top: 50vh; left: 50vw; transform: translateX(-50%); }

.marker-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-lavender);
}

.book-icon .book-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.chapter-marker.visible .book-path {
    animation: book-draw 800ms ease-out forwards;
}

.chapter-marker.visible .book-path:nth-child(2) { animation-delay: 120ms; }
.chapter-marker.visible .book-path:nth-child(3) { animation-delay: 240ms; }

@keyframes book-draw {
    to { stroke-dashoffset: 0; }
}

/* ============================================================
   Reduced motion
   ============================================================ */

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

    .glass-card {
        opacity: 1;
        transform: none;
    }
}

/* ============================================================
   No backdrop-filter fallback
   ============================================================ */

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .glass-card {
        background: rgba(45, 37, 69, 0.78);
    }
    .title-band {
        background: rgba(45, 37, 69, 0.88);
        background-image: none;
    }
}

/* Utility */
.reveal { /* handled by IntersectionObserver in script.js */ }
