/* ═══════════════════════════════════════════════════════════
   Warhammer 40k 5.5 — Codex Viewer  |  Dark gaming theme
   ═══════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #040406;
  --surface:    #08080f;
  --surface2:   #0c0c16;
  --border:     #1a2a1a;
  --accent:     #5aaa5a;
  --accent2:    #2a5a2a;
  --text:       #c8d8c8;
  --text-dim:   #5a7a5a;
  --text-head:  #c0f0c0;
  --red:        #e05040;
  --green:      #5acc5a;
  --blue:       #5a9acc;
  --radius:     1px;
  --gap:        12px;
  /* ── CRT / Machine-spirit variables ── */
  --crt-glow-r: 0;
  --crt-glow-g: 0;
  --crt-glow-b: 0;
  --crt-scanline-opacity: 0.035;
  --crt-vignette-opacity: 0.55;
  --crt-flicker-opacity: 0;
  --font-mono: "Cascadia Code", "Fira Code", "Courier New", monospace;
  /* ── Munitorum Terminal design system ── */
  --terminal-bg:         #040406;
  --terminal-panel:      #080a0f;
  --terminal-panel-2:    #0c0e16;
  --terminal-border:     #1a2a1a;
  --terminal-grid:       rgba(80,170,80,0.06);
  --terminal-invert-bg:  #d8e8d0;
  --terminal-invert-text:#060d06;
  --terminal-danger:     #d04040;
  --terminal-warning:    #d0a040;
  --terminal-chamfer:    10px;
  --terminal-glow:       rgba(90,170,90,0.18);
}

/* ═══════════════════════════════════════════════════════════
   Munitorum Terminal — Reusable Classes
   ═══════════════════════════════════════════════════════════ */

/* ── Terminal shell (outer wrapper) ── */
.terminal-shell {
  background: var(--terminal-bg);
  border: 1px solid var(--terminal-border);
  border-radius: 0;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.5), 0 0 20px rgba(0,0,0,0.4);
}

/* ── Data panel (chamfered corners, solid border) ── */
.data-panel {
  background: var(--terminal-panel);
  border: 1px solid var(--terminal-border);
  border-radius: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 12px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.06);
  position: relative;
}
.data-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(90,170,90,0.08);
  pointer-events: none;
  z-index: 1;
}

/* ── Data panel header ── */
.data-panel-header {
  background: linear-gradient(180deg, var(--terminal-panel-2), var(--terminal-panel));
  border-bottom: 2px solid var(--accent2);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 6px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.25);
  display: flex;
  align-items: center;
  gap: 8px;
}
.data-panel-header::before {
  content: "> ";
  font-size: 0.65rem;
  opacity: 0.7;
}

/* ── Data panel body ── */
.data-panel-body {
  padding: 12px 14px;
}

/* ── Data label ── */
.data-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* ── Data readout ── */
.data-readout {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-head);
  background: rgba(0,20,0,0.2);
  border: 1px solid var(--terminal-border);
  padding: 4px 8px;
  border-radius: 0;
}

/* ── Data grid ── */
.data-grid {
  display: grid;
  gap: 1px;
  background: var(--terminal-border);
  border: 1px solid var(--terminal-border);
}
.data-grid > * {
  background: var(--terminal-panel);
  padding: 6px 10px;
}

/* ── Terminal tag ── */
.terminal-tag {
  display: inline-block;
  background: rgba(0,40,0,0.3);
  border: 1px solid var(--accent2);
  border-radius: 0;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Terminal command button ── */
.terminal-command {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--terminal-panel-2);
  border: 1px solid var(--accent2);
  border-radius: 0;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-head);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.terminal-command:hover {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--accent);
}
.terminal-command:active { transform: scale(0.97); }

/* ── Segmented meter ── */
.segmented-meter {
  display: flex;
  gap: 2px;
  height: 10px;
}
.segmented-meter .seg-fill {
  flex: 1;
  background: var(--accent2);
  border: 1px solid rgba(0,0,0,0.3);
}
.segmented-meter .seg-fill.active { background: var(--accent); }
.segmented-meter .seg-fill.over   { background: var(--terminal-danger); }

/* ── Hash fill background ── */
.hash-fill {
  background-image:
    repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(255,255,255,0.015) 2px, rgba(255,255,255,0.015) 3px),
    repeating-linear-gradient(-45deg, transparent, transparent 2px, rgba(255,255,255,0.015) 2px, rgba(255,255,255,0.015) 3px);
}

/* ── Machine reticle ── */
.machine-reticle {
  position: absolute;
  width: 18px;
  height: 18px;
  pointer-events: none;
  z-index: 2;
}
.machine-reticle::before,
.machine-reticle::after {
  content: "";
  position: absolute;
  background: var(--accent);
  opacity: 0.35;
}
.machine-reticle::before { top: 0; left: 0; width: 6px; height: 1px; box-shadow: 12px 0 0 var(--accent); }
.machine-reticle::after  { top: 0; left: 0; width: 1px; height: 6px; box-shadow: 0 12px 0 var(--accent); }
.machine-reticle.top-right    { top: 8px; right: 8px; }
.machine-reticle.bottom-left  { bottom: 8px; left: 8px; }

/* ── Machine cursor ── */
.machine-cursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--accent);
  vertical-align: middle;
  margin-left: 3px;
  animation: cursorBlink 1.1s steps(2) infinite;
  opacity: 0.85;
}

/* ═══════════════════════════════════════════════════════════
   Low-FPS Terminal Animations (steps-based)
   ═══════════════════════════════════════════════════════════ */
@keyframes choppy-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes choppy-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}
@keyframes cursorBlink {
  0%, 49%  { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Machine reticle uses choppy spin */
.terminal-shell .machine-reticle,
.data-panel .machine-reticle {
  animation: choppy-spin 4s steps(4) infinite;
}

/* Status lamps use choppy pulse */
.status-lamp {
  animation: choppy-pulse 2s steps(2) infinite;
}

html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  line-height: 1.55;
  letter-spacing: 0.01em;
  min-height: 100vh;
  transition: background-color .5s ease, color .4s ease;
  position: relative;
  /* ── CRT screen glow (faction-tinted via JS) ── */
  box-shadow: inset 0 0 180px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.10);
  /* ── CRT static noise texture ── */
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  background-color: var(--bg);
}

/* ═══════════════════════════════════════════════════════════
   CRT glow — lysende tekst på alle overskrifter
   ═══════════════════════════════════════════════════════════ */
h1, h2, h3,
.section-title,
.unit-name,
.bld-panel-title,
.bld-slot-header,
.bld-saved-title,
.home-card-title,
.rule-name,
.vow-name,
.faction-group-title,
.faction-card-name,
.home-menu-title,
.bld-entry-name {
  text-shadow: 0 0 10px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.25),
               0 0 3px rgba(80, 180, 80, 0.15);
}

/* ═══════════════════════════════════════════════════════════
   CRT overlay — scanlines + vignette (body::after)
   ═══════════════════════════════════════════════════════════ */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  /* Scanlines */
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 3px,
      rgba(0, 0, 0, var(--crt-scanline-opacity)) 3px,
      rgba(0, 0, 0, var(--crt-scanline-opacity)) 4px
    );
  /* Subtle vignette (darker corners, brighter center) */
  mask-image: radial-gradient(ellipse 80% 70% at 50% 45%, black 30%, rgba(0,0,0,0.4) 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 45%, black 30%, rgba(0,0,0,0.4) 100%);
  opacity: var(--crt-flicker-opacity, 1);
  transition: opacity 0.08s;
}

/* ── CRT-overlegg — scanlines + vignett (body::after) ── */
h1, h2, h3,
.section-title,
.unit-name,
.unit-section-label,
.bld-panel-title,
.bld-slot-header,
.bld-saved-title,
.home-card-title,
.rule-name {
  font-family: var(--font-mono);
}

/* ── Header — Machine status bar ── */
#header {
  background:
    repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,.004) 2px, rgba(255,255,255,.004) 3px),
    linear-gradient(180deg, #040608 0%, #060d06 40%, #040804 100%);
  border-bottom: 2px solid var(--accent2);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
  box-shadow: 0 1px 0 rgba(0,0,0,.4), 0 3px 0 rgba(255,255,255,.02);
  min-height: 48px;
}
/* ── Machine status indicators (left of title) ── */
#header::before {
  content: "SYS:ONLINE  |  AUTH:OMNISSIAH  |  NODE:PRIMARY";
  position: absolute;
  top: 4px;
  left: 24px;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  color: rgba(90,170,90,0.45);
  text-transform: uppercase;
  pointer-events: none;
}
/* ── Data-kabel / conduit under header ── */
#header::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    var(--accent2) 0px,
    var(--accent2) 3px,
    transparent 3px,
    transparent 6px
  );
  opacity: 0.5;
}
#header h1 {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  flex: 0 1 auto;
  margin-top: 10px;
}
/* ── Terminal-prompt før tittel ── */
#header h1::before {
  content: "> ";
  font-family: var(--font-mono);
  font-size: 1.0rem;
  color: #5a9a5a;
  text-shadow: 0 0 6px rgba(60, 180, 60, 0.4);
  letter-spacing: 0;
}
#army-select {
  display: none;
  background: #0a0f0a;
  color: #7aba7a;
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: .9rem;
  cursor: pointer;
  outline: none;
  font-family: var(--font-mono);
  text-shadow: 0 0 4px rgba(80, 180, 80, 0.2);
}
#army-select:hover { border-color: var(--accent); box-shadow: 0 0 10px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.15); }
#army-select option {
  background: #0a0f0a;
  color: #b0d0b0;
}

/* ── Layout ── */
#app { padding: 20px 24px; max-width: 1300px; margin: 0 auto; }

/* ── Section headings ── */
.section-title {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
  padding-bottom: 5px;
  text-shadow: 0 0 12px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.3);
  margin: 24px 0 14px;
  position: relative;
}
.section-title::after {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  background: var(--accent);
  margin-top: 5px;
  border-radius: 2px;
}

.faction-plate {
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 0 20px;
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 18px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.08);
  position: relative;
}
.faction-plate img {
  display: block;
  width: 100%;
  max-height: 360px;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  object-position: center;
  /* CRT kontrast — kraftigere */
  filter: contrast(1.25) brightness(0.80) sepia(0.22) saturate(0.60);
}
/* ── Faksjonsfarget fosfor-glød over hero-banner ── */
.faction-plate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% 40%, var(--accent) 0%, transparent 70%);
  opacity: 0.06;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
}
/* ── CRT scanlines over hero-banner (animert, grønn fosfor) ── */
.faction-plate::after {
  content: "";
  position: absolute;
  inset: -20px;
  height: calc(100% + 40px);
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 20, 0, 0.45) 2px,
    rgba(0, 20, 0, 0.45) 8px
  );
  pointer-events: none;
  z-index: 2;
  animation: scanlineDrift 4s linear infinite;
}

/* ── Army rules block ── */
.army-rules {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow:
    0 2px 8px rgba(0,0,0,.4),
    0 0 14px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.06),
    inset 0 0 40px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.02);
  transition: border-color .08s;
}
.army-rules:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0,0,0,.5), 0 0 28px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.14);
}
.army-rule + .army-rule { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 10px; }
.army-rule .rule-name {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-head);
  font-size: .9rem;
}
.army-rule .rule-text {
  color: var(--text);
  font-size: .85rem;
  margin-top: 2px;
}

/* ── Vows grid ── */
.vows-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gap);
  margin-bottom: 24px;
}
.vow-card {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-left: 3px solid var(--accent);
  border-radius: 0;
  padding: 12px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 0 10px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.05);
  transition: border-color .08s;
}
.vow-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0,0,0,.5), 0 0 20px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.12);
}
.vow-card .vow-name {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  font-size: .88rem;
  margin-bottom: 4px;
}
.vow-card .vow-text {
  font-size: .82rem;
  color: var(--text);
}

/* ── FOC nav tabs ── */
.foc-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.foc-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px 16px;
  color: var(--text-dim);
  font-size: .82rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .05em;
  transition: background .08s, color .08s, border-color .08s;
}
.foc-btn:hover  { color: var(--text); border-color: var(--accent2); }
.foc-btn.active {
  background: var(--accent2);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
  box-shadow: 0 0 12px rgba(0,0,0,.3);
}

/* ── Unit cards grid ── */
.units-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* ── Unit card ── */
.unit-card {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.5), 0 0 12px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.10);
  transition: border-color .08s;
}
.unit-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(0,0,0,.55), 0 0 22px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.14), 0 0 6px rgba(60, 180, 60, 0.04);
}
.unit-header {
  background: linear-gradient(180deg, var(--surface2), var(--surface));
  border-bottom: 2px solid var(--accent2);
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  position: relative;
}
/* ── Terminal corner marks on unit header ── */
.unit-header::before {
  content: "";
  position: absolute;
  top: 4px; right: 4px;
  width: 8px; height: 8px;
  border-top: 1px solid var(--accent2);
  border-right: 1px solid var(--accent2);
  opacity: 0.5;
  pointer-events: none;
}
.unit-header::after {
  content: "";
  position: absolute;
  bottom: 4px; left: 3px;
  width: 8px; height: 8px;
  border-bottom: 1px solid var(--accent2);
  border-left: 1px solid var(--accent2);
  opacity: 0.5;
  pointer-events: none;
}
.unit-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .98rem;
  color: var(--text-head);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.unit-pts {
  font-size: .82rem;
  color: #000;
  background: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 0;
  font-family: var(--font-mono);
}
.unit-body {
  padding: 14px 18px;
}
/* Fallback image wrapper (used outside .unit-body grid context) */
.unit-image-wrap {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 12px;
  background: var(--surface2);
  overflow: hidden;
  position: relative;
}
.unit-image-wrap .unit-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: contrast(1.15) brightness(0.82) sepia(0.20) saturate(0.65);
  transform: scale(1.10);
}
.unit-image-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 60% at 50% 50%, var(--accent) 0%, transparent 75%);
  opacity: 0.07;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
}
.unit-image-wrap::after {
  content: "";
  position: absolute;
  inset: -20px;
  height: calc(100% + 40px);
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,20,0,.45) 2px, rgba(0,20,0,.45) 8px);
  pointer-events: none;
  z-index: 2;
  animation: scanlineDrift 4s linear infinite;
}
.unit-notes {
  font-size: .84rem;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 10px;
}

