:root {
    --ink: #2e2119;
    --muted: #6d5847;
    --red: #8c1d18;
    --red-dark: #5d100d;
    --gold: #b78a3f;
    --paper: #efe0bd;
    --paper-light: #f7eccf;
    --paper-dark: #d7bf8c;
    --night: #17110e;
    --night-soft: #241a15;
    --border: rgba(78, 48, 26, .38);
    --shadow: 0 14px 35px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--night); }

body {
    margin: 0;
    color: var(--ink);
    font-family: "Libre Baskerville", Georgia, serif;
    background:
        radial-gradient(circle at 15% 10%, rgba(140, 29, 24, .18), transparent 28rem),
        radial-gradient(circle at 80% 30%, rgba(183, 138, 63, .10), transparent 30rem),
        linear-gradient(135deg, #100c0a, #241711 48%, #110d0a);
}

a { color: inherit; }

.compendium-shell { min-height: 100vh; display: flex; flex-direction: column; }

.site-header {
    color: #f6e8c9;
    background: rgba(18, 12, 9, .94);
    border-bottom: 2px solid var(--gold);
    box-shadow: 0 8px 25px rgba(0,0,0,.4);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.header-inner {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    padding: 16px 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.brand strong { display: block; font: 700 1.1rem/1.2 "Cinzel", serif; letter-spacing: .04em; }
.brand small { display: block; color: #c9b58d; margin-top: 3px; }

.brand-mark {
    width: 48px; height: 48px; display: grid; place-items: center;
    border: 2px solid var(--gold); transform: rotate(45deg);
    font: 700 .85rem "Cinzel", serif; color: var(--gold);
}
.brand-mark::first-line { transform: rotate(-45deg); }

.header-search, .hero-search, .filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-search input, .hero-search input, .filter-bar input {
    min-width: 280px;
    border: 1px solid rgba(183,138,63,.55);
    background: rgba(255,255,255,.08);
    color: #fff7e2;
    border-radius: 4px;
    padding: 12px 14px;
    font: inherit;
}

.header-search input::placeholder, .hero-search input::placeholder { color: #c7b99d; }

button, .header-search button, .hero-search button, .filter-bar button {
    border: 0;
    background: linear-gradient(#a52b23, var(--red-dark));
    color: #fff4df;
    padding: 12px 17px;
    border-radius: 4px;
    font: 700 .78rem "Cinzel", serif;
    letter-spacing: .05em;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.main-nav {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    display: flex;
    gap: 4px;
    overflow-x: auto;
}
.main-nav a {
    text-decoration: none;
    color: #d9c7a5;
    padding: 10px 14px 12px;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    font: 600 .76rem "Cinzel", serif;
}
.main-nav a:hover { color: white; border-bottom-color: var(--red); }

.page-wrap {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    padding: 40px 0 70px;
    flex: 1;
}

.parchment {
    background:
        linear-gradient(rgba(255,255,255,.1), rgba(105,69,30,.05)),
        repeating-linear-gradient(0deg, rgba(90,50,20,.018) 0, rgba(90,50,20,.018) 1px, transparent 1px, transparent 4px),
        var(--paper);
    border: 1px solid var(--paper-dark);
    box-shadow: var(--shadow), inset 0 0 30px rgba(92,57,25,.08);
}

.hero {
    min-height: 390px;
    padding: 58px;
    display: grid;
    grid-template-columns: 1fr 280px;
    align-items: center;
    position: relative;
    overflow: hidden;
    border-top: 7px solid var(--red);
}
.hero::after {
    content: "";
    position: absolute;
    inset: 14px;
    border: 1px solid rgba(92,57,25,.28);
    pointer-events: none;
}
.hero h1, .chapter-header h1, .stat-header h1 {
    font: 700 clamp(2.2rem, 5vw, 4.7rem)/1.02 "Cinzel", serif;
    margin: 8px 0 18px;
    color: #45140f;
}
.hero p { max-width: 760px; font-size: 1.1rem; line-height: 1.75; }
.hero-search { margin-top: 28px; position: relative; z-index: 2; }
.hero-search input { flex: 1; background: rgba(255,255,255,.45); color: var(--ink); min-width: 0; }
.hero-sigil {
    width: 220px; height: 220px; display: grid; place-items: center;
    border: 8px double var(--red); color: var(--red); border-radius: 50%;
    font: 700 5rem "Cinzel", serif; transform: rotate(-8deg);
    opacity: .75;
}

.eyebrow {
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: .14em;
    font: 700 .72rem "Cinzel", serif;
}

.section-heading { color: #f3e4c4; text-align: center; padding: 48px 0 24px; }
.section-heading span { color: #c6a66d; text-transform: uppercase; letter-spacing: .15em; font-size: .72rem; }
.section-heading h2 { font: 600 2rem "Cinzel", serif; margin: 8px 0; }

.family-grid, .entry-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}
.family-card, .entry-card {
    text-decoration: none;
    padding: 24px;
    color: var(--ink);
    transition: transform .16s ease, box-shadow .16s ease;
}
.family-card { display: grid; grid-template-columns: 56px 1fr auto; gap: 16px; align-items: start; }
.family-card:hover, .entry-card:hover { transform: translateY(-3px); box-shadow: 0 18px 45px rgba(0,0,0,.38); }
.family-icon { font-size: 2rem; }
.family-card h3, .entry-card h2, .entry-card h3 { font: 700 1.15rem "Cinzel", serif; margin: 0 0 8px; color: #4c160f; }
.family-card p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.family-count { color: var(--red); font: 700 1rem "Cinzel", serif; }

.chapter-header, .stat-header {
    padding: 34px 38px;
    border-top: 6px solid var(--red);
    margin-bottom: 20px;
}
.chapter-header { display: flex; justify-content: space-between; gap: 30px; align-items: center; }
.chapter-header h1, .stat-header h1 { font-size: clamp(2rem, 4vw, 3.3rem); margin-bottom: 8px; }
.chapter-header p, .stat-subtitle { color: var(--muted); line-height: 1.55; margin: 0; }
.chapter-count { white-space: nowrap; font: 700 1rem "Cinzel", serif; color: var(--red); }

.filter-bar { padding: 16px; margin-bottom: 20px; }
.filter-bar input { flex: 1; background: rgba(255,255,255,.45); color: var(--ink); min-width: 0; }
.filter-bar a { color: var(--red); font-weight: bold; }

.entry-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.entry-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.entry-card-top { display: flex; justify-content: space-between; gap: 14px; }
.version-count { color: var(--red); font-size: .72rem; white-space: nowrap; }
.entry-summary, .source-list, .tag-list { display: flex; gap: 8px; flex-wrap: wrap; }
.entry-summary span, .source-list span, .tag-list span, .tag-strip span {
    background: rgba(92,57,25,.09);
    border: 1px solid rgba(92,57,25,.18);
    padding: 5px 8px;
    font-size: .72rem;
}
.source-list { margin-top: 14px; color: var(--muted); }

.pagination {
    margin-top: 24px;
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}
.pagination a:last-child { text-align: right; }
.pagination a { color: var(--red); font-weight: bold; text-decoration: none; }

.search-section { margin-top: 36px; }
.search-section-heading { color: #f4e7cd; display: flex; justify-content: space-between; align-items: end; margin-bottom: 14px; }
.search-section-heading h2 { font: 600 1.7rem "Cinzel", serif; margin: 4px 0; }
.search-section-heading a { color: #dfba78; }

.entry-navigation { margin-bottom: 12px; }
.entry-navigation-links {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    color: #e8d5b4; font-size: .85rem;
}
.entry-navigation-links a { text-decoration: none; }
.entry-navigation-links a:last-child { text-align: right; }
.back-link { color: #d4a95e; font-family: "Cinzel", serif; }

.source-meta, .version-switcher { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.source-meta span, .version-switcher a {
    border: 1px solid rgba(92,57,25,.25);
    background: rgba(255,255,255,.22);
    padding: 7px 10px;
    font-size: .75rem;
    text-decoration: none;
}
.version-switcher { align-items: center; }
.version-switcher > span { color: var(--muted); margin-right: 4px; }
.version-switcher a.active { background: var(--red); border-color: var(--red); color: #fff5e5; }

.stat-ribbon, .ability-table {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 18px;
    overflow: hidden;
}
.stat-ribbon.three { grid-template-columns: repeat(3, 1fr); }
.stat-ribbon > div, .ability-table > div { padding: 20px; border-right: 1px solid var(--border); }
.stat-ribbon > div:last-child, .ability-table > div:last-child { border-right: 0; }
.stat-ribbon span, .ability-table span {
    display: block; color: var(--red); font: 700 .7rem "Cinzel", serif; text-transform: uppercase; margin-bottom: 6px;
}
.stat-ribbon strong { line-height: 1.5; }
.ability-table { grid-template-columns: repeat(6, 1fr); text-align: center; }
.ability-table strong { font-size: 1.35rem; }

.two-column-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); gap: 18px; align-items: start; }
.rule-section, .sidebar-card, .tag-strip { padding: 28px; margin-bottom: 18px; }
.rule-section > h2, .sidebar-card > h2 {
    color: var(--red-dark);
    font: 700 1.35rem "Cinzel", serif;
    margin: 0 0 20px;
    padding-bottom: 10px;
    border-bottom: 3px double rgba(140,29,24,.55);
}
.rule-block { padding: 3px 0 18px; }
.rule-block + .rule-block { border-top: 1px solid rgba(92,57,25,.18); padding-top: 18px; }
.rule-block h3, .rule-block h4 { display: inline; font: 700 1rem "Libre Baskerville", serif; color: #4e1b14; }
.rules-text { line-height: 1.72; }
.rules-text p:first-child { margin-top: 0; }
.rule-caption { color: var(--muted); font-style: italic; }
.nested-rules { margin: 14px 0 0 20px; padding-left: 18px; border-left: 3px solid rgba(140,29,24,.35); }

.sidebar-card dl, .reference-list { margin: 0; }
.sidebar-card dt, .reference-list dt { color: var(--red); font: 700 .7rem "Cinzel", serif; text-transform: uppercase; margin-top: 18px; }
.sidebar-card dt:first-child, .reference-list dt:first-child { margin-top: 0; }
.sidebar-card dd, .reference-list dd { margin: 5px 0 0; line-height: 1.55; }
.reference-list { display: grid; grid-template-columns: 220px 1fr; gap: 12px 20px; }
.reference-list dt { margin: 0; }
.reference-list pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.material-note { background: rgba(140,29,24,.07); padding: 14px; border-left: 4px solid var(--red); }
.tag-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-state { padding: 50px; text-align: center; }
.empty-state h2 { font: 600 1.8rem "Cinzel", serif; color: var(--red-dark); }

.site-footer {
    color: #cbb895;
    border-top: 1px solid rgba(183,138,63,.35);
    padding: 24px 16px;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 14px;
    background: rgba(10,7,5,.7);
}
.site-footer a { color: #dfba78; }
.footer-rune { color: var(--red); }

@media (max-width: 1050px) {
    .family-grid, .entry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .entry-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero { grid-template-columns: 1fr; }
    .hero-sigil { display: none; }
    .two-column-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .header-inner { align-items: stretch; flex-direction: column; }
    .header-search input { min-width: 0; flex: 1; }
    .page-wrap { width: min(100% - 20px, 1400px); padding-top: 18px; }
    .hero, .chapter-header, .stat-header { padding: 26px 22px; }
    .hero-search, .filter-bar { align-items: stretch; flex-direction: column; }
    .family-grid, .entry-grid, .entry-grid.compact { grid-template-columns: 1fr; }
    .chapter-header { align-items: flex-start; flex-direction: column; }
    .stat-ribbon, .stat-ribbon.three { grid-template-columns: 1fr 1fr; }
    .stat-ribbon > div:nth-child(2n) { border-right: 0; }
    .ability-table { grid-template-columns: repeat(3, 1fr); }
    .ability-table > div:nth-child(3n) { border-right: 0; }
    .entry-navigation-links { grid-template-columns: 1fr; gap: 8px; }
    .entry-navigation-links a, .entry-navigation-links a:last-child { text-align: center; }
    .reference-list { grid-template-columns: 1fr; }
}


.reference-link {
    appearance: none;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--red);
    font: inherit;
    font-weight: 700;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    cursor: pointer;
}

.reference-link:hover { color: var(--red-dark); }

body.reference-modal-open { overflow: hidden; }

.reference-modal[hidden] { display: none; }

.reference-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
}

.reference-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 7, 5, .82);
    backdrop-filter: blur(5px);
}

.reference-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(850px, 100%);
    max-height: min(82vh, 900px);
    overflow: auto;
    border-top: 6px solid var(--red);
    animation: reference-modal-in .16s ease-out;
}

.reference-modal-content { min-height: 150px; }

.reference-modal-entry { padding: 34px; }

.reference-modal-header {
    padding-bottom: 20px;
    margin-bottom: 22px;
    border-bottom: 3px double rgba(140, 29, 24, .55);
}

.reference-modal-header h2 {
    margin: 6px 44px 8px 0;
    color: #45140f;
    font: 700 clamp(1.7rem, 4vw, 2.6rem) "Cinzel", serif;
}

.reference-modal-close {
    position: sticky;
    float: right;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 38px;
    height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--red-dark);
    color: #fff5e5;
    font: 400 1.7rem/1 serif;
}

.reference-modal-loading {
    min-height: 220px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-style: italic;
}

.reference-modal-rules .rule-block:last-child { padding-bottom: 0; }

.reference-modal-footer {
    margin: 26px -34px -34px;
    padding: 18px 34px;
    background: rgba(92, 57, 25, .08);
    border-top: 1px solid rgba(92, 57, 25, .18);
    text-align: right;
}

.reference-modal-footer a {
    color: var(--red);
    font-weight: 700;
}

.modal-reference-list { grid-template-columns: 180px 1fr; }

@keyframes reference-modal-in {
    from { opacity: 0; transform: translateY(12px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
    .reference-modal { padding: 10px; }
    .reference-modal-dialog { max-height: 92vh; }
    .reference-modal-entry { padding: 24px 20px; }
    .reference-modal-footer { margin: 24px -20px -24px; padding: 16px 20px; }
    .modal-reference-list { grid-template-columns: 1fr; }
}

/* ========================================================================== */
/* Private DM workspace additions                                              */
/* ========================================================================== */

:root {
    --red-on-dark: #e27d70;
    --red-on-dark-hover: #ffad9f;
    --gold-on-dark: #e8ca7b;
}

html { font-size: 17px; }
body { min-height: 100vh; font-size: 1rem; line-height: 1.62; }

.app-shell { min-height: 100vh; }

.admin-nav {
    display: flex;
    align-items: center;
    gap: 18px;
}

.admin-nav a {
    color: #e4d3b4;
    font: 700 .76rem "Cinzel", serif;
    letter-spacing: .045em;
    text-decoration: none;
    text-transform: uppercase;
}

.admin-nav a:hover { color: #fff3d7; }

.admin-nav .nav-button {
    padding: 8px 12px;
    border: 1px solid rgba(226, 125, 112, .45);
    color: #f1c0b8;
}

.admin-nav .nav-button:hover {
    border-color: var(--red-on-dark-hover);
    background: rgba(226, 125, 112, .1);
    color: #fff4df;
}

.page-heading {
    margin-bottom: 28px;
    color: #f6e8c9;
}

.page-title {
    margin: 0;
    color: #fff0ce;
    font: 800 clamp(2rem, 4vw, 3.4rem)/1.05 "Cinzel", serif;
    letter-spacing: .02em;
    text-shadow: 0 3px 10px rgba(0,0,0,.65);
}

.page-subtitle {
    max-width: 760px;
    margin: 10px 0 0;
    color: #cdbb9c;
    font-size: 1rem;
}

.panel,
.tool-card,
.npc-block,
.description-box {
    position: relative;
    color: var(--ink);
    background:
        linear-gradient(rgba(255,255,255,.1), rgba(105,69,30,.05)),
        repeating-linear-gradient(0deg, rgba(90,50,20,.018) 0, rgba(90,50,20,.018) 1px, transparent 1px, transparent 4px),
        var(--paper);
    border: 1px solid var(--paper-dark);
    border-radius: 0;
    box-shadow: var(--shadow), inset 0 0 30px rgba(92,57,25,.08);
}

.panel::before,
.tool-card::before {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--red-dark), #b43a31, var(--red-dark));
    content: "";
}

.panel-header {
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(140,29,24,.45);
}

.panel-title {
    margin: 0;
    color: #581713;
    font: 800 1.25rem "Cinzel", serif;
}

.info-label {
    margin-bottom: 5px;
    color: #a02720;
    font: 800 .7rem "Cinzel", serif;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.section-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0 0 18px;
    padding: 0;
    color: #f6e8c9;
    text-align: left;
    font: 800 1.3rem "Cinzel", serif;
    letter-spacing: .035em;
    text-transform: uppercase;
}

.section-heading::after {
    height: 2px;
    flex: 1;
    background: linear-gradient(90deg, #c3483d, rgba(195,72,61,0));
    content: "";
}

.tool-card {
    display: flex;
    min-height: 100%;
    flex-direction: column;
    padding: 22px;
    transition: transform .16s ease, box-shadow .16s ease;
}

.tool-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 45px rgba(0,0,0,.42), inset 0 0 30px rgba(92,57,25,.08);
}

.tool-card h2,
.tool-card h3,
.tool-card h4,
.tool-card h5 {
    color: #5a1713;
    font-family: "Cinzel", serif;
    font-weight: 800;
}

.tool-card p { color: #574635; }
.tool-actions { margin-top: auto; }
.muted { color: var(--muted) !important; }

.btn {
    border-radius: 2px;
    font: 800 .72rem "Cinzel", serif;
    letter-spacing: .035em;
    text-transform: uppercase;
}

.btn-primary {
    border-color: #53100d;
    background: linear-gradient(#b43a31, #6b1712);
    color: #fff4df;
}
.btn-primary:hover,
.btn-primary:focus {
    border-color: #3f0b09;
    background: linear-gradient(#c34b40, #53100d);
    color: #fff8e8;
}

.btn-success {
    border-color: #294c25;
    background: linear-gradient(#5c8c4f, #315d2b);
    color: #f7f0db;
}

.btn-outline-secondary {
    border-color: rgba(92,57,25,.42);
    color: #5d1b15;
}
.btn-outline-secondary:hover {
    border-color: var(--red);
    background: rgba(140,29,24,.1);
    color: #4a120f;
}

.btn-outline-danger {
    border-color: rgba(140,29,24,.55);
    color: #8c1d18;
}
.btn-outline-danger:hover {
    border-color: var(--red);
    background: var(--red);
    color: #fff2da;
}

.form-control,
.form-select {
    min-height: 46px;
    border: 1px solid var(--paper-dark);
    border-radius: 2px;
    background: #fff5d8;
    color: var(--ink);
    font-family: "Libre Baskerville", Georgia, serif;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--red);
    background: #fff9e7;
    color: var(--ink);
    box-shadow: 0 0 0 .2rem rgba(140,29,24,.14);
}

.form-label {
    color: #5d1712;
    font: 800 .76rem "Cinzel", serif;
    letter-spacing: .035em;
    text-transform: uppercase;
}

.alert { border-radius: 2px; }
.badge { border-radius: 2px; font-family: "Cinzel", serif; }

/* Make navigation and source controls readable on the dark background. */
.entry-navigation-links,
.entry-navigation-links a,
.back-link,
.page-navigation a,
.source-navigation a {
    color: var(--red-on-dark);
}

.entry-navigation-links a:hover,
.back-link:hover,
.page-navigation a:hover,
.source-navigation a:hover {
    color: var(--red-on-dark-hover);
}

/* Shared monster/content typography. */
.rules-text,
.rule-block,
.sidebar-card,
.stat-ribbon,
.ability-table,
.stat-header,
.chapter-header {
    font-size: 1rem;
}

.rules-text p,
.rules-text li,
.rule-block p,
.rule-block li,
.sidebar-card dd {
    font-size: 1rem;
    line-height: 1.62;
}

.rule-section h2,
.sidebar-card h2 {
    font-size: 1.35rem;
}

.rule-block h3 {
    font-size: 1rem;
}

/* Inline references */
.reference-link,
.dnd-condition-link,
.dnd-spell-link,
.dnd-creature-link,
.dnd-sense-link,
.dnd-language-link,
.dnd-reference-chip {
    appearance: none;
    display: inline-flex;
    max-width: 100%;
    align-items: center;
    margin: 0 .08rem .25rem 0;
    padding: .24rem .5rem;
    border: 1px solid rgba(140,29,24,.4);
    border-radius: 2px;
    background: rgba(140,29,24,.08);
    color: #711b16;
    font: 800 .72rem "Cinzel", serif;
    letter-spacing: .025em;
    line-height: 1.2;
    text-align: left;
    text-transform: uppercase;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.reference-link:hover,
.dnd-condition-link:hover,
.dnd-spell-link:hover,
.dnd-creature-link:hover,
.dnd-sense-link:hover,
.dnd-language-link:hover,
.dnd-reference-chip:hover {
    border-color: var(--red);
    background: rgba(140,29,24,.16);
    color: #4f100d;
}

.dnd-language-list,
.dnd-sense-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
}

/* Dice controls */
.dnd-dice-roll {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    margin: 0 .12rem;
    padding: .16rem .44rem;
    border: 1px solid rgba(140,29,24,.42);
    border-radius: 2px;
    background: linear-gradient(rgba(255,255,255,.2), rgba(92,57,25,.05)), var(--paper-light);
    color: var(--red-dark);
    font: 700 .9rem "Libre Baskerville", Georgia, serif;
    line-height: 1.2;
    cursor: pointer;
}

.dnd-dice-roll:hover {
    border-color: var(--red);
    background-color: #f8e8bd;
    transform: translateY(-1px);
}

.dnd-dice-roll.is-rolling .dnd-dice-icon {
    animation: dnd-dice-spin .45s ease;
}

/* Native reference modal, shared by admin and compendium. */
body.reference-modal-open { overflow: hidden; }
.reference-modal[hidden] { display: none; }
.reference-modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: grid;
    place-items: center;
    padding: 20px;
}
.reference-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8,5,3,.86);
    backdrop-filter: blur(5px);
}
.reference-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(850px, 100%);
    max-height: min(86vh, 900px);
    overflow: auto;
    border-top: 6px solid var(--red);
    animation: reference-modal-in .16s ease-out;
}
.reference-modal-content { min-height: 160px; }
.reference-modal-entry { padding: 34px; }
.reference-modal-header {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 2px solid rgba(140,29,24,.52);
}
.reference-modal-header h2 {
    margin: 6px 50px 8px 0;
    color: #45140f;
    font: 800 clamp(1.8rem, 4vw, 2.7rem) "Cinzel", serif;
}
.reference-modal-close {
    position: sticky;
    top: 12px;
    right: 12px;
    z-index: 2;
    float: right;
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    padding: 0;
    border: 2px solid var(--gold);
    border-radius: 50%;
    background: var(--red-dark);
    color: #fff5e5;
    font-size: 1.65rem;
    line-height: 1;
}
.reference-modal-loading {
    display: grid;
    min-height: 220px;
    place-items: center;
    color: var(--muted);
    font-style: italic;
}
.reference-modal-footer {
    margin: 26px -34px -34px;
    padding: 18px 34px;
    border-top: 1px solid rgba(92,57,25,.18);
    background: rgba(92,57,25,.08);
    text-align: right;
}

/* Dice toast is appended directly to body. */
.dnd-roll-results {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 5000;
    display: flex;
    width: min(24rem, calc(100vw - 2rem));
    flex-direction: column;
    gap: .65rem;
    pointer-events: none;
}
.dnd-roll-result {
    position: relative;
    overflow: hidden;
    padding: 1rem 2.8rem 1rem 1rem;
    border: 1px solid var(--paper-dark);
    border-top: 5px solid var(--red);
    border-radius: 2px;
    background: repeating-linear-gradient(0deg, rgba(92,57,25,.018) 0, rgba(92,57,25,.018) 1px, transparent 1px, transparent 4px), var(--paper-light);
    color: var(--ink);
    box-shadow: 0 14px 36px rgba(0,0,0,.46), inset 0 0 22px rgba(92,57,25,.07);
    pointer-events: auto;
}
.dnd-roll-result-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.dnd-roll-result-expression {
    color: var(--red-dark);
    font: 700 .85rem "Cinzel", serif;
    text-transform: uppercase;
}
.dnd-roll-result-total {
    display: grid;
    min-width: 3rem;
    min-height: 3rem;
    place-items: center;
    border: 2px solid var(--red);
    border-radius: 50%;
    color: var(--red-dark);
    font: 700 1.45rem "Cinzel", serif;
}
.dnd-roll-result-details { margin-top: .55rem; color: var(--muted); font-size: .82rem; }
.dnd-roll-result-close {
    position: absolute;
    top: .35rem;
    right: .35rem;
    width: 1.8rem;
    height: 1.8rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 1.25rem;
}

@keyframes dnd-dice-spin {
    0% { transform: rotate(0deg) scale(1); }
    45% { transform: rotate(190deg) scale(1.35); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes reference-modal-in {
    from { opacity: 0; transform: translateY(12px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
    html { font-size: 16px; }
    .header-inner { align-items: flex-start; }
    .admin-nav { gap: 10px; }
    .admin-nav a { font-size: .68rem; }
    .brand small { display: none; }
    .page-wrap { width: min(100% - 20px, 1400px); padding-top: 24px; }
    .reference-modal { padding: 10px; }
    .reference-modal-dialog { max-height: 92vh; }
    .reference-modal-entry { padding: 24px 20px; }
    .reference-modal-footer { margin: 24px -20px -24px; padding: 16px 20px; }
    .dnd-roll-results { right: .65rem; bottom: .65rem; width: calc(100vw - 1.3rem); }
}

/* ========================================================================== 
   Unified compendium-style content sheets
   ========================================================================== */

:root {
  --red-on-dark: #e68172;
  --red-on-dark-hover: #ffab9d;
  --gold-on-dark: #ead18a;
}

html { font-size: 18px; }
body { font-size: 1rem; line-height: 1.62; }

.content-navigation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  margin-bottom: .85rem;
  font-family: "Cinzel", Georgia, serif;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .035em;
}
.content-navigation a { color: var(--red-on-dark); }
.content-navigation a:hover { color: var(--red-on-dark-hover); }

.parchment-sheet {
  position: relative;
  border: 1px solid var(--paper-dark);
  border-top: 4px solid var(--red);
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(92,57,25,.035), transparent 12%, transparent 88%, rgba(92,57,25,.035)),
    repeating-linear-gradient(0deg, rgba(92,57,25,.018) 0, rgba(92,57,25,.018) 1px, transparent 1px, transparent 4px),
    var(--paper-light);
  color: var(--ink);
  box-shadow: 0 10px 28px rgba(0,0,0,.38), inset 0 0 28px rgba(92,57,25,.07);
}

.monster-page { max-width: 1320px; }
.monster-hero { padding: 2rem 2.2rem 1.7rem; margin-bottom: 1rem; }
.monster-hero .eyebrow,
.reference-modal-header .eyebrow {
  color: var(--red);
  font-family: "Cinzel", Georgia, serif;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.monster-hero h1 {
  margin: .2rem 0 .2rem;
  color: var(--red-dark);
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(2.35rem, 5vw, 3.55rem);
  font-weight: 800;
  line-height: 1.05;
}
.monster-subtitle { margin: 0; color: var(--ink-soft); font-size: 1.08rem; }
.source-meta { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .85rem; }
.source-meta > span {
  padding: .24rem .55rem;
  border: 1px solid rgba(92,57,25,.28);
  background: rgba(255,255,255,.17);
  color: var(--ink-soft);
  font-size: .76rem;
}
.source-versions { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin-top: 1rem; }
.source-versions-label { color: var(--muted); font-size: .9rem; margin-right: .2rem; }
.source-version-link {
  padding: .3rem .55rem;
  border: 1px solid rgba(140,29,24,.3);
  color: #8d2a23;
  font-size: .76rem;
  font-weight: 700;
}
.source-version-link:hover { color: var(--red-dark); border-color: var(--red); background: rgba(140,29,24,.08); }
.source-version-link.is-active { background: var(--red); border-color: var(--red); color: #fff4dc; }

.monster-primary-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}
.monster-stat-cell { min-height: 108px; padding: 1rem 1.15rem; border-right: 1px solid rgba(92,57,25,.22); }
.monster-stat-cell:last-child { border-right: 0; }
.monster-stat-cell > span,
.monster-abilities span,
.sidebar-card dt {
  display: block;
  margin-bottom: .25rem;
  color: var(--red);
  font-family: "Cinzel", Georgia, serif;
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
}
.monster-stat-cell strong { display: block; color: var(--ink); font-size: 1rem; line-height: 1.4; }
.monster-stat-cell small { font-size: .72rem; color: var(--muted); }

.monster-abilities {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 1rem;
}
.monster-abilities > div { padding: .75rem; text-align: center; border-right: 1px solid rgba(92,57,25,.22); }
.monster-abilities > div:last-child { border-right: 0; }
.monster-abilities strong { display: block; color: var(--ink); font-size: 1.25rem; }

.monster-layout { display: grid; grid-template-columns: minmax(0, 2.35fr) minmax(290px, .95fr); gap: 1rem; align-items: start; }
.monster-main-column,
.monster-sidebar { display: grid; gap: 1rem; }
.monster-sidebar { position: sticky; top: 92px; }

.monster-rules-section,
.sidebar-card { padding: 1.35rem 1.5rem; }
.monster-rules-section h2,
.sidebar-card h2 {
  margin: 0 0 1rem;
  padding-bottom: .55rem;
  border-bottom: 2px solid rgba(140,29,24,.52);
  color: var(--red-dark);
  font-family: "Cinzel", Georgia, serif;
  font-size: 1.3rem;
  font-weight: 800;
  text-transform: uppercase;
}
.rule-entry { padding: .15rem 0 1rem; }
.rule-entry + .rule-entry { padding-top: 1rem; border-top: 1px solid rgba(92,57,25,.18); }
.rule-entry:last-child { padding-bottom: 0; }
.rule-entry h3 {
  margin: 0 0 .15rem;
  color: #542019;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
}
.rules-text,
.rules-text p,
.rules-text li,
.rule-entry { font-size: 1rem; line-height: 1.58; }
.rules-text p:last-child { margin-bottom: 0; }
.rule-meta { margin: -.05rem 0 .65rem; color: var(--muted); font-size: .86rem; }
.spell-list-row { margin-top: .45rem; }
.spell-list-row > strong { color: var(--red-dark); }

.inline-reference-link {
  appearance: none;
  padding: 0;
  border: 0;
  border-bottom: 1px dotted currentColor;
  background: transparent;
  color: #9e3027;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.inline-reference-link:hover { color: var(--red-dark); }

.sidebar-card dl { margin: 0; }
.sidebar-card dt:not(:first-child) { margin-top: 1rem; }
.sidebar-card dd { margin: 0; color: var(--ink); font-size: .94rem; line-height: 1.55; }
.reference-chip-list { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .35rem; }
.dnd-reference-chip {
  appearance: none;
  display: inline-flex;
  width: auto;
  max-width: 100%;
  align-items: center;
  padding: .28rem .48rem;
  border: 1px solid rgba(140,29,24,.38);
  border-radius: 0;
  background: rgba(140,29,24,.07);
  color: var(--red-dark);
  font-family: "Cinzel", Georgia, serif;
  font-size: .69rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: .015em;
  text-align: left;
  text-transform: uppercase;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.dnd-reference-chip:hover { border-color: var(--red); background: rgba(140,29,24,.14); color: var(--red-dark); }
.dnd-reference-chip.is-static { cursor: default; }

/* Bootstrap-backed local modals for senses/languages/skills, styled like the compendium. */
.modal-backdrop.show { opacity: .82; }
.modal-content {
  border: 1px solid var(--paper-dark) !important;
  border-top: 5px solid var(--red) !important;
  border-radius: 0 !important;
  background:
    repeating-linear-gradient(0deg, rgba(92,57,25,.018) 0, rgba(92,57,25,.018) 1px, transparent 1px, transparent 4px),
    var(--paper-light) !important;
  color: var(--ink) !important;
  box-shadow: 0 22px 65px rgba(0,0,0,.64), inset 0 0 28px rgba(92,57,25,.08);
}
.modal-header { border-bottom: 2px solid rgba(140,29,24,.45) !important; }
.modal-title { color: var(--red-dark) !important; font-family: "Cinzel", Georgia, serif; font-weight: 800; }
.modal-body,
.modal-body p,
.modal-body li { color: var(--ink) !important; font-size: 1rem; line-height: 1.6; }
.modal-footer { border-top-color: rgba(92,57,25,.2) !important; }
.modal .btn-close { filter: none; opacity: .7; }
.modal .text-light,
.modal .text-muted { color: var(--muted) !important; }
.modal .bg-dark { background: transparent !important; }

/* Brighter controls on the dark application background. */
.page-heading .btn-outline-secondary,
.content-navigation + .btn-outline-secondary { color: var(--red-on-dark); border-color: rgba(230,129,114,.45); }
.page-heading .btn-outline-secondary:hover { color: #fff4df; background: rgba(230,129,114,.12); border-color: var(--red-on-dark-hover); }

@media (max-width: 992px) {
  .monster-layout { grid-template-columns: 1fr; }
  .monster-sidebar { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  html { font-size: 17px; }
  .content-navigation { grid-template-columns: 1fr; text-align: left; }
  .content-navigation > * { text-align: left !important; }
  .monster-hero { padding: 1.35rem 1.15rem; }
  .monster-primary-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .monster-stat-cell:nth-child(2) { border-right: 0; }
  .monster-stat-cell:nth-child(-n+2) { border-bottom: 1px solid rgba(92,57,25,.22); }
  .monster-abilities { grid-template-columns: repeat(3, 1fr); }
  .monster-abilities > div:nth-child(3) { border-right: 0; }
  .monster-abilities > div:nth-child(-n+3) { border-bottom: 1px solid rgba(92,57,25,.22); }
  .monster-sidebar { grid-template-columns: 1fr; }
  .monster-rules-section,
  .sidebar-card { padding: 1.1rem; }
}

.source-versions a,
.source-version-link,
.source-version-button,
.source-meta a,
.monster-source-versions a {
  text-decoration: none !important;
}

.source-versions a:hover,
.source-version-link:hover,
.source-version-button:hover,
.source-meta a:hover,
.monster-source-versions a:hover {
  text-decoration: none !important;
}

.dnd-roll-variable {
  color: var(--muted);
  font-style: italic;
  white-space: nowrap;
}

/*
 * Local admin reference modals
 */

.dnd-local-modal {
  --bs-modal-bg: transparent;
  --bs-modal-border-width: 0;
}

.dnd-local-modal .modal-dialog {
  width: min(850px, calc(100% - 2rem));
  max-width: 850px;
}

.dnd-modal-parchment {
  overflow: hidden;

  border: 1px solid var(--paper-dark);
  border-top: 5px solid var(--red);
  border-radius: 2px;

  background:
    repeating-linear-gradient(
      0deg,
      rgba(92, 57, 25, 0.018) 0,
      rgba(92, 57, 25, 0.018) 1px,
      transparent 1px,
      transparent 4px
    ),
    var(--paper-light);

  color: var(--ink);

  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.62),
    inset 0 0 30px rgba(92, 57, 25, 0.08);
}

.dnd-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;

  padding: 1.8rem 2rem 1.25rem;

  border-bottom: 2px solid rgba(140, 29, 24, 0.5);
}

.dnd-modal-eyebrow {
  margin-bottom: 0.35rem;

  color: var(--red);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.dnd-modal-title {
  margin: 0;

  color: var(--red-dark);
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  font-weight: 800;
  line-height: 1.1;
}

.dnd-modal-source {
  margin-top: 0.65rem;

  color: var(--muted);
  font-size: 0.95rem;
}

.dnd-modal-close {
  display: grid;
  width: 2.45rem;
  height: 2.45rem;
  flex: 0 0 2.45rem;
  place-items: center;

  padding: 0;

  border: 2px solid var(--gold-light);
  border-radius: 50%;

  background: var(--red-dark);
  color: var(--paper-bright);

  font-size: 1.55rem;
  line-height: 1;

  cursor: pointer;
}

.dnd-modal-close:hover {
  background: var(--red);
  color: #fff;
}

.dnd-modal-body {
  padding: 1.6rem 2rem 2rem;

  font-size: 1.05rem;
  line-height: 1.65;
}

/*
 * Senses
 */

.dnd-sense-description {
  padding-left: 1.1rem;
  border-left: 4px solid var(--gold);
}

.dnd-sense-description p {
  margin: 0 0 1rem;
}

.dnd-sense-description p:last-child {
  margin-bottom: 0;
}

/*
 * Languages
 */

.dnd-language-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;

  margin-bottom: 1.5rem;
}

.dnd-reference-fact {
  padding: 1rem;

  border: 1px solid rgba(92, 57, 25, 0.22);
  border-left: 4px solid var(--red);

  background: rgba(166, 124, 50, 0.07);
}

.dnd-reference-label {
  margin-bottom: 0.3rem;

  color: var(--red);
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dnd-reference-value {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 700;
}

.dnd-reference-section {
  padding-top: 1.25rem;
  border-top: 2px solid rgba(140, 29, 24, 0.3);
}

.dnd-reference-heading {
  margin: 0 0 0.9rem;

  color: var(--red-dark);
  font-family: "Cinzel", Georgia, serif;
  font-size: 1.08rem;
  font-weight: 800;
}

.dnd-speaker-list,
.dnd-reference-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.dnd-reference-chip,
.dnd-speaker-chip {
  appearance: none;

  display: inline-flex;
  width: auto;
  max-width: 100%;
  align-items: center;

  padding: 0.3rem 0.58rem;

  border: 1px solid rgba(140, 29, 24, 0.42);
  border-radius: 2px;

  background: rgba(140, 29, 24, 0.08);
  color: var(--red-dark);

  font-family: "Cinzel", Georgia, serif;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.025em;
  text-align: left;
  text-transform: uppercase;

  white-space: normal;
  overflow-wrap: anywhere;

  cursor: pointer;
}

.dnd-reference-chip:hover,
.dnd-speaker-chip:hover {
  border-color: var(--red);
  background: rgba(140, 29, 24, 0.16);
  color: var(--red-dark);
}

.dnd-reference-chip.is-static {
  cursor: default;
}

.dnd-reference-chip.is-static:hover {
  border-color: rgba(140, 29, 24, 0.42);
  background: rgba(140, 29, 24, 0.08);
}

.dnd-empty-message {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 700px) {
  .dnd-local-modal .modal-dialog {
    width: calc(100% - 1rem);
    margin: 0.5rem;
  }

  .dnd-modal-header {
    padding: 1.35rem 1.25rem 1rem;
  }

  .dnd-modal-body {
    padding: 1.25rem;
  }

  .dnd-language-facts {
    grid-template-columns: 1fr;
  }
}
.dnd-speaker-chip.is-static {
  cursor: default;
  opacity: 0.82;
}

.dnd-speaker-chip.is-static:hover {
  border-color: rgba(140, 29, 24, 0.42);
  background: rgba(140, 29, 24, 0.08);
  color: var(--red-dark);
}