/* styles.css — Brutalist Ancient/Futuristic */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root{
    /* Core — obsidian and bone */
    --bg0: #0a0a0a;
    --bg1: #111111;
    --bg2: #1a1a1a;
    --panel: rgba(18, 18, 18, 0.92);
    --panel2: rgba(14, 14, 14, 0.88);
  
    --text: #f0ece4;
    --muted: rgba(240,236,228,0.62);
    --faint: rgba(240,236,228,0.32);
  
    /* Accents — sacred gold and cold steel */
    --gold: #c9a227;
    --gold-dim: rgba(201,162,39,0.55);
    --steel: #8a9ba8;
    --blood: #8b2500;
  
    /* Lines + geometry — harsh, no softness */
    --line: rgba(240,236,228,0.14);
    --line-hard: rgba(201,162,39,0.35);
    --hard: 3px;
    --gap: clamp(16px, 3vw, 32px);
    --radius: 0;
  
    /* Type — ancient meets terminal */
    --serif: 'Cormorant Garamond', 'Iowan Old Style', Garamond, serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

*{ box-sizing: border-box; }
html, body{ height:100%; }
body{
    margin:0;
    color: var(--text);
    background: var(--bg0);
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.55;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
}

::selection{
    background: var(--gold);
    color: var(--bg0);
}

/* Links */
a{ color: inherit; text-decoration: none; }
a:hover{ 
    text-decoration: underline; 
    text-decoration-thickness: 1px; 
    text-underline-offset: 4px;
    text-decoration-color: var(--gold);
}
a:focus-visible{
    outline: 2px solid var(--gold);
    outline-offset: 4px;
}

/* Skip link */
.skip{
    position:absolute;
    left:-999px;
    top:16px;
    padding: 12px 16px;
    border: var(--hard) solid var(--gold);
    background: var(--bg0);
    color: var(--text);
    z-index: 30;
    font-family: var(--mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 11px;
}
.skip:focus{ left: 16px; }

/* Veil — stone texture, not digital noise */
.veil{
    pointer-events:none;
    position: fixed;
    inset: 0;
    opacity: 0.08;
    background-image:
      url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

/* Layout — monolithic, asymmetric */
.page{
    width: min(1200px, calc(100% - 2*var(--gap)));
    margin: 0 auto;
    padding: calc(var(--gap) * 2) 0 calc(var(--gap) * 3);
}

/* Masthead — stone tablet */
.mast{
    display:grid;
    grid-template-columns: 1fr auto;
    gap: var(--gap);
    align-items: end;
  
    border-left: 6px solid var(--gold);
    border-bottom: var(--hard) solid var(--line);
    background: var(--panel);
    padding: calc(var(--gap) * 1.5) var(--gap);
    
    position: relative;
}

.mast::before{
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, var(--gold) 0%, var(--gold) 30%, transparent 30%);
}

.brand{ min-width: 260px; }

.kicker{
    font-family: var(--mono);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    font-size: 10px;
    color: var(--gold);
    margin-bottom: 12px;
    font-weight: 500;
}

h1{
    margin: 0;
    font-family: var(--serif);
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 0.95;
    font-size: clamp(42px, 7vw, 72px);
    text-transform: uppercase;
}

.mark{
    display:inline-block;
    color: var(--gold);
}

.slash{
    opacity: 0.35;
    padding: 0 4px;
    font-weight: 400;
}

.name{
    letter-spacing: 0.18em;
    font-weight: 400;
    color: var(--text);
}

.motto{
    margin: 16px 0 0;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--muted);
    max-width: 64ch;
}

/* Sigil — sacred geometry, stark */
.sigil{
    width: 100px;
    height: 100px;
    display:flex;
    align-items:center;
    justify-content:center;
    color: var(--gold-dim);
    border: 1px solid var(--line);
    background: var(--bg0);
}
.sigil svg{
    width: 80px;
    height: 80px;
    display:block;
}

/* Nav — exposed structure */
.nav{
    display:flex;
    flex-wrap: wrap;
    gap: 0;
    margin: calc(var(--gap) * 1.5) 0;
    border-bottom: var(--hard) solid var(--line);
}

.nav a{
    font-family: var(--mono);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 500;
  
    padding: 14px 20px;
    border-top: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav a:first-child{
    border-left: 1px solid var(--line);
}

.nav a:hover{
    text-decoration: none;
    background: var(--bg2);
    color: var(--text);
}

.nav a.active{
    background: var(--bg0);
    color: var(--gold);
    border-top: 2px solid var(--gold);
}

/* Grid — brutalist asymmetry */
.grid{
    display:grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--gap);
}

/* Panels — stone slabs */
.panel{
    grid-column: span 6;
    position: relative;
  
    border: 1px solid var(--line);
    border-left: 4px solid var(--line-hard);
    background: var(--panel);
    padding: calc(var(--gap) * 1.25);
}

.panel::after{
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 40px;
    height: 40px;
    border-left: 1px solid var(--line);
    border-top: 1px solid var(--line);
    background: 
      linear-gradient(135deg, transparent 50%, var(--bg0) 50%);
}

.panel.wide{ grid-column: span 12; }

.panel h2{
    margin: 0 0 16px;
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
    
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.lead{
    margin: 0 0 16px;
    font-size: 18px;
    font-style: italic;
    color: var(--muted);
    max-width: 72ch;
}

/* Divider rule — ritual mark */
.rule{
    height: 2px;
    margin: 20px 0;
    background: linear-gradient(90deg, var(--gold) 0%, var(--gold) 60px, var(--line) 60px);
}

/* Verse block — scripture */
.verse{
    margin: 0;
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.75;
    padding: 20px;
    padding-left: 24px;
  
    border-left: 3px solid var(--gold);
    background: rgba(201,162,39,0.04);
    color: var(--text);
    font-style: italic;
}

/* Facts grid — doctrine tablets */
.facts{
    margin: 16px 0 0;
    display:grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.fact{
    border: 1px solid var(--line);
    padding: 16px;
    background: var(--bg0);
    position: relative;
}

.fact::before{
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 2px;
    background: var(--gold);
}

.fact dt{
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 10px;
    font-weight: 500;
    color: var(--gold);
    margin-bottom: 8px;
}

.fact dd{
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: var(--muted);
}

/* Fine print */
.fineprint{
    margin: 20px 0 0;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    color: var(--faint);
    text-transform: uppercase;
}

/* Table — ledger/scroll */
.ledger{
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    font-size: 14px;
    color: var(--text);
}

.ledger th,
.ledger td{
    border: 1px solid var(--line);
    padding: 12px 16px;
    vertical-align: top;
    text-align: left;
}

.ledger thead th{
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 10px;
    font-weight: 500;
    background: var(--bg0);
    color: var(--gold);
    border-bottom: 2px solid var(--gold);
}

.ledger tbody tr{
    transition: background 0.1s ease;
}

.ledger tbody tr:hover{
    background: rgba(201,162,39,0.06);
}

.ledger tbody td:first-child{
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

/* Utility */
.mono{ font-family: var(--mono); }

/* Responsive — maintain brutalist structure */
@media (max-width: 920px){
    .panel{ grid-column: span 12; }
    .facts{ grid-template-columns: 1fr; }
    .sigil{ display:none; }
    
    .mast{
        grid-template-columns: 1fr;
    }
    
    .nav{
        flex-direction: column;
    }
    
    .nav a{
        border-left: 1px solid var(--line);
        border-right: 1px solid var(--line);
    }
    
    .nav a:not(:first-child){
        border-top: none;
    }
}

@media (max-width: 600px){
    h1{
        font-size: 32px;
    }

    .panel h2{
        font-size: 22px;
    }

    .verse{
        padding: 16px;
        padding-left: 16px;
    }
}

/* ============================================================
   LIGHT THEME — Parchment Aesthetic
   ============================================================ */

:root.light {
    --bg0: #f5f0e6;
    --bg1: #ebe5d9;
    --bg2: #e0d9cc;
    --panel: rgba(250, 248, 243, 0.95);
    --panel2: rgba(245, 240, 230, 0.92);

    --text: #2a2520;
    --muted: rgba(42, 37, 32, 0.68);
    --faint: rgba(42, 37, 32, 0.38);

    --gold: #8b7355;
    --gold-dim: rgba(139, 115, 85, 0.55);
    --steel: #5a6670;
    --blood: #8b3a3a;

    --line: rgba(42, 37, 32, 0.18);
    --line-hard: rgba(139, 115, 85, 0.45);
}

:root.light .veil {
    opacity: 0.04;
    mix-blend-mode: multiply;
}

/* ============================================================
   ARTICLE PAGE LAYOUT
   ============================================================ */

.article-layout {
    padding-top: calc(var(--gap) * 0.5);
}

/* Reading Progress Bar */
.progress-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--line);
    z-index: 100;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), var(--gold-dim));
    transition: width 0.1s ease-out;
}