/* ── Stat table ── */
.stat-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 10px;
}
.stat-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0;
  font-size: .85rem;
  border-radius: 0;
  overflow: hidden;
  font-family: var(--font-mono);
}
.stat-table th {
  background: #0a0a10;
  color: #5a9a5a;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 5px 8px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: .72rem;
  text-shadow: 0 0 5px rgba(60, 180, 60, 0.3);
}
.stat-table td {
  padding: 5px 8px;
  text-align: center;
  border: 1px solid var(--border);
  color: var(--text);
}
.stat-table td:first-child {
  text-align: left;
  color: var(--text-dim);
  font-size: .8rem;
  font-weight: 600;
}
.stat-table tr:nth-child(even) td { background: rgba(0, 30, 0, 0.08); }
.stat-table tbody tr:hover td { background: rgba(0, 50, 0, 0.12); }
.stat-table .stat-key { font-weight: 700; color: var(--accent); text-shadow: 0 0 6px rgba(200, 200, 80, 0.25); }

/* ── Unit sub-sections ── */
.unit-section { margin-top: 10px; }
.unit-section-label {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin-bottom: 5px;
  opacity: 0.8;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 1px;
  padding: 3px 9px;
  font-size: .8rem;
  color: var(--text);
  cursor: default;
  transition: background .15s, border-color .15s;
  font-family: var(--font-mono);
}
.tag:hover { background: var(--surface); }
.tag.usr-tag {
  border-color: var(--accent2);
  color: var(--accent);
  cursor: help;
}
.tag.wargear-tag {
  border-color: var(--accent2);
  color: var(--text-head);
  cursor: help;
  transition: border-color .15s, background .15s;
}
.tag.wargear-tag:hover {
  border-color: var(--accent);
  background: var(--surface);
}

/* ── Options list ── */
.options-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.options-list li {
  font-size: .84rem;
  color: var(--text);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.options-list li:last-child { border-bottom: none; }
.opt-pts {
  white-space: nowrap;
  color: var(--accent);
  font-weight: 700;
  font-size: .78rem;
  min-width: 56px;
  text-align: right;
  font-family: var(--font-mono);
}

/* ── Unit body: image left, stats & wargear right ── */
.unit-body {
  display: grid;
  grid-template-columns: 195px 1fr 1fr;
  gap: 8px 14px;
  padding: 14px 18px;
}
/* Image wrapper: left column, 9:16 letterboxed (centered, no crop) */
.unit-body .unit-image-wrap {
  grid-column: 1;
  grid-row: 1 / span 30;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface2);
  width: 100%;
  aspect-ratio: 9 / 16;
}
.unit-body .unit-image-wrap .unit-image {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 9 / 16;
  object-fit: contain;
  object-position: center;
  border: none;
  border-radius: 0;
  background: transparent;
  margin-bottom: 0;
  transform: scale(1.10);
  /* CRT contrast filter — kraftigere for tydelig CRT-effekt */
  filter: contrast(1.3) brightness(0.75) sepia(0.28) saturate(0.55);
}

/* ── CRT fosfor-glød over unit-bilde (faksjonsfarget) ── */
.unit-body .unit-image-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 60% at 50% 50%, var(--accent) 0%, transparent 75%);
  opacity: 0.14;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
}

/* ── CRT scanlines over unit-bilde (animert, grønn fosfor) ── */
.unit-body .unit-image-wrap::after {
  content: "";
  position: absolute;
  inset: -20px;
  height: calc(100% + 40px);
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 20, 0, 0.45) 2px,
    rgba(0, 20, 0, 0.45) 8px
  );
  pointer-events: none;
  z-index: 2;
  animation: scanlineDrift 4s linear infinite;
}

/* Notes, stats: full width in right area */
.unit-body .unit-notes       { grid-column: 2 / -1; margin-bottom: 0; }
.unit-body .stat-table-wrap  { grid-column: 2 / -1; margin-bottom: 4px; }
.unit-body .stat-table       { font-size: .82rem; }
.unit-body .stat-table td    { padding: 4px 7px; }
.unit-body .stat-table th    { padding: 4px 7px; font-size: .7rem; }
/* Sections auto-flow into the two right columns */
.unit-body .unit-section     { margin-top: 0; }

/* ── Without image: full-width body ── */
.unit-body:not(:has(.unit-image-wrap)) {
  grid-template-columns: 1fr 1fr;
}
.unit-body:not(:has(.unit-image-wrap)) .unit-notes,
.unit-body:not(:has(.unit-image-wrap)) .stat-table-wrap {
  grid-column: 1 / -1;
}

/* ── Tooltip ── */
.usr-tooltip-wrap {
  position: relative;
  display: inline-block;
}
.usr-tooltip-wrap .tooltip-bubble {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 300px;
  max-width: 90vw;
  max-height: 320px;
  overflow-y: auto;
  background: #0c0f0c;
  border: 1px solid #3a6a3a;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: .8rem;
  color: #b0d0b0;
  z-index: 100;
  pointer-events: none;
  line-height: 1.45;
  box-shadow:
    0 6px 24px rgba(0,0,0,.7),
    0 0 20px rgba(0, 80, 0, 0.12);
  animation: tooltipIn .15s ease-out;
  font-family: var(--font-mono);
}
@keyframes tooltipIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.usr-tooltip-wrap .tooltip-bubble .tooltip-title {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #7acc7a;
  margin-bottom: 4px;
  font-size: .82rem;
  text-shadow: 0 0 5px rgba(80, 200, 80, 0.3);
  border-bottom: 1px solid rgba(80, 180, 80, 0.25);
  padding-bottom: 3px;
}
.usr-tooltip-wrap:hover .tooltip-bubble { display: block; }
/* Touch: tap to toggle tooltip */
.usr-tooltip-wrap:active .tooltip-bubble,
.usr-tooltip-wrap.tooltip-visible .tooltip-bubble { display: block; }

/* ── Weapons table ── */
.weapons-section { margin-top: 28px; }
.weapons-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.weapons-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  border-radius: 0;
  overflow: hidden;
  font-family: var(--font-mono);
}
.weapons-table th {
  background: #0a0a10;
  color: #8a8a5a;
  padding: 5px 10px;
  text-align: left;
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .72rem;
  text-shadow: 0 0 4px rgba(180, 180, 60, 0.25);
}
.weapons-table td {
  padding: 5px 10px;
  border: 1px solid var(--border);
  color: var(--text);
}
.weapons-table tr:nth-child(even) td { background: rgba(30, 30, 0, 0.06); }
.weapons-table tbody tr:hover td { background: rgba(50, 50, 0, 0.10); }

/* ── Empty / loading states ── */
#empty {
  color: var(--text-dim);
  text-align: center;
  margin-top: 60px;
  font-size: 1.05rem;
}

/* ── Keyframe animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes auspexSweep {
  from { background-position: 100% 100%; }
  to   { background-position: 0% 0%; }
}
/* ── Skjerm-av/på ved hærbytte ── */
@keyframes screenOff {
  0%   { opacity: 1; filter: brightness(1); }
  40%  { opacity: 0.3; filter: brightness(2.5) blur(1px); }
  100% { opacity: 0; filter: brightness(0); }
}
@keyframes screenOn {
  0%   { opacity: 0; filter: brightness(0); }
  50%  { opacity: 0.6; filter: brightness(2) blur(1px); }
  100% { opacity: 1; filter: brightness(1); }
}
/* ── CRT scanline vertical drift ── */
@keyframes scanlineDrift {
  0%   { transform: translateY(0); }
  100% { transform: translateY(10px); }
}
.screen-transition {
  animation: screenOff .25s ease-in forwards, screenOn .4s .25s ease-out forwards;
}
.unit-card {
  animation: fadeInUp .3s ease-out both;
}
.units-grid .unit-card:nth-child(1) { animation-delay: .02s; }
.units-grid .unit-card:nth-child(2) { animation-delay: .05s; }
.units-grid .unit-card:nth-child(3) { animation-delay: .08s; }
.units-grid .unit-card:nth-child(4) { animation-delay: .11s; }
.units-grid .unit-card:nth-child(5) { animation-delay: .14s; }
.units-grid .unit-card:nth-child(6) { animation-delay: .17s; }
.units-grid .unit-card:nth-child(7) { animation-delay: .20s; }
.units-grid .unit-card:nth-child(8) { animation-delay: .23s; }
.units-grid .unit-card:nth-child(n+9) { animation-delay: .26s; }

/* Smooth army-switch fade — CRT power-on effect */
#app.fade-in {
  animation: screenOn .35s ease-out;
}

