/* Reusable form and custom-weapon layout styles.
   Keep shared sizing/layout rules here to avoid scattering tweaks in index.html.
   Checkbox styling matches picklists (var(--bg)); checked state uses var(--accent) in the SVG. */

/* With bindDisableFieldDragDrop (index.html): no dragging text out of fields / dropping into them. */
input,
textarea,
select {
  -webkit-user-drag: none;
}

/* Turquoise text selection (replaces default system blue highlight). */
::selection {
  background: var(--accent);
  color: var(--on-accent);
}
::-moz-selection {
  background: var(--accent);
  color: var(--on-accent);
}

/* Native picklists: tint focus / list UI toward app accent where the engine allows. */
select {
  accent-color: var(--accent);
}

select option {
  background-color: var(--bg);
  color: var(--text);
}

select option:hover,
select option:focus {
  background: var(--accent);
  color: var(--on-accent);
}

select option:checked {
  background: color-mix(in srgb, var(--accent) 28%, var(--surface));
  color: var(--text);
}

/* Custom picklist (replaces native Windows/Chrome dropdown — system uses unstylable blue highlight). */
.custom-picklist-shell {
  position: relative;
  width: 100%;
  min-width: 0;
  /* Match `.field select` in index.html (body has no font-size; inherit was ~16px). */
  font-size: 0.9rem;
  font-weight: 400;
  line-height: normal;
}

.custom-picklist-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.custom-picklist-trigger {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  position: relative;
}

