/* ============================================================
   CONCURRENGINE.COM — Maximalist Command Library
   A leather-bound manuscript of concurrent computation
   ============================================================ */

/* === CSS Custom Properties === */
:root {
    --deep-black: #0d0d0d;
    --antique-gold: #c9a84c;
    --parchment-white: #e8e0d0;
    --burnished-bronze: #6b6255;
    --oxblood-red: #8b1a1a;
    --charcoal-leather: #1a1714;
    --pale-gold: #dfc276;
    --ink-black: #000000;
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Crimson Text', 'Georgia', serif;
    --font-mono: 'Inconsolata', 'Courier New', monospace;
}

/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--deep-black);
    color: var(--parchment-white);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
    position: relative;
}

/* === Leather Texture Overlay === */
#leather-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 1.2s ease;
    background:
        radial-gradient(ellipse 2px 3px at 20% 30%, rgba(139, 130, 110, 0.15) 0%, transparent 100%),
        radial-gradient(ellipse 3px 2px at 60% 70%, rgba(107, 98, 85, 0.12) 0%, transparent 100%),
        radial-gradient(ellipse 1px 4px at 40% 50%, rgba(139, 130, 110, 0.1) 0%, transparent 100%),
        radial-gradient(ellipse 4px 1px at 80% 20%, rgba(107, 98, 85, 0.08) 0%, transparent 100%),
        radial-gradient(ellipse 2px 2px at 10% 80%, rgba(139, 130, 110, 0.13) 0%, transparent 100%),
        radial-gradient(ellipse 3px 3px at 90% 40%, rgba(107, 98, 85, 0.1) 0%, transparent 100%);
    background-size: 40px 40px, 50px 50px, 30px 45px, 55px 35px, 45px 55px, 35px 40px;
    filter: contrast(1.4);
}

#leather-texture.visible {
    opacity: 0.08;
}

/* === Thread Lines (Vertical Parallax Gold Lines) === */
#thread-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.thread-line {
    position: absolute;
    top: -20%;
    width: 1px;
    height: 140%;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(201, 168, 76, 0.15) 15%,
        rgba(201, 168, 76, 0.4) 50%,
        rgba(201, 168, 76, 0.15) 85%,
        transparent 100%
    );
    will-change: transform;
}

/* === Timeline Markers (Left Edge Ruler) === */
#timeline-markers {
    position: fixed;
    top: 0;
    left: 0;
    width: 30px;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.timeline-tick {
    position: absolute;
    left: 0;
    width: 12px;
    height: 1px;
    background: var(--antique-gold);
    opacity: 0.5;
}

/* === Marginalia Channel === */
#marginalia-channel {
    position: fixed;
    top: 0;
    right: 0;
    width: 200px;
    height: 100vh;
    overflow: hidden;
    pointer-events: none;
    z-index: 2;
    display: none;
}

@media (min-width: 1200px) {
    #marginalia-channel {
        display: block;
    }
}

.marginalia-item {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--burnished-bronze);
    opacity: 0.3;
    padding: 8px 16px;
    white-space: nowrap;
}

/* === Main Column === */
#main-column {
    position: relative;
    z-index: 5;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 2rem;
}

@media (min-width: 1200px) {
    #main-column {
        margin-right: calc(50% - 250px);
        margin-left: auto;
    }
}

/* === The Frontispiece === */
#frontispiece {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
}

#frontispiece-content {
    text-align: center;
    position: relative;
    z-index: 2;
}

/* Ornamental Border */
.ornamental-border {
    position: absolute;
    top: 3rem;
    left: 3rem;
    right: 3rem;
    bottom: 3rem;
    pointer-events: none;
}

.ornamental-border .border-top,
.ornamental-border .border-bottom {
    position: absolute;
    left: 50%;
    height: 2px;
    background: var(--antique-gold);
    transform: translateX(-50%) scaleX(0);
    transition: transform 1.5s ease-out;
}

.ornamental-border .border-top {
    top: 0;
    box-shadow: 0 10px 0 0 transparent, 0 11px 0 0 transparent;
}