/* Article Header — Minimal */
.article-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: var(--gap);
    border-bottom: 1px solid var(--line);
    gap: 16px;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 8px 12px;
    border: 1px solid var(--line);
    background: transparent;
    transition: all 0.15s ease;
}

.back-link:hover {
    text-decoration: none;
    background: var(--bg2);
    color: var(--gold);
    border-color: var(--gold-dim);
}

.back-icon {
    width: 16px;
    height: 16px;
}

.article-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mini-sigil {
    width: 36px;
    height: 36px;
    color: var(--gold-dim);
}

.mini-sigil svg {
    width: 100%;
    height: 100%;
}

.brand-text {
    font-family: var(--serif);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.brand-slash {
    opacity: 0.4;
    padding: 0 2px;
}

/* Theme Toggle */
.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    font-size: 18px;
}

.theme-toggle:hover {
    background: var(--bg2);
    color: var(--gold);
    border-color: var(--gold-dim);
}

.theme-icon {
    line-height: 1;
}

/* Article Container */
.article-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: calc(var(--gap) * 2);
    align-items: start;
}

/* When ToC is hidden, make article full width */
.article-container.no-toc {
    grid-template-columns: 1fr;
}

.article-container.no-toc .article-main {
    max-width: 72ch;
    margin: 0 auto;
}

