/* ============================================================
   D&D 5e Reference — Fantasy Dark Theme
   Mobile-first, WCAG AA, prefers-reduced-motion
   ============================================================ */

/* --- Design Tokens --- */
:root {
    /* Backgrounds */
    --surface-base: #1a1510;
    --surface-raised: #231e18;
    --surface-card: #2a2419;
    --surface-overlay: #302923;
    --surface-input: #1e1914;

    /* Parchment for stat blocks */
    --parchment: #f4e4c1;
    --parchment-dark: #e8d5a3;

    /* Text */
    --text-primary: #e8dcc8;
    --text-secondary: #c4b699;
    --text-muted: #8a7e6b;
    --text-on-parchment: #1a1510;

    /* Accents */
    --accent-red: #922610;
    --accent-red-light: #c23a1a;
    --accent-gold: #c4a35a;
    --accent-copper: #b87333;
    --accent-green: #5a7247;

    /* Borders */
    --border: #3d3429;
    --border-hover: #574a3a;
    --stat-block-border: #922610;

    /* Fonts — humanist sans body, serif headings for fantasy reference feel */
    --font-heading: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;
    --font-body: 'Trebuchet MS', Verdana, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', Consolas, monospace;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);

    /* Layout */
    --sidebar-width: 220px;
    --top-bar-height: 56px;
    --bottom-nav-height: 60px;
    --source-bar-height: 40px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--surface-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Skip Link --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    background: var(--accent-gold);
    color: var(--surface-base);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-weight: 600;
    z-index: 1000;
    text-decoration: none;
}
.skip-link:focus {
    top: var(--space-sm);
}

/* --- Screen Reader Only --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* --- Top Bar --- */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-bar-height);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    gap: var(--space-md);
    z-index: 100;
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
    background: var(--surface-overlay);
    color: var(--text-primary);
}

.site-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--accent-gold);
    white-space: nowrap;
    flex-shrink: 0;
}
.site-title__link {
    color: inherit;
    text-decoration: none;
}
.site-title__link:hover {
    color: var(--text-primary);
    text-decoration: none;
    display: none;
}

.search-container {
    flex: 1;
    max-width: 500px;
    position: relative;
}

.search-input {
    width: 100%;
    height: 40px;
    background: var(--surface-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0 var(--space-md);
    padding-right: 48px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-body);
    outline: none;
    transition: border-color 0.15s;
}
.search-input::placeholder {
    color: var(--text-muted);
}
.search-input:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(196,163,90,0.25);
}

.search-shortcut {
    position: absolute;
    right: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-body);
    pointer-events: none;
}

/* --- Source Bar --- */
.source-bar {
    position: sticky;
    top: var(--top-bar-height);
    background: var(--surface-base);
    border-bottom: 1px solid var(--border);
    z-index: 99;
}

.source-bar__toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.4rem var(--space-md);
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.source-bar__toggle::-webkit-details-marker { display: none; }
.source-bar__toggle::before {
    content: '▶';
    font-size: 0.6rem;
    transition: transform 0.15s;
}
.source-bar[open] .source-bar__toggle::before {
    transform: rotate(90deg);
}
.source-bar__count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.source-bar__label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.source-bar__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0.5rem var(--space-md);
    max-height: 40vh;
    overflow-y: auto;
}

.source-group-label {
    width: 100%;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding: 0.1rem 0;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: var(--font-body);
}
.source-tag:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}
.source-tag--active {
    background: var(--accent-gold);
    color: var(--surface-base);
    border-color: var(--accent-gold);
    font-weight: 600;
}
.source-tag--noncanon::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent-gold);
    border-radius: 50%;
    margin-left: var(--space-xs);
}
.source-tag--active.source-tag--noncanon::after {
    background: var(--surface-base);
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    padding-top: var(--top-bar-height);
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    width: var(--sidebar-width);
    bottom: var(--bottom-nav-height);
    background: var(--surface-raised);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}
.sidebar--open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.sidebar-overlay--visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar__list {
    list-style: none;
    padding: var(--space-sm) 0;
}

.sidebar__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    min-height: 44px;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-family: var(--font-body);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}
.sidebar__item:hover,
.sidebar__item:focus-visible {
    background: var(--surface-overlay);
    color: var(--text-primary);
}
.sidebar__item--active {
    color: var(--accent-gold);
    background: rgba(196,163,90,0.08);
    border-left: 3px solid var(--accent-gold);
}
.sidebar__item--link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.6rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    width: 100%;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.sidebar__item--link:hover {
    background: var(--surface-overlay);
    color: var(--text-primary);
}
.sidebar__divider {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}
.sidebar__group { list-style: none; }
.sidebar__group-label {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.sidebar__group-label:hover { color: var(--text-secondary); }
.sidebar__group-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar__group-list .sidebar__item {
    padding-left: 2rem;
    font-size: 0.85rem;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    padding: var(--space-md);
    padding-bottom: calc(var(--bottom-nav-height) + var(--space-md));
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* --- Section Heading --- */
.section-heading {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--accent-gold);
    margin-bottom: var(--space-md);
    border-bottom: 2px solid var(--border);
    padding-bottom: var(--space-sm);
}

/* --- List View --- */
.list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.sort-select {
    height: 36px;
    padding: 0 var(--space-sm);
    background: var(--surface-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-body);
    cursor: pointer;
}

.content-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* --- List Items --- */
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: var(--space-sm) var(--space-md);
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    color: inherit;
}
.list-item:hover,
.list-item:focus-visible {
    border-color: var(--accent-gold);
    background: var(--surface-overlay);
    outline: none;
}

