/* ============================================================================
   Codex Entry Page — Wiki Surface (separate from the Book)
   Aesthetic: grimoire-dark, gold accents, mobile-first responsive 320 → 1280+
   ============================================================================ */

:root {
    --codex-gold:        #C8A14A;
    --codex-gold-soft:   #8a6e2e;
    --codex-paper:       #1a1714;
    --codex-leather:     #14110d;
    --codex-ink:         #f3ead4;
    --codex-ink-soft:    #c8bda1;
    --codex-rule:        #3a2e1a;
    --codex-shadow:      0 8px 32px rgba(0,0,0,.55);

    /* Surface tokens — drive light-mode overrides via these names. */
    --cdx-page-bg:       var(--codex-paper);
    --cdx-text:          var(--codex-ink);
    --cdx-text-mute:     var(--codex-ink-soft);
    --cdx-heading:       var(--codex-gold);
    --cdx-accent:        var(--codex-gold);
    --cdx-accent-soft:   var(--codex-gold-soft);
    --cdx-rule:          var(--codex-rule);
    --cdx-card-bg:       rgba(255,255,255,0.02);
    --cdx-card-border:   var(--codex-rule);

    --codex-heaven:      #f6c453;
    --codex-heaven-fg:   #1a1714;
    --codex-hell:        #c0392b;
    --codex-hell-fg:     #fff5e8;
    --codex-violet:      #6b3fa0;
    --codex-violet-fg:   #f5ecff;
    --codex-glitch:      #6dffb5;
    --codex-glitch-fg:   #082319;
    --codex-bone:        #d8c79a;
    --codex-bone-fg:     #1a1714;
    --codex-alive:       #6aff9e;
    --codex-alive-fg:    #082319;
    --codex-dead:        #5a5147;
    --codex-dead-fg:     #f3ead4;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */
.codex-entry-shell {
    background: var(--cdx-page-bg);
    color: var(--cdx-text);
    min-height: 100vh;
    font-family: 'EB Garamond', 'Cormorant Garamond', Georgia, serif;
    line-height: 1.7;
}

/* ── Light-mode tokens ─────────────────────────────────────────────────────
   Triggered by either `[data-theme="light"]` (used by the layout) or
   `body.codex-theme-grimoire-light` (legacy class). Re-binds the shared
   surface tokens so every downstream rule (prose, headings, related cards,
   chips, blockquotes, contributor block) inherits parchment-on-ink contrast
   without per-rule overrides. */
[data-theme="light"],
body.codex-theme-grimoire-light {
    --cdx-page-bg:     #f5e8c2;   /* cream parchment */
    --cdx-text:        #2a1810;   /* deep umber */
    --cdx-text-mute:   #5a3e22;   /* muted brown */
    --cdx-heading:     #1a1208;   /* near-black ink */
    --cdx-accent:      #6b1a1a;   /* wax-seal red */
    --cdx-accent-soft: #8a2418;
    --cdx-rule:        #c9b27e;
    --cdx-card-bg:     rgba(74, 36, 16, 0.04);
    --cdx-card-border: #d6c08a;
    /* Issue 8 (2026-05-11 UAT): hero + memory card were rendering DARK in
       light mode because they referenced the literal --codex-leather token
       (frozen to #14110d in :root). Rebind it here so any rule that uses
       var(--codex-leather) picks up the parchment-toned light-mode value
       and stops bleeding obsidian into the page hero. */
    --codex-leather:   #efe1b8;
    --codex-paper:     #f5e8c2;
    --codex-ink:       #2a1810;
    --codex-ink-soft:  #5a3e22;
    --codex-gold:      #8a5e1a;
    --codex-gold-soft: #6b1a1a;
    --codex-rule:      #c9b27e;
    --codex-shadow:    0 8px 28px rgba(74, 36, 16, 0.18);
}

/* Light-mode legibility: keep grimoire feel but lift contrast. */
[data-theme="light"] .codex-entry-shell,
body.codex-theme-grimoire-light .codex-entry-shell {
    background: var(--cdx-page-bg);
    color: var(--cdx-text);
}

/* ── Creator debug ribbon ──────────────────────────────────────────────── */
.codex-debug-ribbon {
    background: linear-gradient(90deg, #5a0e0e 0%, #c0392b 100%);
    color: #fff5e8;
    padding: 0.85rem 1.25rem;
    text-align: center;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    border-bottom: 2px solid #ff7855;
    box-shadow: 0 2px 12px rgba(192, 57, 43, 0.4);
}
.codex-debug-ribbon .fa-triangle-exclamation {
    margin-right: 0.5rem;
    color: #ffd17a;
}
.codex-debug-ribbon-link {
    display: inline-block;
    margin-left: 0.75rem;
    padding: 0.1rem 0.55rem;
    color: #fff5e8;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 3px;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.82rem;
    transition: background .2s ease, border-color .2s ease;
}
.codex-debug-ribbon-link:hover {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.55);
}

/* Light-mode variant: dark red text on parchment, thin dark border. */
[data-theme="light"] .codex-debug-ribbon,
body.codex-theme-grimoire-light .codex-debug-ribbon {
    background: linear-gradient(90deg, #f5e3c0 0%, #efd29c 100%);
    color: #5a0e0e;
    border-bottom: 2px solid #8a2418;
    box-shadow: 0 2px 8px rgba(74, 36, 16, 0.18);
}
[data-theme="light"] .codex-debug-ribbon .fa-triangle-exclamation,
body.codex-theme-grimoire-light .codex-debug-ribbon .fa-triangle-exclamation {
    color: #8a2418;
}
[data-theme="light"] .codex-debug-ribbon-link,
body.codex-theme-grimoire-light .codex-debug-ribbon-link {
    color: #5a0e0e;
    background: rgba(90, 14, 14, 0.08);
    border-color: rgba(90, 14, 14, 0.45);
}
[data-theme="light"] .codex-debug-ribbon-link:hover,
body.codex-theme-grimoire-light .codex-debug-ribbon-link:hover {
    background: rgba(90, 14, 14, 0.18);
    border-color: rgba(90, 14, 14, 0.7);
}

/* ── Hero header ───────────────────────────────────────────────────────── */
.codex-hero {
    position: relative;
    min-height: 320px;
    padding: 2rem 1.25rem 2.5rem;
    background-color: var(--codex-leather);
    background-image:
        radial-gradient(ellipse at top, rgba(200, 161, 74, 0.15) 0%, transparent 70%),
        var(--codex-hero-img, none);
    background-size: cover;
    /* Wiki image position: configurable via --codex-hero-pos (set inline
       per entry from $entry['image_position']). Default "center 25%"
       (2026-05-20) — user reported heroes sat too high; this shifts the
       focal band up the source image. */
    background-position: var(--codex-hero-pos, center 25%);
    background-repeat: no-repeat;
    border-bottom: 1px solid var(--codex-rule);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}
/* Type-aware fallback gradients when no image is present. */
.codex-hero.no-image {
    background-image:
        linear-gradient(180deg, rgba(200, 161, 74, 0.10) 0%, transparent 65%),
        repeating-linear-gradient(45deg, rgba(200, 161, 74, 0.03) 0 2px, transparent 2px 8px);
}
.codex-hero.no-image.codex-hero-type-character {
    background-image:
        radial-gradient(ellipse at 50% 20%, rgba(246, 196, 83, 0.22) 0%, transparent 60%),
        linear-gradient(180deg, rgba(200, 161, 74, 0.10) 0%, transparent 70%);
}
.codex-hero.no-image.codex-hero-type-location {
    background-image:
        radial-gradient(ellipse at 50% 25%, rgba(192, 57, 43, 0.20) 0%, transparent 60%),
        linear-gradient(180deg, rgba(90, 14, 14, 0.20) 0%, transparent 70%);
}
.codex-hero.no-image.codex-hero-type-artifact {
    background-image:
        radial-gradient(ellipse at 50% 25%, rgba(107, 63, 160, 0.22) 0%, transparent 60%),
        linear-gradient(180deg, rgba(60, 30, 90, 0.18) 0%, transparent 70%);
}
.codex-hero.no-image.codex-hero-type-faction,
.codex-hero.no-image.codex-hero-type-saga {
    background-image:
        radial-gradient(ellipse at 50% 25%, rgba(200, 161, 74, 0.20) 0%, transparent 60%),
        linear-gradient(180deg, rgba(58, 46, 26, 0.30) 0%, transparent 70%);
}

.codex-hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg,
        rgba(20, 17, 13, 0.35) 0%,
        rgba(20, 17, 13, 0.75) 60%,
        rgba(20, 17, 13, 0.95) 100%);
    pointer-events: none;
}
.codex-hero-inner {
    position: relative;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    z-index: 1;
}

