:root {
  --bg: #0b0b0d;
  --bg-2: #0f0f12;
  --panel: #17171b;
  --panel-2: #1d1d22;
  --line: #2a2a31;
  --text: #d7d7db;
  --text-dim: #9a9aa2;
  --text-faint: #6c6c74;
  --arm: #84c8ee;
  --arm-dim: #3d6a86;
  --cor: #ff5a4c;
  --cor-dim: #8a3730;
  --leg: #5fe05a;
  --leg-dim: #3f7a3c;
  --accent: var(--arm);
  --accent-dim: var(--arm-dim);
  --good: #6fce6a;
  --radius: 8px;
}
body.faction-cor { --accent: var(--cor); --accent-dim: var(--cor-dim); }
body.faction-leg { --accent: var(--leg); --accent-dim: var(--leg-dim); }

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over class-level display rules
   (a class selector otherwise beats the UA `[hidden]{display:none}` style). */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Barlow", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-title { font-size: 16px; }
.brand-title em { color: var(--text-faint); font-style: normal; font-weight: 500; }
.faction-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.faction-toggle button {
  background: transparent; color: var(--text-dim); border: 0;
  padding: 7px 20px; font: inherit; font-weight: 600; cursor: pointer; letter-spacing: .4px;
}
.faction-toggle button[data-faction="arm"].active { background: var(--arm); color: #05131c; }
.faction-toggle button[data-faction="cor"].active { background: var(--cor); color: #1c0603; }
.faction-toggle button[data-faction="leg"].active { background: var(--leg); color: #06210a; }
.split-toggle {
  background: var(--panel); color: var(--text-dim); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 16px; font: inherit; font-weight: 600; cursor: pointer; letter-spacing: .3px;
}
.split-toggle:hover { color: var(--text); border-color: var(--accent-dim); }
.split-toggle.active { background: var(--accent); color: #05131c; border-color: var(--accent); }
body.faction-cor .split-toggle.active { color: #1c0603; }
#search {
  margin-left: auto; width: 260px; max-width: 40vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  color: var(--text); padding: 8px 16px; font: inherit;
}
#search:focus { outline: none; border-color: var(--accent-dim); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 56px); }
.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 14px; position: sticky; top: 56px; align-self: start;
  height: calc(100vh - 56px); overflow-y: auto;
}
.nav-section-label {
  font-family: "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: 1.5px;
  font-size: 11px; color: var(--text-faint); margin: 4px 8px 8px;
}
.category-nav { list-style: none; margin: 0 0 22px; padding: 0; }
.category-nav li {
  padding: 8px 12px; border-radius: 6px; cursor: pointer; color: var(--text-dim);
  display: flex; justify-content: space-between; align-items: center; font-weight: 500;
}
.category-nav li:hover { background: var(--panel); color: var(--text); }
.category-nav li.active { background: var(--panel-2); color: var(--accent); font-weight: 600; }
.category-nav li .count { font-size: 12px; color: var(--text-faint); }
.sort-select {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); padding: 8px 10px; border-radius: 6px; font: inherit;
}
.sort-dir { display: flex; align-items: center; gap: 6px; margin: 10px 8px; font-size: 13px; color: var(--text-dim); }
.nav-hint { margin: 18px 8px; font-size: 12px; color: var(--text-faint); line-height: 1.5; }

/* ---------- content ---------- */
.content { padding: 22px 26px 60px; }
.tier-block { margin-bottom: 30px; }
.tier-head {
  display: flex; align-items: center; gap: 12px; margin: 0 0 14px;
}
.tier-badge {
  font-family: "Barlow Semi Condensed"; font-weight: 700; letter-spacing: 1px;
  font-size: 12px; color: var(--accent); border: 1px solid var(--accent-dim);
  padding: 3px 10px; border-radius: 4px; text-transform: uppercase;
}
.tier-head .rule { flex: 1; height: 1px; background: var(--line); }
.tier-head .tier-count { font-size: 12px; color: var(--text-faint); }

.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.unit-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: border-color .12s, transform .12s;
  display: flex; flex-direction: column;
}
.unit-card:hover { border-color: var(--accent-dim); transform: translateY(-2px); }
.unit-card .pic { aspect-ratio: 1; background: #0a0a0c center/cover; position: relative; }
.unit-card .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* minimap symbol overlaid top-left of a unit picture */
/* !important needed: `.unit-card .pic img { width:100% }` etc. are more specific and would otherwise blow these up */
img.mini-icon {
  position: absolute !important; top: 4px; left: 4px; width: 24px !important; height: 24px !important;
  object-fit: contain !important; background: rgba(230,235,240,.92); border: 1px solid rgba(0,0,0,.35);
  border-radius: 4px; padding: 2px; z-index: 3;   /* light backing so the black minimap glyph is legible */
}
img.mini-icon.big { width: 32px !important; height: 32px !important; top: 6px; left: 6px; }
img.mini-icon.sm { width: 15px !important; height: 15px !important; top: 2px; left: 2px; border-radius: 3px; padding: 1px; }
.uc-pic-wrap { position: relative; flex-shrink: 0; }
.build-cell { position: relative; }
.unit-card .tier-tag {
  position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: 700;
  background: rgba(0,0,0,.6); color: var(--accent); padding: 1px 6px; border-radius: 3px; letter-spacing: .5px;
}
.unit-card .statval {
  position: absolute; bottom: 6px; right: 6px; font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,.72); color: var(--text); padding: 2px 7px; border-radius: 3px;
}
.unit-card .meta { padding: 8px 10px 10px; }
.unit-card .uname { font-weight: 600; font-size: 14px; line-height: 1.2; }
.unit-card .udesc { font-size: 11.5px; color: var(--text-faint); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--text-faint); padding: 40px; text-align: center; }