.list-item__name {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-primary);
}

.list-item__meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: var(--space-xs);
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.list-item__badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge--school {
    background: rgba(146,38,16,0.2);
    color: var(--accent-red-light);
    border: 1px solid rgba(146,38,16,0.3);
}
.badge--level {
    background: rgba(196,163,90,0.15);
    color: var(--accent-gold);
    border: 1px solid rgba(196,163,90,0.25);
}
.badge--cr {
    background: rgba(184,115,51,0.15);
    color: var(--accent-copper);
    border: 1px solid rgba(184,115,51,0.25);
}
.badge--type {
    background: rgba(90,114,71,0.15);
    color: var(--accent-green);
    border: 1px solid rgba(90,114,71,0.25);
}
.badge--source {
    background: rgba(196,163,90,0.15);
    color: var(--accent-gold);
    border: 1px solid rgba(196,163,90,0.25);
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-md);
    color: var(--text-muted);
}
.empty-state__icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
}
.empty-state__text {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}
.empty-state__sub {
    font-size: 0.9rem;
}

/* --- Back Button --- */
.back-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: 44px;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: var(--font-body);
    cursor: pointer;
    margin-bottom: var(--space-md);
    transition: all 0.15s;
}
.back-button:hover,
.back-button:focus-visible {
    border-color: var(--accent-gold);
    color: var(--text-primary);
}

/* --- Search Results --- */
.search-results .results-group {
    margin-bottom: var(--space-lg);
}
.search-results .results-group__heading {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--accent-copper);
    margin-bottom: var(--space-sm);
    text-transform: capitalize;
}

/* ============================================================
   EXPANDED LIST ITEMS (languages, etc.)
   ============================================================ */
.list-item--expanded {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--space-sm) var(--space-md);
    cursor: default;
}
.list-item--expanded .list-item__header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
}
.list-item--expanded .list-item__detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.list-item--expanded .list-item__desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: var(--space-xs);
    line-height: 1.5;
}

/* ============================================================
   DETAIL NAV (prev/next browsing)
   ============================================================ */
