/* 40K'47 Studio: dark, high-contrast, readable at a game table.

   Shared pieces for every page and module (D-56). Use these before writing a new rule.
   Tokens      --bg --panel --panel-2 --border --text --muted --accent --accent-ink --ok --warn --err --draft --radius --mono
               --header-h: what the sticky top bar covers. html has scroll-padding-top: var(--header-h), so #anchors land below it.
   Buttons     .btn (neutral)  .btn-primary (the one main action)  .btn-quiet (no box until hovered: secondary and icon actions)
               .btn-danger (retire, archive, remove)  .small (denser; still 40px tall on phones)  .btn-row (a wrapping row of them)
               The older .btn.primary and .btn.danger still work; new markup uses the hyphenated names.
   Chips       .chip, .chip.on; an optional remove link inside it:
               <span class="chip">Necrons <a class="chip-x" href="…" aria-label="Clear the faction filter">✕</a></span>
   Text        .muted .small .mono .pre .nowrap .text-ok .text-warn .text-err .sr-only (for screen readers only)
   Layout      .panel .grid .split .toolbar .page-head .crumbs (breadcrumb line above the h1) .gap-below (space under a block)
               .grid-fill (cards that grow to fill their row; a lone one stops at half the width)
               .empty-state (a centred "nothing here yet" line, with an optional button under it)
               .list-rows (ul: one row per item, its buttons on the right)
   Tables      table.data, .compact, .table-wrap (scrolls sideways when it must)
               table.stack-phone: under 700px each row becomes a block: its first cell on a line of its own, the rest
               flowing under it. A <td data-label="Faction"> shows "Faction: " in front of its value; the header row
               is hidden from sight but still read out.
   Modes       .adv-only is hidden in Simple mode (D-48).
   Feedback    set_flash() / the "studio-flash" and "studio-saved" events show the toast and the "Saved" note (base.html). */
:root {
  --bg: #111315;
  --panel: #1a1d21;
  --panel-2: #22262b;
  --border: #30363d;
  --text: #ece6d8;
  --muted: #9aa2ab;
  --accent: #d0a948;
  --accent-ink: #1a1405;
  --red: #b8453d;
  --ok: #6aa870;
  --warn: #d9a13a;
  --err: #e0655b;
  --draft: #7d9fd4;
  --radius: 8px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --header-h: 3.5rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-padding-top: var(--header-h); }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; letter-spacing: .01em; }
h2 { font-size: 1.15rem; }
h3 { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }
p { margin: 0 0 .8rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
/* keyboard focus is always visible (fields draw their own ring below) */
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 1.2rem;
  padding: .55rem 1rem; background: #0b0c0e; border-bottom: 2px solid var(--red);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 800; letter-spacing: .06em; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 600; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; align-items: center; }
.topbar nav a { color: var(--muted); padding: .3rem .65rem; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.topbar nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.me {
  display: inline-flex; align-items: center; gap: .4rem; color: var(--text);
  border: 1px solid var(--border); border-radius: 999px; padding: .2rem .75rem; white-space: nowrap;
  max-width: 14rem;
}
.me span { overflow: hidden; text-overflow: ellipsis; }  /* a 40-character name must not push the bar onto two rows */
.me::before { content: ""; flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); }
.me:hover { border-color: var(--accent); text-decoration: none; }
.me.anon::before { background: var(--muted); }

main { max-width: 1240px; margin: 0 auto; padding: 1.4rem 1rem 3rem; }
.crumbs { color: var(--muted); font-size: .88rem; margin-bottom: .4rem; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* panels & grids */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.panel + .panel { margin-top: 1rem; }
.split > .panel { margin-top: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); }
.grid-fill { display: flex; flex-wrap: wrap; gap: 1rem; }
.grid-fill > * { flex: 1 1 230px; max-width: calc(50% - .5rem); }
@media (max-width: 700px) { .grid-fill > * { max-width: none; } }
.split { display: grid; gap: 1.2rem; grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }  /* not 1fr: a wide table would push the page sideways */
.card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; color: var(--text); }
a.card:hover { border-color: var(--accent); text-decoration: none; }
.card .big { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.card .label { color: var(--muted); font-size: .85rem; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px;
  padding: .45rem .9rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
/* a file input's "Choose file" button is a .btn too */
input[type=file] { color: var(--muted); }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px; margin-right: .6rem;
  padding: .45rem .9rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); }