/* ── Scrollbar (CRT-grønn) ── */
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #2a4a2a; border-radius: 0; border: 1px solid rgba(60, 180, 60, 0.15); }
::-webkit-scrollbar-thumb:hover { background: #3a6a3a; }

/* ── Responsive ── */
/* Mobile (≤480px) */
@media (max-width: 480px) {
  html { font-size: 13px; }
  #app { padding: 12px 10px; }
  #home { padding: 16px 10px; }

  /* Header stacks vertically */
  #header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 14px;
  }
  #header h1 { text-align: center; font-size: 1.2rem; }
  #army-emblem { display: none; }
  .header-controls {
    flex-direction: column;
    gap: 8px;
  }
  #army-select { width: 100%; }
  .mode-toggle { width: 100%; }
  .mode-btn { flex: 1; text-align: center; }

  /* Single-column grids */
  .units-grid { grid-template-columns: 1fr; }
  .vows-grid { grid-template-columns: 1fr; }
  .home-nav { grid-template-columns: 1fr; }
  .home-chapter { grid-template-columns: 1fr; }

  /* Mobile: image on top, everything stacked */
  .unit-body {
    display: block !important;
  }
  .unit-body .unit-image-wrap {
    width: 100%;
    aspect-ratio: 16 / 9;
    margin-bottom: 10px;
  }
  .unit-body .stat-table { font-size: .82rem; }

  /* Larger touch targets */
  .foc-btn, .bld-tab { padding: 8px 14px; font-size: .8rem; }
  .bld-add-btn { width: 38px; height: 38px; font-size: 1.5rem; }
  .bld-remove-btn { border-radius: 0; padding: 0 6px; font-size: 1.3rem; }
  .bld-opt-cb { width: 18px; height: 18px; }

  /* Builder: vertical stack with toggle */
  .bld-layout {
    flex-direction: column;
    height: auto;
    padding: 8px;
    gap: 10px;
  }
  .bld-units { flex: none; max-height: 45vh; min-width: 0; }
  .bld-list  { flex: none; }
  .bld-unit-thumb { width: 32px; height: 32px; }
  .bld-entry-thumb { width: 28px; height: 28px; }

  /* Saved lists: stack */
  .bld-saved-item { border-color: var(--accent2); flex-direction: column; align-items: stretch; gap: 6px; }
  .bld-saved-btns { justify-content: flex-end; }

  /* FOC nav: scrollable */
  .foc-nav { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .foc-btn { white-space: nowrap; flex-shrink: 0; }

  /* Export modal */
  .bld-export-modal { width: 95vw; padding: 14px; max-height: 85vh; overflow-y: auto; }
  .bld-export-ta { height: 160px; }

  /* ── Admin responsive ── */
  .admin-body { padding: 10px 8px; }
  .admin-login-wrap { min-height: 40vh; gap: 14px; padding: 10px; }
  .admin-login-title { font-size: 1.1rem; }
  .admin-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .admin-header-left { flex-direction: column; align-items: stretch; gap: 8px; }
  .admin-codex-select { min-width: 0; width: 100%; }
  #admin-new-unit-btn { width: 100%; justify-content: center; }
  .admin-form-row,
  .admin-form-row-3 { grid-template-columns: 1fr; }
  .admin-unit-list { gap: 4px; }
  .admin-unit-row { flex-wrap: wrap; gap: 6px; padding: 10px; }
  .admin-unit-row-name { flex: 1 1 100%; }
  .admin-unit-row-slot { font-size: .68rem; }
  .admin-unit-row-pts { font-size: .76rem; }
  .admin-edit-form { padding: 12px 10px; }
  .admin-stat-table { font-size: .68rem; }
  .admin-stat-table th { font-size: .58rem; padding: 4px 2px; }
  .admin-stat-table td { padding: 2px; }
  .admin-stat-table input { font-size: .68rem; padding: 2px 3px; min-width: 32px; }
  .admin-stat-table .admin-stat-name { min-width: 70px; }
  .admin-dyn-list { gap: 8px; }
  .admin-dyn-row { flex-wrap: wrap; }
  .admin-dyn-row .admin-input { flex: 1 1 100%; min-width: 0; }
  .admin-dyn-remove { min-width: 44px; min-height: 44px; font-size: 1.4rem; display: flex; align-items: center; justify-content: center; }
  .admin-modal { width: 92vw; padding: 14px; border-radius: 0; max-height: 90vh; overflow-y: auto; }
  .admin-modal-btns { flex-direction: column; gap: 6px; }
  .admin-modal-btns .admin-btn { width: 100%; justify-content: center; }
  .admin-toast { left: 10px; right: 10px; bottom: 10px; max-width: none; font-size: .78rem; }
  .admin-btn-sm { padding: 6px 14px; font-size: .78rem; }

  /* ── Home cogitator panels ── */
  .home-menu-btn.cogitator-panel {
    clip-path: none;
    min-height: 110px;
    padding: 12px;
  }
  .home-menu-glyph { width: 56px; height: 56px; }
  .home-menu-glyph svg { width: 42px; height: 42px; }
  .home-menu-title { font-size: 1.15rem; }
  .home-menu-main { grid-template-columns: 56px minmax(0, 1fr); gap: 12px; }

  /* ── Faction grid ── */
  .faction-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .faction-card { min-height: 170px; padding: 6px; }
  .faction-card-viewport { min-height: 72px; }
  .faction-card-name { font-size: .78rem; }
  .faction-card-emblem { width: 32px; height: 32px; right: 6px; bottom: 6px; }
  .faction-card-emblem svg { width: 24px; height: 24px; }

  /* ── Faction plate hero banner ── */
  .faction-plate img { aspect-ratio: 16 / 9; max-height: 180px; }

  /* ── Unit body: portrait image on mobile ── */
  .unit-body .unit-image-wrap { aspect-ratio: 9 / 16; }

  /* ── Stat table scroll indicator ── */
  .stat-table-wrap { position: relative; }
  .stat-table-wrap::after {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 24px;
    background: linear-gradient(90deg, transparent, var(--surface));
    pointer-events: none;
    z-index: 1;
  }

  /* ── Touch target enlargements ── */
  .bld-remove-btn { min-width: 38px; min-height: 38px; font-size: 1.3rem; display: inline-flex; align-items: center; justify-content: center; }
  .bld-model-btn { min-width: 34px; min-height: 34px; font-size: .85rem; padding: 2px 8px; }
  .bld-model-btn-sm { min-width: 30px; min-height: 30px; }
  .mode-btn { padding: 8px 16px; }
  .home-back-btn { padding: 8px 16px; min-height: 44px; }

  /* ── FOC nav scrollable ── */
  .foc-nav { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .foc-nav::-webkit-scrollbar { display: none; }

  /* ── Builder actions stack ── */
  .bld-actions { flex-direction: column; }
  .bld-actions .bld-btn { width: 100%; text-align: center; justify-content: center; }

  /* ── CRT performance reduction ── */
  :root {
    --crt-scanline-opacity: 0.02;
    --crt-vignette-opacity: 0.3;
  }
  body {
    background-image: none;
  }

  /* ── Changelog timestamp inline ── */
  .changelog-entry-header { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* Tablet (481–768px) */
@media (min-width: 481px) and (max-width: 768px) {
  html { font-size: 13.5px; }
  #app { padding: 16px 16px; }
  #home { padding: 20px 16px; }

  .units-grid { grid-template-columns: 1fr; }
  .vows-grid { grid-template-columns: repeat(2, 1fr); }
  .home-chapter { grid-template-columns: repeat(2, 1fr); }

  /* Tablet: smaller image column */
  .unit-body {
    grid-template-columns: 145px 1fr 1fr;
    gap: 6px 10px;
  }
  .unit-body .stat-table { font-size: .78rem; }
  .unit-body .stat-table td { padding: 3px 5px; }
  .unit-body .stat-table th { padding: 3px 5px; font-size: .66rem; }

  /* Builder: vertical with shared height */
  .bld-layout {
    flex-direction: column;
    height: auto;
    padding: 12px;
    gap: 12px;
  }
  .bld-units { flex: none; max-height: 40vh; min-width: 0; }
  .bld-list  { flex: none; }

  /* ── Admin tablet ── */
  .admin-body { padding: 16px 14px; }
  .admin-form-row-3 { grid-template-columns: 1fr 1fr; }
  .admin-stat-table { font-size: .74rem; }
  .admin-header-left { gap: 8px; }
  .admin-modal { width: min(480px, 85vw); }

  /* ── Faction grid tablet ── */
  .faction-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .faction-card { min-height: 200px; }

  /* ── Home nav tablet ── */
  .home-nav { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

  /* ── Unit body image column ── */
  .unit-body { grid-template-columns: 120px 1fr 1fr; }

  /* ── Faction plate ── */
  .faction-plate img { max-height: 240px; }

  /* ── Builder export modal ── */
  .bld-export-modal { width: 85vw; max-height: 80vh; overflow-y: auto; }
}

/* Small desktop (769–1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .units-grid { grid-template-columns: 1fr; }
  .home-chapter { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .bld-units { box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.08); flex: 0 0 280px; min-width: 240px; }
}

/* Builder vertical (all screens ≤800px) */
@media (max-width: 800px) {
  .bld-layout {
    flex-direction: column;
    height: auto;
    padding: 10px;
  }
  .bld-units { box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.08); flex: none; max-height: 40vh; }
  .bld-list  { flex: none; }
}

/* Micro-mobile (≤380px) — iPhone SE, small Android */
@media (max-width: 380px) {
  html { font-size: 12px; }
  #header { padding: 10px 8px; }
  #header h1 { font-size: 1.0rem; }
  #home { padding: 12px 6px; }
  #app { padding: 10px 6px; }

  /* Even smaller touch targets where possible */
  .mode-btn { padding: 6px 8px; font-size: .64rem; }
  .foc-btn, .bld-tab { padding: 6px 10px; font-size: .7rem; }

  /* Faction grid: 2 per row */
  .faction-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .faction-card { min-height: 150px; padding: 4px; }
  .faction-card-viewport { min-height: 60px; }

  /* Unit body: even smaller */
  .unit-body .stat-table { font-size: .7rem; }
  .unit-body .stat-table td { padding: 3px 4px; }
  .unit-body .stat-table th { padding: 3px 4px; font-size: .6rem; }

  /* Hide least critical stat columns on micro screens */
  .stat-table th:nth-child(10),
  .stat-table td:nth-child(10),
  .stat-table th:nth-child(11),
  .stat-table td:nth-child(11) { display: none; }

  /* Admin: hide Inv/Comp columns */
  .admin-stat-table th:nth-child(10),
  .admin-stat-table td:nth-child(10),
  .admin-stat-table th:nth-child(11),
  .admin-stat-table td:nth-child(11) { display: none; }

  /* Builder: even more compact */
  .bld-layout { padding: 6px; gap: 6px; }
  .bld-unit-thumb { width: 28px; height: 28px; }
  .bld-entry-thumb { width: 24px; height: 24px; }
  .bld-actions { gap: 4px; }
  .bld-btn { padding: 6px 10px; font-size: .74rem; }

  /* Home menu */
  .home-menu-btn.cogitator-panel { min-height: 90px; padding: 10px; }
  .home-menu-glyph { width: 44px; height: 44px; }
  .home-menu-glyph svg { width: 34px; height: 34px; }
  .home-menu-main { grid-template-columns: 44px minmax(0, 1fr); gap: 10px; }
  .home-menu-title { font-size: 1.0rem; }
  .home-menu-status, .home-menu-footer { font-size: .6rem; }

  /* Admin even more compact */
  .admin-body { padding: 8px 4px; }
  .admin-edit-form { padding: 8px 6px; }
  .admin-form-group { margin-bottom: 8px; }
  .admin-input, .admin-textarea, .admin-select { font-size: .78rem; padding: 5px 7px; }
}

/* Reduced motion — accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .machine-reticle,
  .status-lamp,
  .faction-plate::after,
  .unit-body .unit-image-wrap::after,
  .faction-card-viewport::after { animation: none !important; }
  .machine-cursor { animation: none !important; opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════
   Army emblem
   ═══════════════════════════════════════════════════════════ */
.army-emblem-wrap {
  display: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}
.army-emblem {
  width: 40px;
  height: 40px;
  color: var(--accent);
  opacity: .9;
  filter: drop-shadow(0 0 6px var(--accent2)) drop-shadow(0 0 12px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.3));
  transition: color .35s, filter .35s;
  animation: emblemPulse 3s ease-in-out infinite;
}
@keyframes emblemPulse {
  0%, 100% { filter: drop-shadow(0 0 6px var(--accent2)) drop-shadow(0 0 12px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.3)); }
  50%      { filter: drop-shadow(0 0 10px var(--accent2)) drop-shadow(0 0 20px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.5)); }
}

/* ═══════════════════════════════════════════════════════════
   Background patterns (applied to #app)
   ═══════════════════════════════════════════════════════════ */
.pattern-marines {
  background-image:
    repeating-linear-gradient(0deg,   transparent, transparent 29px, rgba(255,255,255,.012) 29px, rgba(255,255,255,.012) 30px),
    repeating-linear-gradient(90deg,  transparent, transparent 29px, rgba(255,255,255,.012) 29px, rgba(255,255,255,.012) 30px);
}
.pattern-chaos {
  background-image:
    repeating-linear-gradient( 45deg, transparent, transparent 19px, rgba(255,255,255,.014) 19px, rgba(255,255,255,.014) 20px),
    repeating-linear-gradient(-45deg, transparent, transparent 19px, rgba(255,255,255,.010) 19px, rgba(255,255,255,.010) 20px);
}
.pattern-eldar {
  background-image:
    repeating-linear-gradient(55deg, transparent, transparent 23px, rgba(255,255,255,.013) 23px, rgba(255,255,255,.013) 24px),
    repeating-linear-gradient(125deg, transparent, transparent 23px, rgba(255,255,255,.008) 23px, rgba(255,255,255,.008) 24px);
}
.pattern-orks {
  background-image: radial-gradient(circle, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 20px 20px;
}
.pattern-tau {
  background-image:
    repeating-linear-gradient(30deg,  rgba(255,255,255,.012) 0, rgba(255,255,255,.012) 1px, transparent 0, transparent 50%),
    repeating-linear-gradient(150deg, rgba(255,255,255,.012) 0, rgba(255,255,255,.012) 1px, transparent 0, transparent 50%),
    repeating-linear-gradient(90deg,  rgba(255,255,255,.012) 0, rgba(255,255,255,.012) 1px, transparent 0, transparent 50%);
  background-size: 22px 38px;
}
.pattern-necrons {
  background-image: radial-gradient(circle, rgba(0,200,80,.05) 1px, transparent 1px);
  background-size: 16px 16px;
}
.pattern-imperial {
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 19px, rgba(255,255,255,.010) 19px, rgba(255,255,255,.010) 20px);
}
.pattern-tyranids {
  background-image:
    radial-gradient(ellipse 60% 60% at 30% 30%, rgba(255,255,255,.012) 0, transparent 70%),
    radial-gradient(ellipse 60% 60% at 70% 70%, rgba(255,255,255,.010) 0, transparent 70%);
  background-size: 60px 60px;
}
.pattern-inquisition {
  background-image:
    radial-gradient(circle, rgba(255,255,255,.025) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,.015) 1px, transparent 1px);
  background-size: 24px 24px, 12px 12px;
  background-position: 0 0, 6px 6px;
}

/* ═══════════════════════════════════════════════════════════
   Per-army colour themes  (override :root CSS variables)
   ═══════════════════════════════════════════════════════════ */

/* Black Templars — already the default palette */
[data-army="black-templar"] {
  --accent: #5aaa5a; --accent2: #2a5a2a;
  --surface: #16161e; --surface2: #1e1e2a; --border: #2e2e3e;
  --bg: #0e0e12; --text: #d4cfc5; --text-head: #e8dfca;
}
/* Blood Angels */
[data-army="blood-angels"] {
  --accent: #c8304a; --accent2: #7a1a2c;
  --surface: #1e1216; --surface2: #281820; --border: #3e2028;
  --bg: #120a0d; --text: #d4cfc5; --text-head: #f0dce0;
}
/* Dark Angels */
[data-army="dark-angels"] {
  --accent: #3a8c50; --accent2: #1a4a28;
  --surface: #141e18; --surface2: #1c2820; --border: #2c3e30;
  --bg: #0b120d; --text: #d4cfc5; --text-head: #d8eede;
}
/* Space Marines */
[data-army="space-marines"] {
  --accent: #3a60b0; --accent2: #1e3870;
  --surface: #0e1610; --surface2: #141e14; --border: #1e2e1e;
  --bg: #060e06; --text: #d4cfc5; --text-head: #c8e8c8;
}
/* Space Wolves */
[data-army="space-wolves"] {
  --accent: #5a8cb0; --accent2: #2d5a7a;
  --surface: #101810; --surface2: #141e14; --border: #1e2e1e;
  --bg: #0c1218; --text: #d4cfc5; --text-head: #c8e8c8;
}
/* Adeptus Custodes */
[data-army="adeptus-custodes"] {
  --accent: #6acc6a; --accent2: #2a6a2a;
  --surface: #1e180a; --surface2: #282010; --border: #40301a;
  --bg: #130f04; --text: #d4cfc5; --text-head: #f0e4c8;
}
/* Adeptus Mechanicus */
[data-army="adeptus-mechanicus"] {
  --accent: #c84040; --accent2: #7a2020;
  --surface: #1e1210; --surface2: #281818; --border: #3e2820;
  --bg: #120808; --text: #d4cfc5; --text-head: #f0d8d8;
}
/* Imperial Guard */
[data-army="imperial-guard"] {
  --accent: #6a9a5a; --accent2: #2a5a2a;
  --surface: #181810; --surface2: #222218; --border: #363628;
  --bg: #0f0f08; --text: #d4cfc5; --text-head: #e8e0c0;
}
/* Death Korps of Krieg */
[data-army="dkok"] {
  --accent: #7a8a9a; --accent2: #3a4a5a;
  --surface: #0e160e; --surface2: #141e14; --border: #1e2e1e;
  --bg: #080e08; --text: #d4cfc5; --text-head: #c0e0c0;
}
/* Ordo Hereticus */
[data-army="ordo-hereticus"] {
  --accent: #c84a4a; --accent2: #7a2020;
  --surface: #1e1010; --surface2: #281818; --border: #3e2828;
  --bg: #120808; --text: #d4cfc5; --text-head: #f0d8d8;
}
/* Ordo Malleus */
[data-army="ordo-malleus"] {
  --accent: #8a5ac8; --accent2: #4a2880;
  --surface: #18121e; --surface2: #221a28; --border: #362a40;
  --bg: #0e0a14; --text: #d4cfc5; --text-head: #e4d8f0;
}
/* Elysian Drop Troops */
[data-army="elysian-drops"] {
  --accent: #8a9a5a; --accent2: #4a5a2a;
  --surface: #181a10; --surface2: #222418; --border: #363828;
  --bg: #0e1008; --text: #d4cfc5; --text-head: #dce4c0;
}
/* Elysian Drop Troop Veterans */
[data-army="elysian-vets"] {
  --accent: #7a8a4a; --accent2: #3a4a18;
  --surface: #16180f; --surface2: #1e2016; --border: #2e3026;
  --bg: #0c0e07; --text: #d4cfc5; --text-head: #d8dcc0;
}
/* The Tyrant's Legion */
[data-army="tyrants-legion"] {
  --accent: #7a8ab0; --accent2: #3a4a7a;
  --surface: #0e160e; --surface2: #141e14; --border: #1e2e1e;
  --bg: #060e06; --text: #d4cfc5; --text-head: #c0e0c0;
}
/* Chaos Space Marines */
[data-army="chaos-space-marines"] {
  --accent: #c83a2a; --accent2: #7a1a10;
  --surface: #1e1010; --surface2: #281818; --border: #3e2828;
  --bg: #120808; --text: #d4cfc5; --text-head: #f0d8d4;
}
/* Renegades and Heretics */
[data-army="renegades-heretics"] {
  --accent: #9a3a2a; --accent2: #5a1a10;
  --surface: #1c1010; --surface2: #261818; --border: #3c2828;
  --bg: #100808; --text: #d4cfc5; --text-head: #e8d8d4;
}
/* Eldar */
[data-army="eldar"] {
  --accent: #9a5ac8; --accent2: #5a2880;
  --surface: #18121e; --surface2: #22182c; --border: #362840;
  --bg: #0e0a18; --text: #d4cfc5; --text-head: #e8d8f0;
}
/* Dark Eldar */
[data-army="dark-eldar"] {
  --accent: #5a2a8a; --accent2: #280a4a;
  --surface: #140f1e; --surface2: #1c1628; --border: #2c243e;
  --bg: #0a0714; --text: #d4cfc5; --text-head: #d8c8e8;
}
/* Eldar Corsairs */
[data-army="eldar-corsairs"] {
  --accent: #3a7a9a; --accent2: #1a4a6a;
  --surface: #0c140e; --surface2: #101c10; --border: #1a2a1a;
  --bg: #080f18; --text: #d4cfc5; --text-head: #c0e0c0;
}
/* Orks */
[data-army="orks"] {
  --accent: #4a8a2a; --accent2: #265014;
  --surface: #141a10; --surface2: #1c2218; --border: #2c3228;
  --bg: #0a1008; --text: #d4cfc5; --text-head: #d8e8cc;
}
/* Feral Orks */
[data-army="feral-orks"] {
  --accent: #5a7a2a; --accent2: #2d4014;
  --surface: #161a10; --surface2: #1e2218; --border: #2e3228;
  --bg: #0c1008; --text: #d4cfc5; --text-head: #dce8cc;
}
/* Ork Dread Mob */
[data-army="ork-dread-mob"] {
  --accent: #5a8a4a; --accent2: #2a4a1a;
  --surface: #181810; --surface2: #222018; --border: #363028;
  --bg: #0f0e08; --text: #d4cfc5; --text-head: #e0dcc0;
}
/* Tau */
[data-army="tau"] {
  --accent: #3a6a9a; --accent2: #1a3a6a;
  --surface: #0c140e; --surface2: #101c10; --border: #1a2a1a;
  --bg: #050e06; --text: #d4cfc5; --text-head: #c0e0c0;
}
/* Necrons */
[data-army="necrons"] {
  --accent: #1a8a3a; --accent2: #0a4a1a;
  --surface: #0e1610; --surface2: #161e18; --border: #262e28;
  --bg: #060e08; --text: #d4cfc5; --text-head: #c8e8d0;
}
/* Tyranids */
[data-army="tyranids"] {
  --accent: #9a3a8a; --accent2: #5a1a5a;
  --surface: #1e121e; --surface2: #281a28; --border: #3e2a3e;
  --bg: #120a12; --text: #d4cfc5; --text-head: #e8d0e8;
}