.detail-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-xs) 0;
}
.detail-nav--bottom {
    margin-top: var(--space-lg);
    margin-bottom: 0;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border);
}
.detail-nav__btn {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
    cursor: pointer;
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.detail-nav__btn:hover {
    color: var(--accent-gold);
    border-color: var(--accent-gold);
}
.detail-nav__pos {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ============================================================
   SPELL CARD
   ============================================================ */
.spell-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.spell-card__header {
    background: linear-gradient(135deg, rgba(146,38,16,0.15), rgba(196,163,90,0.1));
    border-bottom: 2px solid var(--stat-block-border);
    padding: var(--space-md) var(--space-lg);
}

.spell-card__name {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-variant: small-caps;
    color: var(--accent-gold);
    margin-bottom: var(--space-xs);
}

.spell-card__subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.spell-card__stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}

.spell-card__stat {
    background: var(--surface-card);
    padding: var(--space-sm) var(--space-md);
}
.spell-card__stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.spell-card__stat-value {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.spell-card__body {
    padding: var(--space-md) var(--space-lg);
}

.spell-card__description {
    line-height: 1.7;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
}

.spell-card__higher-levels {
    font-style: italic;
    color: var(--text-secondary);
    border-left: 3px solid var(--accent-red);
    padding-left: var(--space-md);
    margin-bottom: var(--space-md);
}
.spell-card__higher-levels strong {
    font-style: normal;
    color: var(--accent-red-light);
}

.spell-card__footer {
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

/* ============================================================
   STAT BLOCK (Monsters) — Classic D&D Look
   ============================================================ */
.stat-block {
    background: var(--parchment);
    color: var(--text-on-parchment);
    max-width: 600px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
}

/* Tapering red bars — top and bottom */
.stat-block::before,
.stat-block::after {
    content: '';
    display: block;
    height: 5px;
    background: var(--stat-block-border);
    background: linear-gradient(to right,
        transparent 0%,
        var(--stat-block-border) 8%,
        var(--stat-block-border) 92%,
        transparent 100%
    );
}

.stat-block__inner {
    padding: var(--space-md) var(--space-lg);
}

.stat-block__name {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--stat-block-border);
    line-height: 1.2;
}

.stat-block__subtitle {
    font-size: 0.85rem;
    font-style: italic;
    color: #555;
    margin-bottom: var(--space-sm);
}

/* Separator */
.stat-block__separator {
    height: 2px;
    background: linear-gradient(to right,
        transparent 0%,
        var(--stat-block-border) 15%,
        var(--stat-block-border) 85%,
        transparent 100%
    );
    margin: var(--space-sm) 0;
}

/* AC, HP, Speed */
.stat-block__vitals p {
    font-size: 0.9rem;
    line-height: 1.5;
}
.stat-block__vitals strong {
    font-weight: 700;
}

/* Ability Scores */
.stat-block__abilities {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    text-align: center;
    gap: var(--space-xs);
    margin: var(--space-sm) 0;
}
.stat-block__ability {
    font-size: 0.85rem;
}
.stat-block__ability-label {
    font-weight: 700;
    color: var(--stat-block-border);
    font-size: 0.75rem;
    text-transform: uppercase;
}
.stat-block__ability-score {
    font-size: 0.9rem;
}

/* Properties (saves, skills, senses, etc.) */
.stat-block__properties p {
    font-size: 0.85rem;
    line-height: 1.5;
}
.stat-block__properties strong {
    font-weight: 700;
}

/* Section headers (Traits, Actions, etc.) */
.stat-block__section-header {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--stat-block-border);
    border-bottom: 1px solid var(--stat-block-border);
    margin-top: var(--space-sm);
    margin-bottom: var(--space-xs);
    padding-bottom: 2px;
}

/* Traits / Actions */
.stat-block__trait {
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
    line-height: 1.5;
}
.stat-block__trait-name {
    font-weight: 700;
    font-style: italic;
}

.stat-block__source {
    font-size: 0.8rem;
    color: #777;
    text-align: right;
    margin-top: var(--space-sm);
}

/* ============================================================
   CLASS DETAIL
   ============================================================ */
.class-detail {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.class-detail__header {
    background: linear-gradient(135deg, rgba(90,114,71,0.15), rgba(196,163,90,0.1));
    border-bottom: 2px solid var(--accent-green);
    padding: var(--space-md) var(--space-lg);
}

.class-detail__name {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-variant: small-caps;
    color: var(--accent-gold);
}

.class-detail__subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.class-detail__body {
    padding: var(--space-md) var(--space-lg);
}

.class-detail__info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.class-detail__info-item {
    padding: var(--space-sm);
    border-left: 3px solid var(--accent-green);
}
.class-detail__info-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.class-detail__info-value {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Feature table */
.feature-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.feature-table th {
    background: var(--surface-overlay);
    color: var(--accent-gold);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
}
.feature-table td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.feature-table tr:hover td {
    background: rgba(196,163,90,0.05);
}

.feature-expand {
    background: none;
    border: none;
    color: var(--accent-gold);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: underline;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    font-family: var(--font-body);
}
.feature-expand:hover {
    color: var(--text-primary);
}

.feature-description {
    padding: var(--space-sm) var(--space-md);
    background: var(--surface-base);
    border-radius: var(--radius-sm);
    margin-top: var(--space-xs);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Subclass list on class detail */
.subclass-list { margin-bottom: var(--space-lg); }
.subclass-list__item {
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--border);
}
.subclass-list__link {
    color: var(--accent-copper);
    cursor: pointer;
    text-decoration: none;
}
.subclass-list__link:hover { color: var(--accent-gold); text-decoration: underline; }
.class-detail__subclass-of {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}
.subclass-feature { margin-bottom: var(--space-md); }
.subclass-feature__name {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--accent-gold);
    margin: 0 0 var(--space-xs) 0;
}
.subclass-feature__body { font-size: 0.9rem; line-height: 1.6; color: var(--text-secondary); }

/* ============================================================
   CONDITION CARD
   ============================================================ */
.condition-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    border-left: 4px solid var(--accent-copper);
}

.condition-card__name {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-variant: small-caps;
    color: var(--accent-gold);
    margin-bottom: var(--space-sm);
}

.condition-card__effects {
    line-height: 1.7;
    color: var(--text-primary);
}

.condition-card__source {
    margin-top: var(--space-md);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ============================================================
   RULE CARD
   ============================================================ */
.rule-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.rule-card__header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.rule-card__breadcrumb {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}
.rule-card__breadcrumb span {
    color: var(--accent-copper);
}

.rule-card__name {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    color: var(--accent-gold);
}

.rule-card__body {
    padding: var(--space-md) var(--space-lg);
    line-height: 1.7;
    color: var(--text-primary);
}

.rule-card__source {
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ============================================================
   POPOVER
   ============================================================ */
.popover {
    position: fixed;
    z-index: 200;
    background: var(--surface-raised);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 360px;
    width: 90vw;
    max-height: 400px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.popover[hidden] {
    display: none;
}

.popover__header {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border);
    gap: var(--space-xs);
}

.popover__title {
    flex: 1;
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--accent-gold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.popover__pin,
.popover__close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    flex-shrink: 0;
}
.popover__pin:hover,
.popover__close:hover {
    background: var(--surface-overlay);
    color: var(--text-primary);
}
.popover__pin--pinned {
    color: var(--accent-gold);
}

.popover__body {
    padding: var(--space-md);
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    flex: 1;
}

.popover__link {
    display: block;
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border);
    color: var(--accent-gold);
    font-size: 0.85rem;
    text-decoration: none;
    text-align: center;
}
.popover__link:hover {
    background: var(--surface-overlay);
}
.popover__link[hidden] {
    display: none;
}

/* Popover-enabled links in content */
.game-term {
    color: var(--accent-gold);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    cursor: pointer;
}
.game-term:hover {
    color: var(--text-primary);
    text-decoration-style: solid;
}

/* On parchment backgrounds */
.stat-block .game-term {
    color: var(--stat-block-border);
}

/* ============================================================
   LOADING
   ============================================================ */
.loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-base);
    z-index: 500;
    gap: var(--space-md);
}
.loading[hidden] {
    display: none;
}

.loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading__text {
    font-family: var(--font-heading);
    color: var(--text-secondary);
    font-size: 1rem;
}

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

/* ============================================================
   BOTTOM NAV (Mobile)
   ============================================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--surface-raised);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-family: var(--font-body);
    cursor: pointer;
    min-height: 44px;
    padding: var(--space-xs);
    transition: color 0.15s;
}
.bottom-nav__item:hover,
.bottom-nav__item:focus-visible {
    color: var(--text-secondary);
}
.bottom-nav__item--active {
    color: var(--accent-gold);
}

/* ============================================================
   FOCUS STYLES
   ============================================================ */
:focus-visible {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .loading__spinner {
        animation: none;
        border-color: var(--accent-gold);
    }
}

/* ============================================================
   TABLET+ (768px)
   ============================================================ */
