:root {
  --bg: #0d0f13;
  --bg2: #13161c;
  --bg3: #191d25;
  --line: #2a2f3a;
  --line2: #353c49;
  --text: #e8e3d8;
  --muted: #969c9f;
  --dim: #6f7680;
  --gold: #c9a25a;
  --gold2: #e2bf7c;
  --red: #d2685e;
  --blue: #7fa6c9;
  --green: #8fb98a;
  --purple: #b294c9;
  --cyan: #79b9b3;
  --orange: #d79a5b;
  --teal: #86b7a8;
  --pink: #c98fae;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--gold2); text-decoration: none; }
a:hover { text-decoration: underline; }
kbd {
  font-family: var(--mono);
  font-size: 0.78em;
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
  background: var(--bg3);
  white-space: nowrap;
}
::selection { background: rgba(201, 162, 90, 0.35); }

/* ---------- top bar ---------- */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #15181f, #101319);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-family: var(--serif);
  letter-spacing: 0.06em;
  user-select: none;
  flex: none;
}
.brand-pf { font-size: 21px; font-weight: 700; color: var(--gold); }
.brand-one { font-size: 17px; font-weight: 700; color: var(--red); margin: 0 2px; }
.brand-word { font-size: 14px; letter-spacing: 0.28em; color: var(--muted); }
.stats {
  flex: 1;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stats b { color: var(--text); font-weight: 600; }
.tools { display: flex; gap: 6px; flex: none; }
.tool {
  background: var(--bg3);
  border: 1px solid var(--line2);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms;
}
.tool:hover { background: #222733; border-color: #4a5364; }
a.tool { display: inline-block; text-decoration: none; }
a.tool:hover { text-decoration: none; }

/* icons: game-icons.net, CC BY 3.0 — see README */
[data-ico]::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  vertical-align: -2px;
  background: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
[data-ico].icononly::before { margin-right: 0; }
[data-ico="swords"]::before { -webkit-mask-image: url("/static/icons/swords.svg"); mask-image: url("/static/icons/swords.svg"); }
[data-ico="bookmark"]::before { -webkit-mask-image: url("/static/icons/ribbon.svg"); mask-image: url("/static/icons/ribbon.svg"); }
[data-ico="books"]::before { -webkit-mask-image: url("/static/icons/books.svg"); mask-image: url("/static/icons/books.svg"); }
[data-ico="search"]::before { -webkit-mask-image: url("/static/icons/search.svg"); mask-image: url("/static/icons/search.svg"); }
[data-ico="spellbook"]::before { -webkit-mask-image: url("/static/icons/spellbook.svg"); mask-image: url("/static/icons/spellbook.svg"); }
[data-ico="info"]::before { -webkit-mask-image: url("/static/icons/info.svg"); mask-image: url("/static/icons/info.svg"); }

/* inline icon span, used where the icon name is decided at render time */
.gi {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex: none;
  background: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.play h3 { display: flex; align-items: center; gap: 7px; }
.play h3 .gi { color: var(--gold2); }
.hplabel { display: inline-flex; align-items: center; gap: 5px; }
.hplabel .gi { color: var(--red); }
.minilink .gi { width: 12px; height: 12px; vertical-align: -1px; margin-right: 3px; }
.tool.accent { border-color: var(--gold); color: var(--gold2); }
.tool:disabled { opacity: 0.45; cursor: default; }
.iconbtn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 6px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  padding: 0;
}
.iconbtn:hover { color: var(--text); border-color: #4a5364; background: var(--bg3); }

/* ---------- layout ---------- */
.layout {
  display: flex;
  height: calc(100vh - 58px);
  min-height: 0;
}
.left {
  width: clamp(380px, 44vw, 640px);
  min-width: 340px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  min-height: 0;
  background: var(--bg);
}
.layout.full .left { width: 100%; max-width: 1100px; border-right: 0; margin: 0 auto; }
.layout.full .right { display: none; }
.right.textonly .detail { flex: 1; max-height: none; border-bottom: 0; }

/* ---------- search ---------- */
.searchwrap {
  position: relative;
  margin: 15px 16px 10px;
  flex: none;
}
.searchicon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-52%);
  font-size: 22px;
  color: var(--dim);
  pointer-events: none;
}
#q {
  width: 100%;
  height: 52px;
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 9px;
  padding: 0 42px 0 44px;
  font-size: 17px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
  appearance: none;
}
#q::-webkit-search-cancel-button { display: none; }
#q:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 90, 0.12);
}
#q::placeholder { color: #6c727c; }
.clearbtn {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.clearbtn:hover { background: var(--bg3); color: var(--text); }

.kindchips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  padding: 0 16px 10px;
  flex: none;
}
.chip {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.chip:hover { border-color: var(--line2); color: var(--text); }
.chip.on { background: rgba(201, 162, 90, 0.14); border-color: var(--gold); color: var(--gold2); }
.chip .n { color: var(--dim); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip.on .n { color: var(--gold); }

.status {
  padding: 0 17px 8px;
  color: var(--muted);
  font-size: 12px;
  min-height: 20px;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.status b { color: var(--text); font-weight: 600; }
.status .suggest { color: var(--gold2); background: none; border: 0; padding: 0; text-decoration: underline; }

.related {
  padding: 0 16px 9px;
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  flex: none;
  font-size: 11.5px;
  color: var(--dim);
}
.related .label { margin-right: 2px; white-space: nowrap; }
.related .rchip {
  border: 1px dashed var(--line2);
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
}
.related .rchip:hover { color: var(--gold2); border-color: var(--gold); }

.recent {
  margin: 0 16px 10px;
  padding: 10px 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  flex: none;
}
.recent .rlabel { font-size: 10.5px; letter-spacing: 0.14em; color: var(--dim); margin-bottom: 7px; }
.recent .rrow { display: flex; gap: 6px; flex-wrap: wrap; }
.ritem {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 8px;
}
.ritem:hover { color: var(--text); border-color: var(--line2); }

/* ---------- results ---------- */
.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding-bottom: 40px;
}
.results::-webkit-scrollbar { width: 10px; }
.results::-webkit-scrollbar-thumb { background: #2c313c; border-radius: 6px; border: 3px solid var(--bg); }
.results::-webkit-scrollbar-track { background: transparent; }

.grouphead {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 17px 6px;
  background: rgba(13, 15, 19, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.03em;
  color: var(--gold);
}
.grouphead .gcount { color: var(--dim); font-family: var(--sans); font-size: 11px; letter-spacing: 0; }
.grouphead .gmore {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 11px;
  font-family: var(--sans);
  padding: 0;
}
.grouphead .gmore:hover { color: var(--gold2); }

.result {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 11px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #1c2028;
  border-left: 2px solid transparent;
  padding: 10px 16px 11px 14px;
  transition: background 80ms;
}
.result:hover { background: #141821; }
.result.sel { background: #1a1f29; border-left-color: var(--gold); }
.pgbadge {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: 1px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pgbadge .pg { font-size: 12px; color: var(--gold2); }
.pgbadge .pdfpg { font-size: 9.5px; color: var(--dim); }
.rbody { min-width: 0; display: block; }
.rtitle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rtitle .kindtag {
  flex: none;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 1px 4px;
  opacity: 0.72;
}
.kindtag[data-kind="feats"] { color: var(--red); }
.kindtag[data-kind="spells"] { color: var(--blue); }
.kindtag[data-kind="items"] { color: var(--green); }
.kindtag[data-kind="monsters"] { color: var(--purple); }
.kindtag[data-kind="tech"] { color: var(--cyan); }
.kindtag[data-kind="classes"] { color: var(--orange); }
.kindtag[data-kind="races"] { color: var(--teal); }
.kindtag[data-kind="traits"] { color: var(--pink); }
.kindtag[data-kind="rules"] { color: var(--gold); }
.rsnippet {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #b6bbb7;
  font-size: 12.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.rsnippet mark {
  background: rgba(201, 162, 90, 0.24);
  color: #f0d9a8;
  border-radius: 2px;
  padding: 0 1px;
}
.rmeta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  color: var(--dim);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rmeta .errbadge {
  color: var(--red);
  border: 1px solid rgba(210, 104, 94, 0.5);
  background: rgba(210, 104, 94, 0.08);
  border-radius: 3px;
  padding: 0 4px;
  font-size: 9px;
  letter-spacing: 0.08em;
}
.seeall {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #1c2028;
  color: var(--dim);
  font-size: 11.5px;
  padding: 8px 16px;
  text-align: center;
}
.seeall:hover { color: var(--gold2); background: #12161e; }

.empty {
  padding: 40px 26px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  font-size: 13px;
}
.empty .bigglyph { font-size: 34px; color: #2c333f; margin-bottom: 10px; }
.empty h3 { font-family: var(--serif); color: var(--text); font-weight: 500; font-size: 17px; margin: 0 0 8px; }
.empty p { margin: 6px 0; }
.empty .extlinks { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.empty .extlinks a { font-size: 12px; }

/* ---------- right pane ---------- */
.right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #0a0c10;
  min-height: 0;
}
.viewhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  flex: none;
  min-height: 45px;
}
.viewtitle {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.viewtitle b { color: var(--text); font-weight: 500; }
.viewtools { display: flex; align-items: center; gap: 5px; flex: none; }
.pageinput {
  width: 52px;
  height: 27px;
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 5px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 4px;
  outline: none;
  -moz-appearance: textfield;
}
.pageinput::-webkit-outer-spin-button, .pageinput::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pageinput:focus { border-color: var(--gold); }
.pagetotal { font-family: var(--mono); font-size: 11px; color: var(--dim); min-width: 26px; }
.viewtools .tool { padding: 5px 8px; font-size: 11.5px; }
#backBtn { display: none; }

.detail {
  flex: none;
  max-height: 38%;
  overflow-y: auto;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  padding: 12px 18px 14px;
  line-height: 1.5;
}
.detail::-webkit-scrollbar { width: 9px; }
.detail::-webkit-scrollbar-thumb { background: #2c313c; border-radius: 6px; border: 2px solid var(--bg2); }
.detail .dhead {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}
.detail h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  color: var(--text);
  flex: 1;
}
.detail .dmeta {
  color: var(--dim);
  font-size: 11.5px;
  margin-bottom: 9px;
  font-variant-numeric: tabular-nums;
}
.detail .dmeta b { color: var(--gold2); font-weight: 500; }
.detail .dtext {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  color: #c9cdc7;
  margin: 0 0 10px;
}
.detail .dtext p { margin: 0 0 8px; }
.detail .dtext p:last-child { margin-bottom: 0; }
.detail .dtext .dl {
  padding-left: 10px;
  border-left: 2px solid rgba(201, 162, 90, 0.32);
}
.detail .dtext .dl b { color: var(--gold2); font-weight: 650; }
.detail .dtext .formula {
  font-family: var(--mono);
  font-size: 12.4px;
  color: #dfe3d8;
  background: rgba(255, 255, 255, 0.035);
  border-radius: 6px;
  padding: 7px 9px;
  white-space: pre-wrap;
}
.detail .dtext .spellstat {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 10px;
  margin: 0 0 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 7px;
  font-size: 12.4px;
}
.detail .dtext .spellstat dt {
  color: var(--gold2);
  font-weight: 650;
  white-space: nowrap;
}
.detail .dtext .spellstat dd { margin: 0; color: #cfd3c8; }
.detail .erratablock {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border-left: 2px solid var(--red);
  background: rgba(210, 104, 94, 0.07);
  color: #d9b5b0;
  font-size: 12.5px;
  line-height: 1.5;
}
.detail .erratablock .elabel {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  color: var(--red);
  margin-bottom: 3px;
}
.detail .dlinks { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.detail .dlinks a, .detail .dlinks button {
  font-size: 11.5px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--gold2);
}
.detail .dlinks a:hover, .detail .dlinks button:hover { text-decoration: underline; }
.detail .dlinks .spacer { flex: 1; }
.detail .tagrow { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.detail .tag { font-size: 10px; color: var(--dim); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }
.detail .drefs { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin: 0 0 10px; }
.detail .drefs .rlabel { font-size: 9.5px; letter-spacing: 0.12em; color: var(--dim); margin-right: 2px; }
.detail .drefs .refchip {
  background: rgba(201, 162, 90, 0.08);
  border: 1px solid rgba(201, 162, 90, 0.34);
  border-radius: 4px;
  color: var(--gold2);
  font-size: 11px;
  padding: 1px 7px;
}
.detail .drefs .refchip:hover { border-color: var(--gold); background: rgba(201, 162, 90, 0.16); }

.framewrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #1b1f26;
}
#pdfFrame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #1b1f26; }
.frameplaceholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  padding: 30px;
  font-size: 13px;
  line-height: 1.6;
}
.frameplaceholder p { margin: 0; max-width: 440px; }
.frameplaceholder .muted { color: var(--dim); font-size: 12px; }
.frameplaceholder .ph-glyph { font-size: 46px; color: #262c36; }

/* new-tab PDF mode: no embedded viewer, just a big tap target */
.frameopen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: #14181f;
}
.frameopen .fo-glyph { font-size: 38px; color: #262c36; }
.frameopen .fo-title { color: var(--muted); font-size: 12.5px; }
.frameopen .fo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 20px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: rgba(201, 162, 90, 0.12);
  color: var(--gold2);
  font-size: 14px;
}
.frameopen .fo-link:hover { background: rgba(201, 162, 90, 0.2); }
.frameopen .fo-hint { margin: 0; max-width: 320px; color: var(--dim); font-size: 11.5px; line-height: 1.55; }
.frameopen .foalt {
  background: none;
  border: 0;
  padding: 0;
  color: var(--gold2);
  font-size: 11.5px;
  text-decoration: underline;
}

/* ---------- play mode ---------- */
.play {
  height: calc(100vh - 58px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.playhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  flex: none;
}
.playtitle {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--gold2);
  white-space: nowrap;
}
.playchars { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.chartab {
  background: var(--bg3);
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}
.chartab:hover { border-color: var(--gold); color: var(--text); }
.chartab.on { background: rgba(201, 162, 90, 0.16); border-color: var(--gold); color: var(--gold2); }
.playsave { color: var(--dim); font-size: 11px; min-width: 56px; text-align: right; }
.playbody { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.playgrid {
  display: grid;
  grid-template-columns: minmax(300px, 410px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 1500px;
  margin: 0 auto;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}
.chead h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.csum { color: var(--dim); font-size: 12px; margin-top: 2px; }
.play .muted, .playbody .muted { color: var(--dim); }
.hprow { display: flex; align-items: center; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.hplabel { color: var(--muted); font-size: 10.5px; letter-spacing: 0.14em; }
.hpbtn {
  background: var(--bg3);
  border: 1px solid var(--line2);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12px;
}
.hpbtn:hover { border-color: var(--gold); color: var(--gold2); }
.hpval { color: var(--muted); font-size: 13px; }
.hpval b { color: var(--text); font-size: 18px; font-variant-numeric: tabular-nums; }
#hpMax {
  width: 58px;
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
}
.hpbar { height: 7px; border-radius: 4px; background: #241a1a; margin: 9px 0 3px; overflow: hidden; }
.hpbar i { display: block; height: 100%; background: linear-gradient(90deg, #7d2f2f, #c05a50); }
.statrow { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 11px; font-size: 12px; color: var(--muted); }
.stat b { color: var(--gold2); font-weight: 600; }
.card h3 {
  margin: 18px 0 6px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--gold);
  text-transform: uppercase;
  font-weight: 600;
}
.res, .spelllevel, .ability { border-top: 1px solid var(--line); padding: 9px 0; }
.res:first-of-type, .spelllevel:first-of-type, .ability:first-of-type { border-top: 0; }
.resline { display: flex; align-items: baseline; gap: 8px; }
.reslabel { flex: 1; font-size: 13px; color: var(--text); }
.rescount { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.resnote { color: var(--dim); font-size: 11.5px; line-height: 1.5; margin-top: 3px; }
.minilink {
  background: none;
  border: 0;
  padding: 0;
  color: var(--gold2);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.minilink:hover { text-decoration: underline; }
.minilink.reset {
  margin-left: auto;
  border: 1px solid var(--line2);
  border-radius: 4px;
  padding: 3px 8px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}
.minilink.reset:hover { border-color: var(--gold); color: var(--gold2); text-decoration: none; }
.pips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.pip {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line2);
  background: #1b1f27;
  padding: 0;
}
.pip:hover { border-color: var(--gold); }
.pip.used { background: var(--gold); border-color: var(--gold); box-shadow: inset 0 0 0 3px var(--bg2); }
.spelllist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.spelllink {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text);
}
.spelllink:hover { border-color: var(--gold); color: var(--gold2); }
.spelllink.off { color: var(--dim); }
.cnotes { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--dim); font-size: 11.5px; line-height: 1.55; }
.cheatcard .chead { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 2px; }
.cheatsec h3 { margin: 16px 0 2px; }
.cheatrow { padding: 7px 0; border-top: 1px solid var(--line); }
.cheatrow:first-of-type { border-top: 0; }
.cheatline { display: flex; gap: 10px; align-items: baseline; }
.cheatlabel {
  background: none;
  border: 0;
  padding: 0;
  color: var(--gold2);
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
}
.cheatlabel:hover { text-decoration: underline; }
.cheatcite { margin-left: auto; color: var(--dim); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.cheattext { color: #b4b8b3; font-size: 12px; line-height: 1.55; margin-top: 3px; }
.small { font-size: 11px; }

/* ---------- modal / toast ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 5, 8, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modalbox {
  width: min(660px, 100%);
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 10px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55);
}
.modalhead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.modalhead h2 {
  margin: 0;
  flex: 1;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.modalbody {
  padding: 16px 20px 22px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.65;
  color: #bcbfba;
}
.modalbody h3 {
  color: var(--gold2);
  font-family: var(--serif);
  font-weight: 500;
  font-size: 15px;
  margin: 20px 0 7px;
}
.modalbody h3:first-child { margin-top: 0; }
.modalbody code, .modalbody pre {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.modalbody code { padding: 1px 4px; }
.modalbody pre { padding: 10px 12px; overflow-x: auto; line-height: 1.5; }
.modalbody ul { margin: 7px 0; padding-left: 20px; }
.modalbody li { margin: 3px 0; }
.modalbody .kbdrow { display: grid; grid-template-columns: 120px 1fr; gap: 5px 12px; align-items: baseline; }
.modalbody .kbdrow .keys { display: inline-flex; gap: 4px; }
.modalbody .bookrow { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); }
.modalbody .bookrow .bt { flex: 1; color: var(--text); }
.modalbody .bookrow .bc { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.modalbody .saveditem {
  display: flex;
  gap: 10px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}
.modalbody .saveditem button.link {
  flex: 1;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: 13px;
}
.modalbody .saveditem button.link:hover { color: var(--gold2); }
.modalbody .saveditem .smeta { color: var(--dim); font-size: 11px; white-space: nowrap; }
.modalbody .saveditem .rm {
  background: none; border: 0; color: var(--dim); font-size: 15px; padding: 0 2px;
}
.modalbody .saveditem .rm:hover { color: var(--red); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  background: #1d222c;
  border: 1px solid var(--line2);
  border-left: 3px solid var(--gold);
  padding: 10px 16px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-width: 80vw;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; height: calc(100dvh - 58px); }
  .left { width: 100%; min-width: 0; border-right: 0; flex: 0 0 58%; }
  .right { flex: 1; border-top: 1px solid var(--line); }
  .detail { max-height: 30%; }
  .brand-word { display: none; }
  .stats { font-size: 11px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .tool { padding: 5px 7px; }
  .layout.full .left { flex: 1; }
  /* tapping a result swaps the list for a full-height entry + tap-to-open PDF */
  .layout.detailmode .left { display: none; }
  .layout.detailmode .right { flex: 1; border-top: 0; }
  .layout.detailmode #backBtn { display: inline-flex; }
  .layout.detailmode .detail { flex: 1; max-height: none; }
  .layout.detailmode .framewrap { flex: 0 0 auto; min-height: 140px; }
  /* play mode stacks the tracker above the cheat sheet */
  .play { height: calc(100dvh - 58px); }
  .playgrid { grid-template-columns: 1fr; }
  .playbody { padding: 10px; }
  .playtitle { display: none; }
}
@media (max-width: 620px) {
  .left { flex: 1 1 auto; }
  .result { grid-template-columns: 50px minmax(0, 1fr); gap: 8px; padding-right: 10px; }
  .stats { display: none; }
  .viewtitle { display: none; }
  .kindchips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 8px; }
  .chip { flex: none; }
  /* phones: results list only until an entry is opened */
  .right { display: none; }
  .layout.detailmode .right { display: flex; }
  .layout.detailmode .left { display: none; }
  /* the back arrow replaces both pane controls on phones */
  #pdfModeBtn, #hidePdfBtn { display: none; }
  /* comfortable touch targets and reading width */
  .viewhead { padding: 6px 8px; gap: 7px; }
  .viewhead .iconbtn { width: 34px; height: 34px; }
  .viewhead .tool { padding: 8px 9px; }
  .detail { padding: 13px 14px 16px; }
  .detail .dtext { font-size: 14px; }
  .detail h2 { font-size: 20px; }
  /* play mode: touch-sized controls */
  .playhead { padding: 7px 10px; gap: 7px; }
  .playsave { display: none; }
  .chartab { padding: 7px 12px; font-size: 13px; }
  .playbody { padding: 8px; }
  .card { padding: 12px 13px; }
  .hpbtn { padding: 8px 11px; }
  #hpMax { width: 64px; padding: 5px; }
  .pip { width: 28px; height: 28px; }
  .cheatlabel { font-size: 13px; }
  .cheattext { font-size: 12.5px; }
}

/* ---------- Discord auth wall + user chip (see static/auth.js) ---------- */
#authwall {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 14, 0.92); backdrop-filter: blur(3px);
}
.authcard {
  max-width: 380px; margin: 20px; padding: 28px 30px; text-align: center;
  background: var(--bg2, #12151b); border: 1px solid var(--line2, #353c49);
  border-radius: 12px; color: var(--text, #e8e3d8);
  font-family: "Segoe UI", system-ui, sans-serif;
}
.authcard h1 { margin: 0 0 10px; font-size: 20px; letter-spacing: 0.06em; }
.authcard p { margin: 0 0 20px; font-size: 13.5px; line-height: 1.5; color: var(--muted, #969c9f); }
.authbtn {
  display: inline-block; padding: 10px 22px; border-radius: 8px;
  background: #5865f2; color: #fff; font-weight: 600; font-size: 14px;
  text-decoration: none;
}
.authbtn:hover { background: #4752c4; color: #fff; }
.userchip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 6px 3px 3px; border-radius: 14px;
  background: var(--bg3, #191d25); border: 1px solid var(--line2, #353c49);
  font-size: 12px; color: var(--text, #e8e3d8);
}
.userchip img { width: 20px; height: 20px; border-radius: 50%; }
.userchip button {
  border: 0; background: transparent; color: var(--dim, #6f7680);
  font-size: 11px; cursor: pointer; padding: 2px 4px;
}
.userchip button:hover { color: var(--gold, #c9a25a); }
.authtoast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 1000; padding: 9px 18px; border-radius: 8px;
  background: #2a2013; border: 1px solid var(--gold, #c9a25a);
  color: var(--text, #e8e3d8); font-size: 13px;
  font-family: "Segoe UI", system-ui, sans-serif;
}
/* Members see the read-only site; only admins get the reindex button. */
#indexBtn { display: none; }
body.is-admin #indexBtn { display: inline-flex; }