@media (min-width: 1400px) {
    .article-container {
        grid-template-columns: 340px 1fr;
    }

    .article-container.no-toc {
        grid-template-columns: 1fr;
    }
}

/* Table of Contents */
.toc {
    position: sticky;
    top: calc(var(--gap) + 20px);
    width: 100%;
    min-width: 280px;
    max-height: calc(100vh - var(--gap) * 2 - 40px);
    overflow-y: auto;
    border: 1px solid var(--line);
    border-left: 4px solid var(--gold);
    background: var(--panel);
    padding: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.toc.hidden {
    display: none;
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg1);
}

.toc-title {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--gold);
    font-weight: 500;
}

.toc-close {
    display: none;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
}

.toc-close svg {
    width: 16px;
    height: 16px;
}

.toc-nav {
    padding: 12px 0;
}

.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-list li {
    margin: 0;
}

.toc-list a {
    display: block;
    padding: 10px 20px;
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.4;
    color: var(--muted);
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
}

.toc-list a:hover {
    text-decoration: none;
    color: var(--text);
    background: rgba(201, 162, 39, 0.06);
}

.toc-list a.active {
    color: var(--gold);
    border-left-color: var(--gold);
    background: rgba(201, 162, 39, 0.08);
}

.toc-list li.toc-sub a {
    padding-left: 36px;
    font-size: 14px;
    color: var(--faint);
}

/* Article Main */
.article-main {
    min-width: 0;
    max-width: 72ch;
}

.article-meta {
    margin-bottom: calc(var(--gap) * 1.5);
    padding-bottom: var(--gap);
    border-bottom: 1px solid var(--line);
}

.article-title {
    font-family: var(--serif);
    font-size: clamp(28px, 5vw, 42px);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.02em;
    color: var(--text);
    margin: 0 0 12px;
    text-transform: none;
}

.article-date {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
    margin: 0;
}