/* ---------- detail modal ---------- */
.detail-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.72); z-index: 60;
  display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow-y: auto;
}
.detail-modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  width: min(1180px, 100%); position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.detail-toolbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: flex-end; gap: 8px;
  padding: 10px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
}
.detail-close {
  background: var(--panel); border: 1px solid var(--line); color: var(--text-dim);
  width: 34px; height: 34px; border-radius: 6px; cursor: pointer; font-size: 15px;
}
.detail-close:hover { color: var(--text); border-color: var(--accent-dim); }
.detail-toolbar .split-toggle:disabled { opacity: .5; cursor: default; }
.detail-body { display: grid; grid-template-columns: 1fr 1fr; }
.detail-body.single { grid-template-columns: 1fr; }
.unit-col { padding: 24px; }
.unit-col.cor { border-right: 1px solid var(--line); }
.unit-col[data-faction="arm"] { --accent: var(--arm); --accent-dim: var(--arm-dim); }
.unit-col[data-faction="cor"] { --accent: var(--cor); --accent-dim: var(--cor-dim); }
.no-counterpart { padding: 40px 24px; color: var(--text-faint); display: flex; align-items: center; justify-content: center; text-align: center; border-right: 1px solid var(--line); }

.uc-head { display: flex; gap: 16px; align-items: flex-start; }
.uc-pic { width: 110px; height: 110px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; background: #0a0a0c; flex-shrink: 0; }
.uc-title h2 { margin: 0; font-size: 22px; line-height: 1.1; }
.uc-faction { font-family: "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: 1.5px; font-size: 12px; font-weight: 700; color: var(--accent); }
.uc-desc { color: var(--text-dim); font-size: 13.5px; margin-top: 6px; }
.uc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 11px; background: var(--panel); border: 1px solid var(--line); color: var(--text-dim);
  padding: 2px 9px; border-radius: 999px; letter-spacing: .3px; }
.chip.id { font-family: ui-monospace, monospace; color: var(--text-faint); }

.section { margin-top: 20px; }
.section > h3 {
  font-family: "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: 1.2px;
  font-size: 12.5px; color: var(--text-faint); margin: 0 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.traits { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; }
.trait { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dotted #23232a; font-size: 13.5px; }
.trait .k { color: var(--text-dim); }
.trait .v { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.trait .v small { color: var(--text-faint); font-weight: 500; }
.trait.wide { grid-column: 1 / -1; }
.trait.flag .v { color: var(--good); }

.weapon { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.weapon h4 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.weapon h4 .wtype { font-size: 11px; font-weight: 600; color: var(--accent); border: 1px solid var(--accent-dim); padding: 1px 7px; border-radius: 4px; }
.weapon h4 .wtag { font-size: 10px; font-weight: 700; background: var(--panel-2); color: var(--text-dim); padding: 1px 6px; border-radius: 3px; letter-spacing: .4px; }
.dmg-table { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dmg-cell { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 3px 8px; }
.dmg-cell b { color: var(--text); }
.dmg-cell span { color: var(--text-faint); }

.build-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 4px; }
.build-cell { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px; text-align: center; cursor: pointer; }
.build-cell:hover { border-color: var(--accent-dim); }
.build-cell img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; }
.build-cell .bn { font-size: 10.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.1; display: block; }

details.raw { margin-top: 20px; border: 1px solid var(--line); border-radius: 6px; }
details.raw summary { cursor: pointer; padding: 8px 12px; color: var(--text-dim); font-size: 12.5px; font-family: "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: 1px; }
details.raw pre { margin: 0; padding: 12px; overflow-x: auto; font-size: 11.5px; color: var(--text-dim); border-top: 1px solid var(--line); max-height: 360px; }

.token-note { color: var(--text-faint); font-size: 11.5px; margin-top: 6px; }
.token-note em { color: var(--text-dim); font-style: italic; }

/* classification + category tokens */
.chip.cat { cursor: help; border-color: var(--accent-dim); color: var(--text); }
.chip.cat.sm { font-size: 10px; padding: 1px 7px; }
.cat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 4px; }
.cat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin-right: 4px; }
.trait .v.flagv { color: var(--good); font-weight: 500; text-align: right; }
.trait .v[title] { cursor: help; }

/* ---- consistent axis-coloured tags (tier / domain / role / ability) ---- */
.chip.tag-tier   { border-color: #4a4a52; color: #c9c9d2; }
.chip.tag-domain { border-color: #3d6a86; color: #9fd0ef; background: rgba(61,106,134,.12); }
.chip.tag-role   { border-color: #7a5c2e; color: #e6c583; background: rgba(122,92,46,.12); }
.chip.tag-ability{ border-color: #3f7a3c; color: #8fe08a; background: rgba(63,122,60,.12); }
.chip.cat { cursor: help; }
.tag-legend-inline { margin-top: 9px; font-size: 11.5px; color: var(--text-faint); }
.tag-legend-inline b { font-weight: 600; }
.tag-legend-inline b.tag-domain { color: #9fd0ef; }
.tag-legend-inline b.tag-role { color: #e6c583; }
.tag-legend-inline b.tag-ability { color: #8fe08a; }

/* ---- tag filter bar ---- */
.tag-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 0 16px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.tf-label { font-family: "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: 1px; font-size: 11px; color: var(--text-faint); margin-right: 6px; }
.chip.tf { cursor: pointer; user-select: none; }
.chip.tf:hover { filter: brightness(1.25); }
.chip.tf.on { outline: 2px solid currentColor; font-weight: 700; }
.chip.tf-clear { border-color: var(--cor-dim); color: var(--cor); }

.ctrl-layout-note { font-size: 12px; color: var(--text-faint); font-style: italic; margin-top: 6px; max-width: 780px; }

/* patterns tab */
.pat-row { padding: 9px 0; border-top: 1px solid var(--line); }
.pat-row b { font-size: 13.5px; }
.pat-detail { font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.5; }
.pk { display: inline-block; font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; padding: 1px 6px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
.pk.law { background: #3f7a3c; color: #eafbe9; }
.pk.rule { background: #7a5c2e; color: #fdf1d9; }
.pk.tendency { background: #4a4a52; color: #d7d7db; }
.proj-intro .pk { margin: 0 2px; }

/* tag legend (always-readable meanings, no hover needed) */
.tag-legend { margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; }
.tag-legend summary { cursor: pointer; padding: 7px 11px; font-size: 12px; color: var(--accent); font-weight: 600; }
.legend-row { display: grid; grid-template-columns: 92px 1fr; gap: 2px 10px; padding: 7px 11px; border-top: 1px solid var(--line); font-size: 12.5px; }
.legend-tok { font-family: ui-monospace, monospace; color: var(--accent); font-weight: 700; grid-row: span 2; }
.legend-full { color: var(--text); font-weight: 600; }
.legend-def { color: var(--text-dim); grid-column: 2; }

/* weapon extras */
.weapon h4 .wtype[data-ptype] { cursor: pointer; }
.weapon h4 .wtype[data-ptype]:hover { background: var(--accent); color: #05131c; }
.wblock { margin-top: 8px; font-size: 12px; color: var(--text-dim); background: var(--panel-2); border-radius: 5px; padding: 5px 9px; }
.wtargets { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: 12.5px; }
.wtargets .tlab { font-size: 11px; font-weight: 600; color: var(--text-dim); margin-right: 2px; }
.wtargets b { font-weight: 600; }
.hitdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.hitdot.can { background: var(--good); }
.hitdot.cant { background: #ff6b5e; }
.hitdot.any { background: var(--text-faint); }

/* custom hover tooltip (reliable, works everywhere) */
#tip {
  position: fixed; z-index: 200; max-width: 320px; pointer-events: none;
  background: #000; color: var(--text); border: 1px solid var(--accent-dim);
  border-radius: 7px; padding: 8px 11px; font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 8px 28px rgba(0,0,0,.6);
}
[data-tip] { cursor: help; }
.build-cell[data-tip], .proj-tile[data-tip], .wtype[data-ptype] { cursor: pointer; }

/* split-view higher/lower comparison */
.trait .v.cmp-hi { color: var(--good); }
.trait .v.cmp-lo { color: #ff6b5e; }

/* special-trait chips */
.strait-row { display: flex; flex-wrap: wrap; gap: 7px; }
.strait {
  font-size: 12.5px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--accent-dim);
  color: var(--text); padding: 4px 11px; border-radius: 999px;
}
.cat-hint { font-size: 11px; color: var(--text-faint); font-style: italic; margin-left: 4px; }
.udesc.long { -webkit-line-clamp: 4; font-size: 12px; color: var(--text-dim); }

/* controls / how-to-play */
.controls-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.ctrl-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.ctrl-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--accent); }
.ctrl-note { font-size: 12px; color: var(--text-dim); margin: 0 0 10px; line-height: 1.5; }
.ctrl-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); align-items: baseline; }
.ctrl-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; }
.ctrl-keys kbd {
  font-family: ui-monospace, monospace; font-size: 11.5px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; min-width: 16px; text-align: center;
}
.kplus { color: var(--text-faint); font-size: 10px; }
.ctrl-act b { font-size: 13.5px; }
.ctrl-desc { display: block; font-size: 12px; color: var(--text-dim); margin-top: 2px; line-height: 1.45; }

/* projectile tiles (grid) */
.proj-tile { padding: 0; }
.proj-tile-head { padding: 16px 12px; background: #0a0a0c; display: flex; justify-content: center; border-bottom: 1px solid var(--line); }
.proj-tile .proj-count { font-size: 11.5px; color: var(--accent); font-weight: 600; margin-top: 6px; }

/* projectiles reference */
.proj-intro h1 { font-size: 24px; margin: 4px 0 6px; }
.proj-intro p { color: var(--text-dim); max-width: 780px; font-size: 14px; }
.proj-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 16px 0; scroll-margin-top: 70px; }
.proj-card.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); } 100% { border-color: var(--line); box-shadow: none; } }
.proj-head { display: flex; align-items: center; gap: 12px; }
.wtype.big { font-size: 15px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent-dim); padding: 3px 12px; border-radius: 5px; }
.proj-count { font-size: 12px; color: var(--text-faint); }
.proj-def { color: var(--text); font-size: 14px; margin: 10px 0; max-width: 820px; }
.proj-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pflag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim); padding: 2px 9px; border-radius: 999px; }
.proj-firers { display: flex; flex-wrap: wrap; gap: 6px; }
.firer { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 9px; cursor: pointer; }
.firer:hover { border-color: var(--accent-dim); color: var(--accent); }
.fdot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.fdot.arm { background: var(--arm); } .fdot.cor { background: var(--cor); } .fdot.leg { background: var(--leg); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .detail-body { grid-template-columns: 1fr; }
  .unit-col.cor { border-right: 0; border-bottom: 1px solid var(--line); }
  .traits { grid-template-columns: 1fr; }
}
