/* Scrappy fan-site look (ageofindex-style): flat, dense, utilitarian. No rounded corners, no shadows,
   system font, bordered reference tables. Hand-made, not a slick product. */
:root {
  --bg: #141418; --panel: #1b1b20; --panel2: #232329; --line: #3a3a44;
  --ink: #e6e6e8; --dim: #97979f; --accent: #c2964c; --accent2: #7298c8; --good: #3c5a3c;
  --text: 14px; --r: 5px; /* modest rounding on card-like elements; search boxes + tables stay square */
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 Verdana, Geneva, Tahoma, system-ui, sans-serif;
}
a { color: var(--accent2); }

/* centered title block, plain text (no background, no rule); the twist now lives on unit headers (accent left-bar) */
header { padding: 16px 14px 12px; text-align: center; }
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 3px auto 0; max-width: 820px; color: var(--dim); font-size: 12px; }
.headBtns { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.reportBtn { background: var(--panel2); color: var(--accent2); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 15px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.reportBtn:hover { border-color: var(--accent2); color: var(--ink); }

/* global "search anything" box */
.search { position: relative; max-width: 820px; margin: 12px auto 0; padding: 0 14px; }
#globalSearch {
  width: 100%; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 0; padding: 9px 12px; font: inherit; font-size: 15px; outline: none;
}
#globalSearch:focus { border-color: var(--accent); }
#globalSearch::placeholder { color: var(--dim); }
.searchResults {
  position: absolute; top: 100%; left: 14px; right: 14px; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-top: none;
  max-height: 360px; overflow: auto;
}
.searchResults[hidden] { display: none; }
.sr { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 12px; cursor: pointer; border-top: 1px solid var(--line); }
.sr:first-child { border-top: none; }
.sr:hover { background: var(--panel2); }
.srName { font-size: 14px; color: var(--ink); }
.sr:hover .srName { color: var(--accent); }
.srType { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.srGroup { padding: 4px 12px 2px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent2); background: #17171c; border-top: 1px solid var(--line); font-weight: 700; }

.controls {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px; max-width: 1100px; margin: 0 auto;
}
.controlRow { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; align-items: flex-end; } /* row 1: Army + Army List · row 2: Add unit + Lore + Magic Item */
.controls label, .controls .field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--dim); min-width: 200px; }
.controls .field[hidden] { display: none; } /* the .field display:flex would otherwise override the hidden attribute (e.g. the Army-List selector for armies with no variants) */
.controls label.grow, .controls .field.grow { flex: 0 1 340px; } /* don't stretch full-width, so the row stays centered */
.lbl { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.toggles { display: flex; justify-content: center; gap: 16px; padding: 0 14px 10px; max-width: 1100px; margin: 0 auto; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); cursor: pointer; }
.toggle input { accent-color: var(--accent2); cursor: pointer; }
select {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r); padding: 8px 9px; font: inherit; font-size: 14px;
}
select:disabled { opacity: .5; }
#listSelect { width: 100%; }