/* Article Content Typography */
.article-content {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.article-content.loaded {
    opacity: 1;
}

.article-content h1 {
    display: none; /* Hidden - shown in article-title */
}

.article-content h2 {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
    margin: calc(var(--gap) * 2) 0 var(--gap);
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
    text-transform: none;
}

.article-content h3 {
    font-family: var(--serif);
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin: calc(var(--gap) * 1.5) 0 calc(var(--gap) * 0.75);
}

.article-content h4 {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
    margin: var(--gap) 0 calc(var(--gap) * 0.5);
}

.article-content p {
    margin: 0 0 var(--gap);
    line-height: 1.75;
}

.article-content p:first-of-type {
    font-size: 18px;
    color: var(--muted);
    font-style: italic;
}

.article-content ul,
.article-content ol {
    margin: 0 0 var(--gap);
    padding-left: 24px;
}

.article-content li {
    margin-bottom: 8px;
    line-height: 1.65;
}

.article-content li::marker {
    color: var(--gold);
}

.article-content blockquote {
    margin: var(--gap) 0;
    padding: 20px 24px;
    border-left: 3px solid var(--gold);
    background: rgba(201, 162, 39, 0.04);
    font-style: italic;
}

.article-content blockquote p {
    margin: 0;
}

.article-content strong {
    font-weight: 600;
    color: var(--text);
}

.article-content em {
    font-style: italic;
}

.article-content code {
    font-family: var(--mono);
    font-size: 0.9em;
    padding: 2px 6px;
    background: var(--bg2);
    border: 1px solid var(--line);
}

.article-content pre {
    margin: var(--gap) 0;
    padding: 16px 20px;
    background: var(--bg1);
    border: 1px solid var(--line);
    border-left: 3px solid var(--gold-dim);
    overflow-x: auto;
}

.article-content pre code {
    padding: 0;
    background: none;
    border: none;
}

.article-content hr {
    border: none;
    height: 2px;
    margin: calc(var(--gap) * 2) 0;
    background: linear-gradient(90deg, var(--gold) 0%, var(--gold) 60px, var(--line) 60px);
}

.article-content a {
    color: var(--gold);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    text-decoration-color: var(--gold-dim);
}

.article-content a:hover {
    text-decoration-color: var(--gold);
}

/* Article Footer */
.article-footer {
    margin-top: calc(var(--gap) * 3);
    padding-top: var(--gap);
}

.footer-rule {
    height: 2px;
    margin-bottom: var(--gap);
    background: linear-gradient(90deg, var(--gold) 0%, var(--gold) 40px, var(--line) 40px);
}

.footer-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 12px 20px;
    border: 1px solid var(--line);
    transition: all 0.15s ease;
}

.footer-back:hover {
    text-decoration: none;
    background: var(--bg2);
    color: var(--gold);
    border-color: var(--gold-dim);
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(var(--gap) * 4) 0;
    color: var(--muted);
}