/* Smooth theme transitions */
body, #header, .unit-card, .unit-header, .army-rules,
.vow-card, .foc-btn, .stat-table th, .weapons-table th {
  transition: background-color .35s, border-color .35s, color .25s;
}

/* ═══════════════════════════════════════════════════════════
   Utility
   ═══════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   Header — mode toggle + controls
   ═══════════════════════════════════════════════════════════ */
.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-toggle {
  display: flex;
  border: 1px solid var(--accent2);
  border-radius: 0;
  overflow: hidden;
  background: #060a07;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.5);
}
.mode-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-right: 1px solid rgba(90,170,90,0.12);
  padding: 7px 14px;
  font-size: .76rem;
  font-family: var(--font-mono);
  cursor: pointer;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background 0.08s, color 0.08s;
  position: relative;
}
.mode-btn:last-child { border-right: none; }
.mode-btn:hover   { background: rgba(90,170,90,0.08); color: var(--text); }
.mode-btn:active  { background: rgba(90,170,90,0.12); }
.mode-btn.active  {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  box-shadow: inset 0 0 12px rgba(0,0,0,.25);
}
/* ── Blinkende terminal-cursor på aktiv fane ── */
.mode-btn.active::after {
  content: "█";
  font-size: .65rem;
  margin-left: 3px;
  animation: cursorBlink 1.1s steps(2) infinite;
  opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════
   Army Builder — layout
   ═══════════════════════════════════════════════════════════ */
#builder {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.bld-layout {
  display: flex;
  flex-direction: row;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 72px);
  box-sizing: border-box;
  min-height: 0;
}

/* ── Panels ── */
.bld-units,
.bld-list { box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.08);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
.bld-units { box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.08);
  flex: 0 0 340px;
  min-width: 260px;
}
.bld-list { box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.08);
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}

.bld-panel-title {
  background: linear-gradient(180deg, #0a0f0a, var(--surface));
  color: #7aba7a;
  font-family: var(--font-mono);
  font-size: .74rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-bottom: 2px solid #2a4a2a;
  flex-shrink: 0;
  text-shadow: 0 0 5px rgba(80, 180, 80, 0.2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.bld-panel-title::before {
  content: "> ";
  font-family: var(--font-mono);
  font-size: .68rem;
}
/* ── Terminal status indicator on panel title ── */
.bld-panel-title::after {
  content: "READY";
  margin-left: auto;
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  color: rgba(90,170,90,0.4);
  font-weight: 400;
}

/* ── FOC Tabs ── */
.bld-foc-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.bld-tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 10px;
  font-size: .72rem;
  font-family: var(--font-mono);
  cursor: pointer;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background .08s, color .08s, border-color .08s;
}
.bld-tab:hover  { background: var(--surface); color: var(--text); }
.bld-tab.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; box-shadow: 0 0 10px rgba(0,0,0,.3); }

/* ── Unit list (browser) ── */
.bld-unit-list {
  overflow-y: auto;
  flex: 1;
}
.bld-unit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  transition: background .08s;
}
.bld-unit-row:hover { background: var(--surface2); }

.bld-unit-thumb { border-radius: 0;
  width: 42px;
  height: 42px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface2);
  flex-shrink: 0;
  /* Lett CRT-filter — ytelsesvennlig */
  filter: contrast(1.08) brightness(0.88) saturate(0.72);
}

.bld-unit-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.bld-unit-name {
  font-size: .84rem;
  color: var(--text-head);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bld-unit-slot {
  font-size: .68rem;
  padding: 1px 6px;
  border-radius: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: fit-content;
  font-family: var(--font-mono);
}
.bld-unit-opts-hint {
  font-size: .7rem;
  color: var(--accent);
  cursor: default;
}

.bld-unit-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.bld-unit-pts {
  font-size: .78rem;
  color: var(--accent);
  white-space: nowrap;
  font-family: var(--font-mono);
}
.bld-add-btn {
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  border-radius: 0;
  width: 26px;
  height: 26px;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  transition: opacity .08s, box-shadow .08s;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(0,0,0,.3);
}
.bld-add-btn:hover { opacity: .85; box-shadow: 0 0 14px rgba(0,0,0,.4); }
.bld-add-btn:active { transform: scale(0.94); }
.bld-add-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: grayscale(.6);
}
.bld-add-btn:disabled:hover {
  opacity: .35;
  transform: none;
  box-shadow: none;
}

/* ── List header ── */
.bld-list-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.bld-title-input {
  background: #0a0f0a;
  color: #7aba7a;
  border: 1px solid #2a4a2a;
  border-radius: 0;
  padding: 7px 10px;
  font-size: .92rem;
  font-family: var(--font-mono);
  width: 100%;
  box-sizing: border-box;
}
.bld-title-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 10px rgba(0, 80, 0, 0.15); }
.bld-title-input::placeholder { color: #3a5a3a; }

.bld-pts-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bld-pts-label {
  font-size: .75rem;
  color: var(--text);
  letter-spacing: .04em;
}
.bld-pts-select {
  background: #0a0f0a;
  color: #7aba7a;
  border: 1px solid #2a4a2a;
  border-radius: 0;
  padding: 4px 8px;
  font-size: .82rem;
  font-family: var(--font-mono);
  cursor: pointer;
}
.bld-pts-select option { background: #0a0f0a; color: #b0d0b0; }
.bld-pts-manual { background: #0a0f0a; color: #7aba7a; border-color: #2a4a2a; font-family: var(--font-mono);
  background: var(--surface2);
  color: var(--text-head);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 6px;
  font-size: .82rem;
  font-family: inherit;
  width: 68px;
  text-align: right;
  outline: none;
}
.bld-pts-manual:focus { border-color: var(--accent); }
.bld-pts-manual::-webkit-inner-spin-button,
.bld-pts-manual::-webkit-outer-spin-button { opacity: .5; }

/* ── Points bar ── */
.bld-pts-bar-wrap {
  padding: 8px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.bld-pts-bar {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0;
  height: 8px;
  overflow: hidden;
  margin-bottom: 4px;
}
.bld-pts-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0;
  transition: width .5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.bld-pts-fill::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 40%;
  background: rgba(255,255,255,.15);
  border-radius: 4px 4px 0 0;
}
.bld-pts-bar.over .bld-pts-fill { background: #d04040; }
.bld-pts-text {
  font-size: .78rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.bld-pts-text strong { color: var(--text-head); }
.bld-pts-text.over strong { color: #d04040; }
.bld-over-badge {
  background: #d04040;
  color: #fff;
  font-size: .65rem;
  padding: 1px 5px;
  border-radius: 0;
  font-weight: 700;
  letter-spacing: .06em;
}

/* ── Entries ── */
.bld-entries {
  padding: 8px 10px;
}
.bld-slot-group { margin-bottom: 8px; }
.bld-slot-header {
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 4px 4px 4px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.bld-entry { border-color: var(--accent2); box-shadow: 0 1px 4px rgba(0,0,0,.3), 0 0 8px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.04);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 5px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: border-color .08s;
}
.bld-entry:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 14px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.10); }
.bld-entry-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: linear-gradient(135deg, rgba(0,30,0,.15), transparent);
}
/* Entry thumbnail */
.bld-entry-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface2);
  flex-shrink: 0;
  filter: contrast(1.08) brightness(0.88) saturate(0.72);
}
/* Entry info (name + stats) */
.bld-entry-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
/* Compact stats line */
.bld-entry-stats {
  font-size: .64rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* FOC validator bar */
.bld-foc-bar {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  font-size: .68rem;
  font-family: var(--font-mono);
}
.bld-foc-item {
  padding: 2px 6px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  white-space: nowrap;
}
.bld-foc-item.met { border-color: #2a6a2a; color: #5acc5a; }
.bld-foc-item.unmet { border-color: #6a2a2a; color: #cc5a5a; }
.bld-foc-item.hq { border-color: var(--accent); color: var(--accent); }
.bld-foc-item .bld-foc-count { font-weight: 700; }
.bld-entry-name {
  flex: 1;
  font-size: .86rem;
  color: var(--text-head);
}
.bld-entry-pts {
  font-size: .82rem;
  color: var(--accent);
  white-space: nowrap;
  font-family: var(--font-mono);
}
.bld-remove-btn { border-radius: 0;
  background: transparent;
  color: #9a3030;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 0;
  transition: color .08s, background .08s;
}
.bld-remove-btn:hover { color: #d04040; background: rgba(200,50,50,.15); }

/* ── Model counter ── */
.bld-model-count {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 8px;
}
.bld-model-btn {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent2);
  border-radius: 0;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  padding: 1px 6px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.bld-model-btn:hover { background: var(--accent2); color: #fff; }
.bld-model-btn-disabled { opacity: .35; cursor: default; pointer-events: none; }
.bld-model-btn-sm { font-size: .7rem; padding: 0px 5px; }
.bld-model-num {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-head);
  min-width: 1.4em;
  text-align: center;
}
.bld-model-label {
  font-size: .7rem;
  color: var(--text-dim);
  margin-left: 1px;
}
/* ── Option row (counter) ── */
.bld-opt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .79rem;
  line-height: 1.3;
  padding: 1px 0;
}
.bld-opt-row.bld-opt-disabled { opacity: .5; }
.bld-opt-row.bld-opt-counter { }
.bld-opt-counter-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.bld-opt-count {
  font-size: .74rem;
  font-weight: 600;
  color: var(--text-head);
  min-width: 2.4em;
  text-align: center;
}
.bld-opt-req {
  font-size: .7rem;
  color: var(--text-dim);
  font-style: italic;
}
.bld-opt-lbl.bld-opt-disabled { opacity: .5; cursor: default; }
.bld-opt-lbl.bld-opt-disabled .bld-opt-cb { cursor: default; }

/* ── Options ── */
.bld-entry-opts { border-top-color: var(--accent2);
  padding: 4px 10px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.bld-opt-lbl {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  cursor: pointer;
  font-size: .79rem;
  line-height: 1.3;
  padding: 1px 0;
}
.bld-opt-lbl:hover { color: var(--text-head); }
.bld-opt-cb { flex-shrink: 0; cursor: pointer; accent-color: var(--accent); margin-top: 2px; }
.bld-opt-text { flex: 1; color: var(--text); }
.bld-opt-pts {
  color: var(--accent);
  font-size: .74rem;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

/* ── Action buttons ── */
.bld-actions {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.bld-btn { font-family: var(--font-mono);
  padding: 7px 14px;
  border-radius: 0;
  border: none;
  font-size: .82rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.bld-btn:hover { opacity: .82; }
.bld-btn:active { transform: scale(0.96); }
.bld-btn-primary   { background: var(--accent); color: #000; }
.bld-btn-secondary { background: var(--surface2); color: var(--text-head); border: 1px solid var(--border); }
.bld-btn-print     { background: #1e3a2a; color: #5ec47a; border: 1px solid #2e5a3e; }
.bld-btn-print:hover { opacity: 1; background: #264d38; }
.bld-btn-danger    { background: #3a1414; color: #d04040; border: 1px solid #5a2020; }
.bld-btn-sm        { padding: 4px 10px; font-size: .76rem; font-weight: 500; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 0; transition: background .15s, transform .1s; }
.bld-btn-sm:hover  { background: var(--surface2); }
.bld-btn-sm:active { transform: scale(0.96); }
.bld-btn-del       { color: #d04040; border-color: #5a2020; }

/* ── Saved lists ── */
.bld-saved {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.bld-saved-title { font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 8px;
}
.bld-saved-item { border-color: var(--accent2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 5px;
}
.bld-saved-item.current { border-color: var(--accent); }
.bld-saved-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.bld-saved-name {
  font-size: .85rem;
  color: var(--text-head);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bld-saved-meta {
  font-size: .72rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bld-saved-btns { display: flex; gap: 5px; flex-shrink: 0; }

/* ── Empty states ── */
.bld-empty {
  padding: 14px;
  color: var(--text);
  font-size: .82rem;
  opacity: .7;
}
.bld-empty-list {
  text-align: center;
  padding: 24px 14px;
}

/* ── Lock notice ── */
.bld-lock-notice {
  padding: 8px 12px;
  background: rgba(255,255,255,.03);
  border-bottom: 1px solid var(--accent2);
  font-size: .78rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}
.bld-lock-notice strong { color: var(--accent); }

/* ── Toast ── */
.bld-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text-head);
  border: 1px solid var(--accent);
  border-radius: 0;
  padding: 10px 22px;
  font-size: .85rem;
  box-shadow: 0 4px 18px rgba(0,0,0,.5);
  z-index: 9999;
  pointer-events: none;
  transition: opacity .35s, transform .35s;
  animation: slideUp .3s ease-out;
}
.bld-toast-error { border-color: #d04040; color: #d04040; }

/* ── Export modal ── */
.bld-export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}
.bld-export-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 20px;
  width: min(600px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bld-export-title { color: var(--text-head); font-size: .95rem; font-weight: 700; }
.bld-export-ta {
  background: #0a0f0a;
  color: #7aba7a;
  border: 1px solid #2a4a2a;
  border-radius: 0;
  padding: 10px;
  font-size: .8rem;
  font-family: var(--font-mono);
  height: 280px;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
  text-shadow: 0 0 3px rgba(100, 200, 100, 0.2);
}
.bld-export-close { align-self: flex-end; }

/* ══════════════════════════════════════════════════════════
   Home page
   ══════════════════════════════════════════════════════════ */

#home { padding: 28px 24px; max-width: 1200px; margin: 0 auto; }

.home-wrap { display: flex; flex-direction: column; gap: 32px; }

/* ── Nav cards ── */
.home-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.home-nav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1px;
  padding: 28px 24px;
  cursor: pointer;
  text-align: left;
  transition: border-color .08s, background .08s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: inherit;
}
.home-nav-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.home-card-icon {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 2px;
}
.home-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
}
.home-card-desc {
  font-size: .85rem;
  color: var(--text-dim);
  line-height: 1.45;
}

/* ── Rules reference ── */
.home-rules-wrap { display: flex; flex-direction: column; gap: 0; }

.home-chapter {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  padding-top: 14px;
}

.home-rule-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.home-rule-heading {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 2px;
}
.home-rule-text {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.5;
}

/* dl for item lists (terrain types, sequence steps, cover values) */
.home-rule-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  font-size: .82rem;
}
.home-rule-list dt {
  font-weight: 700;
  color: var(--text-head);
  white-space: nowrap;
  padding-top: 1px;
}
.home-rule-list dd {
  color: var(--text);
  line-height: 1.45;
  margin: 0;
}

/* ── Home main menu (3 big buttons) ── */
.home-menu-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 180px);
}

.home-menu {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 600px;
}

.home-menu-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 28px;
  background: var(--surface);
  border: 2px solid var(--accent2);
  border-radius: 1px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  transition: border-color .08s, background .08s;
  box-shadow: 0 2px 12px rgba(0,0,0,.4), 0 0 16px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.06);
}
.home-menu-btn:hover {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 4px 20px rgba(0,0,0,.55), 0 0 28px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.12);
}
.home-menu-btn:active {
  transform: scale(0.98);
}

.home-menu-icon {
  font-size: 2.8rem;
  line-height: 1;
}

.home-menu-title {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.home-menu-sub {
  font-size: .85rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ── Back button ── */
.home-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-dim);
  font-size: .82rem;
  font-family: inherit;
  padding: 6px 14px;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
  width: fit-content;
}
.home-back-btn:hover {
  color: var(--text);
  border-color: var(--accent2);
  background: var(--surface);
}

/* ── Faction grid ── */
.faction-group {
  margin-bottom: 6px;
}
.faction-group-title {
  font-family: var(--font-mono);
  font-size: .9rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 8px 0 6px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.faction-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  padding-top: 4px;
}

.faction-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 14px 18px;
  background: var(--surface);
  border: 2px solid var(--accent2);
  border-radius: 1px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  transition: border-color .08s, background .08s;
  box-shadow: 0 2px 8px rgba(0,0,0,.4), 0 0 14px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.06);
}
.faction-card:hover {
  box-shadow:
    0 8px 30px rgba(0,0,0,.5),
    0 0 40px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), 0.15);
  border-color: var(--fc-accent, var(--accent));
  background: var(--fc-surface, var(--surface2));
}
.faction-card:active {
  transform: scale(0.97);
}
/* Glow on hover using the faction's accent colour */
.faction-card::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 1px;
  opacity: 0;
  box-shadow: 0 0 24px 4px var(--fc-accent, var(--accent));
  transition: opacity .35s;
  pointer-events: none;
  z-index: -1;
}
.faction-card:hover::after {
  opacity: .6;
}

.faction-card-emblem {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fc-accent, var(--accent));
  transition: color .3s;
}
.faction-card-emblem svg {
  width: 44px;
  height: 44px;
}

.faction-card-name {
  font-family: var(--font-mono);
  font-size: .92rem;
  font-weight: 700;
  color: var(--text-head);
  letter-spacing: .04em;
  transition: color .3s;
}
.faction-card:hover .faction-card-name {
  color: var(--fc-accent, var(--accent));
}

.faction-card-ver {
  font-size: .7rem;
  color: var(--text-dim);
  letter-spacing: .06em;
}

/* Switch .faction-card to position relative (for ::after glow) */
.faction-card {
  position: relative;
}

/* Cogitator home panels + faction dataslates */
.home-menu-wrap {
  min-height: calc(100vh - 170px);
  justify-content: center;
}

.home-menu {
  max-width: 820px;
  gap: 16px;
}

.home-menu-btn.cogitator-panel {
  position: relative;
  align-items: stretch;
  gap: 16px;
  min-height: 148px;
  padding: 14px 16px 16px;
  overflow: hidden;
  text-align: left;
  background:
    linear-gradient(90deg, rgba(120,255,120,.04), transparent 22%, rgba(220,160,70,.035) 62%, transparent),
    repeating-linear-gradient(90deg, rgba(255,255,255,.026) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #050906 0%, #0a120b 52%, #050806 100%);
  border: 1px solid rgba(118, 228, 112, .42);
  border-left-width: 4px;
  border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 18px 100%, 0 calc(100% - 18px));
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.035),
    inset 0 0 32px rgba(72, 180, 76, .06),
    0 10px 28px rgba(0,0,0,.58),
    0 0 20px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), .09);
}