/* Top bar holds back-link + type badge with proper gap (Issue 5). */
.codex-hero-topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.codex-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--codex-ink-soft);
    text-decoration: none;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    transition: color .2s ease;
}
.codex-back:hover { color: var(--codex-gold); }
.codex-back .fa-arrow-left { font-size: 0.8rem; }

.codex-hero-type {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.3rem 0.7rem;
    color: var(--codex-gold);
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid rgba(200, 161, 74, 0.35);
    border-radius: 999px;
    font-family: system-ui, sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    font-weight: 700;
}
.codex-hero-type i { font-size: 0.9rem; }

.codex-hero-title {
    font-family: 'Cinzel', 'EB Garamond', Georgia, serif;
    font-size: clamp(1.65rem, 5vw, 3rem);
    font-weight: 700;
    color: var(--codex-ink);
    margin: 0 0 0.4rem;
    line-height: 1.1;
    text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.codex-hero-epithet {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    color: var(--codex-gold);
    font-style: italic;
    margin: 0 0 1.25rem;
    opacity: 0.92;
}

.codex-hero-caption {
    margin: 1rem 0 0;
    font-size: 0.78rem;
    color: var(--codex-ink-soft);
    opacity: 0.65;
    font-style: italic;
}

/* ── Chip row ──────────────────────────────────────────────────────────── */
.codex-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0 0;
}
.codex-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-family: system-ui, sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--codex-ink);
}
.codex-chip i { font-size: 0.72rem; opacity: 0.85; }
.codex-chip-heaven  { background: var(--codex-heaven);  color: var(--codex-heaven-fg);  border-color: rgba(0,0,0,0.15); }
.codex-chip-hell    { background: var(--codex-hell);    color: var(--codex-hell-fg);    border-color: rgba(0,0,0,0.2); }
.codex-chip-violet  { background: var(--codex-violet);  color: var(--codex-violet-fg);  border-color: rgba(0,0,0,0.2); }
.codex-chip-glitch  { background: var(--codex-glitch);  color: var(--codex-glitch-fg);  border-color: rgba(0,0,0,0.25); }
.codex-chip-bone    { background: var(--codex-bone);    color: var(--codex-bone-fg);    border-color: rgba(0,0,0,0.15); }
.codex-chip-neutral { background: #4a4338;              color: #f3ead4;                 border-color: rgba(255,255,255,0.06); }
.codex-chip-alive   { background: var(--codex-alive);   color: var(--codex-alive-fg);   border-color: rgba(0,0,0,0.2); }
.codex-chip-dead    { background: var(--codex-dead);    color: var(--codex-dead-fg);    border-color: rgba(255,255,255,0.06); }
.codex-chip-tier    { background: var(--codex-gold);    color: var(--codex-leather);    font-weight: 800; }

/* Issue 5 scaffold (2026-05-08): creator-only canon badge appended to a
   status chip when the publicly-effective status (from status_history,
   gated by released titles) differs from the latest canon entry. Public
   visitors never see this — server-side $isCreator gates render. */
.codex-canon-badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0 0.35rem;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    color: #ff7a4a;
    background: rgba(255, 122, 74, 0.14);
    border: 1px solid rgba(255, 122, 74, 0.4);
    border-radius: 3px;
    vertical-align: middle;
    line-height: 1.5;
}