@media (min-width: 768px) {
    .site-title {
        display: block;
    }

    .sidebar-toggle {
        display: none;
    }

    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
    }

    .main-content {
        margin-left: var(--sidebar-width);
    }

    .source-bar {
        left: var(--sidebar-width);
    }

    .bottom-nav {
        display: none;
    }

    .main-content {
        padding-bottom: var(--space-lg);
    }

    .spell-card__stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================================
   DESKTOP (1024px)
   ============================================================ */
@media (min-width: 1024px) {
    .search-container {
        max-width: 600px;
    }

    .main-content {
        padding: var(--space-lg) var(--space-xl);
    }
}

/* ============================================================
   {@TAG} RENDERED MARKUP — Cross-reference links
   tags.js outputs .ref-* classes for {@spell}, {@creature}, etc.
   Styled like .game-term but applied as a group selector.
   ============================================================ */
.ref-spell,
.ref-creature,
.ref-condition,
.ref-item,
.ref-class,
.ref-feat,
.ref-species,
.ref-race,
.ref-background,
.ref-rule,
.ref-action,
.ref-hazard,
.ref-variantrule,
.ref-subclass-feature,
.ref-subclassFeature {
    color: var(--accent-gold);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    cursor: pointer;
}
.ref-spell:hover,
.ref-creature:hover,
.ref-condition:hover,
.ref-item:hover,
.ref-class:hover,
.ref-feat:hover,
.ref-species:hover,
.ref-race:hover,
.ref-background:hover,
.ref-rule:hover,
.ref-action:hover,
.ref-hazard:hover,
.ref-variantrule:hover,
.ref-subclass-feature:hover,
.ref-subclassFeature:hover {
    color: var(--text-primary);
    text-decoration-style: solid;
}

/* On parchment backgrounds, use stat block border color */
.stat-block .ref-spell,
.stat-block .ref-creature,
.stat-block .ref-condition,
.stat-block .ref-item,
.stat-block .ref-class,
.stat-block .ref-feat,
.stat-block .ref-species,
.stat-block .ref-background,
.stat-block .ref-rule,
.stat-block .ref-action,
.stat-block .ref-hazard,
.stat-block .ref-subclass-feature {
    color: var(--stat-block-border);
}

/* ============================================================
   {@TAG} RENDERED MARKUP — Inline mechanics
   WCAG 1.4.1: color alone must not convey meaning — font-weight
   added alongside color for all semantic mechanic tags.
   ============================================================ */

/* Damage rolls — red, bold */
.tag-damage {
    color: #c23a1a;
    font-weight: 600;
}

/* DC values — green, bold */
.tag-dc {
    color: #5a8a4a;
    font-weight: 600;
}

/* Attack hit/miss — blue, bold */
.tag-hit {
    color: #4a7aaa;
    font-weight: 600;
}

/* Dice notation — monospace, gold accent */
.tag-dice {
    font-family: var(--font-mono);
    color: var(--accent-gold);
    font-size: 0.9em;
}

/* Skill, sense, status — italic for soft emphasis */
.tag-skill,
.tag-sense,
.tag-status {
    font-style: italic;
}

/* Parchment overrides — darker versions that work on light background */
.stat-block .tag-damage {
    color: #8b1a08;
}
.stat-block .tag-dc {
    color: #2d5c24;
}
.stat-block .tag-hit {
    color: #1a4a7a;
}
.stat-block .tag-dice {
    color: var(--accent-copper);
}

/* ============================================================
   ENTRY TYPE CONTAINERS
   render.js outputs these wrappers for structured entry blocks.
   ============================================================ */

/* Nested {type: "entries"} blocks */
.entry-sub {
    margin: var(--space-sm) 0 var(--space-sm) var(--space-md);
}
.entry-sub > h4,
.entry-sub > h5,
.entry-sub > h6 {
    font-family: var(--font-heading);
    font-size: 1.1em;
    font-weight: 700;
    font-variant: small-caps;
    color: var(--accent-gold);
    margin-bottom: var(--space-xs);
}
/* Ensure sub-headings in stat blocks are larger than body */
.stat-block .entry-sub > h4,
.condition-card .entry-sub > h4 {
    font-size: 1.15em;
    font-weight: 700;
    margin-top: 0.5em;
}

/* {type: "item"} — bold italic name followed by description */
.entry-item {
    margin: var(--space-xs) 0;
}
.entry-item > strong,
.entry-item > b {
    font-weight: 700;
    font-style: italic;
}

/* Sidebar/callout box — inset with gold left border */
.entry-inset {
    margin: var(--space-md) 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--surface-overlay);
    border-left: 3px solid var(--accent-gold);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    box-shadow: var(--shadow-sm);
}
.stat-block .entry-inset {
    background: rgba(0, 0, 0, 0.12);
    border-left-color: var(--stat-block-border);
}

/* Blockquote / flavor text */
.entry-quote {
    margin: var(--space-sm) 0;
    padding: var(--space-sm) var(--space-md);
    border-left: 3px solid var(--text-muted);
    color: var(--text-secondary);
    font-style: italic;
}

/* Attribution line for quotes */
.entry-quote-by {
    display: block;
    text-align: right;
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* Options wrapper — adds spacing between option entries */
.entry-options {
    margin: var(--space-sm) 0;
}
.entry-options > * + * {
    margin-top: var(--space-xs);
}

/* Table scroll wrapper for mobile */
.entry-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--space-sm) 0;
}