.home-menu-btn.cogitator-panel::before,
.home-menu-btn.cogitator-panel::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.home-menu-btn.cogitator-panel::before {
  inset: 8px;
  border: 1px solid rgba(117, 255, 117, .14);
  border-right-color: rgba(220, 160, 70, .20);
}

.home-menu-btn.cogitator-panel::after {
  top: -80%;
  left: -20%;
  width: 36%;
  height: 260%;
  background: linear-gradient(90deg, transparent, rgba(140,255,140,.12), transparent);
  transform: rotate(18deg) translateX(-220%);
  transition: transform .65s ease;
}

.home-menu-btn.cogitator-panel:hover {
  border-color: var(--accent);
  background:
    linear-gradient(90deg, rgba(120,255,120,.07), transparent 24%, rgba(220,160,70,.055) 65%, transparent),
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #071008 0%, #0c170d 52%, #060906 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.045),
    inset 0 0 42px rgba(72, 180, 76, .09),
    0 14px 34px rgba(0,0,0,.66),
    0 0 32px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), .17);
  transition: border-color .08s, background .08s, box-shadow .08s;
}

.home-menu-btn.cogitator-panel:hover::after {
  transform: rotate(18deg) translateX(420%);
}

.home-menu-status,
.home-menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: .68rem;
  color: rgba(202, 235, 190, .66);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.home-menu-footer {
  color: rgba(220, 164, 76, .78);
  border-top: 1px solid rgba(118, 228, 112, .16);
  padding-top: 9px;
}

.status-lamp {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #72f26d;
  box-shadow: 0 0 8px rgba(114, 242, 109, .72), 0 0 18px rgba(114, 242, 109, .30);
}

.home-menu-btn:nth-child(2) .status-lamp {
  background: #e0aa42;
  box-shadow: 0 0 8px rgba(224, 170, 66, .78), 0 0 18px rgba(224, 170, 66, .30);
}

.home-menu-btn:nth-child(3) .status-lamp {
  background: #d95c45;
  box-shadow: 0 0 8px rgba(217, 92, 69, .78), 0 0 18px rgba(217, 92, 69, .28);
}

.home-menu-main {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}

.home-menu-glyph {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background:
    radial-gradient(circle at 50% 50%, rgba(116,255,116,.12), transparent 58%),
    linear-gradient(180deg, rgba(255,255,255,.035), transparent);
  border: 1px solid rgba(118, 228, 112, .26);
  box-shadow: inset 0 0 24px rgba(75, 210, 75, .08);
}

.home-menu-glyph svg {
  width: 58px;
  height: 58px;
  filter: drop-shadow(0 0 8px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), .34));
}

.home-menu-copy {
  min-width: 0;
}

.home-menu-title {
  font-size: 1.42rem;
  letter-spacing: .08em;
  line-height: 1.12;
}

.home-menu-sub {
  margin-top: 6px;
  color: rgba(212, 207, 197, .70);
}

.faction-grid {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.faction-card {
  align-items: stretch;
  gap: 0;
  min-height: 238px;
  padding: 8px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(120,255,120,.035), transparent 34%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.024) 0 1px, transparent 1px 6px),
    #060a07;
  border: 1px solid rgba(118, 228, 112, .32);
  border-left-width: 3px;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.028),
    inset 0 0 28px rgba(66, 170, 70, .055),
    0 8px 20px rgba(0,0,0,.50),
    0 0 16px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), .07);
}

.faction-card:hover {
  border-color: var(--fc-accent, var(--accent));
  background:
    linear-gradient(180deg, rgba(120,255,120,.055), transparent 34%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 1px, transparent 1px 6px),
    var(--fc-surface, #071009);
  transition: border-color .08s, background .08s;
}

.faction-card-viewport {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 104px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(80,255,80,.12), transparent 55%),
    linear-gradient(135deg, rgba(255,255,255,.045), transparent 34%),
    #020402;
  border: 1px solid rgba(118, 228, 112, .24);
  box-shadow: inset 0 0 28px rgba(0,0,0,.72);
}

.faction-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(.58) sepia(.16) hue-rotate(58deg) saturate(1.25) contrast(1.22) brightness(.72);
  opacity: .80;
  transform: scale(1.02);
  transition: filter .3s, opacity .3s, transform .45s;
}

.faction-card:hover .faction-card-thumb {
  filter: grayscale(.28) sepia(.10) hue-rotate(48deg) saturate(1.55) contrast(1.32) brightness(.86);
  opacity: .96;
  transform: scale(1.07);
}

.faction-card-thumb-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--fc-accent, var(--accent));
  opacity: .78;
}

.faction-card-thumb-fallback svg {
  width: 62px;
  height: 62px;
}

.faction-card-viewport::before,
.faction-card-viewport::after,
.faction-card-reticle {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.faction-card-viewport::before {
  background:
    repeating-linear-gradient(0deg, transparent 0 4px, rgba(0,0,0,.30) 4px 5px),
    linear-gradient(180deg, rgba(116,255,116,.11), transparent 38%, rgba(0,0,0,.22));
  mix-blend-mode: screen;
  opacity: .54;
}

.faction-card-viewport::after {
  height: 35%;
  background: linear-gradient(180deg, transparent, rgba(132,255,132,.18), transparent);
  animation: scanlineDrift 3.8s linear infinite;
  opacity: .55;
}

.faction-card-reticle {
  border: 1px solid rgba(150,255,150,.18);
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(150,255,150,.20) 50%, transparent calc(50% + 1px)),
    linear-gradient(0deg, transparent calc(50% - 1px), rgba(150,255,150,.20) 50%, transparent calc(50% + 1px));
}

.faction-card-emblem {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 40px;
  height: 40px;
  color: var(--fc-accent, var(--accent));
  opacity: .88;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(150,255,150,.20);
  box-shadow: 0 0 14px rgba(var(--crt-glow-r, 0), var(--crt-glow-g, 0), var(--crt-glow-b, 0), .20);
}

.faction-card-emblem svg {
  width: 30px;
  height: 30px;
}

.faction-card-lock {
  position: absolute;
  left: 8px;
  top: 7px;
  padding: 2px 6px;
  font-size: .58rem;
  letter-spacing: .10em;
  color: rgba(222, 168, 70, .88);
  background: rgba(0,0,0,.46);
  border: 1px solid rgba(222, 168, 70, .28);
}

.faction-card-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 104px;
  padding: 12px 6px 4px;
}

.faction-card-name {
  min-height: 2.3em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .90rem;
  line-height: 1.15;
  letter-spacing: .035em;
  overflow-wrap: anywhere;
}

.faction-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: rgba(212, 207, 197, .62);
  font-size: .61rem;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.faction-card-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.faction-card:hover .faction-card-lock,
.faction-card:hover .faction-card-name {
  color: var(--fc-accent, var(--accent));
}

/* ── Responsive home menu ── */
@media (max-width: 480px) {
  .home-menu-btn { padding: 22px 18px; }
  .home-menu-icon { font-size: 2.2rem; }
  .home-menu-title { font-size: 1.1rem; }
  .faction-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .faction-card { padding: 16px 10px 14px; }
  .home-menu-btn.cogitator-panel { padding: 12px; min-height: 136px; }
  .home-menu-main { grid-template-columns: 58px minmax(0, 1fr); gap: 12px; }
  .home-menu-glyph { width: 54px; height: 54px; }
  .home-menu-glyph svg { width: 40px; height: 40px; }
  .home-menu-status,
  .home-menu-footer { font-size: .56rem; }
  .faction-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .faction-card { min-height: 218px; padding: 7px; }
  .faction-card-body { min-height: 96px; padding: 10px 4px 3px; }
  .faction-card-name { font-size: .78rem; }
  .faction-card-meta { font-size: .53rem; }
}

/* Stronger grimdark cogitator pass */
.machine-shell {
  position: relative;
  border: 1px solid rgba(88, 180, 82, .42);
  background:
    radial-gradient(circle at 18% 16%, rgba(82, 255, 82, .055), transparent 18%),
    radial-gradient(circle at 86% 84%, rgba(220, 154, 48, .032), transparent 22%),
    repeating-linear-gradient(90deg, rgba(60, 180, 62, .045) 0 1px, transparent 1px 13px),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 19px),
    linear-gradient(180deg, #020402 0%, #050906 45%, #030503 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.035),
    inset 0 0 70px rgba(0,0,0,.72),
    0 18px 46px rgba(0,0,0,.72),
    0 0 34px rgba(68, 190, 70, .08);
}

.machine-shell::before,
.machine-shell::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.machine-shell::before {
  inset: -10px;
  border: 1px solid rgba(84, 170, 78, .18);
  clip-path: polygon(0 0, 150px 0, 150px 2px, 2px 2px, 2px 70px, 0 70px, 0 0, 100% 0, 100% 100%, 0 100%, 0 calc(100% - 70px), 2px calc(100% - 70px), 2px calc(100% - 2px), 150px calc(100% - 2px), 150px 100%, 0 100%);
}

.machine-shell::after {
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 5px, rgba(0,0,0,.20) 5px 6px),
    linear-gradient(90deg, rgba(0,0,0,.38), transparent 22%, transparent 78%, rgba(0,0,0,.42));
  opacity: .62;
  mix-blend-mode: multiply;
}

