/* Warhammer 40k encyclopedia browsing — same grimdark-Imperial palette as the roster
   builder (roster_builder/static/roster_builder/roster.css), so the two feel like one
   experience, but scoped under .w40k-prose / .w40k-* so nothing leaks into other worlds. */

.w40k-prose {
    --w40k-gold: var(--rb-gold);
    --w40k-gold-bright: var(--rb-gold-bright);
    --w40k-border: var(--rb-border);
    --w40k-bg-panel: var(--rb-bg-panel);
    color: var(--rb-text) !important;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    max-width: 60rem;
    line-height: 1.6;
}

.w40k-prose h1 {
    color: var(--w40k-gold-bright) !important;
    font-size: 1.75rem;
    border-bottom: 2px solid var(--w40k-border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.w40k-prose h2 {
    color: var(--w40k-gold) !important;
    font-size: 1.15rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
}

.w40k-prose strong { color: var(--w40k-gold-bright) !important; }

.w40k-prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0 1.25rem;
    background: var(--w40k-bg-panel);
    border: 1px solid var(--w40k-border);
    border-radius: 6px;
    overflow: hidden;
}

.w40k-prose th, .w40k-prose td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--w40k-border);
    text-align: left;
    font-size: 0.9rem;
    color: var(--rb-text) !important;
}

.w40k-prose th {
    background: var(--rb-bg-panel-raised);
    color: var(--w40k-gold) !important;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.w40k-prose tr:last-child td { border-bottom: none; }

.w40k-prose p { margin: 0.5rem 0; }

/* --- Directory / related links --- */
.w40k-directory { margin-top: 2rem; }
.w40k-directory h3 { color: var(--rb-gold); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.9rem; margin-bottom: 0.75rem; }

.w40k-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.75rem;
}