.ornamental-border .border-bottom {
    bottom: 0;
}

.ornamental-border.revealed .border-top,
.ornamental-border.revealed .border-bottom {
    transform: translateX(-50%) scaleX(1);
    width: 100%;
}

.ornamental-border .border-left,
.ornamental-border .border-right {
    position: absolute;
    top: 50%;
    width: 2px;
    background: var(--antique-gold);
    transform: translateY(-50%) scaleY(0);
    transition: transform 1.5s ease-out;
}

.ornamental-border .border-left {
    left: 0;
}

.ornamental-border .border-right {
    right: 0;
}

.ornamental-border.revealed .border-left,
.ornamental-border.revealed .border-right {
    transform: translateY(-50%) scaleY(1);
    height: 100%;
}

/* Corner Ornaments */
.corner {
    position: absolute;
    width: 20px;
    height: 20px;
    opacity: 0;
    transition: opacity 0.6s ease 1.8s;
}

.corner::before,
.corner::after {
    content: '';
    position: absolute;
    background: var(--antique-gold);
}

.corner::before {
    width: 100%;
    height: 1px;
}

.corner::after {
    width: 1px;
    height: 100%;
}

.corner-tl { top: -10px; left: -10px; }
.corner-tl::before { top: 50%; left: 0; }
.corner-tl::after { top: 0; left: 50%; }

.corner-tr { top: -10px; right: -10px; }
.corner-tr::before { top: 50%; right: 0; }
.corner-tr::after { top: 0; right: 50%; }

.corner-bl { bottom: -10px; left: -10px; }
.corner-bl::before { bottom: 50%; left: 0; }
.corner-bl::after { bottom: 0; left: 50%; }

.corner-br { bottom: -10px; right: -10px; }
.corner-br::before { bottom: 50%; right: 0; }
.corner-br::after { bottom: 0; right: 50%; }

.ornamental-border.revealed .corner {
    opacity: 1;
}

/* Inner double rule for frontispiece */
.ornamental-border::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(201, 168, 76, 0.4);
    opacity: 0;
    transition: opacity 0.8s ease 1.5s;
}

.ornamental-border.revealed::before {
    opacity: 1;
}

/* Thread-count pattern along the border */
.ornamental-border::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 4px, rgba(201, 168, 76, 0.12) 4px, rgba(201, 168, 76, 0.12) 5px),
        repeating-linear-gradient(90deg, transparent, transparent 4px, rgba(201, 168, 76, 0.12) 4px, rgba(201, 168, 76, 0.12) 5px);
    background-size: 20px 100%, 100% 20px;
    background-position: top left, top left;
    background-repeat: repeat-x, repeat-y;
    mask-image:
        linear-gradient(to right, black 0px, black 20px, transparent 20px, transparent calc(100% - 20px), black calc(100% - 20px), black 100%),
        linear-gradient(to bottom, black 0px, black 20px, transparent 20px, transparent calc(100% - 20px), black calc(100% - 20px), black 100%);
    -webkit-mask-image:
        linear-gradient(to right, black 0px, black 20px, transparent 20px, transparent calc(100% - 20px), black calc(100% - 20px), black 100%),
        linear-gradient(to bottom, black 0px, black 20px, transparent 20px, transparent calc(100% - 20px), black calc(100% - 20px), black 100%);
    mask-composite: add;
    -webkit-mask-composite: source-over;
    opacity: 0;
    transition: opacity 1s ease 1.6s;
}

.ornamental-border.revealed::after {
    opacity: 1;
}

/* Title */
#title {
    font-family: var(--font-display);
    font-weight: 300;
    font-style: italic;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--antique-gold);
    letter-spacing: -0.02em;
    line-height: 1.1;
    opacity: 0;
    margin-bottom: 1.5rem;
}

#title.visible {
    opacity: 1;
}

#title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.1s ease, transform 0.1s ease;
}