.loading-sigil {
    width: 60px;
    height: 60px;
    border: 2px solid var(--line);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.loading p {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Error State */
.error-message {
    text-align: center;
    padding: calc(var(--gap) * 3) var(--gap);
    border: 1px solid var(--line);
    background: var(--panel);
}

.error-message h2 {
    font-family: var(--serif);
    font-size: 24px;
    color: var(--text);
    margin: 0 0 16px;
}

.error-message p {
    color: var(--muted);
    margin: 0 0 20px;
}

.error-message a {
    color: var(--gold);
}

/* Mobile ToC Toggle */
.toc-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 50px;
    height: 50px;
    border: 2px solid var(--gold);
    background: var(--bg0);
    color: var(--gold);
    cursor: pointer;
    z-index: 90;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.toc-mobile-toggle svg {
    width: 24px;
    height: 24px;
}

/* ============================================================
   ARTICLE PAGE RESPONSIVE
   ============================================================ */

@media (max-width: 920px) {
    .article-container {
        grid-template-columns: 1fr;
    }

    .toc {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: none;
        z-index: 95;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        border: none;
        border-top: 3px solid var(--gold);
    }

    .toc.open {
        transform: translateY(0);
    }

    .toc-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .toc-mobile-toggle {
        display: flex;
    }

    .article-brand {
        display: none;
    }

    .article-header {
        justify-content: space-between;
    }
}

@media (max-width: 600px) {
    .article-title {
        font-size: 24px;
    }

    .article-content h2 {
        font-size: 20px;
    }

    .article-content h3 {
        font-size: 18px;
    }

    .back-link span {
        display: none;
    }

    .back-link {
        padding: 8px;
    }
}

/* Light theme adjustments for article */
:root.light .toc {
    background: var(--panel);
}

:root.light .toc-header {
    background: var(--bg2);
}

:root.light .article-content blockquote {
    background: rgba(139, 115, 85, 0.06);
}

:root.light .article-content code {
    background: var(--bg2);
}

:root.light .article-content pre {
    background: var(--bg2);
}

:root.light .loading-sigil {
    border-color: var(--line);
    border-top-color: var(--gold);
}

:root.light .toc-mobile-toggle {
    background: var(--bg0);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ============================================================
   ENTRY ANIMATIONS — Staggered Reveals
   ============================================================ */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.92);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes drawLine {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes sigilPulse {
    0%, 100% {
        opacity: 0.55;
        filter: drop-shadow(0 0 8px rgba(201, 162, 39, 0));
    }
    50% {
        opacity: 1;
        filter: drop-shadow(0 0 20px rgba(201, 162, 39, 0.4));
    }
}

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

@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 30px rgba(201, 162, 39, 0.08);
    }
    50% {
        box-shadow: 0 0 50px rgba(201, 162, 39, 0.15);
    }
}

/* Page entry animations */
.page {
    animation: fadeIn 0.6s ease-out;
}

.mast {
    animation: fadeInUp 0.7s ease-out both;
}

.nav {
    animation: fadeIn 0.5s ease-out 0.2s both;
}

.nav a {
    opacity: 0;
    animation: fadeInUp 0.4s ease-out both;
}

.nav a:nth-child(1) { animation-delay: 0.25s; }
.nav a:nth-child(2) { animation-delay: 0.30s; }
.nav a:nth-child(3) { animation-delay: 0.35s; }
.nav a:nth-child(4) { animation-delay: 0.40s; }
.nav a:nth-child(5) { animation-delay: 0.45s; }
.nav a:nth-child(6) { animation-delay: 0.50s; }

/* Panel staggered entry */
.grid .panel {
    opacity: 0;
    animation: scaleIn 0.5s ease-out both;
}

.grid .panel:nth-child(1) { animation-delay: 0.4s; }
.grid .panel:nth-child(2) { animation-delay: 0.5s; }
.grid .panel:nth-child(3) { animation-delay: 0.6s; }
.grid .panel:nth-child(4) { animation-delay: 0.7s; }
.grid .panel:nth-child(5) { animation-delay: 0.8s; }

/* Sigil animation */
.sigil {
    animation: sigilPulse 4s ease-in-out infinite;
}

.sigil svg {
    transition: transform 0.6s ease;
}

.sigil:hover svg {
    animation: sigilRotate 8s linear infinite;
}

/* Panel hover effects */
.panel {
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.panel:hover {
    transform: translateY(-4px);
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.4),
        0 0 60px rgba(201, 162, 39, 0.06);
    border-color: var(--line-hard);
}

.panel:hover::after {
    background: linear-gradient(135deg, transparent 50%, var(--bg1) 50%);
}

/* Table row staggered animation */
.ledger tbody tr {
    opacity: 0;
    animation: fadeInUp 0.35s ease-out both;
}

.ledger tbody tr:nth-child(1) { animation-delay: 0.5s; }
.ledger tbody tr:nth-child(2) { animation-delay: 0.52s; }
.ledger tbody tr:nth-child(3) { animation-delay: 0.54s; }
.ledger tbody tr:nth-child(4) { animation-delay: 0.56s; }
.ledger tbody tr:nth-child(5) { animation-delay: 0.58s; }
.ledger tbody tr:nth-child(6) { animation-delay: 0.60s; }
.ledger tbody tr:nth-child(7) { animation-delay: 0.62s; }
.ledger tbody tr:nth-child(8) { animation-delay: 0.64s; }
.ledger tbody tr:nth-child(9) { animation-delay: 0.66s; }
.ledger tbody tr:nth-child(10) { animation-delay: 0.68s; }
.ledger tbody tr:nth-child(n+11) { animation-delay: 0.7s; }

/* ============================================================
   ATMOSPHERE — Vignette, Glows, Depth
   ============================================================ */

/* Vignette overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(
        ellipse 80% 60% at 50% 50%,
        transparent 0%,
        transparent 50%,
        rgba(0, 0, 0, 0.4) 100%
    );
    z-index: 1;
}

/* Ambient glow behind mast */
.mast::after {
    content: "";
    position: absolute;
    top: -40px;
    left: -40px;
    right: -40px;
    bottom: -40px;
    background: radial-gradient(
        ellipse 60% 80% at 20% 80%,
        rgba(201, 162, 39, 0.08) 0%,
        transparent 60%
    );
    pointer-events: none;
    z-index: -1;
}

/* Gold line glow effect */
.mast {
    animation: glowPulse 6s ease-in-out infinite;
}

/* Enhanced sigil glow */
.sigil {
    position: relative;
}

.sigil::before {
    content: "";
    position: absolute;
    inset: -20px;
    background: radial-gradient(
        circle at center,
        rgba(201, 162, 39, 0.12) 0%,
        transparent 70%
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.sigil:hover::before {
    opacity: 1;
}

/* Ledger table enhanced hover - simple background, no position changes */
.ledger tbody tr:hover td {
    background: rgba(201, 162, 39, 0.08);
}

/* Rule line animation on scroll */
.rule {
    position: relative;
    overflow: hidden;
}

.rule::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background: var(--gold);
    animation: drawLine 1s ease-out 0.8s both;
}

/* ============================================================
   ARTICLE TYPOGRAPHY POLISH
   ============================================================ */

/* Drop cap for first paragraph */
.article-content > p:first-of-type::first-letter {
    float: left;
    font-family: var(--serif);
    font-size: 4.2em;
    line-height: 0.8;
    font-weight: 700;
    color: var(--gold);
    padding-right: 12px;
    padding-top: 6px;
    margin-bottom: -8px;
    text-shadow: 2px 2px 0 rgba(201, 162, 39, 0.15);
}

/* Reset first paragraph styling for drop cap compatibility */
.article-content > p:first-of-type {
    font-size: inherit;
    color: var(--text);
    font-style: normal;
}

/* Pull quote styling */
.article-content blockquote {
    position: relative;
    margin: calc(var(--gap) * 2) 0;
    padding: 32px 32px 32px 40px;
    border-left: 4px solid var(--gold);
    background: linear-gradient(
        135deg,
        rgba(201, 162, 39, 0.06) 0%,
        rgba(201, 162, 39, 0.02) 100%
    );
    font-size: 1.15em;
    line-height: 1.7;
}

.article-content blockquote::before {
    content: "\201C";
    position: absolute;
    top: 16px;
    left: 12px;
    font-family: var(--serif);
    font-size: 3em;
    line-height: 1;
    color: var(--gold);
    opacity: 0.4;
}

/* Enhanced heading hierarchy */
.article-content h2 {
    position: relative;
    margin: calc(var(--gap) * 2.5) 0 var(--gap);
    padding-bottom: 16px;
    font-size: 26px;
    letter-spacing: 0.03em;
}

.article-content h2::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60px;
    height: 3px;
    background: var(--gold);
}

.article-content h3 {
    margin: calc(var(--gap) * 2) 0 calc(var(--gap) * 0.75);
    font-size: 21px;
    color: var(--text);
    letter-spacing: 0.02em;
}

.article-content h3::before {
    content: "//";
    color: var(--gold);
    opacity: 0.6;
    margin-right: 8px;
    font-family: var(--mono);
    font-size: 0.8em;
    font-weight: 400;
}

/* List enhancements */
.article-content ul {
    list-style: none;
    padding-left: 0;
}

.article-content ul li {
    position: relative;
    padding-left: 24px;
}

.article-content ul li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.65em;
    width: 8px;
    height: 2px;
    background: var(--gold);
}