.w40k-card {
    display: block;
    background: var(--rb-bg-panel);
    border: 1px solid var(--rb-border);
    border-radius: 6px;
    padding: 0.75rem 1rem;
    text-decoration: none;
    transition: border-color 0.15s;
}
.w40k-card:hover { border-color: var(--rb-gold); }
.w40k-card-title { color: var(--rb-text); font-weight: 600; font-size: 0.95rem; }
.w40k-card-type { color: var(--rb-text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.25rem; }

/* --- Faction page tabs --- */
.w40k-faction-intro { margin-bottom: 1.5rem; }

.w40k-tabs { display: flex; gap: 0.25rem; border-bottom: 2px solid var(--rb-border); margin-bottom: 1rem; }
.w40k-tab {
    background: transparent; border: none; color: var(--rb-text-muted); padding: 0.6rem 1.1rem;
    font-size: 0.9rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color 0.15s, border-color 0.15s;
}
.w40k-tab:hover { color: var(--rb-text); }
.w40k-tab.active { color: var(--rb-gold-bright); border-bottom-color: var(--rb-gold); }
.w40k-tab-count { color: var(--rb-text-muted); font-size: 0.75rem; font-weight: 400; }

.w40k-search {
    display: block; width: 100%; max-width: 24rem; margin-bottom: 1.25rem;
    background: var(--rb-bg); color: var(--rb-text); border: 1px solid var(--rb-border-strong); border-radius: 6px;
    padding: 0.5rem 0.75rem; font-size: 0.9rem;
}
.w40k-search:focus { outline: none; border-color: var(--rb-gold); }

/* ============================================================
   Dedicated 40k shell (w40k/base.html) — reuses roster.css --rb-* tokens
   ============================================================ */

.w40k-body { min-height: 100vh; }

/* --- Top nav --- */
.w40k-topnav {
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
    gap: var(--rb-space-4); padding-bottom: var(--rb-space-4);
    border-bottom: 2px solid var(--rb-border-strong); margin-bottom: var(--rb-space-6);
}
.w40k-brand { color: var(--rb-gold-bright); font-weight: 800; font-size: 1.15rem; letter-spacing: 0.08em; text-decoration: none; }
.w40k-brand:hover { color: var(--rb-gold-bright); text-decoration: none; }
.w40k-brand-mark { color: var(--rb-red-bright); }
.w40k-navlinks { display: flex; align-items: center; gap: var(--rb-space-2); flex-wrap: wrap; }
.w40k-navlinks > a {
    color: var(--rb-text-muted); text-transform: uppercase; letter-spacing: 0.05em;
    font-size: 0.8rem; font-weight: 700; padding: var(--rb-space-2) var(--rb-space-3);
    border-radius: var(--rb-radius); text-decoration: none;
}
.w40k-navlinks > a:hover { color: var(--rb-text); background: var(--rb-bg-panel); text-decoration: none; }
.w40k-navlinks > a.w40k-nav-active { color: var(--rb-gold-bright); background: var(--rb-bg-panel); }
.w40k-navsearch input { min-width: 12rem; }
.w40k-theme-toggle {
    background: transparent; border: 1px solid var(--rb-border-strong); color: var(--rb-gold);
    border-radius: var(--rb-radius); width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem;
    line-height: 1; display: flex; align-items: center; justify-content: center;
}
.w40k-theme-toggle:hover { border-color: var(--rb-gold); color: var(--rb-gold-bright); }

.w40k-breadcrumb { margin-bottom: var(--rb-space-6); }
.w40k-breadcrumb span { color: var(--rb-text); }

.w40k-footer {
    display: flex; justify-content: space-between; gap: var(--rb-space-4);
    margin-top: var(--rb-space-8); padding-top: var(--rb-space-4);
    border-top: 1px solid var(--rb-border); color: var(--rb-text-muted); font-size: 0.8rem;
}

.w40k-page-title { color: var(--rb-gold-bright); font-size: 1.6rem; margin: 0 0 var(--rb-space-6); }
.w40k-page-head { display: flex; align-items: center; gap: var(--rb-space-4); margin-bottom: var(--rb-space-6); }
.w40k-page-head .w40k-page-title { margin: 0; }
.w40k-reading { max-width: 62rem; }
.w40k-subhead { color: var(--rb-gold); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.85rem; margin: var(--rb-space-4) 0 var(--rb-space-2); }

/* --- Hub --- */
.w40k-hero { text-align: center; padding: var(--rb-space-8) 0 var(--rb-space-6); }
.w40k-hero-title { color: var(--rb-gold-bright); font-size: 2.4rem; letter-spacing: 0.06em; margin: 0 0 var(--rb-space-2); }
.w40k-hero-sub { color: var(--rb-text-muted); font-style: italic; margin: 0; }
.w40k-doorways { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: var(--rb-space-6); margin-top: var(--rb-space-6); }
.w40k-doorway {
    display: flex; flex-direction: column; gap: var(--rb-space-3); text-align: center;
    background: var(--rb-bg-panel); border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius);
    padding: var(--rb-space-8) var(--rb-space-6); text-decoration: none; transition: border-color 0.15s, transform 0.15s;
}
.w40k-doorway:hover { border-color: var(--rb-gold); transform: translateY(-2px); text-decoration: none; }
.w40k-doorway-icon { font-size: 2.5rem; color: var(--rb-gold); }
.w40k-doorway-title { color: var(--rb-gold-bright); font-size: 1.3rem; font-weight: 700; }
.w40k-doorway-desc { color: var(--rb-text-muted); font-size: 0.9rem; line-height: 1.5; }

/* --- Faction grid (grouped into grand-alliance columns) --- */
.w40k-faction-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: var(--rb-space-6); align-items: start; }
.w40k-faction-col { background: var(--rb-bg-panel); border: 1px solid var(--rb-border); border-radius: var(--rb-radius); overflow: hidden; }
.w40k-faction-col-head {
    margin: 0; padding: var(--rb-space-3) var(--rb-space-4); background: var(--rb-bg-panel-raised);
    border-bottom: 2px solid var(--rb-gold); color: var(--rb-gold-bright);
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
}
.w40k-faction-col-list { list-style: none; margin: 0; padding: var(--rb-space-2); }
.w40k-faction-col-list li { margin: 0; }
.w40k-faction-col-list a {
    display: block; padding: var(--rb-space-2) var(--rb-space-3); border-radius: var(--rb-radius);
    color: var(--rb-text); font-size: 0.9rem; text-decoration: none;
}
.w40k-faction-col-list a:hover { background: var(--rb-bg-panel-raised); color: var(--rb-gold-bright); text-decoration: none; }

