/* =====================================================
   gabs.wiki — An Encyclopedia of Value
   Dark-academia illuminated manuscript
   ===================================================== */

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

html {
    scroll-behavior: smooth;
}

:root {
    --study-dark: #1a1714;
    --parchment: #e8dcc8;
    --lamp-gold: #c9a84c;
    --ink-sepia: #5c4d3c;
    --vellum: #f2e8d4;
    --leather: #352f28;
    --burgundy: #7a3030;
    --leather-alt: #2a2520;
    --ink-deep: #3a332b;

    --font-display: 'Cinzel', 'Cormorant Garamond', serif;
    --font-body: 'EB Garamond', 'Times New Roman', serif;
    --font-index: 'Alegreya SC', 'EB Garamond', serif;
}

body {
    background: var(--study-dark);
    color: var(--parchment);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.15vw, 1.12rem);
    line-height: 1.85;
    overflow-x: hidden;
}

/* =====================================================
   FRONTISPIECE
   ===================================================== */

.frontispiece {
    position: relative;
    height: 100vh;
    min-height: 700px;
    background: var(--study-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.border-frame {
    position: absolute;
    top: 5%;
    left: 5%;
    right: 5%;
    bottom: 5%;
    border: 1px solid rgba(201, 168, 76, 0.5);
    pointer-events: none;
    z-index: 1;
}

.border-frame .corner {
    position: absolute;
    width: 22px;
    height: 22px;
}

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

.border-frame .corner.top-left {
    top: -1px;
    left: -1px;
}
.border-frame .corner.top-left::before {
    top: 0;
    left: 0;
    width: 22px;
    height: 1px;
}
.border-frame .corner.top-left::after {
    top: 0;
    left: 0;
    width: 1px;
    height: 22px;
}

.border-frame .corner.top-right {
    top: -1px;
    right: -1px;
}
.border-frame .corner.top-right::before {
    top: 0;
    right: 0;
    width: 22px;
    height: 1px;
}
.border-frame .corner.top-right::after {
    top: 0;
    right: 0;
    width: 1px;
    height: 22px;
}

.border-frame .corner.bottom-left {
    bottom: -1px;
    left: -1px;
}
.border-frame .corner.bottom-left::before {
    bottom: 0;
    left: 0;
    width: 22px;
    height: 1px;
}
.border-frame .corner.bottom-left::after {
    bottom: 0;
    left: 0;
    width: 1px;
    height: 22px;
}

.border-frame .corner.bottom-right {
    bottom: -1px;
    right: -1px;
}
.border-frame .corner.bottom-right::before {
    bottom: 0;
    right: 0;
    width: 22px;
    height: 1px;
}
.border-frame .corner.bottom-right::after {
    bottom: 0;
    right: 0;
    width: 1px;
    height: 22px;
}

.frontispiece-inner {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 2rem;
    max-width: 800px;
}

.title-block {
    margin-bottom: 4rem;
}

.codex-title {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--parchment);
    font-size: clamp(2rem, 7vw, 5.5rem);
    letter-spacing: 0.10em;
    text-transform: uppercase;
    line-height: 1.1;
    margin-bottom: 1.5rem;
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
}

.initial-G {
    display: inline-block;
    font-size: 1.8em;
    color: var(--lamp-gold);
    line-height: 0.85;
    border: 1.5px solid var(--lamp-gold);
    padding: 0.05em 0.18em 0.02em 0.18em;
    margin-right: 0.18em;
    box-shadow:
        inset 3px 3px 0 0 var(--lamp-gold),
        inset -3px -3px 0 0 var(--lamp-gold),
        inset 3px -3px 0 0 var(--lamp-gold),
        inset -3px 3px 0 0 var(--lamp-gold);
    position: relative;
    transform: translateY(0.05em);
}

.initial-G::before,
.initial-G::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--lamp-gold);
}

.initial-G::before {
    top: -2px;
    left: -2px;
    box-shadow:
        calc(100% + 2px) 0 0 var(--lamp-gold),
        0 calc(100% + 2px) 0 var(--lamp-gold),
        calc(100% + 2px) calc(100% + 2px) 0 var(--lamp-gold);
}

.title-rule {
    width: 60%;
    height: 1px;
    background: var(--lamp-gold);
    opacity: 0.5;
    margin: 1.5rem auto;
    position: relative;
}

.title-rule::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border: 1px solid var(--lamp-gold);
    background: var(--study-dark);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
}

