/* ═══ Villain range editor — the shared "Edit villain range" component ═══════
   ONE stylesheet, two consumers: the Simulator's modal (simulator-villain-editor.js
   → SimulatorVillainEditor.open) and the Villain Builder's Preflop tab, which
   emits the same markup inline. Linked by index.html and villain-builder.html.

   The look is Study's Edit-villain-range panel (`.st-vre-*` in study.css) —
   every number below is lifted from those rules so the three surfaces read as
   one screen: flat square cells with no chrome, 5px-radius 11px chips inside
   #202c40-bordered toolbar rows, a #0d1524 filter card, and a control card with
   the big SELECTED count over full-width levers.

   It replaces the block that used to sit in simulator-layout-fix.css. That was
   only ever a SKIN — written for the legacy inline editor in simulator.js (hence
   its !importants and [data-sel] selectors), it left the modern shared module
   with no layout at all: every structural div display:block, the 13x13 grid a
   wrapped blob, the sidebar full-width, and cells transparent because the JS
   sets only --sim-split-raise/--sim-split-call-end via style.cssText, so the
   `--split` MODIFIER class the gradient hung on never arrived. */

/* ── shell (Simulator modal only; the builder mounts the parts inline) ── */
.sim-villain-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  background: rgba(3, 6, 12, 0.76);
  backdrop-filter: blur(5px);
  font-family: var(--font-ui, 'Outfit', system-ui, sans-serif);
}
.sim-villain-editor-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: min(1120px, 96vw);
  max-height: 96vh;
  overflow: auto;
  padding: 10px 12px 12px;
  background: #0b1120;
  border: 1px solid #263248;
  border-radius: 10px;
  color: var(--text-primary, #e2e8f0);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.018);
}
.sim-villain-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  margin: -10px -12px 3px;
  padding: 9px 14px;
  background: #0a101d;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px 10px 0 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-bright, #f1f5f9);
}
.sim-villain-editor-subtitle {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted, #94a3b8);
}
.sim-villain-editor-header > button {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-muted, #94a3b8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.sim-villain-editor-header > button:hover {
  color: var(--text-bright, #f1f5f9);
  background: rgba(255, 255, 255, 0.05);
}

/* ── toolbar rows: VILLAIN / PROFILES / seat-or-node tabs ── */
.sim-villain-editor-arch-tabs,
.sim-villain-editor-profile-row,
.sim-villain-editor-node-tabs {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid #202c40;
  border-radius: 7px;
}
/* Row heading ("VILLAIN", "PROFILES", "SEAT", …). A heading that follows a
   control group starts a second group on the same row. */
.sim-villain-editor-bar-lbl {
  flex: 0 0 auto;
  margin-right: 2px;
  color: #64748b;
  font: 750 8.5px/1 var(--font-ui, 'Outfit', system-ui, sans-serif);
  letter-spacing: 0.85px;
  text-transform: uppercase;
}
.sim-villain-editor-bar-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.sim-villain-editor-bar-seg + .sim-villain-editor-bar-lbl {
  margin-left: 5px;
  padding-left: 12px;
  border-left: 1px solid #202c40;
}

/* ── chips: one look for archetypes, seat tabs, profile actions, filters ── */
.sim-villain-editor-chip,
.sim-villain-editor-node-tab,
.sim-villain-editor-filter-chip,
.sim-villain-editor-profile-btn {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 10px;
  border: 1px solid var(--bg-border-solid, #1e293b);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-body, #cbd5e1);
  font-family: var(--font-ui, 'Outfit', system-ui, sans-serif);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sim-villain-editor-chip {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted, #94a3b8);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.sim-villain-editor-chip:hover,
.sim-villain-editor-node-tab:hover,
.sim-villain-editor-filter-chip:hover,
.sim-villain-editor-profile-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text-bright, #f1f5f9);
}
.sim-villain-editor-node-tab.is-active,
.sim-villain-editor-filter-chip.is-active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent-blue, #3b82f6);
  color: var(--text-bright, #f1f5f9);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.2);
}
.sim-villain-editor-chip.is-active {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent-blue, #3b82f6);
  color: #dbeafe;
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.35);
}
.sim-villain-editor-chip:disabled,
.sim-villain-editor-node-tab:disabled,
.sim-villain-editor-filter-chip:disabled,
.sim-villain-editor-profile-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.sim-villain-editor-profile-btn--danger:hover {
  border-color: rgba(239, 68, 68, 0.55);
  color: #fecaca;
}
.sim-villain-editor-profile-btn--primary {
  border-color: var(--accent-blue, #3b82f6);
  background: color-mix(in srgb, var(--accent-blue, #3b82f6) 82%, transparent);
  color: #fff;
}
.sim-villain-editor-profile-btn--primary:hover {
  background: var(--accent-blue, #3b82f6);
  border-color: var(--accent-blue, #3b82f6);
  color: #fff;
}
.sim-villain-editor-profile-row select {
  flex: 0 1 auto;
  min-width: 180px;
  max-width: 320px;
  height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--bg-border-solid, #1e293b);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-body, #cbd5e1);
  font-family: var(--font-ui, 'Outfit', system-ui, sans-serif);
  font-size: 11px;
  cursor: pointer;
}
.sim-villain-editor-profile-row select:disabled { opacity: 0.55; cursor: default; }

/* ── body: matrix left, controls right ── */
/* The matrix column hugs the matrix (they share a max-width), so the filter
   card, grid and legend line up and the pair centres instead of the grid
   drifting to one end of a wide card. */
.sim-villain-editor-body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 14px;
}
.sim-villain-editor-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 440px;
  min-width: 0;
  max-width: min(720px, calc(100vh - 370px));
}
/* The filter card — selection controls banded together above the matrix. It
   stays a wrapping ROW so the Simulator, which drops its chips straight in, gets
   one band; a consumer that wants labelled groups on their own lines nests
   -filter-line children, which claim a full row each. */
.sim-villain-editor-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  margin: 0 0 8px;
  padding: 7px 8px;
  background: #0d1524;
  border: 1px solid #202c40;
  border-radius: 7px;
}
.sim-villain-editor-filter-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  flex: 1 1 100%;
  gap: 5px;
  min-width: 0;
}
.sim-villain-editor-filter-line > .sim-villain-editor-bar-lbl:first-child { flex: 0 0 60px; margin: 0; }
/* a second heading mid-row starts a new group */
.sim-villain-editor-filter-line > .sim-villain-editor-bar-lbl:not(:first-child) {
  margin-left: 4px;
  padding-left: 11px;
  border-left: 1px solid #202c40;
}
/* action swatch inside a filter chip — the colour it will select */
.sim-villain-editor-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 2px;
}

/* Square cells, no chrome — colour IS the data, so borders and shadows only
   add noise. Height comes from the square, capped so the matrix always fits. */
.sim-villain-editor-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  grid-template-rows: repeat(13, minmax(0, 1fr));
  gap: 2px;
  align-self: center;
  flex: 0 1 auto;
  width: 100%;
  aspect-ratio: 1 / 1;
}
.sim-villain-editor-grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: auto;
  min-width: 0;
  padding: 0;
  border: none;
  border-radius: 2px;
  aspect-ratio: 1 / 1;
  color: #f8fafc;
  font-family: var(--font, 'JetBrains Mono', monospace);
  font-size: clamp(8px, 0.82vw, 13px);
  font-weight: 600;
  letter-spacing: -0.15px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.1s ease, filter 0.1s ease;
}
.sim-villain-editor-grid-cell:hover { filter: brightness(1.12); }
.sim-villain-editor-grid-cell.is-selected {
  box-shadow: inset 0 0 0 2px #f8fafc;
  filter: brightness(1.15);
  z-index: 2;
}