.w40k-faction-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--rb-space-3); }
.w40k-faction-card {
    display: flex; align-items: center; min-height: 4.5rem; padding: var(--rb-space-4);
    background: var(--rb-bg-panel); border: 1px solid var(--rb-border); border-left: 3px solid var(--rb-gold);
    border-radius: var(--rb-radius); text-decoration: none; transition: border-color 0.15s, background 0.15s;
}
.w40k-faction-card:hover { border-color: var(--rb-gold); background: var(--rb-bg-panel-raised); text-decoration: none; }
.w40k-faction-card-name { color: var(--rb-gold-bright); font-weight: 700; font-size: 1.05rem; }

/* --- Faction tabs (server-rendered, real URLs) --- */
.w40k-tab-active, .w40k-tab.w40k-tab-active { color: var(--rb-gold-bright); border-bottom-color: var(--rb-gold); }
.w40k-tabs a.w40k-tab { text-decoration: none; }
.w40k-tabs a.w40k-tab:hover { text-decoration: none; }
.w40k-tabpanel { margin-top: var(--rb-space-2); }
.w40k-filter {
    display: block; width: 100%; max-width: 24rem; margin-bottom: var(--rb-space-4);
}
.w40k-detachment .rb-panel-header h3 a { color: var(--rb-gold); }
.w40k-strat-list { display: flex; flex-wrap: wrap; gap: var(--rb-space-2); }
.w40k-strat-row {
    background: var(--rb-bg); border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius);
    padding: var(--rb-space-1) var(--rb-space-3); font-size: 0.85rem; text-decoration: none;
}
.w40k-strat-row:hover { border-color: var(--rb-gold); text-decoration: none; }

/* --- Datasheet card --- */
.w40k-contextnav { position: sticky; top: var(--rb-space-6); max-height: calc(100vh - 3rem); display: flex; flex-direction: column; }
.w40k-contextnav .rb-panel-body { overflow-y: auto; }
.w40k-contextnav-list { display: flex; flex-direction: column; gap: 2px; }
.w40k-contextnav-list a { padding: var(--rb-space-1) var(--rb-space-2); border-radius: var(--rb-radius); font-size: 0.82rem; text-decoration: none; }
.w40k-contextnav-list a:hover { background: var(--rb-bg-panel-raised); text-decoration: none; }
.w40k-contextnav-active { background: var(--rb-bg-panel-raised); color: var(--rb-gold-bright) !important; border-left: 2px solid var(--rb-gold); }

