:root {
    --bg: #f8f5ef;
    --fg: #1c1a17;
    --muted: #6b6660;
    --accent: #7a1f1f;
    --accent-dark: #4b1010;
    --accent-fg: #ffffff;
    --border: #d9d3c5;
    --card: #ffffff;
    --card-hover: #fffaee;
    --mark: #ffe89a;
    --pop-bg: #fff6df;
    --pop-border: #e6d38c;
}

* { box-sizing: border-box; }

html {
    font-size: 18px;
}
html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 1.25rem; }

/* ---------- Header ---------- */
.topbar {
    background: var(--accent);
    color: var(--accent-fg);
    padding: 1rem 0;
    border-bottom: 4px solid var(--accent-dark);
}
.topbar .wrap {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}
.brand {
    color: var(--accent-fg);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.35rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}
.brand:hover { text-decoration: underline; }
.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: #2a0808;
    border: 2px solid #f7d97a;
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
    flex: 0 0 auto;
    display: block;
}
.topsearch {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-width: 280px;
}
.topsearch input[type="search"] {
    flex: 1;
    padding: 0.65rem 0.9rem;
    border: 0;
    border-radius: 6px;
    font-size: 1.05rem;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}
.topsearch button {
    padding: 0.65rem 1.25rem;
    background: #f7d97a;
    color: #1c1a17;
    border: 0;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
}
.topsearch button:hover { background: #ffe58e; }

/* ---------- Main ---------- */
main { padding: 1.75rem 0 3rem; min-height: 60vh; }

h1 { font-size: 2.4rem; margin: 0.3rem 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.5rem; margin: 2rem 0 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
h3 { font-size: 1.2rem; margin: 1.25rem 0 0.5rem; }
p { margin: 0.5rem 0 1rem; }

.lead { color: #3a352e; font-size: 1.1rem; margin: 0.3rem 0 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.crumbs {
    font-size: 1rem;
    margin: 0 0 1rem;
}
.crumbs a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.crumbs a:hover { text-decoration: underline; }

/* ---------- Hero ---------- */
.hero { padding: 1.5rem 0 0.5rem; }
.hero h1 { font-size: 2.6rem; }
.hero-search {
    display: flex;
    gap: 0.6rem;
    margin: 1.2rem 0 0.75rem;
    max-width: 680px;
}
.hero-search input {
    flex: 1;
    padding: 0.9rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1.1rem;
    background: var(--card);
}
.hero-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(122, 31, 31, 0.15);
}
.hero-search button {
    padding: 0.9rem 1.75rem;
    background: var(--accent);
    color: var(--accent-fg);
    border: 0;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
}
.hero-search button:hover { background: var(--accent-dark); }

.ai-badge {
    margin: 1rem 0 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--pop-bg);
    border: 1px solid var(--pop-border);
    border-radius: 8px;
    font-size: 1rem;
}

/* ---------- Pills ---------- */
.pill {
    display: inline-block;
    background: #efe8d6;
    border-radius: 999px;
    padding: 0.1rem 0.7rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #4c4636;
    font-weight: 600;
}
.pill.accent {
    background: var(--accent);
    color: var(--accent-fg);
    margin-right: 0.5rem;
}

/* ---------- Popular categories grid ---------- */
.popular-grid {
    list-style: none;
    padding: 0;
    margin: 1rem 0 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.9rem;
}
.popular-grid a {
    display: flex;
    gap: 0.8rem;
    padding: 1rem 1.1rem;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: var(--fg);
    transition: transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.popular-grid a:hover {
    border-color: var(--accent);
    background: var(--card-hover);
    box-shadow: 0 4px 12px rgba(0,0,0,0.07);
    transform: translateY(-1px);
}
.pop-icon {
    font-size: 2rem;
    line-height: 1;
    flex: 0 0 auto;
}
.pop-body { display: flex; flex-direction: column; gap: 0.15rem; }
.pop-title { font-weight: 700; font-size: 1.15rem; }
.pop-count { color: var(--muted); font-size: 0.9rem; }
.pop-blurb { color: #4a4640; font-size: 0.95rem; margin-top: 0.15rem; }

.more-cats {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.more-cats summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 1.05rem;
}
.more-grid {
    list-style: none;
    padding: 0.75rem 0 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.3rem 1rem;
}
.more-grid a { text-decoration: none; color: var(--accent); font-weight: 500; }
.more-grid a:hover { text-decoration: underline; }

/* ---------- Filters on search page ---------- */
.filters {
    margin: 0 0 1.25rem;
    padding: 0.8rem 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    align-items: flex-end;
}
.filters label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
}
.filters select {
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    min-width: 180px;
}

/* ---------- Search results ---------- */
.result-count { margin: 0.5rem 0 1.25rem; font-size: 1.1rem; }
.results {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.9rem;
}
.results li {
    padding: 1rem 1.1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.result-title {
    font-weight: 700;
    font-size: 1.25rem;
    text-decoration: none;
    color: var(--accent);
}
.result-title:hover { text-decoration: underline; }
.result-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    font-size: 0.95rem;
    margin: 0.3rem 0 0.4rem;
}
.snippet { margin: 0.3rem 0 0; color: #2e2b27; }
.snippet mark { background: var(--mark); padding: 0 2px; border-radius: 2px; }

.empty {
    padding: 1.5rem;
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-size: 1.05rem;
}
.empty p { margin: 0.35rem 0; }

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin: 1.75rem 0 0;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
}
.pager a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
}