/* Generic entry table */
.entry-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 300px;
}
.entry-table caption {
    font-weight: 700;
    text-align: left;
    padding-bottom: var(--space-xs);
    color: var(--text-secondary);
}
.entry-table th {
    text-align: left;
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 2px solid var(--border-hover);
    color: var(--text-secondary);
    font-weight: 700;
    white-space: nowrap;
}
.entry-table td {
    padding: var(--space-xs) var(--space-sm);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.entry-table tr:last-child td {
    border-bottom: none;
}

/* Fallback for unknown entry types — subtle warning indicator */
.entry-unknown {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85em;
    border-left: 2px solid var(--border-hover);
    padding-left: var(--space-sm);
    margin: var(--space-xs) 0;
}

/* ============================================================
   FLUFF SECTION STYLES
   ============================================================ */
.fluff-section {
    margin-top: var(--space-lg);
    border-top: 1px solid var(--border);
    padding-top: var(--space-md);
}

.fluff-section summary {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-xs) 0;
    user-select: none;
    list-style: none;
}
.fluff-section summary::before {
    content: '▶ ';
    font-size: 0.75em;
    opacity: 0.7;
    transition: transform 0.15s;
}
.fluff-section[open] summary::before {
    content: '▼ ';
}
.fluff-section summary:hover {
    color: var(--text-primary);
}

.fluff-images {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin: var(--space-sm) 0;
}
.fluff-images img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* ============================================================
   MOBILE TOUCH TARGETS (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {
    /* Increase tap target size for ref links and game terms
       without breaking surrounding text flow */
    .ref-spell,
    .ref-creature,
    .ref-condition,
    .ref-item,
    .ref-class,
    .ref-feat,
    .ref-species,
    .ref-background,
    .ref-rule,
    .ref-action,
    .ref-hazard,
    .ref-subclass-feature,
    .game-term {
        padding-top: 4px;
        padding-bottom: 4px;
        margin-top: -4px;
        margin-bottom: -4px;
    }

    /* More comfortable reading line-height on mobile */
    .stat-block,
    .spell-detail,
    .condition-detail,
    .rule-detail {
        line-height: 1.8;
    }

    /* Stack list items vertically on mobile — name on top, badges below */
    .list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    .list-item__meta {
        justify-content: flex-start;
    }
    /* Truncate long type badges */
    .badge--type {
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ============================================================
   ABILITY GRID MOBILE COLLAPSE (max-width: 480px)
   Switch from 6 columns to 3x2 grid at small sizes.
   ============================================================ */
@media (max-width: 480px) {
    .ability-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================================
   EDITION BADGES & REPRINT BANNERS
   ============================================================ */
.badge--edition {
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge--2024 { background: var(--accent-green); color: #000; }
.badge--2014 { background: var(--text-muted); color: var(--surface-base); }
.badge--supplement { background: var(--accent-gold); color: #000; font-size: 0.6rem; }

/* Reprint banner */
.reprint-banner {
    background: rgba(255, 200, 50, 0.1);
    border: 1px solid var(--accent-gold);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

/* Source footer */
.source-footer {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface-raised);
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Fluff / lore section */
.fluff-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Action card */
.action-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}
.action-card__name {
    font-family: var(--font-heading);
    color: var(--accent-gold);
    margin-bottom: var(--space-sm);
}
.action-card__time {
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}
.action-card__body {
    color: var(--text-primary);
}

/* ============================================================
   NEW CONTENT TYPE CARDS (Phase 3b)
   ============================================================ */

/* Shared base for all new card types */
.deity-card, .language-card, .bastion-card,
.table-card, .optfeat-card, .trap-card, .object-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
}

/* Shared name style */
.deity-card__name, .language-card__name, .bastion-card__name,
.table-card__name, .optfeat-card__name, .trap-card__name, .object-card__name,
.item-card__name {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-variant: small-caps;
    color: var(--accent-gold);
    margin: 0 0 var(--space-sm) 0;
}

/* Shared stats/meta block */
.deity-card__stats, .language-card__meta, .bastion-card__meta,
.trap-card__meta, .object-card__meta, .optfeat-card__meta,
.item-card__stats {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border);
}
.deity-card__stat, .language-card__stat, .bastion-card__stat,
.trap-card__stat, .object-card__stat, .optfeat-card__stat,
.item-card__stat {
    padding: var(--space-xs) 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}
.deity-card__stat strong, .language-card__stat strong, .bastion-card__stat strong,
.trap-card__stat strong, .object-card__stat strong, .optfeat-card__stat strong,
.item-card__stat strong {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Shared body text */
.deity-card__body, .language-card__body, .bastion-card__body,
.table-card__body, .optfeat-card__body, .trap-card__body, .object-card__body,
.item-card__body {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-secondary);
}
.deity-card__body p, .language-card__body p, .bastion-card__body p,
.table-card__body p, .optfeat-card__body p, .trap-card__body p, .object-card__body p,
.item-card__body p {
    margin: 0 0 var(--space-sm) 0;
}

/* Item-card extras (subtitle, sections) */
.item-card__subtitle { color: var(--text-muted); font-size: 0.9rem; margin: -4px 0 var(--space-sm) 0; }
.item-card__section h3 { font-family: var(--font-heading); font-size: 1.1rem; color: var(--accent-gold); margin: var(--space-md) 0 var(--space-xs) 0; }
.recipe-ingredients, .recipe-instructions { padding-left: 1.2em; color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; }
.recipe-ingredients li, .recipe-instructions li { margin-bottom: var(--space-xs); }

/* Deity-specific */
.deity-card__title { color: var(--text-muted); font-style: italic; margin: 0 0 var(--space-sm) 0; }

/* Optfeat badge */
.optfeat-card__type { display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm);
    background: var(--surface-overlay); color: var(--accent-copper); font-size: 0.75rem;
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: var(--space-sm); }

/* Table card — data tables inside */
.table-card table { width: 100%; border-collapse: collapse; margin: var(--space-sm) 0; font-size: 0.85rem; }
.table-card th { background: var(--surface-overlay); color: var(--accent-gold); font-family: var(--font-heading);
    text-align: left; padding: var(--space-xs) var(--space-sm); border-bottom: 2px solid var(--border); }
.table-card td { padding: var(--space-xs) var(--space-sm); border-bottom: 1px solid var(--border); }
.table-card tr:hover td { background: rgba(196,163,90,0.05); }

/* Object card — AC/HP stats */
.object-card__ac, .object-card__hp {
    display: inline-block; padding: 4px 12px; border-radius: var(--radius-sm);
    background: var(--surface-overlay); margin-right: var(--space-sm); font-size: 0.85rem;
    color: var(--accent-gold); }

/* ============================================================
   LIST FILTER INPUT
   ============================================================ */
.list-filter {
    width: 100%;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface-input);
    border: 1px solid var(--surface-raised);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-body);
}
.list-filter::placeholder {
    color: var(--text-muted);
}
.list-filter:focus {
    outline: 2px solid var(--accent-gold);
    outline-offset: 1px;
}

/* ============================================================
   FLUFF IMAGE FIGURES
   ============================================================ */
/* --- Entry images (inline in book/detail content) --- */
.entry-image {
    margin: 1rem 0;
    text-align: center;
}
.entry-image img {
    max-width: 100%;
    max-height: 500px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}
.entry-image figcaption {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}
.entry-image__credit {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.fluff-image {
    margin: 0.75rem 0;
    text-align: center;
}
.fluff-image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}
.fluff-image figcaption {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

/* ============================================================
   LORE PARAGRAPH SPACING
   ============================================================ */
.fluff-section p {
    margin-bottom: 0.75rem;
}
.fluff-section p:last-child {
    margin-bottom: 0;
}

/* ============================================================
   SUPERSEDED TOGGLE
   ============================================================ */
.superseded-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0;
}
.superseded-toggle input { cursor: pointer; }

/* Clickable feature names in class progression table */
.feature-link {
    color: var(--accent-gold);
    text-decoration: underline dotted;
    cursor: pointer;
}
.feature-link:hover {
    text-decoration: underline solid;
    color: var(--text-primary);
}
.feature-link--open {
    text-decoration: underline solid;
}

/* ============================================================
   LORE (FR WIKI) CARDS & BADGES
   ============================================================ */

/* --- Lore type badges --- */
.badge--lore-type {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge--lore-npc {
    background: rgba(124,58,237,0.15);
    color: #a78bfa;
    border: 1px solid rgba(124,58,237,0.3);
}
.badge--lore-location {
    background: rgba(5,150,105,0.15);
    color: #34d399;
    border: 1px solid rgba(5,150,105,0.3);
}
.badge--lore-organization {
    background: rgba(217,119,6,0.15);
    color: #fbbf24;
    border: 1px solid rgba(217,119,6,0.3);
}
.badge--lore-creature {
    background: rgba(220,38,38,0.15);
    color: #f87171;
    border: 1px solid rgba(220,38,38,0.3);
}
.badge--lore-item {
    background: rgba(37,99,235,0.15);
    color: #60a5fa;
    border: 1px solid rgba(37,99,235,0.3);
}
.badge--lore-spell {
    background: rgba(124,58,237,0.15);
    color: #a78bfa;
    border: 1px solid rgba(124,58,237,0.3);
}
.badge--lore-article {
    background: rgba(107,114,128,0.15);
    color: #9ca3af;
    border: 1px solid rgba(107,114,128,0.3);
}
.badge--enriched {
    background: rgba(196,163,90,0.15);
    color: var(--accent-gold);
    border: 1px solid rgba(196,163,90,0.25);
}

/* --- Lore profile layout --- */
.lore-profile {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
}

.lore-profile__image {
    margin: 0 0 var(--space-lg) 0;
    text-align: center;
}

.lore-profile__image img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius-md);
    object-fit: contain;
}

.lore-profile__header {
    border-left: 5px solid var(--lore-accent, var(--text-muted));
    padding-left: var(--space-md);
    margin-bottom: var(--space-lg);
}

.lore-profile__title {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    color: var(--accent-gold);
    line-height: 1.25;
    margin-bottom: var(--space-xs);
    letter-spacing: -0.01em;
}

.lore-profile__badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-xs);
}