/* clear-X mounted flush to the right of each control (army / army list / unit / lore / item) */
.fieldRow { display: flex; align-items: stretch; }
.fieldRow > .combo, .fieldRow > select { flex: 1 1 auto; min-width: 0; }
.fieldRow > select { width: auto; border-radius: 0; }
.cx { flex: none; width: 34px; display: flex; align-items: center; justify-content: center; background: var(--panel2); color: var(--dim); border: 1px solid var(--line); border-left: none; cursor: pointer; font: inherit; font-size: 20px; line-height: 1; padding: 0; }
.cx:hover { color: #e87; border-color: #e87; }
.cx[hidden] { display: none; }

.sheet { max-width: 1000px; margin: 0 auto 50px; padding: 0 14px; display: flex; flex-direction: column; gap: 16px; }
.groupHead { margin: 8px 0 -4px; padding-bottom: 4px; border-bottom: 2px solid var(--accent2); font-size: 18px; font-weight: 700; }
/* collapsible sheet sections (Army Rules / Units / Lores of Magic / Magic Items) */
.grp { display: flex; flex-direction: column; gap: 14px; }
.grpBody { display: flex; flex-direction: column; gap: 16px; }
.grp.collapsed .grpBody { display: none; }
.grpHead { margin: 0; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 9px; }
.grpHead .caret { flex: none; width: 0; height: 0; border-left: 8px solid var(--accent2); border-top: 6px solid transparent; border-bottom: 6px solid transparent; transition: transform .12s; }
.grp:not(.collapsed) > .grpHead .caret { transform: rotate(90deg); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.card > h2 {
  margin: 0; padding: 8px 12px; font-size: 18px; font-weight: 700;
  background: var(--panel2); border-bottom: 1px solid var(--line); border-left: 3px solid var(--accent);
  cursor: pointer; user-select: none;
}
/* click a card header to collapse that one card (unit/lore/item); caret rotates, body hides */
.card > h2::before {
  content: ''; display: inline-block; vertical-align: middle; margin-right: 8px;
  width: 0; height: 0; border-left: 7px solid var(--accent2);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  transition: transform .12s; transform: rotate(90deg);
}
.card.collapsed > h2::before { transform: rotate(0deg); }
.card.collapsed > h2 { border-bottom: none; }
.card.collapsed > :not(h2) { display: none; }
.meta { padding: 5px 12px; color: var(--dim); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 16px; border-bottom: 1px solid var(--line); }
.meta b { color: var(--ink); }

.stats { display: flex; gap: 0; flex-wrap: wrap; padding: 10px 12px; }
.stat { background: var(--panel2); border: 1px solid var(--line); border-left: none; width: 58px; text-align: center; padding: 5px 3px; }
.stat:first-child { border-left: 1px solid var(--line); }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .k { font-size: 9px; color: var(--dim); line-height: 1.15; margin-top: 2px; }
.modelName { padding: 2px 12px; color: var(--accent); font-weight: 700; font-size: 13px; }

/* reference tables: bordered cells, dense - the fan-site staple */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 4px 9px; border: 1px solid var(--line); }
thead th { background: var(--panel2); color: var(--accent2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.sectionTitle { padding: 8px 12px 3px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent2); font-weight: 700; }
.wnote td { color: var(--dim); font-size: 12px; font-style: italic; background: #1d1d22; } /* weapon rulebook note (e.g. Cannon black-powder text) under its row */

.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; padding: 10px 12px; }
.rule { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.rule .rh { background: var(--good); padding: 5px 9px; font-weight: 700; font-size: 13px; cursor: pointer; }
/* a rule's body collapses individually (click its header); the global "Collapse rules" toggle sets the default */
.rule:not(.spell) .rh { position: relative; padding-right: 22px; }
.rule:not(.spell) .rh::after { content: '▾'; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 9px; opacity: .65; }
.rule:not(.spell).collapsed .rh::after { content: '▸'; }
.rule.collapsed .rb { display: none; }
.spellNum { display: inline-block; min-width: 1.4em; text-align: center; padding: 0 4px; margin-right: 4px; background: rgba(255,255,255,.14); font-size: 11px; border-radius: 3px; }
/* spells are clickable to mark "rolled"; a rolled spell gets a green border (matching the header colour) */
.rule.spell.rolled { border: 2px solid var(--good); }
.rule .rb { padding: 7px 9px; color: #d4d4d8; }

.opts { padding: 6px 12px 12px; }
.optGroup { margin: 7px 0; }
.optGroup .gh { color: var(--accent); font-weight: 700; font-size: 13px; }
.optGroup .gh .choose { color: var(--dim); font-weight: 400; font-size: 12px; }
.choiceRow { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 0; }
.opt { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); padding: 3px 9px; font-size: 12.5px; cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt.on { background: var(--accent); border-color: var(--accent); color: #18120a; font-weight: 700; }
.opt.on .pts { color: #18120a; }
.pts { color: var(--accent); }

/* weapon filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 5px 12px 2px; }
.chip { background: var(--accent2); color: #0c1320; border: 1px solid var(--accent2); border-radius: var(--r); padding: 3px 9px; font-size: 12.5px; cursor: pointer; font-weight: 700; }
.chip:not(.on) { background: var(--panel2); color: var(--dim); border-color: var(--line); font-weight: 400; }
.chip.ghost { background: transparent; color: var(--accent2); border-color: var(--accent2); font-weight: 400; }
.weaponHead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; }
.wbtns { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.hint { color: var(--dim); font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 11px; }
.hint.pad { display: block; padding: 7px 12px; }

.tally { font-size: 12px; color: var(--accent); font-weight: 500; margin-left: 8px; vertical-align: middle; }
.x { float: right; background: transparent; border: none; color: var(--dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.x:hover { color: #e87; }

.kw { padding: 8px 12px 12px; color: var(--dim); font-size: 12.5px; }
.kw b { color: var(--ink); }
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* "This Turn" whole-list checklist: a reset bar, then phase header, sub-phase sub-header, then each ability
   as a checkbox + clickable name (opens the rule/spell) + its source units/lores. */
.ckBar { padding: 6px 12px; border-bottom: 1px solid var(--line); }
.ckPhase { padding: 6px 12px 8px; }
.ckPhase + .ckPhase { border-top: 1px solid var(--line); }
.ckPhaseHead { color: var(--accent2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.ckSub { margin: 2px 0 4px 10px; }
.ckSubHead { color: var(--dim); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.ckItem { display: flex; align-items: baseline; gap: 7px; font-size: 13px; padding: 2px 0; cursor: default; }
.ckBox { flex: 0 0 auto; margin: 0; transform: translateY(1px); cursor: pointer; }
.ckName { font: inherit; font-weight: 700; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.ckName:hover { text-decoration: underline; }
.ckBox:checked ~ .ckName { color: var(--dim); text-decoration: line-through; font-weight: 400; }
.ckBox:checked ~ .hint { opacity: .5; }
.tag { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); padding: 1px 7px; color: #c8c8d0; font-size: 11.5px; }
.empty { color: var(--dim); text-align: center; padding: 36px; }

/* inline rule cross-links + modal */
.ruleref { background: none; border: none; color: var(--accent2); font: inherit; padding: 0; cursor: pointer; border-bottom: 1px dotted var(--accent2); }
.ruleref:hover { color: #9fb6da; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: flex; align-items: flex-start; justify-content: center; padding: 24px 14px; z-index: 50; overflow: auto; }
.modal[hidden] { display: none; }
.modalCard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; max-width: 680px; width: 100%; margin: auto; position: relative; }
.modalCard.modalWide { max-width: 940px; }
.modalCard h2 { margin: 0; padding: 10px 40px 10px 14px; font-size: 18px; font-weight: 700; background: var(--panel2); border-bottom: 1px solid var(--line); }
.modalText { padding: 12px 14px; font-size: var(--text); }
/* item flavour lore: italic prose shown above the rules in magic/runic item modals */
.itemLore { padding: 4px 14px 8px; font-style: italic; color: var(--dim); font-size: 13px; line-height: 1.5; }

/* rich-text bodies (rules, spells, items) emitted by formatText(): one standard size everywhere */
.rt { font-size: var(--text); }
.rt > p { margin: 0 0 .5em; }
.rt > p:last-child { margin-bottom: 0; }
.rt > .li { display: flex; gap: .5em; margin: .18em 0; }
.rt > .th { font-weight: 700; color: var(--accent); margin: .6em 0 .2em; }
.rt > .th:first-child { margin-top: 0; }
.li-m { flex: none; min-width: 1.1em; color: var(--accent2); }
/* markdown tables rendered inside rule/spell/item prose (e.g. misfire tables) */
.mdTable { border-collapse: collapse; width: 100%; margin: .55em 0; }
.mdTable th, .mdTable td { border: 1px solid var(--line); padding: 4px 8px; font-size: 13px; text-align: left; vertical-align: top; }
.mdTable th { background: var(--panel2); font-weight: 700; }
.modalClose { position: absolute; top: 6px; right: 10px; background: none; border: none; color: var(--dim); font-size: 24px; line-height: 1; cursor: pointer; }
.modalClose:hover { color: var(--ink); }

/* anonymous feedback form */
.fbCard { max-width: 540px; padding-bottom: 14px; }
.fbForm { display: flex; flex-direction: column; gap: 9px; padding: 12px 14px 0; }
.fbForm > label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
.fbForm input, .fbForm select, .fbForm textarea { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 9px; font: inherit; font-size: 14px; }
.fbForm textarea { resize: vertical; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.fbActions { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.fbActions .hint { margin-right: auto; }
.fbActions button { background: var(--accent2); color: #0c1320; border: none; border-radius: var(--r); padding: 7px 16px; font: inherit; font-weight: 700; cursor: pointer; }
.fbActions button:disabled { opacity: .6; cursor: default; }

/* unit search combobox: pills live inside the input, which grows as they wrap */
.combo { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 0; padding: 5px 7px; min-height: 38px; position: relative; }
.combo:focus-within { border-color: var(--accent2); }
.cChips { display: contents; }
.cInput { flex: 1 1 90px; min-width: 90px; background: transparent; border: none; color: var(--ink); font: inherit; font-size: 14px; outline: none; padding: 3px 2px; }
.cInput:disabled { cursor: not-allowed; }
.cMenu { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-top: none; max-height: 280px; overflow: auto; }
.cMenu[hidden] { display: none; }
.comboItem { padding: 7px 11px; font-size: 14px; cursor: pointer; border-top: 1px solid var(--line); }
.comboItem:first-child { border-top: none; }
.comboItem:hover { background: var(--panel2); color: var(--accent); }
.comboNone { padding: 7px 11px; font-size: 13px; color: var(--dim); }
.uchip { display: inline-flex; align-items: center; gap: 5px; background: var(--panel2); border: 1px solid var(--accent2); border-radius: var(--r); padding: 3px 5px 3px 9px; font-size: 13px; }
.uchip button { background: #33333c; border: none; color: var(--dim); width: 17px; height: 17px; line-height: 1; cursor: pointer; font-size: 14px; }
.uchip button:hover { color: #e87; }

/* Weapons use a bordered table on every width (mobile + desktop parity); just shrink it on phones. */
@media (max-width: 560px) {
  table { font-size: 12px; }
  th, td { padding: 3px 5px; }
  .stat { width: 52px; }
  .stat .v { font-size: 18px; }
}

/* "Scry" advanced-search button on the builder header - neutral bordered button (the site's default button look) */
.scryBtn { display: inline-block; background: var(--panel2); color: var(--accent2); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 15px; font: inherit; font-size: 13px; font-weight: 700; text-decoration: none; cursor: pointer; }
.scryBtn:hover { border-color: var(--accent2); color: var(--ink); }

/* ====== Scry: advanced-search page (browse.html / browse.js) ====== */
/* fluid width: fills the screen up to a generous cap so the results table fits all its columns with room,
   and shrinks naturally (vw) on laptops/phones - the table wrap scrolls horizontally only on tiny screens.
   The filter form fills the same width as the results so the two line up (no left-bias). */
.scry { max-width: min(1700px, 95vw); margin: 0 auto 50px; padding: 0 14px; }
.scryForm { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel); max-width: 1100px; margin: 0 auto; }
.scryRow { display: flex; align-items: flex-start; gap: 14px; padding: 11px 14px; border-top: 1px solid var(--line); }
.scryRow:first-child { border-top: none; }
.scryLbl { flex: none; width: 150px; padding-top: 6px; color: var(--accent2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.scryCtl { flex: 1 1 auto; min-width: 0; }
.scryInput, .scrySel { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 0; padding: 8px 10px; font: inherit; font-size: 14px; outline: none; }
.scryInput { width: 100%; }
.scryInput:focus, .scrySel:focus { border-color: var(--accent); }
.segs, .chipWrap { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { background: var(--panel2); color: var(--dim); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 13px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.seg.on { background: var(--accent2); color: #0c1320; border-color: var(--accent2); }
/* reuse .chip from the builder for the multi-select filters */
.statBuilder { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.statLine { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.statLine .statVal { width: 110px; }
.statRm { background: transparent; color: var(--dim); border: 1px solid var(--line); border-radius: var(--r); width: 30px; height: 32px; cursor: pointer; font-size: 16px; }
.statRm:hover { color: #e87; border-color: #e87; }
.statAdd { background: none; border: none; color: var(--accent2); font: inherit; font-size: 13px; cursor: pointer; padding: 2px; text-decoration: underline; }
.statAdd:hover { color: var(--ink); }
.scryOut { margin-top: 16px; }
.resultMeta { font-size: 13px; color: var(--accent); font-weight: 700; padding: 4px 2px 8px; }
.resTableWrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
.resTable { width: 100%; border-collapse: collapse; font-size: 13px; }
.resTable th, .resTable td { text-align: left; padding: 5px 9px; border: 1px solid var(--line); white-space: nowrap; }
.resTable thead th, .resTable tr:first-child th { background: var(--panel2); color: var(--accent2); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
.resRow { cursor: pointer; }
.resRow:nth-child(even) { background: #1b1b20; }
.resRow:hover { background: var(--panel2); }
.resRow:hover td:first-child { color: var(--accent); }
.resTable th.sortable { cursor: pointer; user-select: none; }
.resTable th.sortable:hover { color: var(--accent); }
.chip.exc { background: #5a2b2b; color: #f2c4c4; border-color: #7a3a3a; text-decoration: line-through; } /* excluded (NOT) filter chip */
.copyLink { background: none; border: none; color: var(--accent2); font: inherit; font-size: 12px; font-weight: 400; cursor: pointer; text-decoration: underline; margin-left: 8px; }
.copyLink:hover { color: var(--ink); }
@media (max-width: 640px) {
  .scryRow { flex-direction: column; gap: 6px; }
  .scryLbl { width: auto; padding-top: 0; }
}