.sim-villain-editor-legend {
  display: flex;
  align-items: center;
  align-self: center;
  gap: 14px;
  width: 100%;
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-muted, #94a3b8);
}
.sim-villain-editor-legend > span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 3px;
  border-radius: 2px;
  vertical-align: middle;
  background: currentColor;
}
.sim-villain-editor-legend > span:nth-child(1) { color: #dc2626; }
.sim-villain-editor-legend > span:nth-child(2) { color: #22c55e; }
.sim-villain-editor-legend > span:nth-child(3) { color: #3b82f6; }
.sim-villain-editor-legend-hint { margin-left: auto; color: var(--text-dim, #475569); }
.sim-villain-editor-legend-hint::before { display: none !important; }

/* ── control column ── */
.sim-villain-editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 0 0 clamp(214px, 18vw, 300px);
  width: clamp(214px, 18vw, 300px);
  min-width: 0;
}
@media (max-width: 860px) {
  .sim-villain-editor-sidebar { flex: 1 1 100%; width: auto; }
}
/* SELECTED + levers + resulting mix are one card, as in the reference. */
.sim-villain-editor-selected {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}
.sim-villain-editor-selected > span {
  color: var(--text-muted, #94a3b8);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}
.sim-villain-editor-selected > strong {
  margin-top: 2px;
  color: var(--text-bright, #f1f5f9);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}
.sim-villain-editor-selected small,
.sim-villain-editor-selected > strong > span {
  color: var(--text-muted, #94a3b8);
  font-size: 10px;
  font-weight: 600;
}

.sim-villain-editor-levers { display: flex; flex-direction: column; }
.sim-villain-editor-levers label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 3px 8px;
  margin-bottom: 7px;
  font-size: 12px;
}
.sim-villain-editor-levers output {
  color: var(--text-primary, #e2e8f0);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.sim-villain-editor-levers input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  max-width: 260px;
  height: 14px;
  margin: 0;
  /* form controls don't inherit colour, so currentColor would resolve to the
     UA default — take it from the label explicitly. */
  color: inherit;
  accent-color: currentColor;
}

.sim-villain-editor-result > span {
  display: block;
  margin: 1px 0 3px;
  color: var(--text-dim, #475569);
  font-size: 9px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}
/* Same split the cells use, so the mix you're writing reads in the colours it
   will land in. */
.sim-villain-editor-result > div {
  height: 8px;
  border-radius: 4px;
  border: 1px solid var(--bg-border, rgba(255, 255, 255, 0.08));
}
.sim-villain-editor-grid-cell,
.sim-villain-editor-result > div {
  background:
    linear-gradient(90deg,
      #dc2626 0 var(--sim-split-raise, 33%),
      #22c55e var(--sim-split-raise, 33%) var(--sim-split-call-end, 66%),
      #3b82f6 var(--sim-split-call-end, 66%) 100%);
}

.sim-villain-editor-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 11px;
  border-top: 1px solid var(--bg-border, rgba(255, 255, 255, 0.06));
}
.sim-villain-editor-footer button,
.sim-villain-editor-actions button {
  padding: 6px 14px;
  border: 1px solid var(--bg-border-solid, #1e293b);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-body, #cbd5e1);
  font-family: var(--font-ui, 'Outfit', system-ui, sans-serif);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sim-villain-editor-footer button:hover { background: rgba(255, 255, 255, 0.07); color: var(--text-bright, #f1f5f9); }
.sim-villain-editor-actions { display: flex; gap: 8px; }
.sim-villain-editor-footer .danger:hover { border-color: rgba(239, 68, 68, 0.55); color: #fecaca; }
.sim-villain-editor-footer .primary {
  border-color: var(--accent-blue, #3b82f6);
  background: color-mix(in srgb, var(--accent-blue, #3b82f6) 82%, transparent);
  color: #fff;
}
.sim-villain-editor-footer .primary:hover { background: var(--accent-blue, #3b82f6); color: #fff; }

/* ── Future-streets tendency: sidebar trigger + nested popup ── */
.sim-villain-editor-tend {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid #202c40;
}
.sim-villain-editor-tend-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #263248;
  border-radius: 7px;
  background: #0d1524;
  color: var(--text-body, #cbd5e1);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.sim-villain-editor-tend-trigger:hover { border-color: var(--accent-blue, #3b82f6); background: rgba(255, 255, 255, 0.05); }
.sim-villain-editor-tend-ic { flex: 0 0 auto; font-size: 13px; color: #60a5fa; }
.sim-villain-editor-tend-tx { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.sim-villain-editor-tend-t {
  color: var(--text-primary, #e2e8f0);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.sim-villain-editor-tend-sum {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim, #64748b);
  font-size: 10.5px;
  font-weight: 600;
}
.sim-villain-editor-tend.is-active .sim-villain-editor-tend-sum { color: #93c5fd; }
.sim-villain-editor-tend.is-active .sim-villain-editor-tend-trigger {
  border-color: rgba(96, 165, 250, 0.6);
  background: rgba(59, 130, 246, 0.12);
}
.sim-villain-editor-tend-go { flex: 0 0 auto; font-size: 12px; color: #64748b; transition: transform 0.14s ease, color 0.14s ease; }
.sim-villain-editor-tend-trigger:hover .sim-villain-editor-tend-go { color: #93c5fd; transform: translateX(2px); }

.sim-villain-editor-tend-pop {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.sim-villain-editor-tend-pop[hidden] { display: none; }
.sim-villain-editor-tend-scrim {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 12, 0.72);
  backdrop-filter: blur(3px);
  animation: sim-vte-fade 0.16s ease;
}
.sim-villain-editor-tend-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 16px 18px 18px;
  background: #0b1120;
  border: 1px solid #263248;
  border-radius: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.72);
  animation: sim-vte-pop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sim-vte-fade { from { opacity: 0; } }
@keyframes sim-vte-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.sim-villain-editor-tend-phd {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sim-villain-editor-tend-pttl { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.sim-villain-editor-tend-pttl > span:first-child {
  color: var(--text-bright, #f1f5f9);
  font-size: 15px;
  font-weight: 700;
}
.sim-villain-editor-tend-psub { color: var(--text-muted, #94a3b8); font-size: 11px; font-weight: 500; }
.sim-villain-editor-tend-x {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-muted, #94a3b8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.sim-villain-editor-tend-x:hover { color: var(--text-bright, #f1f5f9); background: rgba(255, 255, 255, 0.05); }
.sim-villain-editor-tend-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .sim-villain-editor-tend-body { grid-template-columns: 1fr; } }
.sim-villain-editor-tend-street {
  margin: 0;
  padding: 10px;
  border-radius: 7px;
  background: #0d1524;
  border: 1px solid #202c40;
}
.sim-villain-editor-tend-sthd {
  margin-bottom: 6px;
  color: #64748b;
  font-size: 8.5px;
  font-weight: 750;
  letter-spacing: 0.85px;
  text-transform: uppercase;
}
.sim-villain-editor-tend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sim-villain-editor-tend-lbl { flex: 0 0 68px; color: var(--text-body, #cbd5e1); font-size: 10.5px; font-weight: 600; }
.sim-villain-editor-tend-seg { display: flex; flex: 1; gap: 3px; }
.sim-villain-editor-tend-seg button {
  flex: 1;
  min-height: 22px;
  padding: 0;
  border: 1px solid var(--bg-border-solid, #1e293b);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted, #94a3b8);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sim-villain-editor-tend-seg button:hover { border-color: rgba(255, 255, 255, 0.2); color: var(--text-bright, #f1f5f9); }
.sim-villain-editor-tend-seg button.on {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent-blue, #3b82f6);
  color: var(--text-bright, #f1f5f9);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.2);
}
.sim-villain-editor-tend-sizes {
  flex: 1;
  min-height: 26px;
  padding: 0 6px;
  border: 1px solid var(--bg-border-solid, #1e293b);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-body, #cbd5e1);
  font-size: 10.5px;
}
.sim-villain-editor-tend-note {
  grid-column: 1 / -1;
  margin-top: 2px;
  color: var(--text-dim, #475569);
  font-size: 10px;
  line-height: 1.4;
}