.custom-picklist-trigger.custom-picklist-trigger--unit {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.custom-picklist-unit-points {
  color: var(--accent);
  font-weight: 700;
  flex: 0 0 3.1rem;
  padding: 0 0.35rem;
  text-align: center;
}

.custom-picklist-unit-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-picklist-trigger:hover {
  border-color: var(--accent);
}

.custom-picklist-trigger:focus {
  outline: none;
  border-color: var(--accent);
}

.custom-picklist-trigger::after {
  content: '';
  position: absolute;
  right: 0.7rem;
  top: 50%;
  margin-top: -0.2rem;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
  opacity: 0.85;
}

.custom-picklist-panel {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 80;
  max-height: min(22rem, 60vh);
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

/* Author `display: flex` on --filterable must not beat the HTML hidden attribute */
.custom-picklist-panel[hidden] {
  display: none !important;
}

/* Faction / unit search: filter stays visible; options scroll below.
   Keep position from `.custom-picklist-panel` (absolute); do not use relative here — it
   would put the open panel in normal flow and shift the whole page. `.custom-picklist-shell`
   is already `position: relative` for positioning. */
.custom-picklist-panel.custom-picklist-panel--filterable {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

/* Search field hidden until the user types (see index.html picklist mount). */
.custom-picklist-panel--filterable.custom-picklist-panel--filter-collapsed .custom-picklist-filter {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.custom-picklist-filter {
  box-sizing: border-box;
  width: 100%;
  flex: 0 0 auto;
  margin: 0;
  padding: 0.45rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
}

.custom-picklist-filter:focus {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.custom-picklist-panel .custom-picklist-options {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.custom-picklist-empty {
  padding: 0.65rem 1.125rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.custom-picklist-group-label {
  padding: 0.2625rem 1.125rem 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
  /* Avoid position:sticky on each optgroup label — they stack at top:0 and overlap while scrolling. */
}

.custom-picklist-option {
  display: block;
  box-sizing: border-box;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 0.36rem 1.125rem;
  font: inherit;
  cursor: pointer;
}

.custom-picklist-option.custom-picklist-option--unit {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.custom-picklist-option:last-child {
  border-bottom: none;
}

/* Top match while filter text is active (first row of filtered list) */
.custom-picklist-option.custom-picklist-option--filter-first {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}

.custom-picklist-option.custom-picklist-option--filter-first:hover,
.custom-picklist-option.custom-picklist-option--filter-first:focus {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Dim turquoise for current value — visible in closed trigger via sync; in open panel too */
.custom-picklist-option.is-selected {
  background: color-mix(in srgb, var(--accent) 28%, var(--surface));
  color: var(--text);
}

/* openPanel() focuses the selected row; keep dim turquoise instead of bright --accent-hover */
.custom-picklist-option.is-selected:focus {
  background: color-mix(in srgb, var(--accent) 30%, var(--surface));
  color: var(--text);
  outline: none;
}

.custom-picklist-option.is-selected:hover {
  background: color-mix(in srgb, var(--accent) 40%, var(--surface));
  color: var(--text);
}

.custom-picklist-option:hover,
.custom-picklist-option:focus {
  background: var(--accent-hover);
  color: var(--on-accent);
  outline: none;
}

/* Desktop (768px+): roomy faction/unit picklists; one-line option labels */
@media (min-width: 768px) {
  #attackerPanel > .row > .field:has(#attackerFaction) {
    flex: 1 1 18rem;
    min-width: 16rem;
    max-width: 34rem;
  }

  #attackerPanel > .row > .field:has(#attackerWeaponType) {
    flex: 0 0 auto;
    min-width: 9rem;
  }

  .panel .row > .field:has(#targetFaction) {
    flex: 1 1 16rem;
    min-width: 14rem;
    max-width: 28rem;
  }

  .panel .row > .field:has(#targetUnit) {
    flex: 2 1 26rem;
    min-width: 22rem;
    max-width: none;
  }

  #attackerPanel .attacker-unit-card .attacker-unit-header-row {
    flex-wrap: nowrap;
    gap: 0.75rem;
    align-items: center;
  }

  /* Catalogue unit row: Unit field grows; Models + remove stay compact */
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:has([data-role="unit-select"]) {
    flex: 1 1 24rem;
    min-width: 22rem;
    max-width: 52rem;
  }

#attackerPanel .attacker-unit-card .attacker-unit-header-row .field:has([data-role="remove-instance"]) {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  align-self: center;
  width: auto;
  min-width: 0;
}

@media (max-width: 767px) {
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:has([data-role="unit-select"]) {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
  }
}

  .field:has(#attackerFaction) .custom-picklist-trigger,
  .field:has(#targetFaction) .custom-picklist-trigger,
  .field:has(#targetUnit) .custom-picklist-trigger,
  .field:has([data-role="unit-select"]) .custom-picklist-trigger {
    white-space: nowrap;
    padding: 0.275rem 2.15rem 0.275rem 0.9rem;
  }

  .field:has(#attackerFaction) .custom-picklist-trigger,
  .field:has(#targetFaction) .custom-picklist-trigger,
  .field:has(#targetUnit) .custom-picklist-trigger,
  .field:has([data-role="unit-select"]) .custom-picklist-trigger {
    min-height: 37px;
  }

  .field:has(#attackerFaction) .custom-picklist-option,
  .field:has(#targetFaction) .custom-picklist-option,
  .field:has(#targetUnit) .custom-picklist-option,
  .field:has([data-role="unit-select"]) .custom-picklist-option {
    white-space: nowrap;
    padding: 0.4125rem 2px;
  }

  /* Widen list to longest option (not only trigger width) */
  .field:has(#attackerFaction) .custom-picklist-panel,
  .field:has(#targetFaction) .custom-picklist-panel,
  .field:has(#targetUnit) .custom-picklist-panel,
  .field:has([data-role="unit-select"]) .custom-picklist-panel {
    width: max-content;
    min-width: 100%;
    /* cap to viewport so width:max-content cannot force page scroll (exact cap refined in JS on open) */
    max-width: min(52rem, 96vw, calc(100vw - 1rem));
  }

  /* Keep catalogue model rows constrained on mobile cards. */
  #attackerPanel .catalogue-model-row,
  #attackerPanel .catalogue-model-row__title-wrap,
  #attackerPanel .catalogue-model-row__body,
  #attackerPanel .catalogue-model-row__main,
  #attackerPanel .catalogue-model-row__selection,
  #attackerPanel .catalogue-model-row__slot-block,
  #attackerPanel .catalogue-model-row .field,
  #attackerPanel .catalogue-model-row .custom-picklist-shell,
  #attackerPanel .catalogue-model-row .custom-picklist-trigger {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }
  #attackerPanel .catalogue-model-row {
    overflow: visible;
  }
  #attackerPanel .catalogue-model-row .custom-picklist-panel {
    z-index: 140;
  }
  #attackerPanel .catalogue-model-row__selection {
    flex: 1 1 100%;
    width: 100%;
  }
  #attackerPanel .catalogue-model-row__checkboxes .checkbox-label {
    width: 100%;
    min-width: 0;
    align-items: flex-start;
  }
  #attackerPanel .catalogue-model-row__checkboxes .checkbox-label > span {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

/* Same surface as .field select / picklists; turquoise checkmark when checked */
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  vertical-align: middle;
  cursor: pointer;
  font: inherit;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.65rem auto;
}

input[type="checkbox"]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%2314d9c4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.2L5 8.8l4.5-5.6'/%3E%3C/svg%3E");
}

/* Radio: black surface, turquoise selection dot */
input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  vertical-align: middle;
  cursor: pointer;
  font: inherit;
  background-color: #000;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-grid;
  place-content: center;
}

input[type="radio"]::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: #14d9c4;
  transform: scale(0);
  transition: transform 120ms ease-in-out;
}

input[type="radio"]:checked::before {
  transform: scale(1);
}

/* Shared label style for checkbox-like inline controls */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.3;
}

/* Beat `.field label { color: var(--muted); }` from index.html */
.field label.checkbox-label {
  color: var(--text);
}

.checkbox-label--static {
  cursor: default;
}

/* Author `display` on .checkbox-label must not defeat the HTML `hidden` attribute */
.checkbox-label[hidden] {
  display: none !important;
}

.panel-subsection[hidden] {
  display: none !important;
}

.field input[type="checkbox"],
.attacker-unit-card .field input[type="checkbox"],
.attacker-unit-card .checkbox-label input[type="checkbox"] {
  padding: 0;
  width: 1.125rem;
  height: 1.125rem;
  min-width: 1.125rem;
}

.btn-dark {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  /* Match main action button sizing in attacker cards */
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-dark:hover {
  border-color: var(--accent);
}

.btn-dark.btn-danger:hover {
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--danger);
}

.btn-icon {
  /* Match other small icon buttons (remove/duplicate) */
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-icon svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

/* Ensure icon buttons stay compact inside attacker cards (override the more-specific action button rules in index.html). */
.attacker-unit-card button.btn-icon {
  width: 2rem;
  height: 2rem;
  padding: 0;
  min-width: 2rem;
}

/* Extra top margin when Keywords follows Abilities (defender profile). Pairs with .unit-section-title */
.defender-section-title--keywords {
  margin-top: 0.9rem;
}

.defender-keywords-text {
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Let panels/cards use full horizontal space (no extra side inset) */
body {
  padding-inline: 0;
}

.field input[type="number"],
.attacker-unit-card .field input[type="number"] {
  min-width: 0;
  width: auto;
  inline-size: 6.5ch;
  max-inline-size: 8ch;
}

/* Catalogue model type count (#): 3 digits; hide steppers so they don’t overlap digits (Win/Chrome). */
.catalogue-model-card__qty-field input[type="number"][data-role="catalogue-model-type-count"],
input[type="number"][data-role="catalogue-model-type-count"] {
  box-sizing: border-box;
  -moz-appearance: textfield;
  appearance: textfield;
  inline-size: 9ch;
  min-inline-size: 9ch;
  max-inline-size: 11ch;
  text-align: center;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}
.catalogue-model-card__qty-field input[type="number"][data-role="catalogue-model-type-count"]::-webkit-outer-spin-button,
.catalogue-model-card__qty-field input[type="number"][data-role="catalogue-model-type-count"]::-webkit-inner-spin-button,
input[type="number"][data-role="catalogue-model-type-count"]::-webkit-outer-spin-button,
input[type="number"][data-role="catalogue-model-type-count"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Label left of control (e.g. strat reroll damage threshold) */
.field.field--inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}

.field.field--inline label {
  margin: 0;
  flex-shrink: 0;
}

/* .custom-picklist-shell defaults to width:100% for stacked fields; in row layouts that
   resolves against .field and draws the trigger over the label. Share remaining width instead. */
.field.field--inline .custom-picklist-shell {
  width: auto;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
}

.custom-weapon-editor {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.5rem;
  padding-top: 0.9rem;
  margin-bottom: 0.5rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  position: relative;
}

.custom-weapon-editor .custom-weapon-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
}

.custom-weapon-editor .custom-weapon-title-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  margin: 0;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.custom-weapon-editor .custom-weapon-title-btn:hover {
  color: var(--text);
}

.custom-weapon-editor .custom-weapon-duplicate-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: auto;
}

.custom-weapon-editor .custom-weapon-header-remove-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 6px;
  font-size: 1.2rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.custom-weapon-editor .custom-weapon-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.35rem;
  align-items: end;
  margin-bottom: 0.4rem;
  min-width: 0;
  grid-auto-flow: row;
}

/* Name + # on first full row; Type/Range/stats follow */
.custom-weapon-editor .cw-name-qty-row {
  display: flex;
  flex: 1 1 100%;
  flex-basis: 100%;
  width: 100%;
  align-items: flex-end;
  gap: 0.35rem;
  min-width: 0;
  flex-wrap: nowrap;
}

.custom-weapon-editor .cw-name-qty-row .field--cw-name {
  flex: 1 1 0;
  min-width: 0;
}

.custom-weapon-editor .cw-name-qty-row .field--cw-qty {
  flex: 0 0 4rem;
  min-width: 0;
}

.custom-weapon-editor .field--cw-name,
.custom-weapon-editor .field--cw-range,
.custom-weapon-editor .field--cw-kind,
.custom-weapon-editor .field--cw-qty,
.custom-weapon-editor .field--cw-stat {
  min-width: 0;
  flex: 0 0 auto;
}

.custom-weapon-editor .field--cw-kind { flex: 0 0 9rem; }
.custom-weapon-editor .field--cw-qty { flex: 0 0 4rem; }
.custom-weapon-editor .field--cw-range { flex: 0 0 auto; }
.custom-weapon-editor .field--cw-stat { flex: 0 0 auto; }

/* Treat A/BS(WS)/S/AP/D as one cohesive cluster */
.custom-weapon-editor .cw-stat-pack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5ch, 1fr));
  gap: 0.35rem;
  flex: 1 1 20rem;
  min-width: 0;
}

.custom-weapon-editor .cw-stat-pack .field--cw-stat {
  min-width: 0;
}

.custom-weapon-editor .field--cw-range,
.custom-weapon-editor .field--cw-stat,
.custom-weapon-editor .field--cw-qty {
  align-self: end;
}

.custom-weapon-editor .field--cw-range input {
  width: auto;
  inline-size: 8ch;
  max-inline-size: 10ch;
}

.custom-weapon-editor .field--cw-stat input {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  text-align: center;
  padding-left: 0.2rem;
  padding-right: 0.2rem;
  min-width: 0;
}

.custom-weapon-editor .field--cw-qty input {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  min-width: 0;
}

.custom-weapon-editor.is-collapsed .custom-weapon-fields,
.custom-weapon-editor.is-collapsed .custom-keyword-block {
  display: none;
}

.custom-weapon-editor.is-collapsed {
  padding-top: 0.5rem;
  cursor: pointer;
}

/* Unit/model header action controls */
.custom-unit-header,
.custom-model-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  justify-content: space-between;
}

.custom-unit-header {
  flex-wrap: wrap;
}

.custom-model-header {
  flex-wrap: wrap;
}

.custom-unit-title,
.custom-model-title {
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  margin-right: auto;
}

.custom-unit-name-inline {
  flex: 1 1 12rem;
  min-width: 10rem;
  margin-right: auto;
}

/* Model type name + count: one row on mobile (avoids width:100% per .field stacking) */
.custom-model-name-qty-row {
  display: flex;
  flex: 1 1 12rem;
  min-width: 0;
  align-items: flex-end;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.custom-model-name-qty-row .custom-model-name-inline {
  flex: 1 1 0;
  min-width: 0;
}

.custom-model-name-inline {
  min-width: 0;
}

.custom-unit-name-inline input,
.custom-model-name-inline input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  min-height: 2rem;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
}

.custom-unit-name-inline label,
.custom-model-name-inline label {
  white-space: nowrap;
}

.custom-unit-models-inline {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 0;
}

.custom-unit-models-inline input[type="number"] {
  width: auto;
  min-width: 0;
  inline-size: 6.5ch;
  max-inline-size: 8ch;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  min-height: 2rem;
  padding: 0.3rem 0.4rem;
  font-size: 0.82rem;
  text-align: center;
}

.custom-unit-name-inline input:hover,
.custom-model-name-inline input:hover,
.custom-unit-models-inline input[type="number"]:hover {
  border-color: var(--accent);
}

.custom-unit-name-inline input:focus,
.custom-model-name-inline input:focus,
.custom-unit-models-inline input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
}

/* Custom unit: count of models for this type (row), between name and + */
.custom-model-type-qty-inline {
  flex: 0 0 auto;
  min-width: 0;
}

.custom-model-type-qty-inline label {
  text-align: center;
}

.custom-model-type-qty-inline input[type="number"] {
  width: auto;
  min-width: 0;
  inline-size: 5.5ch;
  max-inline-size: 7ch;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  min-height: 2rem;
  padding: 0.3rem 0.35rem;
  font-size: 0.82rem;
  text-align: center;
  box-sizing: border-box;
}

.custom-model-type-qty-inline input[type="number"]:hover,
.custom-model-type-qty-inline input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
}

.custom-unit-action-btn,
.model-action-icon-btn,
.custom-weapon-editor .custom-weapon-duplicate-btn,
.custom-weapon-editor .custom-weapon-header-remove-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  align-self: end;
}

.custom-model-header [data-role="add-custom-weapon"] {
  align-self: end;
}

.custom-weapon-editor .field--cw-kind select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.custom-weapon-editor .field--cw-name input,
.custom-weapon-editor .field--cw-range input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 767px) {
  /* Full-bleed only on narrow viewports: negative margins break multi-column #attackerUnitComposer on desktop. */
  #attackerPanel {
    --mobile-outer-card-bleed: 1.25rem;
    --mobile-inner-card-bleed: 0.85rem;
  }

  #attackerPanel .attacker-unit-card {
    margin-inline: calc(var(--mobile-outer-card-bleed) * -1);
    border-radius: 0;
  }

  #attackerPanel .custom-model-row,
  #attackerPanel .weapon-profile-card {
    margin-inline: calc(var(--mobile-inner-card-bleed) * -1);
    border-radius: 0;
  }

  #attackerPanel .custom-model-row .weapon-profile-card {
    margin-inline: 0;
    border-radius: 8px;
  }

  #attackerPanel .custom-model-row .custom-weapon-editor {
    width: calc(100% + 1.1rem);
    max-width: none;
    margin-left: -0.55rem;
    margin-right: -0.55rem;
    border-radius: 0;
  }

  /* Match Unit header behavior to Model header on mobile */
  #attackerPanel .custom-unit-header {
    justify-content: flex-start;
    flex-wrap: nowrap;
  }
  #attackerPanel .custom-unit-header .custom-unit-name-inline {
    flex: 1 1 10rem;
    min-width: 0;
    width: auto;
    margin-right: 0;
  }
  #attackerPanel .custom-unit-header .custom-unit-models-inline {
    flex: 0 0 auto;
    width: auto;
    margin-left: 0;
    margin-right: 0;
  }
  #attackerPanel .custom-unit-header .custom-unit-action-btn {
    flex: 0 0 auto;
    align-self: end;
  }

  /* Keep non-custom attacker header controls on one row on mobile */
  #attackerPanel .attacker-unit-card .attacker-unit-header-row {
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 0.35rem;
  }
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field {
    min-width: 0;
  }
  /* Unit: grow; min-width stops the column shrinking to 0 (labels overlapped when width hit 0) */
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:nth-child(1) {
    flex: 1 1 0;
    min-width: clamp(7rem, 42vw, 100%);
  }
  /* Models + icon buttons: fixed intrinsic width only */
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:nth-child(2),
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:nth-child(n + 3) {
    flex: 0 0 auto;
  }
  #attackerPanel .attacker-unit-card .attacker-unit-header-row .field:has([data-role="remove-instance"]) {
    display: flex;
    align-items: center;
    align-self: center;
    width: auto;
    min-width: 0;
  }
  #attackerPanel .attacker-unit-card .attacker-unit-header-row select[data-role="unit-select"] {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .field input[type="number"],
  .attacker-unit-card .field input[type="number"] {
    min-inline-size: 6.5ch;
    inline-size: 6.5ch;
    max-inline-size: 8ch;
    width: auto;
  }

  .catalogue-model-card__qty-field input[type="number"][data-role="catalogue-model-type-count"],
  #attackerPanel input[type="number"][data-role="catalogue-model-type-count"] {
    min-inline-size: 9ch;
    inline-size: 9ch;
    max-inline-size: 11ch;
  }

  /* Name + # row, then Type / Range, then stats */
  #attackerPanel .custom-weapon-editor .custom-weapon-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "nameqty nameqty"
      "kind range"
      "stats stats";
    align-items: end;
  }
  #attackerPanel .custom-weapon-editor .cw-name-qty-row {
    grid-area: nameqty;
    display: flex;
    width: 100%;
    min-width: 0;
    flex-wrap: nowrap;
    flex-basis: auto;
    flex-grow: 0;
  }
  #attackerPanel .custom-weapon-editor .cw-name-qty-row .field--cw-name {
    flex: 1 1 0;
    min-width: 0;
  }
  #attackerPanel .custom-weapon-editor .cw-name-qty-row .field--cw-qty {
    flex: 0 0 4rem;
    width: auto;
  }
  #attackerPanel .custom-weapon-editor .field--cw-kind { grid-area: kind; min-width: 7.5rem; }
  #attackerPanel .custom-weapon-editor .field--cw-range { grid-area: range; width: 6.5rem; }
  #attackerPanel .custom-weapon-editor .cw-stat-pack { grid-area: stats; }

  #attackerPanel .custom-weapon-editor[data-role="catalog-weapon-editor"] .custom-weapon-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "nameqty nameqty"
      "kind range"
      "stats stats";
    align-items: end;
  }
  #attackerPanel .custom-weapon-editor[data-role="catalog-weapon-editor"] .field--cw-kind { grid-area: kind; min-width: 7.25rem; }
  #attackerPanel .custom-weapon-editor[data-role="catalog-weapon-editor"] .field--cw-range { grid-area: range; min-width: 6.25rem; }
  #attackerPanel .custom-weapon-editor[data-role="catalog-weapon-editor"] .cw-stat-pack { grid-area: stats; }

  #attackerPanel .custom-weapon-editor .field--cw-qty input,
  #attackerPanel .custom-weapon-editor .field--cw-range input {
    width: 100%;
    max-width: 100%;
  }

  /* Inline name + # rows: don't let page-wide `.field { width:100% }` stack them */
  #attackerPanel .custom-model-header .custom-model-name-qty-row > .field {
    width: auto;
    max-width: none;
  }
  #attackerPanel .custom-weapon-editor .cw-name-qty-row > .field {
    width: auto;
    max-width: none;
  }

  /* Keep collapse behavior working after mobile grid overrides */
  #attackerPanel .custom-weapon-editor.is-collapsed .custom-weapon-fields {
    display: none;
  }

  /* Don't stretch checkboxes when .field input is full-width on mobile */
  .field input[type="checkbox"] {
    width: 1.125rem;
    min-width: 1.125rem;
    max-width: none;
  }

  /* Unit modifiers — ability rerolls: pair Hit+Link, Wound+Link, Damage+Damage X per row */
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.55rem 0.65rem;
    align-items: end;
    width: 100%;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    max-width: none;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    width: auto;
    max-width: none;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(5) {
    grid-column: 1;
    grid-row: 3;
    min-width: 0;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field:nth-child(6) {
    grid-column: 2;
    grid-row: 3;
    width: auto;
    max-width: none;
  }
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field.ability-builder-link .custom-picklist-shell,
  #attackerPanel .unit-modifiers-panel .ability-builder-grid:not(.unit-modifiers-scope-row) > .field.ability-builder-link .custom-picklist-trigger {
    min-width: 0;
    width: 100%;
    max-width: 5.75rem;
  }

  /* Scope row: weapon type full width; BS/WS and Crit picklists share one row */
  #attackerPanel .unit-modifiers-panel .unit-modifiers-scope-row.ability-builder-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.55rem 0.65rem;
    align-items: end;
    width: 100%;
  }
  #attackerPanel .unit-modifiers-panel .unit-modifiers-scope-row.ability-builder-grid > .field:nth-child(1) {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
  }
  #attackerPanel .unit-modifiers-panel .unit-modifiers-scope-row.ability-builder-grid > .field:nth-child(2) {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
  }
  #attackerPanel .unit-modifiers-panel .unit-modifiers-scope-row.ability-builder-grid > .field:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
  }

}