.lore-profile__quickfacts {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: var(--space-xs);
}

/* Summary */
.lore-profile__summary {
    margin-bottom: var(--space-lg);
    line-height: 1.7;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Infobox details — two-column grid */
.lore-profile__details {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-sm) var(--space-lg);
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--surface-overlay);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.lore-profile__detail {
    min-width: 0;
}

.lore-profile__detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.lore-profile__detail-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    word-break: break-word;
}

/* Timeline */
.lore-timeline {
    margin-bottom: var(--space-lg);
}

.lore-timeline__heading {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.lore-timeline__track {
    position: relative;
    padding-left: var(--space-lg);
}

.lore-timeline__track::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border-hover);
}

.lore-timeline__event {
    position: relative;
    padding-bottom: var(--space-md);
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.lore-timeline__event:last-child {
    padding-bottom: 0;
}

.lore-timeline__dot {
    position: absolute;
    left: calc(-1 * var(--space-lg) + 3px);
    top: 5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--lore-accent, var(--accent-gold));
    border: 2px solid var(--surface-card);
    box-shadow: 0 0 0 2px var(--border-hover);
    flex-shrink: 0;
}

.lore-timeline__content {
    display: flex;
    flex-direction: column;
}

.lore-timeline__year {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-gold);
}

.lore-timeline__desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Categories */
.lore-profile__categories {
    margin-bottom: var(--space-md);
}