#title .char.stamped {
    opacity: 1;
    transform: translateY(0);
    animation: stamp-shake 0.3s ease-in-out;
}

@keyframes stamp-shake {
    0% { transform: translateX(0) translateY(2px); }
    15% { transform: translateX(3px) translateY(0); }
    30% { transform: translateX(-3px) translateY(0); }
    45% { transform: translateX(2px) translateY(0); }
    60% { transform: translateX(-2px) translateY(0); }
    75% { transform: translateX(1px) translateY(0); }
    100% { transform: translateX(0) translateY(0); }
}

/* Subtitle */
#subtitle {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(0.75rem, 1.5vw, 1rem);
    color: var(--parchment-white);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#subtitle.visible {
    opacity: 1;
}

/* === Section Plates === */
.section-plate {
    position: relative;
    padding: 4rem 0;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.section-plate.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* Section Double-Rule Borders */
.section-border {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.border-rule-top,
.border-rule-bottom {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    overflow: visible;
}

.border-rule-top {
    top: 0;
}

.border-rule-bottom {
    bottom: 0;
}

.border-rule-top::before,
.border-rule-bottom::before {
    content: '';
    position: absolute;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--antique-gold);
    transform: translateX(-50%);
    transition: width 0.8s ease-out;
}

.border-rule-top::after,
.border-rule-bottom::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 0;
    height: 1px;
    background: rgba(201, 168, 76, 0.5);
    transform: translateX(-50%);
    transition: width 0.8s ease-out 0.15s;
}

.border-rule-top::before { top: 0; }
.border-rule-top::after { top: 10px; }
.border-rule-bottom::before { bottom: 0; }
.border-rule-bottom::after { bottom: 10px; }

.section-plate.in-view .border-rule-top::before,
.section-plate.in-view .border-rule-top::after,
.section-plate.in-view .border-rule-bottom::before,
.section-plate.in-view .border-rule-bottom::after {
    width: 100%;
}

/* Section Headings */
.section-heading {
    font-family: var(--font-display);
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    color: var(--antique-gold);
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 2rem;
    padding-top: 1.5rem;
    position: relative;
}

/* Shake-stamp effect for headings */
.section-heading.shake-stamp {
    animation: heading-stamp 0.3s ease-in-out;
}

@keyframes heading-stamp {
    0% { transform: translateX(0); background-color: transparent; }
    10% { transform: translateX(3px); background-color: rgba(139, 26, 26, 0.15); }
    20% { transform: translateX(-3px); }
    30% { transform: translateX(2px); }
    40% { transform: translateX(-2px); background-color: rgba(139, 26, 26, 0.08); }
    60% { transform: translateX(1px); }
    80% { transform: translateX(-1px); background-color: transparent; }
    100% { transform: translateX(0); background-color: transparent; }
}

/* Section Body */
.section-body {
    padding: 0 1rem;
}

.section-body p {
    margin-bottom: 1.5rem;
    color: var(--parchment-white);
    text-indent: 2em;
}

.section-body p:first-child {
    text-indent: 0;
}

.section-body p:first-child::first-letter {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 3.2em;
    float: left;
    line-height: 0.8;
    padding-right: 0.1em;
    padding-top: 0.05em;
    color: var(--antique-gold);
}

/* === Thread-Count Badges === */
.thread-badge-cluster {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding: 1.5rem 1rem 0;
}

.thread-badge {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid var(--antique-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--antique-gold);
    letter-spacing: 0.02em;
    cursor: default;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.thread-badge:hover {
    transform: scale(1.15);
    box-shadow: 0 0 20px rgba(201, 168, 76, 0.25);
}

/* === Loom Dividers === */
.loom-divider-full {
    height: 40px;
    position: relative;
    margin: 1rem 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 3px,
            rgba(201, 168, 76, 0.08) 3px,
            rgba(201, 168, 76, 0.08) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 7px,
            rgba(201, 168, 76, 0.06) 7px,
            rgba(201, 168, 76, 0.06) 8px
        );
    background-size: 100% 100%;
}