/* Unit modifiers — flex OR/AND row */
.unit-modifiers-panel .unit-mod-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
  max-width: 42rem;
}

.unit-modifiers-panel .unit-mod-or-and {
  font-weight: 600;
  color: var(--accent);
}

.unit-modifiers-panel input.unit-mod-num-tight {
  width: auto;
  min-width: 0;
  max-width: 5rem;
  inline-size: 5ch;
  text-align: center;
}

.unit-modifiers-panel .ability-builder-grid .field label {
  font-size: 0.78rem;
}

.unit-modifiers-panel .ability-builder-link select {
  min-width: 4.5rem;
}

.custom-model-row {
  margin-bottom: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
  padding: 0.5rem 0.55rem;
}

/* --- Rule debug log (results panel) --- */
button.debug-log-toggle {
  margin-top: 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

button.debug-log-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#debugLogPanel {
  display: none;
  margin-top: 0.75rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
}

#debugLogPanel.is-open {
  display: block;
}

.debug-log-intro {
  color: var(--muted);
  margin: 0 0 0.75rem 0;
}

.debug-log-block {
  margin-top: 0.75rem;
}

.debug-log-block h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.4rem 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.debug-log-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

#debugLogContext.debug-log-context {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.debug-log-global-block {
  margin-bottom: 0.85rem;
}