.article-content ol {
    list-style: none;
    padding-left: 0;
    counter-reset: item;
}

.article-content ol li {
    position: relative;
    padding-left: 36px;
    counter-increment: item;
}

.article-content ol li::before {
    content: counter(item);
    position: absolute;
    left: 0;
    top: 0;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--gold);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gold-dim);
}

/* Horizontal rule enhancement */
.article-content hr {
    position: relative;
    border: none;
    height: 1px;
    margin: calc(var(--gap) * 2.5) 0;
    background: var(--line);
}

.article-content hr::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border: 2px solid var(--gold);
    background: var(--bg0);
    transform: translate(-50%, -50%) rotate(45deg);
}

/* Link hover enhancement */
.article-content a {
    position: relative;
    color: var(--gold);
    text-decoration: none;
    background: linear-gradient(
        to right,
        var(--gold-dim) 0%,
        var(--gold-dim) 100%
    );
    background-size: 100% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 0.3s ease, color 0.2s ease;
}

.article-content a:hover {
    background-size: 100% 100%;
    color: var(--bg0);
    text-decoration: none;
}

/* ============================================================
   PREV/NEXT NAVIGATION
   ============================================================ */

.article-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap);
    margin-top: calc(var(--gap) * 2);
    padding-top: var(--gap);
    border-top: 1px solid var(--line);
}

.article-nav-link {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px;
    border: 1px solid var(--line);
    background: var(--panel);
    transition: all 0.25s ease;
    text-decoration: none;
}

.article-nav-link:hover {
    text-decoration: none;
    border-color: var(--gold-dim);
    background: var(--bg1);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.article-nav-link.next {
    text-align: right;
}

.article-nav-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 6px;
}

.article-nav-link.next .article-nav-label {
    justify-content: flex-end;
}

.article-nav-title {
    font-family: var(--serif);
    font-size: 16px;
    color: var(--text);
    line-height: 1.4;
}

.article-nav-link.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* ============================================================
   READING TIME
   ============================================================ */

.reading-time {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-left: 16px;
}

.reading-time::before {
    content: "";
    width: 4px;
    height: 4px;
    background: var(--gold);
    transform: rotate(45deg);
}

/* ============================================================
   SEARCH/FILTER
   ============================================================ */

.search-container {
    margin-bottom: var(--gap);
    animation: fadeInUp 0.5s ease-out 0.45s both;
}