.w40k-datasheet { background: var(--rb-bg-panel); border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius); overflow: hidden; }
.w40k-ds-header { background: var(--rb-bg-panel-raised); border-bottom: 2px solid var(--rb-gold); padding: var(--rb-space-4) var(--rb-space-6); }
.w40k-ds-name { color: var(--rb-gold-bright); font-size: 1.5rem; margin: 0 0 var(--rb-space-3); }
.w40k-modelline { display: flex; align-items: center; flex-wrap: wrap; gap: var(--rb-space-3); margin-bottom: var(--rb-space-2); }
.w40k-modelline:last-child { margin-bottom: 0; }
.w40k-model-name { min-width: 8rem; color: var(--rb-gold-bright); font-weight: 700; font-size: 0.9rem; }
.w40k-statline { display: flex; flex-wrap: wrap; gap: var(--rb-space-2); }
.w40k-stat {
    display: flex; flex-direction: column; align-items: center; min-width: 3.2rem;
    background: var(--rb-bg); border: 1px solid var(--rb-border-strong); border-radius: var(--rb-radius); padding: var(--rb-space-1) var(--rb-space-2);
}
.w40k-stat-label { color: var(--rb-gold); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; }
.w40k-stat-val { color: var(--rb-text); font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.w40k-ds-section { color: var(--rb-gold); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.9rem; margin: var(--rb-space-6) var(--rb-space-6) var(--rb-space-2); }
.w40k-datasheet .w40k-table-scroll { overflow-x: auto; margin: 0 var(--rb-space-6); }
.w40k-weapons { min-width: 34rem; }
.w40k-weapons td, .w40k-weapons th { white-space: nowrap; }
.w40k-weapons td:first-child, .w40k-weapons th:first-child { white-space: normal; min-width: 12rem; }
.w40k-wkeywords { display: block; margin-top: 2px; }
.w40k-wk { color: var(--rb-gold); font-size: 0.72rem; letter-spacing: 0.03em; margin-right: 0.4rem; }
.w40k-usr {
    display: inline; background: none; border: none; padding: 0; margin-right: 0.4rem; cursor: pointer;
    color: var(--rb-gold-bright); font-size: 0.72rem; letter-spacing: 0.03em;
    text-decoration: underline dotted; text-underline-offset: 2px; font-family: inherit;
}
.w40k-usr:hover { color: #fff; }

/* --- Composition & wargear --- */
.w40k-loadout { padding: 0 var(--rb-space-6); display: grid; gap: var(--rb-space-3); }
.w40k-loadout-model { background: var(--rb-bg); border: 1px solid var(--rb-border); border-radius: var(--rb-radius); padding: var(--rb-space-3) var(--rb-space-4); }
.w40k-loadout-head { color: var(--rb-gold-bright); font-weight: 700; margin-bottom: var(--rb-space-2); }
.w40k-loadout-count { color: var(--rb-text-muted); font-variant-numeric: tabular-nums; }
.w40k-loadout-line { font-size: 0.88rem; padding: 2px 0; }
.w40k-loadout-tag {
    display: inline-block; min-width: 6.5rem; margin-right: var(--rb-space-2);
    color: var(--rb-text-muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
}
.w40k-tag-choice { color: var(--rb-gold); }
.w40k-choice-label { color: var(--rb-text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.w40k-choice-of { color: var(--rb-text-muted); font-size: 0.82rem; }
.w40k-opt-max { color: var(--rb-gold); font-size: 0.75rem; }
.w40k-slash { color: var(--rb-text-muted); }

/* --- USR popover --- */
.w40k-usr-pop {
    position: absolute; z-index: 50; max-width: 22rem;
    background: var(--rb-bg-panel-raised); border: 1px solid var(--rb-gold); border-radius: var(--rb-radius);
    padding: var(--rb-space-3) var(--rb-space-4); box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.w40k-usr-pop-close { position: absolute; top: 4px; right: 8px; background: none; border: none; color: var(--rb-text-muted); font-size: 1.1rem; cursor: pointer; }
.w40k-usr-pop-term { margin: 0 0 var(--rb-space-2); color: var(--rb-gold-bright); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.04em; }
.w40k-usr-pop-def { margin: 0; font-size: 0.85rem; line-height: 1.5; color: var(--rb-text); white-space: pre-wrap; }

/* --- Pinned glossary chunks in the sidebar --- */
.w40k-usr-demo { color: var(--rb-gold-bright); text-decoration: underline dotted; text-underline-offset: 2px; }
.w40k-gloss-chunk { border-top: 1px solid var(--rb-border); padding: var(--rb-space-2) 0; }
.w40k-gloss-chunk:first-child { border-top: none; padding-top: 0; }
.w40k-gloss-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--rb-space-2); }
.w40k-gloss-term { color: var(--rb-gold-bright); font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
.w40k-gloss-x { background: none; border: none; color: var(--rb-text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; }
.w40k-gloss-x:hover { color: var(--rb-red-bright); }
.w40k-gloss-def { margin: var(--rb-space-1) 0 0; font-size: 0.82rem; line-height: 1.45; color: var(--rb-text-muted); white-space: pre-wrap; }
.w40k-abilities { padding: 0 var(--rb-space-6) var(--rb-space-6); }
.w40k-ability { padding: var(--rb-space-3) 0; border-bottom: 1px solid var(--rb-border); }
.w40k-ability:last-child { border-bottom: none; }
.w40k-ability-name { color: var(--rb-gold-bright); font-weight: 700; }
.w40k-ability-kind { color: var(--rb-text-muted); font-weight: 400; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.w40k-ability-desc { max-width: none; margin-top: var(--rb-space-1); }
.w40k-ability-desc p { margin: 0.25rem 0; }

.w40k-points { list-style: none; margin: 0; padding: 0; }
.w40k-points li { display: flex; justify-content: space-between; padding: var(--rb-space-1) 0; border-bottom: 1px solid var(--rb-border); font-size: 0.9rem; }
.w40k-points li:last-child { border-bottom: none; }
.w40k-points-val { color: var(--rb-gold-bright); font-weight: 700; }
.w40k-keywords { display: flex; flex-wrap: wrap; gap: var(--rb-space-2); }
.w40k-block-btn { display: block; text-align: center; text-decoration: none; }
.w40k-block-btn:hover { text-decoration: none; }