input[type=file]::file-selector-button:hover { border-color: var(--accent); }
.btn-primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover, .btn.primary:hover { filter: brightness(1.08); }
.btn-danger, .btn.danger { color: var(--err); }
.btn-danger:hover, .btn.danger:hover { border-color: var(--err); }
.btn-quiet { background: none; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--text); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; min-height: 24px; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: .1rem .45rem; border-radius: 4px; border: 1px solid currentColor; vertical-align: middle; }
.badge.draft { color: var(--draft); }
.badge.published { color: var(--ok); }
.badge.retired { color: var(--muted); }
.badge.error { color: var(--err); }
.badge.warning { color: var(--warn); }
.badge.info { color: var(--draft); }

/* tables */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data td { vertical-align: baseline; }  /* a cell in smaller type (a date) lines up with its row's first line */
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
table.data tr:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* tabs / filters */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs a { padding: .25rem .7rem; margin-right: .2rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: .88rem; }
.tabs a.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.toolbar { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: .6rem; }
.toolbar > h2 { margin: 0; }

/* forms */
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0 0 1rem; background: var(--panel); }
legend { padding: 0 .4rem; color: var(--accent); font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.field { margin-bottom: .85rem; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.field .err { color: var(--err); font-size: .85rem; margin-top: .2rem; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--err); }
.req { color: var(--err); margin-left: .15rem; }
input[type=text], input[type=number], input[type=search], input[type=date], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: #0f1113; border: 1px solid var(--border);
  border-radius: 6px; padding: .45rem .6rem;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 7rem; resize: vertical; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 600; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.form-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .8rem 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.form-actions input[type=text] { flex: 1; min-width: 12rem; }

/* notices */
.notice { padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.notice.ok { border-color: var(--ok); color: var(--ok); background: rgba(106, 168, 112, .08); }
.notice.warn { border-color: var(--warn); color: var(--warn); background: rgba(217, 161, 58, .08); }
.notice.err { border-color: var(--err); color: var(--err); background: rgba(224, 101, 91, .08); }

/* history & diffs */
.history { list-style: none; margin: 0; padding: 0; }
.history > li { border-left: 2px solid var(--border); padding: 0 0 .9rem .8rem; position: relative; }
.history > li::before { content: ""; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--panel-2); border: 2px solid var(--accent); }
.history .meta { font-size: .85rem; }
.history .meta strong { color: var(--text); }
.history .msg { font-style: italic; color: var(--muted); font-size: .88rem; }
.changes { list-style: none; margin: .3rem 0 0; padding: 0; font-size: .85rem; }
.changes li { margin: .15rem 0; overflow-wrap: anywhere; }
.changes .path { font-family: var(--mono); color: var(--accent); }
.changes del { color: var(--err); text-decoration: line-through; opacity: .85; }
.changes ins { color: var(--ok); text-decoration: none; }
details summary { cursor: pointer; color: var(--muted); font-size: .85rem; }

/* name picker */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin: 1rem 0 1.4rem; }
.people button { font: inherit; font-size: 1.1rem; font-weight: 700; padding: 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
.people button:hover { border-color: var(--accent); }
.people button.else { border-style: dashed; color: var(--muted); font-weight: 600; }
.people button.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.narrow { max-width: 640px; margin: 0 auto; }

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-list li { padding: .35rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.issue-list li:last-child { border-bottom: 0; }
.empty { color: var(--muted); font-style: italic; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 1.4rem 1rem; color: var(--muted); text-align: center; }
.empty-state p { margin: 0; }
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-rows > li { display: flex; align-items: center; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; padding: .6rem 0; border-top: 1px solid var(--border); }
.gap-below { margin-bottom: 1.4rem; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-err { color: var(--err); }
[x-cloak] { display: none !important; }
/* D-48: Simple mode (the default) hides advanced options; the switch is in the top bar */
.mode-simple .adv-only { display: none !important; }
/* the Simple | Advanced switch after the nav: two buttons, the pressed one is the mode you are in */
.mode-switch { margin: 0; display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.mode-switch button { font: inherit; font-size: .85rem; font-weight: 600; padding: .25rem .6rem; border: 0; background: var(--panel-2); color: var(--muted); cursor: pointer; }
.mode-switch button:hover { color: var(--text); }
.mode-switch button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }
.mode-switch button:focus-visible { outline-offset: -2px; outline-color: var(--text); }

/* a nav strip that scrolls sideways (phones) shows a fade and a chevron at an edge with more links past it (base.html
   sets the classes). Each is stuck to its edge and takes no width of its own (the negative margin). */
.topbar nav::before, .topbar nav::after { display: none; position: sticky; z-index: 1; flex: none; width: 1.75rem; align-self: stretch;
  align-items: center; pointer-events: none; color: var(--accent); font-size: 1.4rem; font-weight: 700; }
.topbar nav.more-left::before { content: "‹"; display: flex; left: 0; margin-right: -1.75rem; background: linear-gradient(to right, #0b0c0e 55%, transparent); }
.topbar nav.more-right::after { content: "›"; display: flex; justify-content: flex-end; right: 0; margin-left: -1.75rem; background: linear-gradient(to left, #0b0c0e 55%, transparent); }
/* phones: brand, search and name on one 48px row that scrolls away; only the row under it stays stuck (the negative
   top): the nav, one strip that scrolls sideways if it must, and the mode switch in a cell of its own beside it. */
@media (max-width: 700px) {
  :root { --header-h: 3rem; }
  /* a grid, so the first row can never wrap: a long name shrinks (its column may go down to nothing) */
  .topbar { display: grid; grid-template-columns: auto 1fr auto minmax(0, max-content); grid-template-rows: 48px 44px; gap: 0 .6rem; padding: 0 .75rem; top: -48px; }
  .topbar > .brand { grid-area: 1 / 1; }
  .topbar > .gsearch { grid-area: 1 / 3; margin: 0; }
  .topbar > .me { grid-area: 1 / 4; min-width: 0; max-width: 8.5rem; justify-self: end; }  /* its column is the switch's too */
  .topbar nav { grid-area: 2 / 1 / 3 / 4; min-width: 0; flex-wrap: nowrap; gap: 0; overflow-x: auto; scrollbar-width: none; }
  .topbar nav a { flex: none; min-height: 40px; display: inline-flex; align-items: center; padding: .3rem .5rem; }
  .topbar > .mode-switch { grid-area: 2 / 4; justify-self: end; }
  .mode-switch button { min-height: 40px; padding: .25rem .4rem; font-size: .8rem; }
  main { padding: 1rem .75rem 2.5rem; }
  /* iOS zooms into any field under 16px; !important beats the per-class font sizes */
  input, select, textarea { font-size: 16px !important; }
  /* fingers, not a mouse pointer: every button and unit pick at least 40px tall (and wide: the icon-only ✕ buttons) */
  .btn, .btn.small, .pick-unit, .roster-list li a { min-height: 40px; min-width: 40px; }
  .btn-primary:not(.small), .btn.primary:not(.small) { min-height: 44px; }
  .pick-unit, .roster-list li a { align-items: center; }
  .filters label { width: 100%; }
  /* the dashboard's buttons: the main one across, the others in equal halves, every one 44px */
  .dash-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dash-actions > .btn-primary { grid-column: 1 / -1; }
  .dash-actions > .btn, .list-rows .btn-row > .btn { min-height: 44px; }
  .list-rows .btn-row > .btn { min-width: 7rem; }
}

.name-form { display: flex; gap: .6rem; margin: 1rem 0; }
.name-form input { font-size: 1.15rem; padding: .6rem .8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* table.stack-phone: see the top of this file */
@media (max-width: 700px) {
  table.stack-phone thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack-phone, table.stack-phone tbody { display: block; }
  table.stack-phone tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .8rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
  table.stack-phone td, table.stack-phone tbody th { display: block; border: 0; padding: .1rem 0; }
  table.stack-phone td:first-child, table.stack-phone tbody th:first-child { flex-basis: 100%; }
  table.stack-phone td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  table.stack-phone td:empty { display: none; }
}

.choice-new { display: flex; gap: .4rem; align-items: center; }
.choice-new input { flex: 1; }
dl.dv { display: grid; grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr); gap: .25rem .9rem; margin: 0; }
dl.dv dt { color: var(--muted); font-size: .85rem; text-transform: capitalize; }
dl.dv dd { margin: 0; }
table.data.compact th, table.data.compact td { padding: .3rem .45rem; font-size: .88rem; }
.pre { white-space: pre-wrap; }
.section-head { margin: 1.6rem 0 .6rem; }
.section-head:first-of-type { margin-top: 0; }

/* unit editor */
.row2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: .2rem 1rem; }
.rows { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.row-line { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.row-line > .picker { flex: 1 1 220px; min-width: 200px; }
.picker { display: inline-flex; gap: .3rem; align-items: center; width: 100%; }
.picker select { width: 100%; }
.picker-new { display: flex; gap: .3rem; align-items: center; width: 100%; }
.picker-new input { flex: 1; min-width: 8rem; }
.w-xs { width: 4.2rem !important; }
.w-s { width: 7rem !important; }
.w-m { width: 11rem !important; }
.w-l { width: 16rem !important; max-width: 100%; }
.slot { border: 1px solid var(--border); border-radius: 6px; padding: .6rem .7rem; margin-bottom: .7rem; background: var(--panel-2); }
.slot-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.slot-head strong { flex: 1; }
.expr { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.expr code { background: #0f1113; padding: .3rem .5rem; border-radius: 4px; border: 1px solid var(--border); }
table.loadout th { width: 12rem; font-size: .85rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.sticky-actions { position: sticky; bottom: .5rem; z-index: 5; box-shadow: 0 -4px 16px rgba(0,0,0,.4); }
.big-num { font-size: 2rem; font-weight: 800; color: var(--accent); }
.notice.small { font-size: .85rem; padding: .4rem .6rem; }
.notice ul { margin: .3rem 0 0 1.2rem; padding: 0; }

.summary-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; gap: .35rem; align-items: center; padding: .2rem .55rem; border: 1px solid var(--border); border-radius: 999px; color: var(--text); font-size: .85rem; }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.on { border-color: var(--accent); background: rgba(208, 169, 72, .12); }
.chip-x { display: inline-flex; align-items: center; justify-content: center; min-width: 1.4rem; min-height: 1.4rem; margin-right: -.3rem; border-radius: 50%; color: var(--muted); }
.chip-x:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
a.badge:hover { text-decoration: none; filter: brightness(1.2); }
a.badge { display: inline-flex; align-items: center; min-height: 24px; }  /* badge links (Health counts) stay tappable */

.field-label { font-weight: 600; margin-bottom: .25rem; }
.faction-picks { display: flex; flex-wrap: wrap; gap: .4rem 2rem; }
.faction-col { display: flex; flex-direction: column; gap: .1rem; min-width: 170px; }
.faction-picks .check { font-weight: 500; }
.faction-picks .depth-0 { font-weight: 700; color: var(--accent); }
.faction-picks .depth-1 { padding-left: 1rem; }
.faction-picks .depth-2 { padding-left: 2rem; }
.faction-picks .depth-3 { padding-left: 3rem; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { padding: .15rem 0; }
.tree .depth-0 { font-weight: 700; margin-top: .4rem; }
.tree .depth-1 { padding-left: 1.2rem; }
.tree .depth-2 { padding-left: 2.4rem; }
.tree .depth-3 { padding-left: 3.6rem; }
.bulk-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; padding: .6rem .8rem; }

/* builder */
.pointsbar { display: flex; align-items: center; gap: .8rem; padding: .6rem .9rem; margin-bottom: 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); font-size: 1.1rem; flex-wrap: wrap; }
.pointsbar strong { font-size: 1.5rem; color: var(--accent); }
.pointsbar.over strong { color: var(--err); }
.pointsbar .bar { flex: 1; min-width: 120px; height: .6rem; background: #0f1113; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.pointsbar .bar span { display: block; height: 100%; background: var(--accent); }
.pointsbar.over .bar span { background: var(--err); }
td.over { color: var(--err); font-weight: 700; }
.builder-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .builder-grid { grid-template-columns: minmax(0, 1fr); } }
.roster-list { list-style: none; margin: 0; padding: 0; }
.roster-list li a { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem .5rem; border-radius: 6px; color: var(--text); }
.roster-list li a:hover { background: var(--panel-2); text-decoration: none; }
.roster-list li.on a { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.unit-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.unit-head h2 { margin: 0; font-size: 1.3rem; }
.picker-list { max-height: 60vh; overflow-y: auto; }
.pick-faction { margin: .6rem 0 .2rem; color: var(--accent); }
.pick-cat { margin: .4rem 0 .1rem; text-transform: uppercase; letter-spacing: .05em; font-size: .72rem; }
.pick-unit { display: flex; justify-content: space-between; width: 100%; gap: .5rem; font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
  background: none; border: 0; border-radius: 5px; padding: .3rem .4rem; color: var(--text); }
.pick-unit:hover { background: var(--panel-2); }
.loadout-form table th { width: 11rem; }

.template-panel { margin-bottom: 1rem; }
.template-panel summary { cursor: pointer; color: var(--text); font-size: .95rem; }

.vet-choice { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: .3rem; }
.vet-btn { font: inherit; font-weight: 600; padding: .4rem .8rem; background: #0f1113; color: var(--text); border: 0; border-right: 1px solid var(--border); cursor: pointer; }
.vet-btn:last-child { border-right: 0; }
.vet-btn.on { background: var(--accent); color: var(--accent-ink); }
.vet-btn:disabled { color: var(--muted); opacity: .45; cursor: not-allowed; }

/* Excel bridge */
ul.plain { list-style: none; margin: .3rem 0; padding: 0; }
ul.plain > li { margin: .25rem 0; overflow-wrap: anywhere; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.diff-entity { border-top: 1px solid var(--border); padding: .6rem 0; }
.diff-entity h3 { margin: 0 0 .3rem; font-size: 1rem; }
.diff-list label.check { align-items: baseline; }

/* changelog */
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end; }
.filters label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .2rem; width: 14rem; max-width: 100%; }
/* a short menu (no search box) looks like the long ones: the same width and the same ▾ */
.filters label > select:not(.combo-native) { appearance: none; padding-right: 1.7rem; cursor: pointer;
  background: #0f1113 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%239aa2ab'/%3E%3C/svg%3E") no-repeat right .65rem center; }
.pager { display: flex; gap: .5rem; margin: 1rem 0; }
.nowrap { white-space: nowrap; }
.diff-table td { vertical-align: top; overflow-wrap: anywhere; }
.diff-table del { color: var(--err); text-decoration: line-through; opacity: .85; }
.diff-table ins { color: var(--ok); text-decoration: none; }
.diff-table .path { color: var(--accent); }
.notes h2 { font-size: 1.3rem; } .notes h3 { font-size: 1.05rem; margin-top: 1.1rem; }
.notes ul { padding-left: 1.2rem; }

/* global search */
.gsearch { margin-left: auto; margin-right: .6rem; }
.gsearch kbd { font-family: var(--mono); font-size: .7rem; opacity: .7; margin-left: .3rem; }
.gsearch-modal { width: min(640px, calc(100% - 32px)); max-width: none; margin: 10vh auto 0; padding: 0; border: 0; background: none; color: inherit; }
.gsearch-modal::backdrop { background: rgba(0, 0, 0, .55); }
.gsearch-box { max-height: 70vh; overflow: auto; }
.gsearch-head { display: flex; gap: .5rem; align-items: center; }
.gsearch-head input { flex: 1; min-width: 0; font-size: 1.05rem; }
.search-results { list-style: none; margin: .6rem 0 0; padding: 0; }
.search-results a { display: block; padding: .35rem .4rem; border-radius: 6px; }
.search-results a:hover, .search-results a:focus { background: var(--panel-2); text-decoration: none; }
.search-results .excerpt { display: block; }
@media (max-width: 700px) {
  .gsearch kbd { display: none; }
  .gsearch-modal { margin-top: 1rem; }
  .gsearch-box { max-height: 80vh; }
  .search-results a { padding: .6rem .4rem; }
}

/* searchable dropdowns (D-26): the box is the control you see. It shows the current choice (as its placeholder) until
   you type; the popup list is placed, fixed, on screen by searchable-selects.js. The native select stays the source
   of truth: 1px and see-through, so forms, labels and tests still work it, but it takes no room. */
.combo { position: relative; display: inline-block; vertical-align: middle; width: 100%; max-width: 100%; }
.combo .select-search { width: 100%; padding-right: 1.7rem; text-overflow: ellipsis; }
.combo .select-search::placeholder { color: var(--text); opacity: 1; }
.combo .select-search:focus::placeholder { color: var(--muted); }
.combo .select-search[aria-invalid=true] { border-color: var(--err); }
.combo::after { content: "▾"; position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.combo:focus-within::after { display: none; }  /* the box's own clear button sits there while you type */
select.combo-native { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.combo-list { position: fixed; z-index: 40; margin: 0; padding: .2rem 0; list-style: none; overflow-y: auto; overflow-x: hidden;
  width: max-content; max-width: min(30rem, calc(100vw - 8px)); background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, .6); }
.combo-list[hidden] { display: none; }
.combo-list li { padding: .35rem .7rem; cursor: pointer; overflow-wrap: anywhere; }
.combo-list li[aria-selected=true] { font-weight: 700; }
.combo-list li.on, .combo-list li[role=option]:hover { background: var(--accent); color: var(--accent-ink); }
.combo-list li.combo-none { color: var(--muted); cursor: default; }
.combo-list mark { background: none; color: inherit; text-decoration: underline; font-weight: 700; }
@media (max-width: 700px) {
  .combo-list li { padding: .6rem .7rem; }  /* 40px tall. Not a flex box: that put each piece around a highlighted match in its own column */
}

/* global htmx feedback: a sliding bar at the top while any request runs, busy cursor, dimmed buttons */
.htmx-request { cursor: progress; }
button.htmx-request, .btn.htmx-request { opacity: .6; pointer-events: none; }
body:has(.htmx-request)::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) 0 0 / 40% 100% no-repeat;
  animation: htmx-bar 1s ease-in-out infinite;
}
@keyframes htmx-bar { from { background-position: -40% 0; } to { background-position: 140% 0; } }
@media (prefers-reduced-motion: reduce) { body:has(.htmx-request)::before { animation: none; background-size: 100% 100%; opacity: .6; } }

/* the toast (script in base.html): errors, and a handler's flash message with its Undo button */
.toast {
  position: fixed; left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 120;
  width: fit-content; max-width: min(32rem, calc(100vw - 2rem)); margin: 0 auto; padding: .7rem 1rem; border-radius: var(--radius); cursor: pointer;
  background: #2a1513; color: var(--text); border: 1px solid var(--err); box-shadow: 0 6px 24px rgba(0, 0, 0, .6); font-weight: 600;
}
.toast[hidden] { display: none; }
.toast.flash { display: flex; align-items: center; gap: .8rem; background: var(--panel-2); border-color: var(--accent); }
.toast.flash[hidden] { display: none; }
.toast form { margin: 0 0 0 auto; }
/* "Saved ✓" (script in base.html): a small note that comes and goes, clear of the toast */
.saved-note {
  position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 110; pointer-events: none;
  padding: .3rem .7rem; border-radius: 999px; background: var(--panel-2); color: var(--ok); border: 1px solid var(--ok); font-size: .85rem; font-weight: 600;
}
.saved-note[hidden] { display: none; }

/* builder: unit action bar, summary, abilities with their rule on hover / tap / keyboard focus */
.unit-actions { margin-bottom: .7rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.unit-summary { margin-bottom: .6rem; }
.unit-summary p { margin: .25rem 0; }
.abilities { position: relative; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: .4rem 0; }
.ability { border: 1px dashed var(--border); border-radius: 999px; padding: .1rem .55rem; font-size: .85rem; cursor: help; }
.ability:hover, .ability:focus { border-color: var(--accent); }
.ability-tip { display: none; position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin-top: .25rem; padding: .5rem .7rem;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: var(--radius); font-size: .85rem; white-space: pre-line;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5); }
.ability:hover .ability-tip, .ability:focus .ability-tip { display: block; }
/* an in-place save briefly holds the old and new #builder; anchoring to the old one would scroll the page away */
.builder { overflow-anchor: none; }
/* phone: each loadout label sits above its menu, so the menu (with its points) gets the full width */
@media (max-width: 700px) {
  .loadout-form table.data tr, .loadout-form table.data th, .loadout-form table.data td { display: block; width: auto; }
  .loadout-form table.data th { border-bottom: 0; padding-bottom: 0; }
  /* fingers: the links, chips and toggles tapped outside the nav are 40px tall too (after a.badge's 24px above) */
  /* only a cell's own links: a link inside a sentence (a div or span of text) stays inline, so its line isn't 40px tall */
  .me, .tabs a, .crumbs a, a.badge, .chip, table.data td > a, table.data th > a, .card h2 > a { display: inline-flex; align-items: center; min-height: 40px; }
  details > summary { min-height: 40px; padding: .6rem 0; }
  input[type=file], input[type=date] { min-height: 40px; }
  label.check { min-height: 40px; min-width: 40px; }  /* the whole label toggles its checkbox or radio, so it is the tap target */
  label.check > input[type=checkbox] { width: 22px; height: 22px; }
  .ability, .issue-list a, .help-toc a, .chip-x { display: inline-flex; align-items: center; min-height: 40px; }
  .ability { padding: .1rem .8rem; }
  .vet-btn { min-height: 40px; min-width: 40px; }
  td > input[type=checkbox], th > input[type=checkbox] { width: 28px; height: 28px; margin: 6px; }  /* a bare one: 40px with its margin */
}

/* D-62: the footer's quiet link to /suggestions, and the shift-click suggestion box (js/suggest.js places it by the click) */
.foot { max-width: 1240px; margin: 0 auto; padding: 0 1rem 1.5rem; }
.foot a { color: var(--muted); }
.foot .count { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-align: center; }
.suggest { position: fixed; inset: auto; margin: 0; padding: 0; border: 0; background: none; color: inherit; width: min(24rem, calc(100vw - 16px)); max-width: none; }
.suggest::backdrop { background: rgba(0, 0, 0, .35); }
.suggest form { margin: 0; border-color: var(--accent); box-shadow: 0 6px 24px rgba(0, 0, 0, .6); }
.suggest p { overflow-wrap: anywhere; }
.suggest textarea { min-height: 5.5rem; margin-bottom: .5rem; }
.suggestions > li { flex-wrap: nowrap; align-items: flex-start; }
.suggestion-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.suggestion-body p { margin: .2rem 0; }
@media (max-width: 700px) {
  .suggest { left: 8px !important; right: 8px; top: 1rem !important; width: auto; }  /* a phone: across the top, wherever the hold was */
  .suggestions > li { flex-wrap: wrap; }
}