/* ---------- Browse ---------- */
.browse-list {
    columns: 2 220px;
    column-gap: 1.75rem;
    padding-left: 1.25rem;
    font-size: 1.05rem;
}
.browse-list li { break-inside: avoid; margin-bottom: 0.4rem; }
.browse-list a { color: var(--accent); text-decoration: none; font-weight: 600; }
.browse-list a:hover { text-decoration: underline; }

/* ---------- Detail page ---------- */
.detail-head { margin-bottom: 1rem; }
.kind-tag {
    margin: 0 0 0.3rem;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.85rem;
}

.detail .stats {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1.25rem;
    margin: 1rem 0 1.5rem;
    padding: 0.9rem 1.1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1.05rem;
}
.detail .stats dt { font-weight: 700; color: #3a352e; }
.detail .stats dd { margin: 0; }

table.ability-scores {
    border-collapse: collapse;
    margin: 0.5rem 0 1.25rem;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 1.05rem;
}
table.ability-scores th, table.ability-scores td {
    padding: 0.5rem 1.1rem;
    border-bottom: 1px solid var(--border);
}
table.ability-scores thead { background: #efe8d6; }
table.ability-scores tr:last-child td { border-bottom: 0; }

table.scaling {
    border-collapse: collapse;
    margin: 0.25rem 0 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 1rem;
}
table.scaling th, table.scaling td {
    padding: 0.4rem 1.1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
table.scaling th { background: #efe8d6; font-weight: 700; }
table.scaling tr:last-child td { border-bottom: 0; }

/* ---------- Prose (Markdown-rendered content) ---------- */
.prose {
    font-size: 1.05rem;
}
.prose p { margin: 0.6rem 0 1rem; }
.prose h1, .prose h2, .prose h3, .prose h4 {
    margin: 1.5rem 0 0.5rem;
    line-height: 1.3;
}
.prose h1 { font-size: 1.6rem; }
.prose h2 {
    font-size: 1.35rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3rem;
}
.prose h3 { font-size: 1.15rem; }
.prose ul, .prose ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0 1rem;
}
.prose li { margin: 0.25rem 0; }
.prose strong { color: #2b2823; }
.prose code {
    background: #efe8d6;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    font-size: 0.95em;
}
.prose pre {
    background: #efe8d6;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
}
.prose blockquote {
    border-left: 4px solid var(--accent);
    background: #faf4e3;
    padding: 0.6rem 1rem;
    margin: 1rem 0;
    color: #3a352e;
}

.prose table {
    border-collapse: collapse;
    margin: 1rem 0 1.5rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 1rem;
    width: auto;
    min-width: 320px;
}
.prose thead { background: #efe8d6; }
.prose th, .prose td {
    padding: 0.5rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.prose th { font-weight: 700; }
.prose tr:last-child td { border-bottom: 0; }
.prose td[align="center"], .prose th[align="center"] { text-align: center; }
.prose td[align="right"], .prose th[align="right"] { text-align: right; }

/* ---------- Detail footer ---------- */
.detail-foot {
    margin: 2rem 0 0;
    padding: 1rem 0 0;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.btn-back {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    background: var(--accent);
    color: var(--accent-fg);
    text-decoration: none;
    border-radius: 6px;
    font-weight: 700;
}
.btn-back:hover { background: var(--accent-dark); }
.raw-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.raw-link:hover { text-decoration: underline; color: var(--accent); }

/* ---------- Footer ---------- */
footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.95rem;
    padding: 1.25rem 0 2rem;
    background: #f0ead8;
}
footer p { margin: 0.35rem 0; }
footer a { color: var(--accent); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
    html { font-size: 17px; }
    h1 { font-size: 2rem; }
    .hero h1 { font-size: 2.1rem; }
    .brand-text { display: none; }
    .brand-logo { width: 40px; height: 40px; }
    .hero-search { flex-direction: column; }
    .hero-search button { width: 100%; }
    .filters { flex-direction: column; align-items: stretch; }
    .filters select { min-width: 0; width: 100%; }
    .detail-foot { flex-direction: column-reverse; align-items: stretch; }
    .btn-back { text-align: center; }
}
