/* ui.css — Campaign Manager design system (rebuild, 2026-09).
   Tokens → shell (sidebar + topbar) → primitives → page layouts.
   Page-specific styles for pages not yet migrated live in legacy.css. */

/* ── Tokens ────────────────────────────────────────────────────────────────── */
:root {
  --bg:        #101318;
  --bg-tile:   url('/static/bg/slate-dark.jpg');
  --bg-tile-opacity: 0.32;
  --surface:   #171b22;
  --surface2:  #1e242d;
  --surface3:  #262d38;
  --border:    #2b333f;
  --border2:   #38424f;
  --text:      #e7e9ed;
  --text2:     #b4bbc6;
  --muted:     #8690a0;
  --accent:    #c9a45f;
  --on-accent: #16120a;
  --accent2:   #7ea6c8;
  --danger:    #d46b5b;
  --success:   #7fb08a;
  --warn:      #d9a441;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 0 0 1px rgba(0,0,0,.15);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  --radius:    6px;
  --radius-lg: 10px;
  /* aliases used by the pages that still carry their own CSS */
  --gold: var(--accent); --text-dim: var(--text2); --text-muted: var(--muted); --bg-alt: var(--surface2);
  --sidebar-w: 248px;
  --topbar-h:  52px;

  --font-head: 'Fraunces', Georgia, serif;
  --font-body: 'Inter Tight', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}
[data-theme="light"] {
  --bg:        #ede8de;
  --bg-tile:   url('/static/bg/paper-light.jpg');
  --bg-tile-opacity: 0.45;
  --surface:   #fbf9f4;
  --surface2:  #f3efe6;
  --surface3:  #e9e3d6;
  --border:    #d3cbbc;
  --border2:   #bfb6a5;
  --text:      #1c1a16;
  --text2:     #4a463f;
  --muted:     #6f6a61;
  --accent:    #8a5a1c;
  --on-accent: #fff8ec;
  --accent2:   #3d5a80;
  --danger:    #9b3a2c;
  --success:   #34613f;
  --warn:      #8a6414;
  --shadow:    0 1px 2px rgba(40,30,10,.10), 0 0 0 1px rgba(40,30,10,.04);
  --shadow-lg: 0 12px 32px rgba(40,30,10,.18);
}

/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
html::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--bg-tile) center / cover no-repeat; opacity: var(--bg-tile-opacity);
}
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.25; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: 0.86em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sb-scrim { display: none; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sb-brand {
  display: flex; align-items: center; gap: .65rem;
  height: var(--topbar-h); padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text); font-family: var(--font-head); font-weight: 600; font-size: 1.02rem;
  white-space: nowrap;
}
.sb-brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 5px;
  background: var(--accent); color: var(--on-accent);
  font-family: var(--font-mono); font-size: .68rem; font-weight: 700; letter-spacing: .05em;
}
.sb-section { padding: .9rem .75rem .35rem; }
.sb-label {
  display: block; padding: 0 .5rem .4rem;
  font-family: var(--font-mono); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}
.sb-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .6rem; border-radius: var(--radius);
  color: var(--text2); font-size: .9rem; font-weight: 500;
  transition: background .12s, color .12s;
}
.sb-link:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.sb-link.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sb-link .ico { width: 16px; text-align: center; opacity: .8; font-size: .85rem; }
.sb-link .count { margin-left: auto; font-family: var(--font-mono); font-size: .68rem; color: var(--muted); }