.machine-shell > * {
  position: relative;
  z-index: 1;
}

.machine-shell-top,
.machine-shell-bottom {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 12px;
  color: rgba(140, 240, 130, .60);
  font-size: .62rem;
  letter-spacing: .11em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(84, 170, 78, .22);
}

.machine-shell-bottom {
  border-top: 1px solid rgba(84, 170, 78, .22);
  border-bottom: 0;
  color: rgba(222, 166, 60, .66);
}

.home-menu-wrap {
  padding-top: 32px;
}

.home-console {
  width: min(980px, 92vw);
  padding: 0;
  clip-path: polygon(0 0, calc(100% - 26px) 0, 100% 26px, 100% 100%, 26px 100%, 0 calc(100% - 26px));
}

.home-console-grid {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) 116px;
  gap: 14px;
  padding: 18px;
}

.home-console-rail,
.faction-console-rail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px;
  min-width: 0;
  color: rgba(144, 235, 132, .62);
  font-size: .61rem;
  letter-spacing: .10em;
  text-transform: uppercase;
  border: 1px solid rgba(84, 170, 78, .24);
  background:
    linear-gradient(180deg, rgba(80,180,80,.08), transparent 48%),
    rgba(0,0,0,.26);
}

.home-console-rail-right {
  color: rgba(220, 140, 72, .68);
  border-color: rgba(220, 140, 72, .22);
}

.rail-sigil {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  color: rgba(122, 255, 116, .86);
  border: 1px solid rgba(122, 255, 116, .30);
  box-shadow: inset 0 0 18px rgba(122,255,116,.08);
  font-weight: 700;
}

.rail-meter {
  height: 54px;
  margin-top: auto;
  border: 1px solid rgba(122,255,116,.20);
  background: linear-gradient(180deg, transparent, rgba(122,255,116,.05));
  overflow: hidden;
}

.rail-meter span {
  display: block;
  width: 100%;
  height: 58%;
  margin-top: 22%;
  background:
    repeating-linear-gradient(0deg, rgba(122,255,116,.52) 0 2px, transparent 2px 5px);
  box-shadow: 0 0 14px rgba(122,255,116,.28);
}

.home-menu {
  max-width: none;
  gap: 10px;
}

.home-menu-btn.cogitator-panel {
  min-height: 126px;
  border-left-width: 8px;
  border-color: rgba(80, 168, 76, .38);
  background:
    linear-gradient(90deg, rgba(100,255,100,.08), transparent 16%, rgba(0,0,0,.30) 72%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.022) 0 1px, transparent 1px 9px),
    #030603;
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.032),
    inset 0 0 44px rgba(0,0,0,.58),
    0 6px 20px rgba(0,0,0,.50);
}

.home-menu-btn.cogitator-panel:hover {
  background:
    linear-gradient(90deg, rgba(118,255,118,.12), transparent 16%, rgba(0,0,0,.20) 72%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.028) 0 1px, transparent 1px 9px),
    #050b05;
}

.home-menu-main {
  grid-template-columns: 72px minmax(0, 1fr);
}

.home-menu-glyph {
  width: 62px;
  height: 62px;
  color: rgba(120, 255, 110, .82);
  background: rgba(0,0,0,.32);
}

.home-menu-glyph svg {
  width: 43px;
  height: 43px;
}

.home-menu-title {
  font-size: 1.25rem;
}

.home-menu-runes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 5px 0 2px 90px;
  color: rgba(125, 210, 120, .48);
  font-size: .56rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.home-menu-runes span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.faction-console-wrap {
  max-width: 1240px;
}

.faction-console {
  display: grid;
  grid-template-columns: 154px minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
  margin-top: 18px;
}

.faction-console-main {
  min-width: 0;
}

.faction-console .faction-group {
  margin-bottom: 20px;
  padding: 10px 10px 14px;
  border: 1px solid rgba(84, 170, 78, .16);
  background: rgba(0,0,0,.18);
}

.faction-group-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(116, 255, 112, .78);
  border-bottom-color: rgba(84, 170, 78, .25);
}

.faction-group-title span:last-child {
  color: rgba(218, 164, 70, .62);
  font-size: .68rem;
}

.faction-grid {
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 10px;
}

.faction-card {
  min-height: 214px;
  padding: 7px;
  border-left-width: 6px;
  border-color: rgba(76, 155, 72, .35);
  background:
    linear-gradient(180deg, rgba(80,180,80,.055), transparent 30%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.020) 0 1px, transparent 1px 8px),
    #020502;
}

.faction-card-topline,
.faction-card-seal {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: rgba(218, 164, 70, .64);
  font-size: .54rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.faction-card-topline {
  padding: 1px 2px 6px;
}

.faction-card-viewport {
  min-height: 82px;
  border-color: rgba(118, 228, 112, .18);
  box-shadow: inset 0 0 34px rgba(0,0,0,.86);
}

.faction-card-thumb {
  filter: grayscale(1) sepia(.42) hue-rotate(54deg) saturate(1.65) contrast(1.55) brightness(.48);
  opacity: .66;
}

.faction-card:hover .faction-card-thumb {
  filter: grayscale(.88) sepia(.42) hue-rotate(54deg) saturate(1.9) contrast(1.75) brightness(.62);
  opacity: .82;
}

.faction-card-viewport::before {
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.42) 3px 4px),
    repeating-linear-gradient(90deg, transparent 0 9px, rgba(120,255,120,.08) 9px 10px),
    radial-gradient(circle at 50% 50%, rgba(120,255,120,.16), transparent 52%),
    linear-gradient(180deg, rgba(116,255,116,.14), transparent 38%, rgba(0,0,0,.40));
  opacity: .78;
}

.faction-card-reticle {
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(150,255,150,.16) 50%, transparent calc(50% + 1px)),
    linear-gradient(0deg, transparent calc(50% - 1px), rgba(150,255,150,.16) 50%, transparent calc(50% + 1px)),
    radial-gradient(circle, transparent 0 24px, rgba(150,255,150,.20) 25px, transparent 26px);
}

.faction-card-emblem {
  width: 33px;
  height: 33px;
  opacity: .58;
  filter: grayscale(1);
}

.faction-card-emblem svg {
  width: 24px;
  height: 24px;
}

.faction-card-lock {
  color: rgba(218, 164, 70, .72);
  background: rgba(0,0,0,.62);
}

.faction-card-name {
  min-height: 2.1em;
  color: rgba(224, 232, 205, .82);
  font-size: .82rem;
}

.faction-card-meta {
  color: rgba(190, 205, 178, .48);
  font-size: .55rem;
}

.faction-card-seal {
  margin-top: auto;
  padding-top: 7px;
  border-top: 1px solid rgba(84, 170, 78, .16);
}

@media (max-width: 820px) {
  .home-console-grid,
  .faction-console {
    grid-template-columns: 1fr;
  }
  .home-console-rail,
  .faction-console-rail {
    display: none;
  }
  .home-menu-runes {
    grid-template-columns: 1fr;
    padding-left: 0;
  }
}

/* Faction matrix pass: no thumbnails, all factions visible on desktop */
@keyframes cogitatorPan {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: 140px 0, -80px 60px, 0 96px, 32px 0, 0 0; }
}

@keyframes signalBlink {
  0%, 44%, 100% { opacity: .42; }
  45%, 54% { opacity: 1; }
}

@keyframes runeCycle {
  0%, 44% { transform: translateY(0); }
  50%, 94% { transform: translateY(-1.25em); }
  100% { transform: translateY(0); }
}

@keyframes scanAcross {
  0% { transform: translateX(-120%); opacity: 0; }
  12%, 70% { opacity: .75; }
  100% { transform: translateX(170%); opacity: 0; }
}

@keyframes tileTelemetry {
  0%, 100% { opacity: .18; transform: translateY(-1px); }
  42% { opacity: .52; transform: translateY(0); }
  46% { opacity: .08; transform: translateY(1px); }
  50% { opacity: .46; transform: translateY(0); }
}

@keyframes matrixTicker {
  0%, 28% { transform: translateY(0); }
  33%, 61% { transform: translateY(-1.25em); }
  66%, 94% { transform: translateY(-2.5em); }
  100% { transform: translateY(0); }
}

.machine-shell {
  background:
    linear-gradient(115deg, transparent 0 42%, rgba(125,255,120,.06) 43%, transparent 45%),
    radial-gradient(circle at 18% 16%, rgba(82, 255, 82, .055), transparent 18%),
    repeating-linear-gradient(90deg, rgba(60, 180, 62, .045) 0 1px, transparent 1px 13px),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 19px),
    linear-gradient(180deg, #020402 0%, #050906 45%, #030503 100%);
  background-size: 220px 220px, 100% 100%, 96px 96px, 140px 140px, 100% 100%;
  animation: cogitatorPan 18s linear infinite;
}

.rune-cycle,
.rail-cycle,
.matrix-ticker {
  display: inline-block;
  height: 1.2em;
  overflow: hidden;
  vertical-align: bottom;
}

.rune-cycle > span,
.rail-cycle > span,
.matrix-ticker > span {
  display: block;
  height: 1.25em;
}

.rune-cycle > span {
  animation: runeCycle 4.6s steps(1, end) infinite;
}

.rail-cycle > span {
  animation: matrixTicker 6.8s steps(1, end) infinite;
}

.matrix-ticker > span {
  animation: matrixTicker 7.2s steps(1, end) infinite;
}

.status-lamp,
.rail-sigil {
  animation: signalBlink 2.8s steps(1, end) infinite;
}

.home-menu-btn:nth-child(2) .status-lamp {
  animation-duration: 1.7s;
}

.home-menu-btn:nth-child(3) .status-lamp {
  animation-duration: 3.4s;
}

.faction-console {
  grid-template-columns: 142px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: auto;
  margin-top: 0;
}

#home:has(.faction-console-wrap) {
  padding-top: 16px;
}

.faction-console-wrap {
  gap: 14px;
}

.faction-console-wrap .section-title {
  margin: 4px 0 0;
}

.faction-console-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faction-matrix-head,
.faction-matrix-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 10px;
  border: 1px solid rgba(84,170,78,.22);
  background: rgba(0,0,0,.30);
  color: rgba(132, 240, 124, .70);
  font-size: .62rem;
  letter-spacing: .10em;
  text-transform: uppercase;
}

.faction-matrix-foot {
  color: rgba(218, 164, 70, .66);
}

.faction-matrix {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.faction-card.faction-matrix-tile {
  min-height: 86px;
  height: 86px;
  padding: 6px 7px;
  position: relative;
  align-items: stretch;
  justify-content: space-between;
  border-left-width: 5px;
  border-color: rgba(78, 170, 74, .34);
  background:
    linear-gradient(90deg, rgba(90,220,90,.060), transparent 35%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 1px, transparent 1px 7px),
    #020502;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.022),
    inset 0 0 24px rgba(0,0,0,.72),
    0 5px 12px rgba(0,0,0,.40);
  text-align: left;
}

.faction-card.faction-matrix-tile::before {
  content: "";
  position: absolute;
  top: 5px;
  right: 6px;
  width: 28px;
  height: 9px;
  opacity: .22;
  background:
    linear-gradient(90deg, var(--group-signal, rgba(116,255,116,.7)) 0 3px, transparent 3px 6px),
    linear-gradient(90deg, transparent 0 8px, var(--group-signal, rgba(116,255,116,.7)) 8px 11px, transparent 11px 15px),
    linear-gradient(90deg, transparent 0 18px, var(--group-signal, rgba(116,255,116,.7)) 18px 28px);
  box-shadow: 0 0 10px rgba(100,255,100,.20);
}

.faction-card.faction-matrix-tile:hover {
  border-color: var(--fc-accent, var(--accent));
  background:
    linear-gradient(90deg, rgba(116,255,116,.105), transparent 35%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.024) 0 1px, transparent 1px 7px),
    #041004;
}

.group-astartes { --group-signal: rgba(190,255,190,.72); }
.group-imperial { --group-signal: rgba(218, 164, 70, .76); }
.group-chaos { --group-signal: rgba(230, 78, 62, .78); }
.group-xenos { --group-signal: rgba(96, 220, 190, .72); }

.faction-card.faction-matrix-tile {
  border-left-color: var(--group-signal, rgba(78,170,74,.42));
}

.matrix-tile-top,
.matrix-tile-bottom {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  position: relative;
  z-index: 1;
  color: rgba(218, 164, 70, .64);
  font-size: .49rem;
  letter-spacing: .075em;
  text-transform: uppercase;
  line-height: 1;
}

.matrix-tile-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  align-items: center;
  position: relative;
  z-index: 1;
  min-height: 42px;
}

.matrix-copy {
  min-width: 0;
}

.faction-matrix-tile .faction-card-name {
  min-height: 0;
  display: block;
  color: rgba(225, 242, 205, .88);
  font-family: var(--font-mono);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .075em;
  line-height: 1.02;
  text-align: left;
  text-transform: uppercase;
  white-space: normal;
  overflow-wrap: anywhere;
  text-shadow:
    0 0 10px rgba(90, 255, 90, .18),
    1px 0 0 rgba(132, 255, 132, .10);
}

.faction-matrix-tile .faction-card-meta {
  display: block;
  margin-top: 5px;
  color: rgba(218, 164, 70, .62);
  font-family: var(--font-mono);
  font-size: .48rem;
  letter-spacing: .055em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.faction-matrix-tile .faction-card-meta-secondary {
  margin-top: 4px;
  color: rgba(148, 210, 132, .54);
}

.matrix-tile-bottom {
  color: rgba(148, 210, 132, .48);
}

.group-chaos .matrix-tile-bottom,
.group-chaos .matrix-tile-top {
  color: rgba(230, 82, 66, .62);
}

.group-xenos .matrix-tile-bottom {
  color: rgba(96, 220, 190, .55);
}

.matrix-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.matrix-scan::before {
  content: "";
  position: absolute;
  top: -20%;
  left: 0;
  width: 34%;
  height: 150%;
  background: linear-gradient(90deg, transparent, rgba(132,255,132,.13), transparent);
  transform: translateX(-130%);
}

.faction-matrix-tile:hover .matrix-scan::before {
  animation: scanAcross .52s linear;
}

.faction-card-viewport,
.faction-card-thumb,
.faction-card-thumb-fallback,
.faction-card-reticle,
.faction-card-lock,
.faction-card-seal {
  display: none;
}

@media (max-height: 820px) and (min-width: 900px) {
  .faction-console-wrap {
    padding-top: 10px;
  }
  .faction-console {
    margin-top: 10px;
  }
  .faction-card.faction-matrix-tile {
    height: 76px;
    min-height: 76px;
  }
  .faction-matrix-tile .faction-card-name {
    font-size: .70rem;
  }
  .matrix-tile-top,
  .matrix-tile-bottom,
  .faction-matrix-tile .faction-card-meta {
    font-size: .43rem;
  }
}

@media (max-width: 980px) {
  .faction-matrix {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

/* ═══════════════════════════════════════════════════════════
   Endringslogg — TRANSMISSION LOG
   ═══════════════════════════════════════════════════════════ */
#changelog {
  padding: 20px 24px;
  max-width: 900px;
  margin: 0 auto;
}

.changelog-loading {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 1rem;
}

.changelog-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.changelog-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: .6;
}
.changelog-empty p {
  font-size: 1.05rem;
  margin-bottom: 8px;
}
.changelog-empty-sub {
  font-size: .82rem !important;
  max-width: 420px;
  margin: 0 auto;
  line-height: 1.5;
}

/* ── Timeline layout ── */
.changelog-timeline {
  position: relative;
  padding-left: 0;
}
/* Vertical data conduit */
.changelog-timeline::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg,
    var(--accent2) 0%, var(--accent2) 40%,
    rgba(90,170,90,0.15) 40%, rgba(90,170,90,0.15) 42%,
    var(--accent2) 42%, var(--accent2) 100%);
  background-size: 100% 8px;
}