.lore-profile__categories summary {
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-xs) 0;
}
.lore-profile__categories summary:hover {
    color: var(--text-secondary);
}

.lore-profile__cat-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding-top: var(--space-sm);
}

.lore-profile__cat {
    display: inline-block;
    padding: 2px 8px;
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Footer */
.lore-profile__footer {
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border);
}

.lore-profile__wiki-link {
    font-size: 0.85rem;
    color: var(--accent-gold);
    text-decoration: none;
}
.lore-profile__wiki-link:hover {
    text-decoration: underline;
    color: var(--text-primary);
}

/* Lore section content */
.lore-sections {
    margin-top: var(--space-lg);
}

.lore-section {
    margin-bottom: var(--space-xs);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.lore-section__heading {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.65rem var(--space-md);
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--accent-gold);
    cursor: pointer;
    background: var(--surface-card);
    border-left: 4px solid var(--lore-accent, var(--accent-gold));
    transition: background 0.15s, border-color 0.15s;
}

.lore-section__heading::marker {
    color: var(--accent-gold);
    font-size: 0.7em;
}

.lore-section__heading:hover {
    background: var(--surface-hover);
}

.lore-section[open] > .lore-section__heading {
    border-bottom: 1px solid var(--border);
    background: rgba(196, 163, 90, 0.06);
}

.lore-section__body {
    padding: var(--space-md);
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.lore-section__body p {
    margin-bottom: 0.85em;
}

.lore-section__body p:last-child {
    margin-bottom: 0;
}

.lore-section__list {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.lore-section__list li {
    margin-bottom: 0.4em;
    line-height: 1.55;
}

/* Inline images within sections */
.lore-inline-img {
    margin: 1em auto;
    text-align: center;
    max-width: 100%;
}

.lore-inline-img img {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.lore-inline-img figcaption {
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-muted);
    margin-top: var(--space-xs);
    line-height: 1.35;
}

@media (min-width: 600px) {
    .lore-inline-img {
        float: right;
        max-width: 300px;
        margin: 0 0 var(--space-md) var(--space-md);
    }

    .lore-section__body::after {
        content: '';
        display: table;
        clear: both;
    }
}

.lore-quote {
    margin: 1em 0;
    padding: 0.75em 1em;
    border-left: 3px solid var(--accent-gold);
    background: rgba(196, 163, 90, 0.06);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: var(--text-primary);
}

.lore-quote p {
    margin: 0;
    line-height: 1.6;
}

.lore-quote cite {
    display: block;
    margin-top: 0.4em;
    font-size: 0.85em;
    font-style: normal;
    color: var(--text-muted);
}

.lore-subsection {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border);
}

.lore-subsection__heading {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-gold);
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-xs);
    border-bottom: 1px dotted rgba(196, 163, 90, 0.3);
}

.lore-section__appearances {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.lore-section__app-tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    font-style: italic;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    transition: background 0.15s;
}

.lore-section__app-tag:hover {
    background: rgba(196, 163, 90, 0.12);
}

.lore-section__count {
    font-weight: 400;
    font-size: 0.85em;
    color: var(--text-muted);
}

/* Gallery grid */
.lore-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-sm);
}

.lore-gallery__item {
    margin: 0;
    text-align: center;
}

.lore-gallery__item figcaption {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
    line-height: 1.3;
}

.lore-gallery__img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.lore-gallery__placeholder {
    aspect-ratio: 1;
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs);
}

.lore-gallery__filename {
    font-size: 0.65rem;
    color: var(--text-muted);
    word-break: break-all;
    text-align: center;
}

/* ============================================================
   Year Timeline View — Interactive
   ============================================================ */

.year-tl__eras {
    display: flex;
    gap: 0.4rem;
    margin-bottom: var(--space-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.year-tl__eras::-webkit-scrollbar { display: none; }

.year-tl__era {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.8rem;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid var(--era-color, var(--border));
}

.year-tl__era:hover { background: var(--surface-hover); }

.year-tl__era--active {
    background: rgba(196, 163, 90, 0.08);
    border-color: var(--era-color);
}

.year-tl__era-label {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.year-tl__era-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Year chip strip */
.year-tl__strip {
    margin-bottom: var(--space-md);
}

.year-tl__strip--hidden { display: none; }

.year-tl__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.year-tl__chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.3rem 0.5rem;
    min-width: 3.2rem;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.12s;
}

.year-tl__chip:hover {
    background: var(--surface-hover);
    border-color: var(--era-color);
}

.year-tl__chip--selected {
    background: rgba(196, 163, 90, 0.12);
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 1px var(--accent-gold);
}

.year-tl__chip--focus {
    border-color: var(--accent-gold);
}

.year-tl__chip--md { min-width: 3.6rem; }
.year-tl__chip--lg {
    min-width: 4rem;
    border-left: 3px solid var(--era-color);
}

.year-tl__chip-year {
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

.year-tl__chip-count {
    font-size: 0.6rem;
    color: var(--text-muted);
    line-height: 1;
    margin-top: 1px;
}

/* Detail panel */
.year-tl__detail {
    margin-top: var(--space-sm);
    min-height: 100px;
}

.year-tl__detail-empty {
    text-align: center;
    padding: var(--space-lg);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.year-tl__detail-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--accent-gold);
    margin-bottom: var(--space-md);
}

.year-tl__detail-title {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    color: var(--accent-gold);
    margin: 0;
}

.year-tl__detail-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Alternating card timeline */
.tl-cards {
    position: relative;
    padding: var(--space-sm) 0;
}

.tl-cards__line {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, transparent, var(--accent-gold) 2rem, var(--accent-gold) calc(100% - 2rem), transparent);
    transform: translateX(-1px);
}

.tl-card {
    position: relative;
    display: flex;
    margin-bottom: 0.5rem;
    width: 50%;
}

.tl-card--left {
    padding-right: 1.5rem;
    justify-content: flex-end;
}

.tl-card--right {
    margin-left: 50%;
    padding-left: 1.5rem;
}

.tl-card__dot {
    position: absolute;
    top: 0.7rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-gold);
    border: 2px solid var(--surface-base);
    z-index: 1;
}