.search-input {
    width: 100%;
    padding: 14px 20px;
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.04em;
    color: var(--text);
    background: var(--bg1);
    border: 1px solid var(--line);
    border-left: 3px solid var(--gold-dim);
    outline: none;
    transition: all 0.2s ease;
}

.search-input::placeholder {
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.search-input:focus {
    border-color: var(--gold-dim);
    background: var(--bg0);
    box-shadow: 0 0 30px rgba(201, 162, 39, 0.08);
}

.search-hint {
    margin-top: 8px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faint);
}

.search-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg2);
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
}

.ledger tbody tr.hidden {
    display: none;
}

.no-results {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: none;
}

.no-results.visible {
    display: table-row;
}

/* ============================================================
   KEYBOARD SHORTCUTS HINT
   ============================================================ */

.shortcuts-hint {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    gap: 12px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    color: var(--faint);
    opacity: 0;
    animation: fadeIn 0.5s ease-out 2s both;
    z-index: 50;
}

.shortcuts-hint span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.shortcuts-hint kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--bg2);
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
    color: var(--gold);
}

@media (max-width: 920px) {
    .shortcuts-hint {
        display: none;
    }
}

/* ============================================================
   SCROLL TO TOP
   ============================================================ */

.scroll-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg0);
    border: 2px solid var(--gold);
    color: var(--gold);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 80;
}

.scroll-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top:hover {
    background: var(--gold);
    color: var(--bg0);
}

.scroll-top svg {
    width: 20px;
    height: 20px;
}

/* ============================================================
   LIGHT THEME ADJUSTMENTS FOR NEW FEATURES
   ============================================================ */

:root.light body::before {
    background: radial-gradient(
        ellipse 80% 60% at 50% 50%,
        transparent 0%,
        transparent 60%,
        rgba(0, 0, 0, 0.08) 100%
    );
}

:root.light .mast::after {
    background: radial-gradient(
        ellipse 60% 80% at 20% 80%,
        rgba(139, 115, 85, 0.08) 0%,
        transparent 60%
    );
}

:root.light .article-content > p:first-of-type::first-letter {
    text-shadow: 2px 2px 0 rgba(139, 115, 85, 0.1);
}

:root.light .article-content blockquote {
    background: linear-gradient(
        135deg,
        rgba(139, 115, 85, 0.08) 0%,
        rgba(139, 115, 85, 0.03) 100%
    );
}

:root.light .article-nav-link:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

:root.light .search-input:focus {
    box-shadow: 0 0 30px rgba(139, 115, 85, 0.1);
}

:root.light .scroll-top {
    background: var(--bg0);
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
}

/* ============================================================
   LIBRARY PAGE — Card Grid
   ============================================================ */

.library-header {
    margin-bottom: calc(var(--gap) * 2);
    padding-bottom: var(--gap);
    border-bottom: 1px solid var(--line);
    animation: fadeInUp 0.5s ease-out both;
}

.library-header h2 {
    font-family: var(--serif);
    font-size: clamp(32px, 5vw, 48px);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
    margin: 0 0 12px;
}

.library-header .lead {
    margin: 0 0 var(--gap);
    font-size: 18px;
    font-style: italic;
    color: var(--muted);
}

.library-header .search-container {
    max-width: 400px;
}

/* Card Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gap);
}

@media (max-width: 1100px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

/* Article Card */
.article-card {
    display: flex;
    flex-direction: column;
    padding: 24px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--gold-dim);
    background: var(--panel);
    text-decoration: none;
    transition: all 0.25s ease;
    opacity: 0;
    animation: fadeInUp 0.4s ease-out both;
}

.article-card:hover {
    text-decoration: none;
    border-color: var(--line-hard);
    border-left-color: var(--gold);
    background: var(--bg1);
    transform: translateY(-4px);
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.3),
        0 0 40px rgba(201, 162, 39, 0.06);
}

.card-date {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 12px;
}

.card-title {
    font-family: var(--serif);
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
    margin: 0 0 12px;
    transition: color 0.2s ease;
}

.article-card:hover .card-title {
    color: var(--gold);
}

.card-excerpt {
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.6;
    color: var(--muted);
    margin: 0 0 16px;
    flex-grow: 1;
}