.changelog-date-group {
  margin-bottom: 28px;
  position: relative;
}

.changelog-date-marker {
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 6px 0 6px 40px;
  margin-bottom: 8px;
  position: relative;
}
.changelog-date-marker::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 0;
  background: var(--accent);
  border: 2px solid var(--bg);
  z-index: 2;
  box-shadow: 0 0 6px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.3);
}

/* ── Entry cards — terminal log panels ── */
.changelog-entry {
  display: flex;
  gap: 0;
  margin-bottom: 6px;
  margin-left: 40px;
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-left: 3px solid var(--accent2);
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
  transition: border-color .08s;
}
.changelog-entry:hover {
  border-color: var(--accent);
  border-left-color: var(--accent);
  box-shadow: 0 3px 12px rgba(0,0,0,.4);
}

.changelog-entry-accent {
  width: 4px;
  flex-shrink: 0;
  min-height: 100%;
}

.changelog-entry-content {
  padding: 10px 14px;
  flex: 1;
  min-width: 0;
}

.changelog-entry-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.changelog-entry-type {
  font-size: .76rem;
  font-weight: 600;
  color: var(--text-head);
}

.changelog-entry-army {
  font-size: .72rem;
  color: var(--accent);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 0;
  border: 1px solid var(--border);
}

.changelog-entry-unit {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-head);
  margin-bottom: 2px;
}

.changelog-entry-desc {
  font-size: .8rem;
  color: var(--text-dim);
  line-height: 1.45;
}

@media (max-width: 480px) {
  #changelog { padding: 12px 10px; }
  .changelog-timeline::before { left: 13px; }
  .changelog-date-marker { padding-left: 32px; font-size: .72rem; }
  .changelog-date-marker::before { left: 9px; width: 8px; height: 8px; }
  .changelog-entry { margin-left: 32px; }
  .changelog-entry-content { padding: 8px 10px; }
}

/* ═══════════════════════════════════════════════════════════
   Admin panel — terminal form styles
   ═══════════════════════════════════════════════════════════ */
.admin-body {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 24px;
}

.admin-login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 20px;
}

.admin-login-title {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  color: var(--text-head);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--accent2);
  padding-bottom: 12px;
}

.admin-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Form elements ── */
.admin-form-group {
  margin-bottom: 14px;
}

.admin-label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
  font-family: var(--font-mono);
}

.admin-input,
.admin-textarea,
.admin-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--accent2);
  border-radius: 0;
  padding: 7px 10px;
  font-size: .86rem;
  font-family: var(--font-mono);
  width: 100%;
  box-sizing: border-box;
  transition: border-color .08s, box-shadow .08s;
}
.admin-input:focus,
.admin-textarea:focus,
.admin-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(var(--crt-glow-r,0),var(--crt-glow-g,0),var(--crt-glow-b,0),0.15);
}
.admin-input.error,
.admin-textarea.error {
  border-color: var(--red);
}

.admin-textarea {
  min-height: 70px;
  resize: vertical;
}

.admin-input-sm {
  width: 70px;
  text-align: center;
  padding: 5px 6px;
}

.admin-error-msg {
  font-size: .74rem;
  color: var(--red);
  margin-top: 3px;
  display: none;
}
.admin-error-msg.visible { display: block; }

/* ── Buttons ── */
.admin-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--accent2);
  text-transform: uppercase;
  letter-spacing: .04em;
  transition: background .08s, border-color .08s, opacity .08s;
}
.admin-btn:active { transform: scale(0.97); }
.admin-btn:disabled { opacity: .4; cursor: not-allowed; }

.admin-btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.admin-btn-primary:hover { opacity: .85; }

.admin-btn-secondary {
  background: var(--surface2);
  color: var(--text);
}
.admin-btn-secondary:hover { background: var(--surface); border-color: var(--accent2); }

.admin-btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}
.admin-btn-danger:hover { background: rgba(192,80,64,.1); }

.admin-btn-sm {
  padding: 4px 10px;
  font-size: .76rem;
}

/* ── Codex selector + unit list ── */
.admin-codex-select {
  min-width: 240px;
}

.admin-unit-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
}

.admin-unit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-left: 2px solid var(--accent2);
  border-radius: 0;
  transition: background .08s, border-color .08s;
}
.admin-unit-row:hover { background: var(--surface2); border-color: var(--accent); border-left-color: var(--accent); }

.admin-unit-row-name {
  font-size: .86rem;
  color: var(--text-head);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-unit-row-slot {
  font-size: .7rem;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 0;
  border: 1px solid var(--border);
}

.admin-unit-row-pts {
  font-size: .8rem;
  color: var(--accent);
  font-weight: 600;
}

/* ── Edit form ── */
.admin-edit-form {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-left: 3px solid var(--accent);
  border-radius: 0;
  padding: 20px;
  margin-bottom: 20px;
}

.admin-edit-title {
  font-family: var(--font-mono);
  font-size: .95rem;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent2);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.admin-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.admin-form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

/* ── Stat profile table (editable) ── */
.admin-stat-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: .8rem;
}
.admin-stat-table th {
  background: #0a0a10;
  color: var(--accent);
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 5px 4px;
  text-align: center;
  border: 1px solid var(--accent2);
  font-family: var(--font-mono);
}
.admin-stat-table td {
  padding: 3px 4px;
  border: 1px solid var(--border);
  text-align: center;
}
.admin-stat-table input {
  width: 100%;
  min-width: 40px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 3px 5px;
  font-size: .78rem;
  font-family: inherit;
  text-align: center;
  box-sizing: border-box;
}
.admin-stat-table input:focus {
  outline: none;
  border-color: var(--accent);
}
.admin-stat-table .admin-stat-name {
  min-width: 100px;
}

/* ── Dynamic list (wargear, special rules, options, etc.) ── */
.admin-dyn-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.admin-dyn-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-dyn-row .admin-input {
  flex: 1;
}

.admin-dyn-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 0;
  transition: color .15s, background .15s;
}
.admin-dyn-remove:hover {
  color: var(--red);
  background: rgba(192,80,64,.1);
}

/* ── Autocomplete ── */
.admin-autocomplete-wrap {
  position: relative;
  flex: 1;
}

.admin-autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  display: none;
}
.admin-autocomplete-dropdown.visible { display: block; }

.admin-autocomplete-item {
  padding: 7px 10px;
  font-size: .82rem;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.admin-autocomplete-item:hover,
.admin-autocomplete-item.active {
  background: var(--surface2);
  color: var(--accent);
}
.admin-autocomplete-new {
  color: var(--accent);
  font-style: italic;
}

/* ── Modal overlay ── */
.admin-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.admin-modal {
  background: var(--surface);
  border: 1px solid var(--accent2);
  border-radius: 10px;
  padding: 24px;
  width: min(500px, 90vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}

.admin-modal-title {
  font-family: var(--font-mono);
  font-size: .95rem;
  color: var(--text-head);
  margin-bottom: 14px;
}

.admin-modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ── Toast notification ── */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  font-size: .84rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp .3s ease-out;
  max-width: 380px;
}
.admin-toast.success { border-color: var(--green); }
.admin-toast.error   { border-color: var(--red); }
.admin-toast.success .admin-toast-icon { color: var(--green); }
.admin-toast.error   .admin-toast-icon { color: var(--red); }

.admin-toast-icon { font-size: 1.1rem; }

/* ── Responsive admin ── */
@media (max-width: 640px) {
  .admin-body { padding: 12px 10px; }
  .admin-form-row,
  .admin-form-row-3 { grid-template-columns: 1fr; }
  .admin-header { flex-direction: column; align-items: stretch; }
  .admin-unit-row { flex-wrap: wrap; }
  .admin-codex-select { min-width: 0; width: 100%; }
  .admin-autocomplete-dropdown { left: 0; right: 0; max-width: none; }
}

/* ═══════════════════════════════════════════════════════════
   Sub-faction selector — Codex Viewer & Army Builder
   ═══════════════════════════════════════════════════════════ */

/* ── Selector bar ── */
.subfaction-bar {
  margin-bottom: 12px;
}

.subfaction-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: .92rem;
  font-family: var(--font-mono);
  cursor: pointer;
  outline: none;
  min-width: 280px;
}
.subfaction-select:hover,
.subfaction-select:focus {
  border-color: var(--accent);
}

/* ── Info panel (Codex) ── */
.subfaction-panel {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.subfaction-flavor {
  font-style: italic;
  color: var(--text-dim);
  font-size: .88rem;
  margin-bottom: 10px;
}

.subfaction-rules {
  margin-top: 8px;
}

.subfaction-rule {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 6px;
}

.subfaction-global {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.subfaction-global-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.subfaction-tag {
  background: var(--accent2);
  color: var(--accent);
  border-color: var(--accent);
}

.subfaction-exclude {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--red);
}

.subfaction-exclude-label {
  font-weight: 600;
}

/* ── Unit card modifiers ── */
.unit-card-excluded {
  opacity: 0.45;
  filter: grayscale(0.5);
}

.unit-card-excluded:hover {
  opacity: 0.7;
}

.unit-card-modified {
  border-left: 3px solid var(--accent);
}

.unit-excluded-badge {
  font-size: .7rem;
  background: var(--red);
  color: #fff;
  padding: 2px 8px;
  border-radius: 0;
  margin-left: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}

/* ── Builder excluded unit rows ── */
.bld-unit-row.bld-unit-excluded {
  opacity: 0.4;
  filter: grayscale(0.6);
}

.bld-unit-row.bld-unit-excluded:hover {
  opacity: 0.65;
}

/* ── Subfaction-granted options ── */
.opt-subfaction {
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}

.opt-sf-tag {
  font-size: .7rem;
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}

/* ── Stat modifiers ── */
.stat-modified {
  color: var(--accent);
  font-weight: 700;
}

.stat-improved {
  color: var(--green);
  font-weight: 700;
}

.stat-degraded {
  color: var(--red);
  font-weight: 700;
}

.stat-original {
  text-decoration: line-through;
  color: var(--text-dim);
  font-size: .75rem;
  margin-right: 4px;
}

/* ── Builder sub-faction styles ── */
.bld-subfaction-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.bld-subfaction-label {
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

.bld-subfaction-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: .82rem;
  cursor: pointer;
  outline: none;
  flex: 1;
  min-width: 180px;
}

.bld-subfaction-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bld-subfaction-select:hover:not(:disabled),
.bld-subfaction-select:focus:not(:disabled) {
  border-color: var(--accent);
}

.bld-subfaction-info {
  font-size: .75rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 2px solid var(--accent);
}

/* Simple faction index pass: title list + hover inspection panel */
.faction-index-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 12px;
  align-items: stretch;
}

.faction-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
  align-content: start;
}

.faction-list .faction-card.faction-matrix-tile {
  min-height: 27px;
  height: 27px;
  padding: 0 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  border-left-width: 4px;
  background:
    linear-gradient(90deg, rgba(100, 220, 100, .075), transparent 34%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.016) 0 1px, transparent 1px 9px),
    rgba(0,0,0,.38);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.018),
    inset 0 0 14px rgba(0,0,0,.65);
}

.faction-list .faction-card.faction-matrix-tile::before {
  display: none;
}

.faction-list .faction-card.faction-matrix-tile:hover,
.faction-list .faction-card.faction-matrix-tile:focus-visible {
  outline: none;
  border-color: var(--fc-accent, var(--accent));
  background:
    linear-gradient(90deg, rgba(132, 255, 132, .16), transparent 46%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.026) 0 1px, transparent 1px 9px),
    rgba(3, 16, 4, .82);
}

.faction-list .faction-card-name {
  min-height: 0;
  display: block;
  width: 100%;
  color: rgba(226, 246, 208, .86);
  font-family: var(--font-mono);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .085em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.faction-list .faction-card:hover .faction-card-name,
.faction-list .faction-card:focus-visible .faction-card-name {
  color: var(--fc-accent, var(--accent));
}

.faction-inspector {
  position: relative;
  min-height: 100%;
  padding: 14px;
  border: 1px solid rgba(84, 170, 78, .26);
  background:
    linear-gradient(180deg, rgba(84,170,78,.070), transparent 38%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.016) 0 1px, transparent 1px 12px),
    rgba(0,0,0,.34);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.020),
    inset 0 0 34px rgba(0,0,0,.68);
  overflow: hidden;
}

.faction-inspector::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(84, 170, 78, .14);
  pointer-events: none;
}

.inspector-kicker {
  color: rgba(218, 164, 70, .70);
  font-size: .58rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.inspector-title {
  margin-top: 12px;
  color: rgba(226, 246, 208, .92);
  font-family: var(--font-mono);
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: .09em;
  line-height: 1.08;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(90,255,90,.18);
}

.inspector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

.inspector-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(84, 170, 78, .18);
  background: rgba(0,0,0,.26);
}

.inspector-grid span {
  display: block;
  color: rgba(148, 210, 132, .48);
  font-size: .50rem;
  letter-spacing: .10em;
  text-transform: uppercase;
}

