:root {
  --bg: #050910;
  --panel: #0b1320;
  --panel2: #101d31;
  --line: #29476f;
  --text: #f3f0e5;
  --muted: #b8c3d4;
  --green: #98c7ff;
  --gold: #d8b76a;
  --red: #c05d52;
  --blue: #2f73d8;
  --ink: #050607;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 76% 0, #12325f 0, transparent 34rem),
    radial-gradient(circle at 8% 18%, #0d1d35 0, transparent 30rem),
    linear-gradient(180deg, #04070d, var(--bg));
  font: 16px/1.62 "Segoe UI", system-ui, sans-serif;
}
a { color: var(--green); }
button, input { font: inherit; }
.layout { min-height: 100vh; display: grid; grid-template-columns: 18rem minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 10;
  padding: 1.2rem; border-right: 1px solid var(--line); background: #040811dc;
  backdrop-filter: blur(14px);
}
.brand { padding: .4rem .45rem 1rem; border-bottom: 1px solid var(--line); }
.brand-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.brand-logo {
  display: block;
  width: 4.25rem;
  height: 4.25rem;
  object-fit: contain;
  margin: 0 0 .55rem -.35rem;
  filter: drop-shadow(0 0 10px #1e69d955);
}
.brand strong { display: block; font: 700 1.13rem Georgia, serif; letter-spacing: .02em; }
.brand small, .sidebar-note { color: var(--muted); }
.menu-toggle {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .65rem;
  color: var(--text);
  background: #071325;
  cursor: pointer;
}
.mode-toggle {
  margin-top: .75rem;
  width: 100%;
  border: 1px solid #356fb7;
  border-radius: 8px;
  padding: .48rem .7rem;
  color: #f7e7b6;
  background: linear-gradient(180deg, #102b52, #08162a);
  cursor: pointer;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-size: .73rem;
}
.mode-toggle:hover { border-color: var(--gold); box-shadow: 0 0 0 3px #2f73d822; }
.mode-label { display: block; margin-top: .45rem; font-size: .72rem; }
.nav { padding: .8rem 0; }
.nav a {
  display: grid; grid-template-columns: 1.45rem 1fr; gap: .45rem; align-items: baseline;
  padding: .38rem .5rem; margin: .08rem 0; border-radius: 7px;
  color: var(--muted); text-decoration: none; font-size: .84rem;
}
.nav a b { color: var(--gold); font: 700 .68rem Georgia, serif; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--panel2); }
.sidebar-note { padding: .8rem .45rem; border-top: 1px solid var(--line); font-size: .72rem; }
.page { min-width: 0; }
.page-head {
  padding: 3rem clamp(1rem, 5vw, 4.5rem) 2rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(100deg, #07101ee8, #123a7499),
    repeating-linear-gradient(90deg, transparent 0 14px, #d8b76a0a 14px 15px);
  position: relative;
}
.page-head::after {
  content: "";
  position: absolute;
  left: clamp(1rem, 5vw, 4.5rem);
  right: clamp(1rem, 5vw, 4.5rem);
  bottom: .7rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .65;
}
.codex-head h1 { text-transform: uppercase; letter-spacing: .06em; }
.codex-head .kicker::before { content: "◆ "; opacity: .75; }
.codex-head .kicker::after { content: " ◆"; opacity: .75; }
.kicker { color: var(--gold); text-transform: uppercase; letter-spacing: .15em; font-size: .71rem; font-weight: 800; }
.page-head h1 { margin: .3rem 0 .65rem; font: 700 clamp(2.3rem, 6vw, 4.5rem)/.95 Georgia, serif; letter-spacing: -.035em; }
.page-head p { max-width: 54rem; margin: 0; color: #d3d8d1; }
.toolbar {
  position: sticky; top: 0; z-index: 8; display: flex; gap: .55rem;
  padding: .7rem clamp(1rem, 5vw, 4.5rem); border-bottom: 1px solid var(--line);
  background: #050910ed; backdrop-filter: blur(14px);
}
.search { position: relative; flex: 1; max-width: 50rem; }
.search input {
  width: 100%; padding: .62rem 6.5rem .62rem .8rem; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; background: #030710; outline: none;
}
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #2f73d830; }
.search-count { position: absolute; right: .7rem; top: .65rem; color: var(--muted); font-size: .76rem; }
.btn {
  border: 1px solid var(--line); border-radius: 9px; padding: .55rem .75rem;
  color: var(--text); background: var(--panel); cursor: pointer;
}
.content { max-width: 92rem; padding: 1rem clamp(1rem, 5vw, 4.5rem) 6rem; }
.chapter { padding-top: 2.8rem; scroll-margin-top: 4.5rem; }
.chapter > h2 {
  margin: 0 0 1rem; padding-bottom: .65rem; border-bottom: 1px solid var(--line);
  font: 700 clamp(1.65rem, 3vw, 2.5rem) Georgia, serif;
}
.chapter-intro { max-width: 60rem; color: var(--muted); margin: -0.45rem 0 1.2rem; }
h3 { font-family: Georgia, serif; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: .85rem; }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 29rem), 1fr)); }
.card {
  padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(145deg, var(--panel2), var(--panel)); box-shadow: 0 8px 22px #0003;
}
.dossier-card {
  position: relative;
  border-color: #365f93;
  background:
    linear-gradient(145deg, #10213bf2, #080d18f2),
    repeating-linear-gradient(135deg, #ffffff05 0 1px, transparent 1px 8px);
}
.dossier-card::before {
  content: "COMMONWEALTH HANDBOOK";
  position: absolute;
  top: .55rem;
  right: .75rem;
  color: #c7a25d33;
  font: 700 .58rem Georgia, serif;
  letter-spacing: .14em;
}
.card h3 { margin: .08rem 0 .45rem; font-size: 1.12rem; line-height: 1.25; }
.card p { margin: .4rem 0; }
.edge-card .req { color: #d7e4f7; font-size: .92rem; }
.power-card .detail { padding: 0; border-top: 0; }
.stat-card p strong { color: #f1d487; }
.card ul, .card ol { margin: .45rem 0; padding-left: 1.2rem; }
.card li + li { margin-top: .22rem; }
.meta { color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.rule, .note, .warning {
  margin: .75rem 0; padding: .65rem .8rem; border-left: 3px solid var(--green); background: #080d0a99;
}
.note { border-color: var(--blue); }
.warning { border-color: var(--red); }
.term { color: var(--green); font-weight: 700; }
.term-tip {
  position: relative;
  display: inline-block;
  color: #a9d2ff;
  border-bottom: 1px dotted #6ea8ff;
  cursor: help;
  font-weight: 650;
}
.term-tip > .tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + .55rem);
  transform: translateX(-50%) translateY(.25rem);
  z-index: 30;
  width: min(22rem, 82vw);
  padding: .75rem .85rem;
  border: 1px solid #3f78bd;
  border-radius: 10px;
  background:
    linear-gradient(180deg, #102b52f7, #071325f7),
    repeating-linear-gradient(135deg, #ffffff08 0 1px, transparent 1px 7px);
  color: var(--text);
  box-shadow: 0 14px 34px #000b;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  font-weight: 400;
  line-height: 1.45;
}
.term-tip > .tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: .45rem solid transparent;
  border-top-color: #3f78bd;
}
.term-tip > .tooltip > strong {
  display: block;
  color: var(--gold);
  font-family: Georgia, serif;
  margin-bottom: .25rem;
}
.term-tip > .tooltip > span { display: block; }
.term-tip > .tooltip .nested-term { display: inline-block; }
.term-tip > .tooltip > a {
  display: inline-block;
  margin-top: .45rem;
  color: #b9dcff;
  text-decoration: none;
  font-weight: 800;
}
.term-tip:hover > .tooltip,
.term-tip:focus > .tooltip,
.term-tip:focus-within > .tooltip {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: #071325; }
th, td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #102b52; color: var(--gold); font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #10213b; }
details.card { padding: 0; position: relative; }
details.card summary { cursor: pointer; list-style: none; padding: .9rem 2.5rem .9rem 1rem; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; position: absolute; top: .55rem; right: .9rem; color: var(--gold); font-size: 1.35rem; }
details.card[open] summary::after { content: "−"; }
.detail { padding: .2rem 1rem 1rem; border-top: 1px solid var(--line); }
.pill { display: inline-block; padding: .12rem .45rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .71rem; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(15rem, 1fr); gap: 1rem; }
.compact-list { columns: 2 18rem; }
.codex-plate {
  margin: 1rem 0 0;
  padding: .65rem;
  border: 1px solid #365f93;
  border-radius: var(--radius);
  background: #030710;
  box-shadow: 0 16px 40px #0008;
}
.codex-plate img {
  display: block;
  width: 100%;
  border-radius: calc(var(--radius) - 4px);
}
.codex-plate figcaption {
  padding: .55rem .35rem .1rem;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.faction-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.faction-card { overflow: hidden; padding-top: .75rem; }
.faction-icon {
  display: grid;
  place-items: center;
  height: 10rem;
  margin: -.75rem -.75rem .8rem;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 40%, #163b75 0, transparent 60%),
    linear-gradient(180deg, #040811, #081323);
}
.faction-icon img {
  width: min(78%, 8.7rem);
  height: min(88%, 8.9rem);
  object-fit: contain;
  filter: drop-shadow(0 8px 16px #000a);
}
.commonwealth { border-color: #2f67be; }
.crimson { border-color: #8e2420; }
.dominion { border-color: #777; }
.meridian { border-color: #7b399a; }
.crescent { border-color: #5f8d3a; }
.african { border-color: #a8741a; }
.briarwake { border-color: #a73568; }
.glass { border-color: #d8c47b; }
.gm-secret {
  border-color: #9b6a28;
  background:
    linear-gradient(145deg, #2a1d10f2, #0d0b08f2),
    repeating-linear-gradient(135deg, #d8b76a12 0 1px, transparent 1px 8px);
}
.gm-secret::before { content: "GM EYES ONLY"; color: #d8b76a55; }
.visibility-note {
  display: inline-block;
  margin-bottom: .75rem;
  padding: .25rem .55rem;
  border: 1px solid #365f93;
  border-radius: 999px;
  color: #d9e8ff;
  background: #081a33;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
}
html[data-mode="player"] [data-visibility="gm"] { display: none !important; }
html[data-mode="gm"] [data-player-only] { display: none !important; }
html[data-mode="gm"] .mode-toggle { border-color: var(--gold); background: linear-gradient(180deg, #4a2d0c, #1a1006); }
.timeline {
  display: grid;
  gap: .85rem;
  counter-reset: step;
}
.timeline .card {
  position: relative;
  padding-left: 3.2rem;
}
.timeline .card::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 1rem;
  top: 1rem;
  width: 1.45rem;
  height: 1.45rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  color: var(--gold);
  font: 700 .85rem Georgia, serif;
  background: #080908;
}
.toc { columns: 2 18rem; padding-left: 1.3rem; }
.toc li { break-inside: avoid; margin-bottom: .25rem; }
.hidden { display: none !important; }
.empty { display: none; padding: 4rem 1rem; text-align: center; color: var(--muted); }
.empty.show { display: block; }
.page-footer { margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; }
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: sticky; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding-bottom: .8rem; }
  .brand-logo { width: 3.2rem; height: 3.2rem; margin-bottom: .25rem; }
  .menu-toggle { display: inline-block; }
  .nav { display: none; max-height: 55vh; overflow-y: auto; padding-bottom: .4rem; }
  .sidebar.open .nav { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
  .nav a { display: block; white-space: normal; }
  .nav a b { margin-right: .25rem; }
  .sidebar-note { display: none; }
  .mode-toggle { max-width: 13rem; }
  .split { grid-template-columns: 1fr; }
  .toolbar { top: 0; }
  .term-tip > .tooltip { left: 0; transform: translateY(.25rem); }
  .term-tip:hover > .tooltip,
  .term-tip:focus > .tooltip,
  .term-tip:focus-within > .tooltip { transform: translateY(0); }
}
@media print {
  :root { --bg: #fff; --panel: #fff; --panel2: #fff; --text: #111; --muted: #555; --line: #aaa; }
  body { background: #fff; font-size: 10pt; }
  .sidebar, .toolbar, .no-print { display: none !important; }
  .layout { display: block; }
  .page-head { padding: 0 0 1cm; background: #fff; }
  .content { max-width: none; padding: 0; }
  .chapter { break-before: page; }
  .card { box-shadow: none; background: #fff; break-inside: avoid; }
  details.card .detail { display: block; }
}