.loom-divider-full::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent,
        rgba(201, 168, 76, 0.4) 20%,
        var(--antique-gold) 50%,
        rgba(201, 168, 76, 0.4) 80%,
        transparent
    );
}

.loom-divider-full::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border: 1px solid var(--antique-gold);
    background: var(--deep-black);
    rotate: 45deg;
}

/* Section-internal loom divider */
.section-plate .loom-divider {
    height: 20px;
    margin-bottom: 1rem;
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 5px,
            rgba(201, 168, 76, 0.05) 5px,
            rgba(201, 168, 76, 0.05) 6px
        );
}

/* === The Colophon === */
#colophon {
    position: relative;
    padding: 4rem 0 6rem;
    margin-top: 2rem;
    background: var(--charcoal-leather);
    border-radius: 2px;
    padding: 3rem 2rem 4rem;
    margin-bottom: 4rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

#colophon.in-view {
    opacity: 1;
    transform: translateY(0);
}

.colophon-border {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--antique-gold);
}

.colophon-border::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(201, 168, 76, 0.4);
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-style: italic;
    font-size: 1.5rem;
    color: var(--antique-gold);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 2rem;
}

#colophon-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    transition: opacity 0.6s ease;
}

@media (min-width: 600px) {
    #colophon-body {
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
        column-rule: 1px solid rgba(201, 168, 76, 0.25);
    }
}

.colophon-column p {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    color: var(--burnished-bronze);
    line-height: 2;
    transition: color 0.4s ease;
}

#colophon.in-view .colophon-column p {
    color: var(--parchment-white);
}

.colophon-label {
    color: var(--antique-gold);
    font-weight: 400;
}

/* Leather texture on colophon */
#colophon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 2px;
    background:
        radial-gradient(ellipse 2px 3px at 30% 40%, rgba(139, 130, 110, 0.12) 0%, transparent 100%),
        radial-gradient(ellipse 3px 2px at 70% 60%, rgba(107, 98, 85, 0.1) 0%, transparent 100%),
        radial-gradient(ellipse 1px 4px at 50% 50%, rgba(139, 130, 110, 0.08) 0%, transparent 100%);
    background-size: 35px 35px, 45px 45px, 25px 40px;
    filter: contrast(1.3);
    opacity: 0.15;
    pointer-events: none;
}

/* === Animations === */

/* Oxblood flash behind headings */
.section-heading::before {
    content: '';
    position: absolute;
    top: 0;
    left: -1rem;
    right: -1rem;
    bottom: 0;
    background: var(--oxblood-red);
    opacity: 0;
    z-index: -1;
    border-radius: 2px;
    pointer-events: none;
}

.section-heading.oxblood-flash::before {
    animation: oxblood-fade 0.4s ease-out;
}

@keyframes oxblood-fade {
    0% { opacity: 0.2; }
    30% { opacity: 0.15; }
    100% { opacity: 0; }
}

/* === Responsive === */
@media (max-width: 768px) {
    #main-column {
        padding: 0 1.2rem;
    }

    #frontispiece {
        padding: 2rem 1rem;
    }

    .ornamental-border {
        top: 1.5rem;
        left: 1.5rem;
        right: 1.5rem;
        bottom: 1.5rem;
    }

    .section-plate {
        padding: 3rem 0;
    }

    .section-body {
        padding: 0 0.5rem;
    }

    .section-body p:first-child::first-letter {
        font-size: 2.5em;
    }

    .thread-badge-cluster {
        gap: 0.75rem;
    }

    .thread-badge {
        width: 46px;
        height: 46px;
        font-size: 0.55rem;
    }
}

@media (max-width: 480px) {
    .ornamental-border {
        top: 1rem;
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }
}

/* === Selection Color === */
::selection {
    background: rgba(201, 168, 76, 0.3);
    color: var(--parchment-white);
}

/* === Scrollbar styling (Webkit) === */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--deep-black);
}

::-webkit-scrollbar-thumb {
    background: var(--burnished-bronze);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--antique-gold);
}