.sb-system { margin-bottom: .35rem; }
.sb-system-head {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .6rem; border-radius: var(--radius);
  color: var(--text2); font-size: .9rem; font-weight: 500; cursor: pointer;
  transition: background .12s, color .12s;
}
.sb-system-head:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.sb-system.open .sb-system-head { color: var(--text); }
.sb-system-head > span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-system-head .chev { margin-left: auto; font-size: .7rem; color: var(--muted); transition: transform .15s; }
.sb-system.open .chev { transform: rotate(90deg); }
.sys-badge {
  font-family: var(--font-mono); font-size: .62rem; letter-spacing: .06em;
  padding: .1rem .4rem; border-radius: 999px;
  border: 1px solid var(--border2); color: var(--muted); min-width: 40px; text-align: center;
}
.sb-system.active .sys-badge { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.sb-system-pages { display: none; padding: .15rem 0 .25rem 1.1rem; }
.sb-system.open .sb-system-pages { display: block; }
.sb-system-pages .sb-link { padding: .32rem .6rem; font-size: .85rem; }

.sb-foot {
  margin-top: auto; padding: .75rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .4rem; align-items: center;
}
.sb-foot .spacer { flex: 1; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  height: var(--topbar-h); padding: 0 1.5rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: .5rem; min-width: 0; flex: 1; overflow: hidden; white-space: nowrap; font-size: .88rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumbs .sep { opacity: .5; }
.crumbs .here { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }
.menu-btn { display: none; }

.content { flex: 1; padding: 1.5rem; width: 100%; }
.content.narrow { max-width: 860px; margin: 0 auto; }
.content.wide { max-width: 1400px; margin: 0 auto; }

.foot {
  padding: .7rem 1.5rem; font-size: .68rem; color: var(--muted);
  border-top: 1px solid var(--border); background: var(--surface);
}

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .2rem; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; }
.eyebrow { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: .3rem; }

/* ── Primitives ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.card-pad { padding: 1.1rem 1.25rem; }
.card-head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .45rem .9rem; border-radius: var(--radius);
  border: 1px solid var(--border2); background: var(--surface2); color: var(--text);
  font-size: .86rem; font-weight: 500; line-height: 1.2; white-space: nowrap;
  transition: border-color .12s, background .12s, color .12s;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: .3rem .6rem; font-size: .78rem; }
.btn.icon { padding: .35rem .5rem; }
.btn:disabled { opacity: .5; cursor: default; }

.input, .select, .textarea {
  width: 100%; padding: .48rem .7rem;
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius);
  color: var(--text); font-size: .9rem;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input::placeholder { color: var(--muted); }
.select { appearance: none; padding-right: 1.8rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > label { font-size: .74rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.field .hint { font-size: .76rem; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center;
  padding: .1rem .5rem; border-radius: 999px;
  border: 1px solid var(--border2); background: var(--surface2);
  font-size: .7rem; font-weight: 500; color: var(--text2); letter-spacing: .02em; white-space: nowrap;
}
.pill.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); }
.pill.uncommon { border-color: #b3804a; color: #d9a26a; }
.pill.rare { border-color: #3d6fae; color: #7ea6c8; }
.pill.unique { border-color: #8a5aa6; color: #b592cc; }
[data-theme="light"] .pill.uncommon { color: #8a5218; }
[data-theme="light"] .pill.rare { color: #2c5183; }
[data-theme="light"] .pill.unique { color: #64407c; }
.pills { display: flex; flex-wrap: wrap; gap: .3rem; }

.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; overflow-x: auto; }
.tab {
  padding: .55rem .9rem; color: var(--muted); font-size: .88rem; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar .input { flex: 1; min-width: 220px; }
.toolbar .select { width: auto; min-width: 140px; }
.toolbar .result-count { margin-left: auto; font-family: var(--font-mono); font-size: .74rem; color: var(--muted); }

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; }
.stat { padding: .6rem .75rem; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); }
.stat .k { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat .v { font-family: var(--font-mono); font-size: 1.05rem; margin-top: .1rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .88rem; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--text); }

.prose { font-size: .92rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.prose table { border-collapse: collapse; margin: .4rem 0; font-size: .85rem; white-space: normal; }
.prose th, .prose td { border: 1px solid var(--border); padding: .2rem .5rem; text-align: left; }
.prose th { background: var(--surface2); font-weight: 600; }
.prose strong { color: var(--text); }
.prose.dim { color: var(--text2); }
.divider { height: 1px; background: var(--border); margin: .9rem 0; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.source { font-family: var(--font-mono); font-size: .68rem; color: var(--muted); letter-spacing: .03em; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-family: var(--font-head); font-size: 1.05rem; margin-bottom: .3rem; }

details.disclosure { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.disclosure > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .75rem; padding: .6rem .9rem; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: '›'; color: var(--muted); font-size: 1rem; transition: transform .15s; }
details.disclosure[open] > summary::before { transform: rotate(90deg); }
details.disclosure > .body { padding: .5rem .9rem 1rem 2.15rem; border-top: 1px solid var(--border); }

/* FR/EN description switch inside prose blocks */
.desc { position: relative; }
.desc .fr, .desc .en { display: none; }
html[lang="fr"] .desc .fr, html[lang="en"] .desc .en { display: block; }
html[lang="fr"] .desc.no-fr .en { display: block; }

/* ── Popover (hover stat block) ────────────────────────────────────────────── */
.popover {
  position: fixed; z-index: 200; width: 360px; max-height: 70vh; overflow: auto;
  padding: .85rem 1rem;
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); font-size: .82rem;
}
.popover[hidden] { display: none; }
.popover .po-head { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .35rem; }
.popover .po-name { font-family: var(--font-head); font-size: 1rem; font-weight: 600; color: var(--text); }
.popover .po-right { margin-left: auto; font-family: var(--font-mono); font-size: .7rem; color: var(--accent); white-space: nowrap; }
.popover .kv { font-size: .8rem; }
.popover .prose { font-size: .8rem; max-height: 160px; overflow: hidden; }
.popover .d-head { padding: 0 0 .5rem; }
.popover .d-body { padding: .6rem 0 0; gap: .6rem; }
.popover .d-head h2 { font-size: 1.05rem; }
.popover .attacks { max-height: 120px; overflow: hidden; }