.tl-card--left .tl-card__dot {
    right: -6px;
}

.tl-card--right .tl-card__dot {
    left: -6px;
}

.tl-card__body {
    background: linear-gradient(135deg, var(--surface-card) 0%, rgba(196,163,90,0.04) 100%);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent-gold);
    border-radius: 2px var(--radius) var(--radius) 2px;
    padding: 0.6rem 0.75rem;
    max-width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.tl-card__body:hover {
    border-color: rgba(196, 163, 90, 0.5);
    box-shadow: 0 3px 12px rgba(0,0,0,0.35);
    transform: translateY(-1px);
}

.tl-card__img {
    float: left;
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    margin: 0 0.5rem 0.25rem 0;
    border: 1px solid var(--border);
}

.tl-card__text {
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-secondary);
    margin: 0;
}

.tl-card__expand {
    display: inline;
}

.tl-card__expand summary {
    display: inline;
    font-size: inherit;
    color: var(--accent-gold);
    cursor: pointer;
    font-weight: 600;
    list-style: none;
}
.tl-card__expand summary::-webkit-details-marker { display: none; }

.tl-card__expand summary:hover {
    text-decoration: underline;
}

.tl-card__expand[open] summary { display: none; }

.tl-card__full {
    font-size: inherit;
    line-height: inherit;
    color: var(--text-secondary);
}

.tl-cards__overflow {
    margin-top: var(--space-sm);
}

.tl-cards__overflow-btn {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-gold);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    background: var(--surface-card);
    border: 1px dashed var(--border);
}

.tl-cards__overflow-btn:hover {
    background: var(--surface-hover);
}

/* Mobile: stack cards to one side */
@media (max-width: 599px) {
    .tl-cards__line {
        left: 0.6rem;
    }

    .tl-card,
    .tl-card--left,
    .tl-card--right {
        width: auto;
        margin-left: 2rem;
        padding-left: 0;
        padding-right: 0;
        justify-content: flex-start;
    }

    .tl-card__dot {
        left: -1.65rem !important;
        right: auto !important;
    }

    .tl-card__body {
        border-left: 3px solid var(--accent-gold);
    }
}

.list-count-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    padding: var(--space-xs) 0;
    margin-bottom: var(--space-xs);
}

/* Lore type filter pills */
.lore-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.lore-type-btn {
    font-size: 0.75rem;
    padding: 0.2em 0.6em;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    background: none;
    color: #9ca3af;
    cursor: pointer;
}

.lore-type-btn--active {
    background: rgba(255, 255, 255, 0.1);
    color: #f3f4f6;
    border-color: rgba(255, 255, 255, 0.3);
}

/* --- Wiki Lore Enrichment (cross-referenced from FR wiki) --- */
.wiki-lore-section {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border);
}

.wiki-lore-summary h3 {
    font-family: var(--font-heading);
    color: var(--accent-gold);
    font-size: 1.1rem;
    margin-bottom: var(--space-sm);
}

.wiki-lore-summary p {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.9rem;
}

.wiki-lore-link {
    display: inline-block;
    margin-top: var(--space-sm);
    color: var(--accent-copper);
    text-decoration: none;
    font-size: 0.85rem;
}

.wiki-lore-link:hover {
    text-decoration: underline;
}

/* --- Spell School Icons --- */
.school-icon {
    display: inline-flex;
    align-items: center;
    vertical-align: -2px;
    margin-right: 1px;
}

.school-icon svg {
    width: 14px;
    height: 14px;
}

/* --- Map Iframe View --- */
.map-view {
    position: absolute;
    inset: 0;
}
.map-view[hidden] {
    display: none !important;
}
.map-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ============================================================
   HOMEPAGE
   ============================================================ */
.homepage {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
}
.homepage__hero {
    text-align: center;
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border);
}
.homepage__title {
    font-family: var(--font-heading);
    font-size: 2.4rem;
    font-variant: small-caps;
    color: var(--accent-gold);
    margin: 0 0 var(--space-xs) 0;
    letter-spacing: 1px;
}
.homepage__subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    margin: 0;
}
.homepage__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}
.homepage__section h3 {
    font-family: var(--font-heading);
    font-variant: small-caps;
    font-size: 1.1rem;
    color: var(--accent-gold);
    margin: 0 0 var(--space-sm) 0;
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--border);
}
.homepage__links {
    list-style: none;
    padding: 0;
    margin: 0;
}
.homepage__links li {
    padding: var(--space-xs) 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-muted);
}
.homepage__links a {
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}
.homepage__links a:hover {
    color: var(--accent-gold);
}
.homepage__links a strong {
    font-weight: 600;
}
.homepage__count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}
.homepage__footer {
    text-align: center;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}
.homepage__footer kbd {
    background: var(--surface-overlay);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 0.8em;
}
@media (max-width: 639px) {
    .homepage__grid {
        grid-template-columns: 1fr;
    }
    .homepage__title {
        font-size: 1.8rem;
    }
}