.codex-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1rem, 1.6vw, 1.4rem);
    color: var(--parchment);
    letter-spacing: 0.04em;
    opacity: 0.85;
}

.frontispiece-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.2rem;
    font-family: var(--font-index);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    color: var(--ink-sepia);
    margin-bottom: 5rem;
}

.frontispiece-meta .meta-dot {
    color: var(--lamp-gold);
    font-size: 0.55rem;
}

.scroll-indicator {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-index);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    color: var(--ink-sepia);
    z-index: 3;
}

.scroll-arrow {
    font-size: 1rem;
    color: var(--lamp-gold);
    animation: scroll-drift 2.4s ease-in-out infinite;
}

@keyframes scroll-drift {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* =====================================================
   CODEX — sidebar + main column grid
   ===================================================== */

.codex {
    display: grid;
    grid-template-columns: minmax(180px, 20%) minmax(0, 55ch) 1fr;
    gap: 0;
    background: var(--study-dark);
    padding-top: 4vh;
}

/* =====================================================
   SIDEBAR
   ===================================================== */

.sidebar {
    border-right: 1px solid rgba(92, 77, 60, 0.3);
    padding: 0 2rem 0 4vw;
}

.sidebar-inner {
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    padding: 1rem 0;
    scrollbar-width: thin;
    scrollbar-color: var(--ink-sepia) transparent;
}

.sidebar-inner::-webkit-scrollbar {
    width: 4px;
}

.sidebar-inner::-webkit-scrollbar-thumb {
    background: var(--ink-sepia);
}

.sidebar-label {
    font-family: var(--font-index);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    color: var(--lamp-gold);
    text-transform: uppercase;
    margin-bottom: 0.6rem;
}

.sidebar-rule {
    height: 1px;
    background: rgba(92, 77, 60, 0.5);
    margin: 0.8rem 0 1rem 0;
    position: relative;
}

.sidebar-rule::before {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border: 1px solid var(--lamp-gold);
    background: var(--study-dark);
    top: 50%;
    left: 0;
    transform: translateY(-50%) rotate(45deg);
}

.toc {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.4rem 0;
}

.toc-entry {
    font-family: var(--font-index);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    color: var(--parchment);
    text-decoration: none;
    padding: 0.55rem 0.8rem 0.55rem 0.6rem;
    display: grid;
    grid-template-columns: 2.1rem 1fr;
    gap: 0.4rem;
    align-items: baseline;
    border-left: 1px solid transparent;
    transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

.toc-entry .numeral {
    color: var(--ink-sepia);
    font-weight: 500;
    text-align: right;
    font-feature-settings: "smcp";
    transition: color 0.4s ease;
}

.toc-entry .toc-text {
    line-height: 1.3;
}

.toc-entry:hover {
    color: var(--lamp-gold);
    background: rgba(53, 47, 40, 0.4);
}

.toc-entry:hover .numeral {
    color: var(--lamp-gold);
}

.toc-entry.active {
    background: var(--leather);
    color: var(--lamp-gold);
    border-left-color: var(--lamp-gold);
}

.toc-entry.active .numeral {
    color: var(--lamp-gold);
}

.sidebar-foot {
    font-family: var(--font-index);
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    color: var(--ink-sepia);
    margin-top: 1rem;
    text-align: left;
}

/* =====================================================
   MAIN COLUMN
   ===================================================== */

.main-column {
    padding: 2rem 0 6rem 3rem;
    max-width: 100%;
}

.margin-empty {
    /* intentionally empty - the "ma" */
}

/* =====================================================
   ENTRY (dark)
   ===================================================== */

.entry {
    padding: 6vh 0;
    position: relative;
    color: var(--parchment);
}

.entry-numeral {
    font-family: var(--font-index);
    font-size: 0.78rem;
    letter-spacing: 0.22em;
    color: var(--ink-sepia);
    margin-bottom: 0.9rem;
}

.entry-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    letter-spacing: 0.10em;
    color: var(--parchment);
    line-height: 1.2;
    margin-bottom: 1.4rem;
}

.entry-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.15vw, 1.12rem);
    line-height: 1.85;
    color: var(--parchment);
}

.entry-text p {
    margin-bottom: 1.4rem;
    text-align: justify;
    hyphens: auto;
}

.entry-text em {
    color: var(--vellum);
    font-style: italic;
}