/* ── Library: master / detail ──────────────────────────────────────────────── */
.split { display: grid; grid-template-columns: minmax(300px, 5fr) minmax(360px, 6fr); gap: 1rem; align-items: start; }
.list { display: flex; flex-direction: column; gap: .3rem; }
.row {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .75rem;
  padding: .55rem .85rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.row:hover { border-color: var(--border2); background: var(--surface2); }
.row.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.row .name { font-weight: 600; font-size: .92rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.row .tag { font-family: var(--font-mono); font-size: .72rem; color: var(--accent); white-space: nowrap; min-width: 2.2rem; text-align: right; }

.detail { position: sticky; top: calc(var(--topbar-h) + 1.5rem); max-height: calc(100vh - var(--topbar-h) - 3rem); overflow: auto; }
.detail .d-head { display: flex; align-items: flex-start; gap: .75rem; padding: 1.1rem 1.25rem .8rem; border-bottom: 1px solid var(--border); }
.detail .d-head h2 { flex: 1; font-size: 1.3rem; }
.detail .d-head h2 a { color: var(--text); }
.detail .d-right { text-align: right; }
.detail .d-right .lvl { font-family: var(--font-mono); font-size: .8rem; color: var(--accent); }
.detail .d-right .act { font-size: 1rem; color: var(--text2); }
.detail .d-body { padding: 1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: .9rem; }
.detail .placeholder { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.attacks { font-family: var(--font-mono); font-size: .8rem; white-space: pre-wrap; line-height: 1.5; padding: .6rem .8rem; background: var(--surface2); border-radius: var(--radius); }

/* ── Grids ─────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.tile {
  display: block; padding: 1.1rem 1.2rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  color: var(--text); transition: border-color .12s, transform .1s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.tile .t-top { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.tile .t-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 600; }
.tile .t-count { font-family: var(--font-mono); font-size: .8rem; color: var(--accent); }
.tile .t-desc { color: var(--muted); font-size: .86rem; margin-top: .3rem; line-height: 1.45; }

.sys-card { border-left: 3px solid var(--accent); }
.sys-card .card-head h2 { font-size: 1.05rem; }
.sys-card .links { display: flex; flex-wrap: wrap; gap: .45rem; padding: .9rem 1.25rem 1.1rem; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .detail { position: static; max-height: none; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 100;
    transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow-lg); }
  body.sb-open .sidebar { transform: none; }
  .sb-scrim { position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,.45); }
  body.sb-open .sb-scrim { display: block; }
  .menu-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
}

/* ── Campaigns & adventures ────────────────────────────────────────────────── */
.subtabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.subtabs .btn.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.area { font-family: var(--font-mono); font-size: .74rem; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 4px; padding: .12rem .4rem; white-space: nowrap; }
.progress { height: 6px; background: var(--surface3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--success); }
.note { font-size: .84rem; background: var(--surface2); border-left: 2px solid var(--accent); border-radius: var(--radius); padding: .4rem .65rem; margin-top: .45rem; }
.item { display: flex; align-items: flex-start; gap: .85rem; padding: .7rem 1rem; }
.item + .item { border-top: 1px solid var(--border); }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { font-size: .82rem; color: var(--muted); margin-top: .1rem; }
.item.done { opacity: .55; }
.item.done .title { text-decoration: line-through; }
.status-pending  { --st: var(--border2); }
.status-active   { --st: var(--warn); }
.status-completed, .status-alive, .status-qualified { --st: var(--success); }
.status-skipped, .status-missing, .status-upcoming { --st: var(--accent); }
.status-dead, .status-enemy, .status-defeated { --st: var(--danger); }
.status-ally, .status-allied { --st: #a78bfa; }
.status-captured, .status-corrupted { --st: var(--warn); }
.status-fled, .status-unknown { --st: var(--muted); }
.st-bar { border-left: 3px solid var(--st, var(--border2)); }
.st-pill { border-color: var(--st, var(--border2)); color: var(--st, var(--text2)); }
.section-title { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 1.5rem 0 .6rem; }
.section-title:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; }
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { flex: 1; min-width: 140px; }
.form-row .field.fixed { flex: 0 0 auto; }
.textarea { resize: vertical; min-height: 2.5rem; }
details.inline > summary { list-style: none; cursor: pointer; font-size: .8rem; color: var(--muted); }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline > summary:hover { color: var(--text); }
details.inline[open] > summary { color: var(--text); margin-bottom: .5rem; }

/* Long-form lore text */
.lore { font-size: .97rem; line-height: 1.7; }
.lore p { margin: 0 0 .85em; }
.lore .lore-heading { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; margin: 1.4em 0 .5em; color: var(--accent); }
.lore .lore-stat { font-family: var(--font-mono); font-size: .8rem; color: var(--text2); background: var(--surface2); padding: .3rem .6rem; border-radius: var(--radius); margin: .4em 0; white-space: pre-wrap; }
.lore .entity-link { color: var(--accent); text-decoration: underline dotted; cursor: help; }
.reader { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 2rem; align-items: start; }
.toc { position: sticky; top: calc(var(--topbar-h) + 1.5rem); max-height: calc(100vh - var(--topbar-h) - 3rem); overflow: auto; font-size: .85rem; }
.toc a { display: block; padding: .25rem .5rem; color: var(--muted); border-radius: var(--radius); }
.toc a:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
@media (max-width: 900px) { .reader { grid-template-columns: 1fr; } .toc { position: static; max-height: none; } }

/* ── Encounter builder ─────────────────────────────────────────────────────── */
.seg { display: flex; flex-wrap: wrap; gap: .3rem; }
.seg .btn.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.xp-head { display: flex; justify-content: space-between; align-items: baseline; }
.xp-value { font-family: var(--font-mono); font-size: 1.35rem; color: var(--accent); }
.diff-badge { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; padding: .15rem .5rem; border-radius: 999px; border: 1px solid var(--border2); color: var(--muted); }
.diff-badge.diff-trivial  { color: var(--muted); }
.diff-badge.diff-low      { color: var(--success); border-color: var(--success); }
.diff-badge.diff-moderate { color: var(--accent2); border-color: var(--accent2); }
.diff-badge.diff-severe   { color: var(--warn); border-color: var(--warn); }
.diff-badge.diff-extreme  { color: var(--danger); border-color: var(--danger); }
.hook-sentence { font-family: var(--font-head); font-size: 1.1rem; line-height: 1.4; }
.hook-slots { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .6rem; }
.hook-slot { cursor: pointer; user-select: none; padding: .15rem .55rem; border-radius: 999px; border: 1px dashed var(--border2); font-size: .78rem; color: var(--text2); }
.hook-slot:hover { border-color: var(--accent); }
.hook-slot.locked { border-style: solid; border-color: var(--accent); color: var(--accent); }
.hook-slot.locked::after { content: " 🔒"; font-size: .65rem; }
.hook-terrain { color: var(--muted); font-size: .84rem; margin-top: .5rem; }
.creature-row { border-top: 1px solid var(--border); padding: .6rem 1rem; }
.creature-row:first-child { border-top: none; }
.creature-main { display: flex; align-items: center; gap: .75rem; }
.creature-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.creature-name { font-weight: 600; }
.creature-meta { font-size: .76rem; color: var(--muted); }
.creature-xp { font-family: var(--font-mono); font-size: .78rem; color: var(--accent); white-space: nowrap; }
.qty-controls { display: inline-flex; align-items: center; border: 1px solid var(--border2); border-radius: var(--radius); overflow: hidden; }
.qty-btn { background: var(--surface2); border: none; color: var(--text); width: 26px; height: 26px; cursor: pointer; }
.qty-btn:hover { background: var(--surface3); }
.qty-value { font-family: var(--font-mono); font-size: .8rem; min-width: 26px; text-align: center; }
.remove-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: .2rem .4rem; border-radius: var(--radius); }
.remove-btn:hover { color: var(--danger); background: var(--surface2); }
.hp-tracker { display: flex; align-items: center; gap: .5rem; margin-top: .45rem; flex-wrap: wrap; }
.hp-label { font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hp-instances { display: flex; flex-wrap: wrap; gap: .35rem; }
.hp-instance { display: inline-flex; align-items: center; gap: .25rem; font-size: .74rem; color: var(--muted); }
.hp-input { width: 4rem; padding: .15rem .35rem; background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text); font-family: var(--font-mono); font-size: .78rem; }
.monster-row { display: flex; align-items: center; gap: .6rem; padding: .45rem 1rem; border-top: 1px solid var(--border); }
.monster-row:hover { background: var(--surface2); }
.monster-info { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .5rem; }
.monster-name { font-weight: 600; font-size: .9rem; }
.monster-meta { font-size: .74rem; color: var(--muted); }
.level-shortcuts { display: flex; flex-wrap: wrap; gap: .25rem; }
.browser-card { padding: .7rem .9rem; cursor: pointer; }
.browser-card:hover { border-color: var(--accent); }
.browser-card-header { display: flex; gap: .5rem; align-items: center; margin-bottom: .2rem; }
.enc-code { font-family: var(--font-mono); font-size: .74rem; color: var(--accent); }
.enc-level { font-size: .74rem; color: var(--muted); }
.enc-name { font-weight: 600; }
.enc-adventure { font-size: .76rem; color: var(--muted); }
.detail-header { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.detail-header h2 { flex: 1; font-size: 1.15rem; }
.detail-creature { display: flex; gap: .5rem; align-items: baseline; padding: .3rem 0; border-top: 1px solid var(--border); font-size: .9rem; }
.detail-actions { margin-top: .9rem; }
.loot-gold { display: flex; align-items: baseline; gap: .5rem; font-family: var(--font-mono); font-size: 1.2rem; color: var(--accent); }
.gold-note { font-size: .78rem; color: var(--muted); font-family: var(--font-body); }
.loot-section-title { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: .9rem 0 .35rem; }
.loot-item-row { display: flex; align-items: baseline; gap: .5rem; padding: .35rem .6rem; border-left: 3px solid var(--border2); background: var(--surface2); border-radius: 0 var(--radius) var(--radius) 0; margin-bottom: .25rem; font-size: .88rem; }
.loot-item-row .item-name { font-weight: 600; flex: 1; }
.loot-item-row .item-qty, .loot-item-row .item-range, .loot-item-row .item-note { font-size: .76rem; color: var(--muted); }
.loot-item-row .item-rarity-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.item-rarity-dot { display: none; }
.rarity-uncommon { border-left-color: #b3804a; }
.rarity-rare { border-left-color: var(--accent2); }
.rarity-unique { border-left-color: #8a5aa6; }
.roll-log { margin: .5rem 0 0 1rem; font-family: var(--font-mono); font-size: .74rem; color: var(--muted); }
.action-row { display: flex; justify-content: flex-end; gap: .5rem; }

/* ── Character sheet ───────────────────────────────────────────────────────── */
.sheet-name { font-family: var(--font-head); font-size: 1.5rem; padding: .35rem .6rem; width: 100%; }
.sheet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.sheet-grid .wide { grid-column: 1 / -1; }
@media (max-width: 1000px) { .sheet-grid { grid-template-columns: 1fr; } }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .5rem; }
.stat-box { text-align: center; padding: .6rem .3rem; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-box .k { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .1em; color: var(--muted); }
.stat-box .pair { display: flex; align-items: center; justify-content: center; gap: .2rem; margin: .3rem 0 .15rem; }
.stat-box .pair input { width: 2.4rem; text-align: center; padding: .15rem .1rem; font-family: var(--font-mono); font-size: .85rem; -moz-appearance: textfield; }
.stat-box .pair input::-webkit-inner-spin-button { display: none; }
.stat-box .pair span { color: var(--muted); }
.stat-box .sub { display: flex; justify-content: center; gap: .6rem; font-size: .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-box .mod { font-family: var(--font-mono); font-size: 1.05rem; color: var(--accent); margin-top: .2rem; }
.hb { display: flex; gap: 2px; flex: 1; }
.hb span { flex: 1; height: 1rem; border-radius: 2px; background: var(--surface3); }
.hb span.g { background: var(--success); } .hb span.y { background: var(--warn); } .hb span.r { background: var(--danger); }
.mini { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .5rem; }
.mini .field > label { font-size: .64rem; }
.mini input { padding: .3rem .45rem; font-size: .85rem; }
.picker { position: relative; }
.picker .menu { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; max-height: 240px; overflow: auto; background: var(--surface); border: 1px solid var(--border2); border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-lg); }
.picker .menu[hidden] { display: none; }
.picker .menu div { padding: .4rem .7rem; cursor: pointer; font-size: .86rem; }
.picker .menu div:hover { background: var(--surface2); }
.chips { display: flex; flex-direction: column; gap: .3rem; margin-top: .5rem; }
.chip-row { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; background: var(--surface2); border-radius: var(--radius); font-size: .88rem; }
.chip-row .n { flex: 1; min-width: 0; }
.chip-row .d { font-size: .76rem; color: var(--muted); white-space: pre-wrap; }
.chip-row input[type=number] { width: 3.4rem; text-align: center; padding: .15rem; font-family: var(--font-mono); }
.x { background: none; border: none; color: var(--muted); cursor: pointer; padding: .1rem .35rem; border-radius: var(--radius); }
.x:hover { color: var(--danger); background: var(--surface3); }
.rows { display: flex; flex-direction: column; gap: .35rem; }
.rows .r { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.rows .r input { padding: .3rem .5rem; font-size: .86rem; }
.gear { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; }
.hot { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .4rem; }
.pick-desc { font-size: .82rem; color: var(--text2); background: var(--surface2); border-left: 2px solid var(--accent); padding: .45rem .7rem; border-radius: var(--radius); margin-top: .5rem; max-height: 7rem; overflow: auto; }
.pick-desc b { color: var(--text); }

/* ── Guided creator ────────────────────────────────────────────────────────── */
.creator { border: 1px solid var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent), var(--shadow-lg); }
.creator .c-head { display: flex; align-items: center; gap: 1rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--border); }
.creator .c-head h2 { flex: 1; font-size: 1.1rem; }
.steps { display: flex; gap: .25rem; flex-wrap: wrap; padding: .6rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface2); }
.steps .s { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .55rem; border-radius: 999px; font-size: .74rem; color: var(--muted); border: 1px solid transparent; cursor: pointer; }
.steps .s .n { font-family: var(--font-mono); font-size: .66rem; width: 1.2rem; height: 1.2rem; display: inline-grid; place-items: center; border-radius: 50%; background: var(--surface3); }
.steps .s.done { color: var(--text2); } .steps .s.done .n { background: var(--success); color: #fff; }
.steps .s.cur { color: var(--text); border-color: var(--accent); } .steps .s.cur .n { background: var(--accent); color: var(--on-accent); }
.c-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(240px, 2fr); gap: 1.25rem; padding: 1.25rem; }
@media (max-width: 900px) { .c-body { grid-template-columns: 1fr; } }
.c-main { display: flex; flex-direction: column; gap: .9rem; }
.c-main h3 { font-size: 1.25rem; }
.c-why { background: var(--surface2); border-left: 3px solid var(--accent2); padding: .7rem .9rem; border-radius: var(--radius); font-size: .88rem; line-height: 1.55; }
.c-why b { color: var(--text); }
.c-why ul { margin: .4rem 0 0 1.1rem; padding: 0; }
.c-side { display: flex; flex-direction: column; gap: .75rem; }
.c-side .card-pad { font-size: .86rem; }
.c-foot { display: flex; align-items: center; gap: .5rem; padding: .85rem 1.25rem; border-top: 1px solid var(--border); }
.c-foot .spacer { flex: 1; }
.opt { display: grid; gap: .5rem; }
.opt.cols-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.opt .o { text-align: left; padding: .6rem .8rem; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; color: var(--text); font-size: .88rem; transition: border-color .12s, background .12s; }
.opt .o:hover { border-color: var(--border2); }
.opt .o.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface2)); }
.opt .o small { display: block; color: var(--muted); font-size: .76rem; margin-top: .15rem; }
.die { font-family: var(--font-mono); font-size: 1.4rem; color: var(--accent); min-width: 2.2rem; text-align: center; }
.roll-line { display: flex; align-items: center; gap: .8rem; padding: .45rem .7rem; background: var(--surface2); border-radius: var(--radius); }
.roll-line .lbl { width: 4rem; font-family: var(--font-mono); font-size: .74rem; letter-spacing: .08em; color: var(--muted); }
.roll-line .expl { flex: 1; font-size: .8rem; color: var(--text2); }
.summary { font-size: .86rem; }
.summary dt { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; margin-top: .55rem; }
.summary dd { margin: 0; }
.summary dd.empty-v { color: var(--muted); font-style: italic; }
table.modtab { border-collapse: collapse; font-size: .78rem; width: 100%; }
table.modtab td { padding: .15rem .4rem; border-bottom: 1px solid var(--border); font-family: var(--font-mono); }
table.modtab td:last-child { color: var(--accent); text-align: right; }