.card-link {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-link::after {
    content: "→";
    transition: transform 0.2s ease;
}

.article-card:hover .card-link {
    color: var(--gold);
}

.article-card:hover .card-link::after {
    transform: translateX(4px);
}

/* Library count */
.library-count {
    margin-top: calc(var(--gap) * 2);
    padding-top: var(--gap);
    border-top: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
    text-align: center;
}

/* No results in card grid */
.card-grid .no-results {
    grid-column: 1 / -1;
    padding: 60px 20px;
    text-align: center;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid var(--line);
    background: var(--panel);
}

/* Light theme card adjustments */
:root.light .article-card:hover {
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.1),
        0 0 40px rgba(139, 115, 85, 0.06);
}

/* ============================================================
   PROTOCOLS PAGE
   ============================================================ */

.protocols-header {
    margin-bottom: calc(var(--gap) * 2);
    animation: fadeInUp 0.5s ease-out both;
}

.protocols-header h2 {
    font-family: var(--serif);
    font-size: clamp(32px, 5vw, 48px);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
    margin: 0 0 12px;
}

.protocols-header .lead {
    margin: 0 0 var(--gap);
    font-size: 18px;
    font-style: italic;
    color: var(--muted);
    max-width: 60ch;
}

.protocols-intro {
    max-width: 72ch;
    padding: 24px;
    border-left: 3px solid var(--gold);
    background: rgba(201, 162, 39, 0.04);
    margin-bottom: calc(var(--gap) * 2);
}

.protocols-intro p {
    margin: 0 0 16px;
    font-size: 16px;
    line-height: 1.7;
    color: var(--muted);
}

.protocols-intro p:last-child {
    margin-bottom: 0;
    font-style: italic;
    color: var(--text);
}

/* Protocol Section */
.protocol-section {
    margin-bottom: calc(var(--gap) * 3);
    opacity: 0;
    animation: fadeInUp 0.5s ease-out both;
}

.protocol-section:nth-child(2) { animation-delay: 0.1s; }
.protocol-section:nth-child(3) { animation-delay: 0.2s; }
.protocol-section:nth-child(4) { animation-delay: 0.3s; }
.protocol-section:nth-child(5) { animation-delay: 0.4s; }
.protocol-section:nth-child(6) { animation-delay: 0.5s; }

.section-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 16px;
    margin-bottom: var(--gap);
    padding-bottom: var(--gap);
    border-bottom: 1px solid var(--line);
}

.section-numeral {
    font-family: var(--serif);
    font-size: 48px;
    font-weight: 300;
    color: var(--gold);
    line-height: 1;
    opacity: 0.6;
}

.section-header h3 {
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
    margin: 0;
    flex-grow: 1;
}

.section-desc {
    width: 100%;
    margin: 8px 0 0;
    font-family: var(--serif);
    font-size: 16px;
    font-style: italic;
    color: var(--muted);
    max-width: 60ch;
}

/* Protocol Grid */
.protocol-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--gap);
}

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

/* Protocol Card */
.protocol-card {
    padding: 24px;
    border: 1px solid var(--line);
    border-top: 3px solid var(--gold-dim);
    background: var(--panel);
    transition: all 0.25s ease;
}

.protocol-card:hover {
    border-top-color: var(--gold);
    background: var(--bg1);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.protocol-card h4 {
    font-family: var(--serif);
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 16px;
    letter-spacing: 0.01em;
}

.protocol-card p {
    font-family: var(--serif);
    font-size: 15px;
    line-height: 1.7;
    color: var(--muted);
    margin: 0 0 12px;
}

.protocol-card p:last-of-type {
    margin-bottom: 16px;
}

.protocol-card em {
    display: block;
    padding: 16px;
    margin: 0 0 16px;
    background: rgba(201, 162, 39, 0.06);
    border-left: 2px solid var(--gold);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

.protocol-link {
    display: inline-flex;
    align-items: center;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
    text-decoration: none;
    transition: color 0.2s ease;
}

.protocol-link:hover {
    color: var(--text);
    text-decoration: none;
}

/* Protocols Footer */
.protocols-footer {
    max-width: 72ch;
    margin: calc(var(--gap) * 2) auto 0;
    text-align: center;
}

.protocols-footer .rule {
    margin: 0 auto var(--gap);
    max-width: 200px;
}

.closing-verse {
    font-family: var(--serif);
    font-size: 16px;
    line-height: 1.7;
    color: var(--muted);
    margin: 0 0 16px;
}

.closing-verse:last-child {
    margin-bottom: 0;
}

.closing-verse em {
    color: var(--text);
}

/* Light theme protocol adjustments */
:root.light .protocols-intro {
    background: rgba(139, 115, 85, 0.06);
}

:root.light .protocol-card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

:root.light .protocol-card em {
    background: rgba(139, 115, 85, 0.06);
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */

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