/* The Illuminated Initial Cap */
.entry-text p.with-cap::first-letter {
    float: left;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 3.5em;
    line-height: 0.85;
    color: var(--lamp-gold);
    margin: 0.05em 0.18em 0 0;
    padding: 0.15em 0.22em;
    border: 1.5px solid var(--lamp-gold);
    box-shadow:
        inset 3px 3px 0 0 var(--lamp-gold),
        inset -3px -3px 0 0 var(--lamp-gold),
        inset 3px -3px 0 0 var(--lamp-gold),
        inset -3px 3px 0 0 var(--lamp-gold);
}

/* Margin marks */
.margin-mark {
    position: absolute;
    left: -2.2rem;
    top: 7vh;
    font-size: 0.95rem;
    color: var(--ink-sepia);
    opacity: 0.4;
    transition: opacity 0.5s ease, color 0.5s ease;
    line-height: 1;
}

.entry:hover .margin-mark {
    opacity: 0.85;
    color: var(--lamp-gold);
}

/* =====================================================
   ORNAMENTAL DIVIDER
   ===================================================== */

.ornamental-divider {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin: 1.8rem 0;
    width: 100%;
}

.ornamental-divider .line {
    flex: 1;
    height: 1px;
    background: rgba(92, 77, 60, 0.4);
}

.ornamental-divider .diamond {
    width: 8px;
    height: 8px;
    transform: rotate(45deg);
    border: 1px solid var(--lamp-gold);
    background: transparent;
    flex: 0 0 auto;
}

.ornamental-divider.light .line {
    background: rgba(92, 77, 60, 0.4);
}

.ornamental-divider.light .diamond {
    border-color: var(--ink-sepia);
}

.ornamental-divider.small {
    margin: 1rem auto;
    max-width: 200px;
}

/* =====================================================
   LIGHT PANEL (Index Page)
   ===================================================== */

.light-panel {
    background: var(--parchment);
    color: var(--ink-deep);
    padding: 8vh 0;
    margin: 4vh 0;
    position: relative;
}

.light-panel .panel-inner {
    padding: 0 4rem 0 0;
}

.folio {
    font-family: var(--font-index);
    font-size: 0.78rem;
    letter-spacing: 0.28em;
    color: var(--ink-sepia);
    text-align: center;
    margin-bottom: 1.6rem;
}

.folio.dark {
    color: var(--lamp-gold);
}

.folio-bottom {
    font-family: var(--font-index);
    font-size: 0.72rem;
    letter-spacing: 0.32em;
    color: var(--ink-sepia);
    text-align: center;
    margin-top: 2.5rem;
    opacity: 0.6;
}

.entry-heading.light {
    color: var(--ink-deep);
    text-align: center;
}

.entry-text.light {
    color: var(--ink-deep);
}

.entry-text.light em {
    color: var(--burgundy);
}

.entry-text.light p.with-cap::first-letter {
    color: var(--burgundy);
    border-color: var(--burgundy);
    box-shadow:
        inset 3px 3px 0 0 var(--burgundy),
        inset -3px -3px 0 0 var(--burgundy),
        inset 3px -3px 0 0 var(--burgundy),
        inset -3px 3px 0 0 var(--burgundy);
}

/* =====================================================
   MARGINALIA
   ===================================================== */

.marginalia {
    background: var(--study-dark);
    padding: 8vh 0 6vh 0;
    margin: 6vh 0;
    position: relative;
    /* full-width effect by extending beyond column */
    width: calc(100% + 4rem);
    margin-left: -2rem;
}

.marginalia::before,
.marginalia::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(201, 168, 76, 0.35);
}

.marginalia::before {
    top: 0;
}

.marginalia::after {
    bottom: 0;
}

.marginalia-header {
    text-align: center;
    margin-bottom: 4rem;
    padding: 0 2rem;
}

.marginalia-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 2.6vw, 2.2rem);
    letter-spacing: 0.16em;
    color: var(--lamp-gold);
    text-transform: uppercase;
    margin: 0.6rem 0 0.4rem 0;
}

.marginalia-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--parchment);
    opacity: 0.7;
    margin-bottom: 1.2rem;
}

.marginalia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 3rem 2.4rem;
    padding: 0 2rem;
}

.margin-quote {
    font-family: var(--font-body);
    font-style: italic;
    color: var(--parchment);
    line-height: 1.7;
    padding: 0.5rem 0;
    border-left: 1px solid rgba(201, 168, 76, 0.4);
    padding-left: 1.2rem;
    transition: border-color 0.5s ease;
}