.debug-log-global-block:last-of-type {
  margin-bottom: 0.65rem;
}

.debug-log-global-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.35rem 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.debug-log-line-list {
  margin: 0;
  padding-left: 1.15rem;
  list-style: disc;
}

.debug-log-line-list li {
  margin: 0.12rem 0;
}

.debug-log-line-list--thresholds {
  font-family: ui-monospace, 'Cascadia Code', monospace;
}

.debug-log-line-list--rules {
  color: var(--muted);
}

.debug-log-weapon-card {
  margin-top: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface, var(--bg));
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.debug-log-weapon-head {
  margin: 0 0 0.55rem 0;
  font-size: 0.95rem;
  line-height: 1.35;
}

/* Same typographic treatment as .panel h2 (e.g. “Attacker Global Modifiers”) */
.debug-log-weapon-head .debug-log-weapon-name {
  display: inline;
  margin: 0 0.35rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: inherit;
  vertical-align: baseline;
}

.debug-log-weapon-head .debug-log-weapon-tail {
  color: var(--muted);
  font-weight: 500;
}

.debug-log-weapon-head .debug-log-weapon-count {
  font-weight: 600;
}

/* Defender wound allocation grid (weapon contribution: median-damage round; debug log may reuse styles) */
.weapon-profile-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.weapon-profile-title-row .weapon-profile-name {
  margin: 0;
}