/* ── Body ──────────────────────────────────────────────────────────────── */
.codex-entry-body {
    max-width: 760px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

.codex-prose {
    font-size: clamp(1rem, 2.4vw, 1.125rem);
    line-height: 1.8;
    color: var(--cdx-text);
}
.codex-prose p { margin: 0 0 1.25rem; }
.codex-prose strong { color: var(--cdx-accent); font-weight: 700; }
.codex-prose em { color: var(--cdx-text-mute); }
.codex-prose h1, .codex-prose h2, .codex-prose h3, .codex-prose h4 {
    color: var(--cdx-heading);
    font-family: 'Cinzel', 'EB Garamond', Georgia, serif;
}
/* Issue 4 (2026-05-08 polish): tuned for the entry route's wider prose
   surface — gold left-rule, parchment wash, decorative open-quote glyph,
   subtle drop-cap on the first paragraph's first letter. Reads as the
   Codex's own marginalia voice. */
.codex-prose blockquote {
    position: relative;
    margin: 1.75rem 0;
    padding: 1.1rem 1.4rem 1.1rem 1.6rem;
    border-left: 3px solid var(--codex-gold);
    background:
        linear-gradient(90deg,
            rgba(200, 161, 74, .12) 0,
            rgba(200, 161, 74, .04) 60%,
            rgba(200, 161, 74, .02) 100%);
    color: var(--codex-ink-soft);
    font-style: italic;
    border-radius: 0 4px 4px 0;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, .15);
}
.codex-prose blockquote::before {
    content: '“';
    position: absolute;
    top: 0.15em;
    left: 8px;
    font-family: 'Cinzel', 'EB Garamond', Georgia, serif;
    font-size: 3.2rem;
    line-height: 1;
    color: var(--codex-gold);
    opacity: .35;
    pointer-events: none;
}
.codex-prose blockquote p:first-of-type::first-letter {
    font-family: 'Cinzel', 'EB Garamond', Georgia, serif;
    font-size: 1.45em;
    color: var(--codex-gold);
    font-style: normal;
    margin-right: 1px;
    line-height: 1;
}
[data-theme="light"] .codex-prose blockquote {
    border-left-color: #8a2418;
    background:
        linear-gradient(90deg,
            rgba(138, 36, 24, .06) 0,
            rgba(74, 36, 16, .03) 60%,
            rgba(74, 36, 16, .02) 100%);
    color: #2a1f12;
    box-shadow: inset 0 0 10px rgba(74, 36, 16, .08);
}
[data-theme="light"] .codex-prose blockquote::before { color: #8a2418; opacity: .4; }
[data-theme="light"] .codex-prose blockquote p:first-of-type::first-letter { color: #6b1a1a; }
.codex-prose a { color: var(--codex-gold); text-decoration: none; border-bottom: 1px dashed var(--codex-gold-soft); }
.codex-prose a:hover { color: #f3d27e; border-bottom-style: solid; }

/* Auto-injected entity links — same style, but a subtle marker. */
.codex-link {
    color: var(--codex-gold) !important;
    text-decoration: none;
    border-bottom: 1px dashed var(--codex-gold-soft);
    transition: color .2s ease, border-color .2s ease;
}
.codex-link:hover { color: #f3d27e !important; border-bottom-style: solid; }

.codex-link-locked {
    color: var(--cdx-text-mute) !important;
    border-bottom-color: rgba(200, 161, 74, 0.35);
    cursor: help;
}
/* Locked chip — amber lock badge, theme-aware. Replaces the old "[LOCKED Tx]"
   text-only red box with an informational chip ("Released after Tx"). */
.codex-lock-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.4rem;
    padding: 0.18rem 0.55rem;
    font-family: system-ui, sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    background: rgba(232, 165, 60, 0.14);
    color: #e8a53c;
    border: 1px solid rgba(232, 165, 60, 0.45);
    border-radius: 999px;
    vertical-align: middle;
    line-height: 1.2;
}
.codex-lock-tag i { font-size: 0.7rem; opacity: 0.9; }
[data-theme="light"] .codex-lock-tag,
body.codex-theme-grimoire-light .codex-lock-tag {
    background: rgba(176, 116, 28, 0.12);
    color: #8a4d10;
    border-color: rgba(138, 77, 16, 0.5);
}

/* ── Section headings ─────────────────────────────────────────────────── */
.codex-section-heading {
    font-family: 'Cinzel', 'EB Garamond', Georgia, serif;
    font-size: 1.05rem;
    color: var(--cdx-heading);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--cdx-rule);
}
.codex-section-heading i { margin-right: 0.5rem; opacity: 0.85; }

/* ── Memory section (Vaelor layout: leather card, bullets) ────────────── */
.codex-memory {
    background: var(--codex-leather);
    border: 1px solid var(--codex-rule);
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    box-shadow: var(--codex-shadow);
    margin-top: 2rem;
}
.codex-memory .codex-section-heading { margin-top: 0; border: none; padding-bottom: 0.25rem; }
.codex-memory-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.codex-memory-list li {
    position: relative;
    padding: 0.5rem 0 0.5rem 1.5rem;
    border-bottom: 1px dashed rgba(200, 161, 74, 0.15);
    font-size: 0.95rem;
    line-height: 1.55;
}
.codex-memory-list li:last-child { border-bottom: none; }
.codex-memory-list li::before {
    content: "❖";
    position: absolute;
    left: 0;
    top: 0.55rem;
    color: var(--codex-gold);
    font-size: 0.85rem;
}
.codex-memory-ts {
    display: inline-block;
    margin-right: 0.5rem;
    font-family: system-ui, sans-serif;
    font-size: 0.7rem;
    color: var(--codex-gold-soft);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ── Cross-links (lore map etc) ───────────────────────────────────────── */
.codex-crosslinks {
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.codex-crosslink {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1.1rem;
    background: rgba(200, 161, 74, 0.08);
    border: 1px solid var(--codex-gold-soft);
    color: var(--codex-gold);
    text-decoration: none;
    border-radius: 4px;
    font-family: system-ui, sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    transition: background .2s ease, border-color .2s ease;
}
.codex-crosslink:hover {
    background: rgba(200, 161, 74, 0.18);
    border-color: var(--codex-gold);
}
.codex-crosslink .fa-arrow-right { margin-left: auto; opacity: 0.7; }

/* ── Appears-in tags ──────────────────────────────────────────────────── */
.codex-tag-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.codex-tag {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    background: rgba(200, 161, 74, 0.1);
    color: var(--cdx-accent);
    font-family: system-ui, sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    border: 1px solid var(--cdx-accent-soft);
    border-radius: 3px;
}
[data-theme="light"] .codex-tag,
body.codex-theme-grimoire-light .codex-tag {
    background: rgba(138, 36, 24, 0.06);
}

/* ── Related entries ─────────────────────────────────────────────────── */
.codex-related-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.6rem;
}
.codex-related-list a {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.85rem 1rem;
    background: var(--cdx-card-bg);
    border: 1px solid var(--cdx-card-border);
    border-radius: 4px;
    color: var(--cdx-text);
    text-decoration: none;
    transition: border-color .2s ease, background .2s ease;
}
.codex-related-list a:hover {
    border-color: var(--cdx-accent-soft);
    background: rgba(200, 161, 74, 0.08);
}
[data-theme="light"] .codex-related-list a:hover,
body.codex-theme-grimoire-light .codex-related-list a:hover {
    background: rgba(138, 36, 24, 0.06);
}
.codex-related-list .codex-related-title {
    font-family: 'Cinzel', Georgia, serif;
    font-weight: 700;
    color: var(--cdx-accent);
    font-size: 0.95rem;
}
.codex-related-list .codex-related-type {
    font-family: system-ui, sans-serif;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--cdx-text-mute);
    opacity: 0.85;
}

/* ── Contributor block ─────────────────────────────────────────────── */
.codex-contributor {
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--cdx-rule);
    font-family: system-ui, sans-serif;
    font-size: 0.82rem;
    color: var(--cdx-text-mute);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
.codex-contributor-label { opacity: 0.85; }
.codex-contributor-link  { color: var(--cdx-accent); text-decoration: none; font-weight: 700; }
.codex-contributor-link:hover { text-decoration: underline; }
.codex-contributor-tier {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    background: rgba(200, 161, 74, 0.12);
    border: 1px solid var(--cdx-accent-soft);
    color: var(--cdx-accent);
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 3px;
    letter-spacing: 0.04em;
}
[data-theme="light"] .codex-contributor-tier,
body.codex-theme-grimoire-light .codex-contributor-tier {
    background: rgba(138, 36, 24, 0.08);
}

/* ── Mobile responsive (320 → 1280+) ──────────────────────────────────── */
@media (min-width: 480px) {
    .codex-hero { padding: 2.5rem 1.75rem 3rem; min-height: 360px; }
    .codex-entry-body { padding: 2.5rem 1.75rem 4rem; }
}
@media (min-width: 768px) {
    .codex-hero { padding: 3rem 2.5rem 3.5rem; min-height: 420px; }
    .codex-entry-body { padding: 3rem 2.5rem 5rem; }
    .codex-prose { font-size: 1.13rem; }
}
@media (min-width: 1024px) {
    .codex-hero { min-height: 480px; }
}

/* Reduce motion users — kill any transitions. */
@media (prefers-reduced-motion: reduce) {
    .codex-back, .codex-link, .codex-crosslink, .codex-related-list a {
        transition: none;
    }
}

/* ── Light-mode hero polish ────────────────────────────────────────────────
   Issue 8 (2026-05-11 UAT): hero used to stay DARK in light mode because the
   --codex-leather token was frozen. With the token now rebound at the
   :root[data-theme="light"] scope above, the hero inherits parchment-tones.
   But because the hero ALSO uses a hardcoded `rgba(20,17,13,...)` overlay
   we must override the overlay gradient explicitly for light mode so the
   title block sits over a parchment-amber wash, not a dark wash. */
[data-theme="light"] .codex-hero,
body.codex-theme-grimoire-light .codex-hero {
    border-bottom-color: var(--cdx-rule);
    box-shadow: 0 1px 0 rgba(74, 36, 16, 0.08);
    /* Use the rebound --codex-leather (now parchment) instead of the frozen
       dark value. Background-image already inherits the radial wash + any
       hero image; only background-color changes. */
    background-color: var(--codex-leather);
}
[data-theme="light"] .codex-hero-overlay,
body.codex-theme-grimoire-light .codex-hero-overlay {
    /* Parchment-amber overlay so the hero gradient stays readable in light
       mode without going dark. Title + chips re-coloured below. */
    background: linear-gradient(180deg,
        rgba(245, 232, 194, 0.15) 0%,
        rgba(245, 232, 194, 0.65) 60%,
        rgba(239, 225, 184, 0.92) 100%);
}
[data-theme="light"] .codex-back,
body.codex-theme-grimoire-light .codex-back {
    /* Now sits over parchment overlay — use dark umber for legibility. */
    color: var(--cdx-text-mute);
}
[data-theme="light"] .codex-back:hover,
body.codex-theme-grimoire-light .codex-back:hover {
    color: var(--cdx-accent);
}
/* Hero title text — in light mode the wash is parchment, so title goes
   deep umber / heading colour rather than gold-on-dark. */
[data-theme="light"] .codex-hero h1,
[data-theme="light"] .codex-hero .codex-hero-title,
body.codex-theme-grimoire-light .codex-hero h1,
body.codex-theme-grimoire-light .codex-hero .codex-hero-title {
    color: var(--cdx-heading);
    text-shadow: 0 1px 0 rgba(245, 232, 194, .6);
}
[data-theme="light"] .codex-hero-type,
body.codex-theme-grimoire-light .codex-hero-type {
    background: rgba(74, 36, 16, 0.08);
    border-color: var(--cdx-accent-soft);
    color: var(--cdx-accent);
}
/* Section heading + memory card chrome lift in light mode. */
[data-theme="light"] .codex-memory,
body.codex-theme-grimoire-light .codex-memory {
    background: #efe1b8;
    border-color: var(--cdx-rule);
    box-shadow: 0 4px 16px rgba(74, 36, 16, 0.10);
}
[data-theme="light"] .codex-memory-list li::before,
body.codex-theme-grimoire-light .codex-memory-list li::before {
    color: var(--cdx-accent);
}
[data-theme="light"] .codex-memory-list li,
body.codex-theme-grimoire-light .codex-memory-list li {
    border-bottom-color: rgba(138, 36, 24, 0.18);
}
[data-theme="light"] .codex-crosslink,
body.codex-theme-grimoire-light .codex-crosslink {
    background: rgba(138, 36, 24, 0.06);
    border-color: var(--cdx-accent-soft);
    color: var(--cdx-accent);
}
[data-theme="light"] .codex-crosslink:hover,
body.codex-theme-grimoire-light .codex-crosslink:hover {
    background: rgba(138, 36, 24, 0.14);
    border-color: var(--cdx-accent);
}

/* Auto-injected entity links in light mode — readable, themed accent. */
[data-theme="light"] .codex-prose a,
[data-theme="light"] .codex-link,
body.codex-theme-grimoire-light .codex-prose a,
body.codex-theme-grimoire-light .codex-link {
    color: var(--cdx-accent) !important;
    border-bottom-color: var(--cdx-accent-soft);
}
[data-theme="light"] .codex-prose a:hover,
[data-theme="light"] .codex-link:hover,
body.codex-theme-grimoire-light .codex-prose a:hover,
body.codex-theme-grimoire-light .codex-link:hover {
    color: #4a0d0d !important;
    border-bottom-style: solid;
}