.margin-quote:hover {
    border-left-color: var(--lamp-gold);
}

.margin-quote blockquote {
    font-size: 0.98rem;
    margin-bottom: 0.6rem;
    color: var(--vellum);
}

.margin-quote .gloss {
    display: block;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--parchment);
    opacity: 0.65;
    margin-top: 0.4rem;
    font-family: var(--font-body);
}

.margin-quote figcaption {
    font-family: var(--font-index);
    font-style: normal;
    font-size: 0.74rem;
    letter-spacing: 0.16em;
    color: var(--ink-sepia);
    text-transform: uppercase;
}

.margin-quote figcaption em {
    text-transform: none;
    letter-spacing: 0.04em;
    font-style: italic;
}

/* =====================================================
   COLOPHON
   ===================================================== */

.colophon {
    position: relative;
    padding: 12vh 0;
    text-align: center;
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.colophon .border-frame.inner {
    top: 5%;
    left: 5%;
    right: 5%;
    bottom: 5%;
}

.colophon-inner {
    position: relative;
    z-index: 2;
    max-width: 500px;
    margin: 0 auto;
    padding: 2rem;
}

.cartouche {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2.5rem;
    animation: cartouche-pulse 8s ease-in-out infinite;
}

@keyframes cartouche-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1.0; }
}

.cartouche-bar {
    width: 130%;
    height: 1px;
    background: var(--lamp-gold);
    position: relative;
}

.cartouche-bar::before,
.cartouche-bar::after {
    content: '';
    position: absolute;
    width: 1px;
    height: 6px;
    background: var(--lamp-gold);
    top: -3px;
}

.cartouche-bar::before {
    left: 0;
}

.cartouche-bar::after {
    right: 0;
}

.cartouche-bar.bottom::before,
.cartouche-bar.bottom::after {
    top: -2px;
}

.cartouche-char {
    font-family: var(--font-display);
    font-size: 3rem;
    color: var(--lamp-gold);
    padding: 1rem 1.6rem;
    line-height: 1;
    border-left: 1px solid rgba(201, 168, 76, 0.4);
    border-right: 1px solid rgba(201, 168, 76, 0.4);
}

.colophon-line {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1rem;
    color: var(--parchment);
    line-height: 1.8;
    opacity: 0.85;
}

.colophon-meta {
    font-family: var(--font-index);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    color: var(--ink-sepia);
    margin-top: 1rem;
    text-transform: lowercase;
}

.colophon-meta.small {
    font-size: 0.7rem;
    letter-spacing: 0.32em;
    color: var(--lamp-gold);
    opacity: 0.7;
    margin-top: 0.6rem;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */

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

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 50;
        background: var(--study-dark);
        border-right: none;
        border-bottom: 1px solid rgba(92, 77, 60, 0.4);
        padding: 0;
        margin-bottom: 1.5rem;
    }

    .sidebar-inner {
        position: static;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        padding: 0.6rem 5vw;
        display: flex;
        align-items: center;
        gap: 0.6rem;
    }

    .sidebar-label,
    .sidebar-rule,
    .sidebar-foot {
        display: none;
    }

    .toc {
        flex-direction: row;
        gap: 0.4rem;
        padding: 0;
    }

    .toc-entry {
        display: inline-flex;
        flex: 0 0 auto;
        padding: 0.4rem 0.7rem;
        gap: 0.4rem;
        border-left: none;
        border-bottom: 1px solid transparent;
    }

    .toc-entry .numeral {
        text-align: left;
    }

    .toc-entry.active {
        border-left: none;
        border-bottom-color: var(--lamp-gold);
    }

    .main-column {
        padding: 2rem 5vw 4rem 5vw;
    }

    .margin-mark {
        left: -1rem;
        font-size: 0.8rem;
    }

    .entry-text p.with-cap::first-letter {
        font-size: 2.5em;
    }

    .border-frame {
        top: 3%;
        left: 3%;
        right: 3%;
        bottom: 3%;
    }

    .light-panel .panel-inner {
        padding: 0 1rem;
    }

    .marginalia {
        width: calc(100% + 10vw);
        margin-left: -5vw;
    }

    .marginalia-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .codex-title {
        flex-direction: column;
        gap: 0.3rem;
    }

    .initial-G {
        margin-right: 0;
    }
}