.weapon-profile-preview-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.defender-profile-heading-row .unit-section-title {
  margin: 0;
}

.weapon-preview-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.weapon-preview-anchor .weapon-preview-toggle {
  width: 1.55rem;
  height: 1.55rem;
  min-width: 1.55rem;
  padding: 0.2rem;
}

.weapon-preview-anchor .weapon-preview-toggle--red {
  color: #f06a74;
  border-color: color-mix(in srgb, #f06a74 50%, var(--border));
  background: color-mix(in srgb, #f06a74 10%, var(--surface));
}

.weapon-preview-anchor .weapon-preview-toggle--red:hover {
  color: #ff9ca5;
  border-color: color-mix(in srgb, #ff9ca5 56%, var(--border));
  background: color-mix(in srgb, #ff9ca5 16%, var(--surface));
}

.weapon-preview-anchor .weapon-preview-toggle--turquoise {
  color: #35d7d0;
  border-color: color-mix(in srgb, #35d7d0 52%, var(--border));
  background: color-mix(in srgb, #35d7d0 11%, var(--surface));
}

.weapon-preview-anchor .weapon-preview-toggle--turquoise:hover {
  color: #7feee7;
  border-color: color-mix(in srgb, #7feee7 56%, var(--border));
  background: color-mix(in srgb, #7feee7 16%, var(--surface));
}

.weapon-preview-popover {
  /* Positioned via JS to stay inside viewport. */
  position: fixed;
  top: 0;
  left: 0;
  transform: translateY(-35%);
  width: min(26rem, calc(100vw - 2rem));
  max-height: min(24rem, 70vh);
  overflow: auto;
  padding: 0.62rem 0.66rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  background: color-mix(in srgb, var(--surface) 95%, #000 5%);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.46);
  z-index: 38;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease, visibility 120ms ease, transform 120ms ease;
}

.weapon-preview-popover.weapon-preview-popover--red {
  border-color: color-mix(in srgb, #e04050 48%, var(--border));
}

.weapon-preview-popover.weapon-preview-popover--turquoise {
  border-color: color-mix(in srgb, #22c5be 44%, var(--border));
}

.weapon-preview-anchor:hover .weapon-preview-popover,
.weapon-preview-anchor:focus-within .weapon-preview-popover {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(-50%);
}

.weapon-preview-anchor.weapon-preview-anchor--flip-left .weapon-preview-popover {
  left: 0;
  right: auto;
}

.weapon-preview-anchor.weapon-preview-anchor--suppress .weapon-preview-popover {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.weapon-preview-head {
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.45rem;
}

.weapon-preview-grid {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.weapon-preview-row {
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
}

.weapon-preview-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.weapon-preview-label {
  font-size: 0.74rem;
  color: var(--text);
}

.weapon-preview-value {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

.weapon-preview-track {
  margin-bottom: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
}

.weapon-preview-bar {
  --funnel-bar-bg: #2ee6d6;
  opacity: 0.96;
}

.weapon-preview-overkill-bar {
  --funnel-bar-bg: color-mix(in srgb, #e04050 86%, #1a0307);
  opacity: 0.95;
}

.weapon-preview-multi-kill-bar {
  --funnel-bar-bg: color-mix(in srgb, #ffffff 90%, #a7b5c2);
  opacity: 0.98;
}

.weapon-best-target-bar {
  --funnel-bar-bg: color-mix(in srgb, #e04050 86%, #2a050a);
  opacity: 0.95;
}

.weapon-preview-value.weapon-preview-value--red {
  color: #f07a84;
}

.weapon-preview-meta {
  font-size: 0.66rem;
  color: var(--muted);
}

.weapon-preview-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

@media (max-width: 980px) {
  .weapon-preview-popover {
    left: auto;
    right: 0;
  }
}

@media (max-width: 720px) {
  .weapon-preview-popover {
    top: calc(100% + 0.35rem);
    left: 0;
    right: auto;
    transform: none;
    width: min(21.5rem, 88vw);
  }
  .weapon-preview-anchor:hover .weapon-preview-popover,
  .weapon-preview-anchor:focus-within .weapon-preview-popover {
    transform: none;
  }
}

.contrib-defender-grid-host {
  margin-top: 0.55rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.contrib-pool-target-line {
  font-size: 0.82em;
  color: var(--muted);
}

.contrib-pool-defender-block {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.contrib-pool-defender-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.debug-log-defender-grid-wrap {
  margin: 0 0 0.65rem 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  box-sizing: border-box;
}

.debug-log-defender-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: clamp(0.25rem, 2%, 0.45rem);
  align-items: flex-start;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.68rem;
  padding: 0.35rem 0;
}

.debug-log-defender-grid-col {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  align-items: stretch;
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
}

.debug-log-defender-grid-wounds {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 0;
  gap: 3px;
  align-items: stretch;
  justify-content: stretch;
}

/* Reuse weapon-funnel bar tracks; stretch equally under each model column */
.debug-log-defender-grid-wounds > .contrib-funnel-bar-track {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
  background: rgba(255, 255, 255, 0.07);
}

/* Filled portion = remaining wounds (bright turquoise); does not use per-weapon accent */
.debug-log-defender-grid-wounds .contrib-funnel-bar.debug-log-defender-wound-bar {
  --funnel-bar-bg: #2ee6d6;
  background-color: #2ee6d6;
  opacity: 1;
  /* Keep remaining wound fill on the right so damage visually accumulates left-to-right. */
  margin-left: auto;
}

.debug-log-defender-grid-wounds .debug-log-defender-wound-group-track--discrete {
  display: flex;
  /* Segment width scales with wound count in that segment (e.g. 5-wide vs 3-wide). */
  flex: var(--wound-segment-size, 1) 1 0;
  gap: 0;
  padding: 0;
  background: #000;
  justify-content: stretch;
}

/* Highlight only the partially split segment (has both lost + remaining). */
.debug-log-defender-grid-wounds .debug-log-defender-wound-group-track--split {
  background: #000;
}

.debug-log-defender-grid-wounds .debug-log-defender-wound-pip {
  flex: 1 1 0;
  min-width: 0;
  height: 4px;
  border-radius: 2px;
  box-sizing: border-box;
  border-right: 2px solid #000;
}

.debug-log-defender-grid-wounds .debug-log-defender-wound-pip--damaged {
  background: color-mix(in srgb, #e04050 72%, rgba(20, 8, 10, 0.92));
}

.debug-log-defender-grid-wounds .debug-log-defender-wound-pip--remaining {
  background: #2ee6d6;
}

.debug-log-defender-grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  min-height: 1.15rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  line-height: 1;
  text-transform: lowercase;
  font-weight: 600;
}

.debug-log-defender-grid-model-span {
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
  min-height: 1.35rem;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  line-height: 1.15;
  text-transform: none;
  font-weight: 600;
  font-size: 0.88rem;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  text-align: center;
  word-break: break-word;
  hyphens: auto;
}

.debug-log-defender-grid__alive {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.debug-log-defender-grid__dead {
  color: #e04050;
  background: color-mix(in srgb, #e04050 14%, transparent);
  border-color: color-mix(in srgb, #e04050 40%, var(--border));
}

.debug-log-defender-grid-caption {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.25rem;
  line-height: 1.35;
}

/* Match weapon-profile / grid keyword accent */
.debug-log-line-list .keyword-values {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.debug-log-weapon-sub {
  color: var(--muted);
  font-weight: 400;
}

.debug-log-weapon-targeting {
  margin: 0.35rem 0 0.15rem 0;
}

.debug-log-phase {
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.debug-log-phase:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.debug-log-phase-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.35rem 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.debug-log-subheading {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.35rem 0 0.2rem 0;
}

.debug-log-defender-kw {
  margin: 0.25rem 0 0.35rem 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.debug-log-defender-kw .keyword-values {
  display: inline-block;
  margin-right: 0.4rem;
}

.debug-log-stats-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.78rem;
}

.debug-log-stats-row:last-child {
  border-bottom: none;
}

.debug-log-stats-key {
  color: var(--text);
}

.debug-log-stats-val {
  color: var(--accent);
  flex-shrink: 0;
}

.debug-log-about-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.debug-log-about-row {
  margin-bottom: 0.5rem;
}

.chart-section-header--spaced {
  margin-top: 1rem;
}

.chart-section-header--pool-grid {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chart-section-header--pool-grid .chart-section-title {
  flex: 0 1 auto;
  text-align: center;
}

#chartModelsKilledTotalHeader.section-heading-note-row {
  justify-content: center;
}

.chart-wrap--mini {
  height: 294px;
}

.chart-by-defender-host {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.chart-by-defender-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 10px 10px 12px;
}

.chart-by-defender-title {
  font-size: 13px;
  line-height: 1.2;
  color: #e4e4e7;
  margin: 0 0 8px;
  opacity: 0.95;
  text-align: center;
}

button.debug-log-toggle--flush-top {
  margin-top: 0;
}

.contrib-panel .panel-subheading--flush {
  margin: 0;
}

.contrib-note--weapon-intro {
  margin: 0 0 0.5rem 0;
}

.contrib-funnel-caption--tight {
  margin: 0;
}

#weaponContributionToggle.is-hidden,
#weaponContributionPanel.is-hidden {
  display: none !important;
}

#metricLethalSustainedWrap.is-hidden {
  display: none !important;
}

.metric-saved-failed {
  color: #e04050;
}

/* Profile keyword accent (shared with debug log .keyword-values) */
.profile-grid .keyword-values,
.weapon-profile-keywords .keyword-values {
  color: var(--accent);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Weapon contribution rows: set --contrib-accent on the element for dynamic colour */
.contrib-list .contrib-row {
  border-left-width: 3px;
  border-left-color: var(--contrib-accent, rgba(255, 255, 255, 0.08));
}

.contrib-list .contrib-row .contrib-name {
  color: var(--contrib-accent, var(--text));
}

.contrib-funnel-bar {
  width: var(--funnel-bar-width, 0%);
  background-color: var(--funnel-bar-bg, var(--accent));
}

/* Army builder roster textareas */
#attackerRosterInput,
#defenderRosterInput {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  caret-color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.35;
}
#attackerRosterInput:focus,
#defenderRosterInput:focus {
  outline: none;
  border-color: var(--accent);
}
#attackerRosterInput::placeholder,
#defenderRosterInput::placeholder {
  color: var(--muted);
  opacity: 1;
}