.inspector-grid strong {
  display: block;
  margin-top: 5px;
  color: rgba(210, 226, 192, .82);
  font-size: .58rem;
  letter-spacing: .055em;
  line-height: 1.15;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.inspector-warning,
.inspector-subwarning {
  margin-top: 14px;
  padding: 9px 10px;
  border-left: 3px solid rgba(218, 164, 70, .72);
  background: rgba(218, 164, 70, .06);
  color: rgba(226, 180, 78, .82);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .075em;
  line-height: 1.2;
  text-transform: uppercase;
}

.inspector-subwarning {
  margin-top: 8px;
  border-left-color: rgba(84, 170, 78, .52);
  background: rgba(84, 170, 78, .055);
  color: rgba(146, 214, 132, .72);
}

.inspector-bars {
  position: absolute;
  right: 14px;
  bottom: 14px;
  left: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.inspector-bars span {
  height: 5px;
  background: rgba(84, 255, 84, .32);
  box-shadow: 0 0 10px rgba(84, 255, 84, .18);
}

@media (max-height: 820px) and (min-width: 900px) {
  .faction-list .faction-card.faction-matrix-tile {
    height: 24px;
    min-height: 24px;
  }

  .faction-list .faction-card-name {
    font-size: .61rem;
  }

  .inspector-title {
    font-size: .96rem;
  }

  .inspector-grid {
    margin-top: 12px;
  }

  .inspector-warning,
  .inspector-subwarning {
    margin-top: 10px;
  }
}

@media (max-width: 980px) {
  .faction-index-layout {
    grid-template-columns: 1fr;
  }

  .faction-list {
    grid-template-columns: 1fr;
  }

  .faction-inspector {
    min-height: 220px;
  }
}

@keyframes railReadoutSweep {
  0% { transform: translateY(-115%); opacity: 0; }
  15%, 75% { opacity: .7; }
  100% { transform: translateY(115%); opacity: 0; }
}

@keyframes railFluffCycle {
  0%, 20% { transform: translateY(0); }
  25%, 45% { transform: translateY(-3.6em); }
  50%, 70% { transform: translateY(-7.2em); }
  75%, 95% { transform: translateY(-10.8em); }
  100% { transform: translateY(0); }
}

.faction-console-rail {
  position: relative;
  overflow: hidden;
  gap: 8px;
}

.faction-console-rail::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(84, 170, 78, .10);
  pointer-events: none;
}

.faction-console-rail .rail-sigil {
  margin-bottom: 2px;
}

.rail-label {
  color: rgba(146, 235, 132, .66);
}

.rail-fluff {
  min-height: 4.2em;
  max-height: 4.2em;
  padding: 8px 7px;
  border-left: 3px solid rgba(122, 255, 116, .30);
  background: rgba(0, 0, 0, .24);
  color: rgba(226, 246, 208, .76);
  font-size: .55rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: .075em;
  overflow: hidden;
}

.rail-fluff span {
  display: block;
  min-height: 3.6em;
  animation: railFluffCycle 18s steps(1, end) infinite;
}

.rail-scripture {
  padding: 7px 6px;
  color: rgba(218, 164, 70, .72);
  border: 1px solid rgba(218, 164, 70, .18);
  background: rgba(218, 164, 70, .040);
  font-size: .50rem;
  line-height: 1.35;
  letter-spacing: .08em;
}

.rail-static-lines {
  display: grid;
  gap: 5px;
  padding: 6px;
  border: 1px solid rgba(84, 170, 78, .13);
  background: rgba(0, 0, 0, .18);
}

.rail-static-lines span {
  height: 3px;
  background: linear-gradient(90deg, rgba(122,255,116,.44), transparent);
  box-shadow: 0 0 8px rgba(122,255,116,.16);
}

.rail-static-lines span:nth-child(2) { width: 72%; }
.rail-static-lines span:nth-child(3) { width: 84%; }
.rail-static-lines span:nth-child(4) { width: 52%; }

.rail-live-name {
  min-height: 2.5em;
  padding: 7px 6px;
  border-left: 3px solid rgba(122, 255, 116, .38);
  background: rgba(0, 0, 0, .26);
  color: rgba(226, 246, 208, .88);
  font-size: .62rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: .075em;
  overflow-wrap: anywhere;
}

.rail-live-class {
  padding: 6px;
  color: rgba(218, 164, 70, .76);
  border: 1px solid rgba(218, 164, 70, .20);
  background: rgba(218, 164, 70, .045);
  font-size: .54rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.rail-counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 2px;
}

.rail-counts div {
  padding: 5px;
  border: 1px solid rgba(84, 170, 78, .16);
  background: rgba(0, 0, 0, .24);
}

.rail-counts span,
.rail-counts strong {
  display: block;
}

.rail-counts span {
  color: rgba(148, 210, 132, .46);
  font-size: .43rem;
  line-height: 1;
}

.rail-counts strong {
  margin-top: 4px;
  color: rgba(132, 240, 124, .82);
  font-size: .72rem;
  line-height: 1;
}

.rail-sweep {
  position: relative;
  height: 40px;
  border: 1px solid rgba(84, 170, 78, .15);
  background:
    repeating-linear-gradient(90deg, rgba(84, 170, 78, .035) 0 1px, transparent 1px 9px),
    rgba(0,0,0,.20);
  overflow: hidden;
}

.rail-sweep span {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(132, 255, 132, .18), transparent);
  animation: railReadoutSweep 2.7s linear infinite;
}

.rail-live-status {
  min-height: 2.4em;
  padding-top: 2px;
  color: rgba(132, 240, 124, .62);
  font-size: .50rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* Archaic cogitator finish: horizontal CRT sweep, rivets, heavier machine casing */
@keyframes cogitatorHorizontalSweep {
  0% { background-position: 0 -160px, 0 0, 0 0, 0 0, 0 0, 0 0; }
  100% { background-position: 0 520px, 0 0, 0 64px, 48px 0, 0 0, 0 0; }
}

@keyframes relicFlicker {
  0%, 100% { opacity: .78; }
  47% { opacity: .70; }
  49% { opacity: .88; }
  52% { opacity: .64; }
  55% { opacity: .82; }
}

.machine-shell {
  border: 2px solid rgba(82, 154, 72, .46);
  background:
    linear-gradient(180deg, transparent 0 38%, rgba(132, 255, 132, .070) 42%, transparent 48%),
    radial-gradient(circle at 18px 18px, rgba(218,164,70,.24) 0 2px, transparent 3px),
    repeating-linear-gradient(0deg, rgba(72, 184, 70, .050) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(90deg, rgba(72, 184, 70, .035) 0 1px, transparent 1px 18px),
    radial-gradient(circle at 18% 16%, rgba(82, 255, 82, .045), transparent 18%),
    linear-gradient(180deg, #010301 0%, #050805 48%, #020302 100%);
  background-size: 100% 680px, 100% 100%, 100% 64px, 144px 100%, 100% 100%, 100% 100%;
  animation: cogitatorHorizontalSweep 14s linear infinite;
  box-shadow:
    inset 0 0 0 1px rgba(226, 180, 78, .10),
    inset 0 0 0 6px rgba(0,0,0,.34),
    inset 0 0 90px rgba(0,0,0,.82),
    0 20px 52px rgba(0,0,0,.80),
    0 0 38px rgba(68, 190, 70, .09);
}

.machine-shell::after {
  background:
    repeating-linear-gradient(0deg, transparent 0 4px, rgba(0,0,0,.30) 4px 5px),
    radial-gradient(circle at 12px 12px, rgba(218,164,70,.22) 0 2px, transparent 3px),
    radial-gradient(circle at calc(100% - 12px) 12px, rgba(218,164,70,.22) 0 2px, transparent 3px),
    radial-gradient(circle at 12px calc(100% - 12px), rgba(218,164,70,.18) 0 2px, transparent 3px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), rgba(218,164,70,.18) 0 2px, transparent 3px),
    linear-gradient(90deg, rgba(0,0,0,.48), transparent 18%, transparent 82%, rgba(0,0,0,.52));
  opacity: .72;
  mix-blend-mode: multiply;
  animation: relicFlicker 7s steps(1, end) infinite;
}

.machine-shell-top,
.machine-shell-bottom,
.faction-matrix-head,
.faction-matrix-foot {
  background:
    linear-gradient(180deg, rgba(218,164,70,.045), transparent),
    rgba(0,0,0,.24);
  border-color: rgba(218, 164, 70, .22);
}

.machine-shell-top::before,
.machine-shell-bottom::before {
  content: "+++";
  color: rgba(218, 164, 70, .62);
  margin-right: 6px;
}

.home-menu-btn.cogitator-panel,
.faction-list .faction-card.faction-matrix-tile,
.faction-inspector,
.faction-console-rail {
  border-top-color: rgba(174, 132, 54, .28);
  border-bottom-color: rgba(35, 96, 38, .62);
  box-shadow:
    inset 0 0 0 1px rgba(226,180,78,.055),
    inset 0 0 24px rgba(0,0,0,.76),
    0 6px 16px rgba(0,0,0,.46);
}

.home-menu-btn.cogitator-panel::after {
  left: 0;
  top: -34%;
  width: 100%;
  height: 28%;
  background: linear-gradient(180deg, transparent, rgba(132,255,132,.12), transparent);
  transform: translateY(-120%);
}

.home-menu-btn.cogitator-panel:hover::after {
  transform: translateY(560%);
}

.faction-inspector::after,
.faction-console-rail::after {
  content: "";
  position: absolute;
  inset: 6px;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(218,164,70,.20) 0 12px, transparent 12px calc(100% - 12px), rgba(218,164,70,.16) calc(100% - 12px)),
    linear-gradient(180deg, rgba(218,164,70,.16) 0 1px, transparent 1px calc(100% - 1px), rgba(218,164,70,.12) calc(100% - 1px));
  opacity: .40;
}

.inspector-warning,
.rail-scripture {
  background:
    repeating-linear-gradient(90deg, rgba(218,164,70,.045) 0 1px, transparent 1px 7px),
    rgba(218, 164, 70, .070);
}

.home-console-litany {
  padding: 7px 14px;
  border-top: 1px solid rgba(218, 164, 70, .16);
  border-bottom: 1px solid rgba(84, 170, 78, .16);
  background:
    repeating-linear-gradient(90deg, rgba(218,164,70,.040) 0 1px, transparent 1px 10px),
    rgba(0,0,0,.28);
  color: rgba(218, 164, 70, .72);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
}

.home-console-grid {
  background:
    radial-gradient(circle at 17px 17px, rgba(218,164,70,.18) 0 2px, transparent 3px),
    radial-gradient(circle at calc(100% - 17px) 17px, rgba(218,164,70,.16) 0 2px, transparent 3px),
    linear-gradient(180deg, rgba(0,0,0,.16), transparent 22%, rgba(0,0,0,.18));
}

.home-menu-btn.cogitator-panel {
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
}

.home-menu-btn.cogitator-panel::before {
  border-color: rgba(218, 164, 70, .17);
  background:
    linear-gradient(90deg, rgba(84,170,78,.08) 0 4px, transparent 4px calc(100% - 4px), rgba(218,164,70,.10) calc(100% - 4px)),
    linear-gradient(180deg, rgba(218,164,70,.08) 0 1px, transparent 1px calc(100% - 1px), rgba(84,170,78,.08) calc(100% - 1px));
}

.home-menu-title {
  text-shadow:
    0 0 12px rgba(90, 255, 90, .24),
    1px 0 0 rgba(218, 164, 70, .10);
}

.home-menu-sub {
  max-width: 46ch;
  color: rgba(218, 214, 194, .76);
}

.home-menu-runes {
  border-top: 1px solid rgba(84, 170, 78, .13);
  border-bottom: 1px solid rgba(218, 164, 70, .11);
  background:
    linear-gradient(90deg, rgba(0,0,0,.18), transparent),
    rgba(84, 170, 78, .025);
}

.home-console-rail .rail-fluff {
  min-height: 5.2em;
  max-height: 5.2em;
}

.home-console-rail .rail-fluff span {
  min-height: 4.4em;
}

.home-console-rail-right {
  background:
    linear-gradient(180deg, rgba(218, 100, 62, .08), transparent 45%),
    rgba(0,0,0,.30);
}

.rail-warning-scripture {
  color: rgba(232, 142, 78, .78);
  border-left: 3px solid rgba(218, 100, 62, .48);
}

.rail-static-lines-amber span {
  background: linear-gradient(90deg, rgba(218,164,70,.46), transparent);
  box-shadow: 0 0 8px rgba(218,164,70,.15);
}

/* Home refinement: square machine casing, richer command headings */
.home-console,
.home-menu-btn.cogitator-panel {
  clip-path: none;
}

.home-console {
  border-style: double;
  border-width: 3px;
}

.home-console::before {
  inset: -8px;
  clip-path: none;
  border-color: rgba(218, 164, 70, .18);
}

.home-console-grid {
  position: relative;
}

.home-console-grid::before,
.home-console-grid::after {
  content: "";
  position: absolute;
  pointer-events: none;
  width: 88px;
  height: 42px;
  border-color: rgba(218, 164, 70, .32);
}

.home-console-grid::before {
  top: 10px;
  left: 10px;
  border-top: 1px solid rgba(218, 164, 70, .32);
  border-left: 1px solid rgba(218, 164, 70, .32);
}

.home-console-grid::after {
  right: 10px;
  bottom: 10px;
  border-right: 1px solid rgba(218, 164, 70, .32);
  border-bottom: 1px solid rgba(218, 164, 70, .32);
}

.home-menu-title {
  font-size: 1.18rem;
  letter-spacing: .105em;
  color: rgba(126, 238, 118, .90);
}

.home-menu-sub {
  color: rgba(222, 216, 190, .78);
  font-size: .82rem;
  line-height: 1.45;
}

.home-menu-btn.cogitator-panel::before {
  inset: 7px;
}

/* Final mobile overrides: keep these after the late cogitator passes. */
@media (max-width: 820px) {
  .faction-console {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .faction-console-rail,
  .faction-inspector {
    display: none;
  }

  .faction-index-layout,
  .faction-console-main {
    width: 100%;
    min-width: 0;
  }

  .faction-index-layout,
  .faction-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 800px) {
  .bld-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 95px);
    padding: 10px;
    gap: 10px;
    overflow-x: hidden;
  }

  .bld-units,
  .bld-list {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .bld-units {
    max-height: 45vh;
  }

  .bld-list {
    overflow-y: visible;
  }
}

@media (max-width: 480px) {
  .bld-layout {
    padding: 8px 6px;
  }

  .bld-panel-title,
  .bld-list-header,
  .bld-pts-bar-wrap {
    padding-left: 10px;
    padding-right: 10px;
  }

  .bld-pts-row {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .bld-pts-label {
    flex: 1 0 100%;
  }

  .bld-pts-select {
    flex: 1 1 140px;
    min-width: 0;
  }

  .bld-pts-manual {
    flex: 0 0 76px;
    max-width: 100%;
  }
}
