/* components.css — reusable UI pieces (buttons, cards, tables, tooltips, dice, tokens, forms) */

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 38px; padding: 0 var(--space-4); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  font-size: var(--fs-md); font-weight: 600; cursor: pointer; transition: .13s; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn.sm { height: 30px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
.btn.icon { width: 38px; padding: 0; }
.btn.primary { background: var(--accent); border-color: transparent; color: #0a1220; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.gold { background: var(--gold); border-color: transparent; color: #241803; }
.btn.blue { background: var(--blue); border-color: transparent; color: #041016; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #5a2c2c; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.close { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-soft); background: var(--bg-2); color: var(--muted); cursor: pointer; font-size: 18px; }
.close:hover { color: var(--text); }

/* ── Cards & panels ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: var(--space-4); }
.section-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 1.2px; color: var(--faint); font-weight: 700; margin-bottom: var(--space-2); }
.grid { display: grid; gap: var(--space-4); }

/* ── Badges / chips ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 700; background: var(--panel-3); color: var(--muted); border: 1px solid var(--line-soft); }
.badge.gold { color: var(--gold-2); background: var(--gold-dim); border-color: #d9a44140; }
.badge.blue { color: var(--blue-2); background: var(--blue-dim); border-color: #4f9dd640; }
.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }
.badge.bad  { color: var(--bad); }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Stat blocks ── */
.stat-line { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 52px;
  padding: 6px 8px; background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
}
.stat .k { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); }
.stat .v { font-size: var(--fs-md); font-weight: 700; font-family: var(--mono); }
/* compact variant for builder catalog/roster rows */
.stat-line.sm { gap: 4px; }
.stat.sm { min-width: 40px; padding: 2px 6px; }
.stat.sm .k { font-size: 9px; letter-spacing: .3px; }
.stat.sm .v { font-size: var(--fs-sm); }
/* a stat the item doesn't have ('-', '0', blank) — present but dimmed, not hidden */
.stat.na .v { color: var(--faint); font-weight: 600; }

/* clickable item name that opens a full stat card */
.stat-name {
  background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
  color: var(--text); font-weight: 700; font-size: var(--fs-md); font-family: inherit;
}
.stat-name:hover, .stat-name:focus-visible { color: var(--accent); text-decoration: underline; }

/* ── Tables ── */
.tbl-scroll { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.tbl th, table.tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.tbl th { background: var(--bg-2); color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: var(--panel-2); }

/* ── Forms ── */
.input, .select, textarea.input {
  width: 100%; height: 38px; padding: 0 var(--space-3); border-radius: var(--radius);
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text); font-size: var(--fs-md);
}
textarea.input { height: auto; min-height: 72px; padding: var(--space-2) var(--space-3); resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stepper button { width: 34px; height: 34px; border: 0; background: var(--panel-2); color: var(--text); font-size: 18px; cursor: pointer; }
.stepper button:hover { background: var(--panel-3); }
.stepper .n { min-width: 34px; text-align: center; font-family: var(--mono); font-weight: 700; }
.toggle-chip { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); cursor: pointer; font-size: var(--fs-sm); font-weight: 600; }
.toggle-chip[aria-pressed="true"] { color: var(--text); background: var(--accent); border-color: transparent; }
.toggle-chip[aria-pressed="true"].on-good { background: var(--good); color: #06130c; }

/* ── Tooltip bubble ── */
.tip {
  position: absolute; max-width: 340px; pointer-events: auto;
  background: #0c1017; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--space-3); font-size: var(--fs-sm); color: var(--text);
  line-height: 1.5;
}
.tip .tip-title { font-weight: 700; margin-bottom: 4px; color: var(--gold-2); }
.tip .tip-short { color: var(--muted); }
.tip .tip-more { margin-top: var(--space-2); display: inline-flex; }
.tip-anchor { border-bottom: 1px dotted var(--faint); cursor: help; }
[data-tip] { cursor: help; }

/* ── Info dot ── */
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; font-size: 11px; font-weight: 700;
  background: var(--panel-3); color: var(--muted); border: 1px solid var(--line-soft); cursor: help; margin-left: 4px;
}
.info-dot:hover { color: var(--gold-2); border-color: var(--gold); }

/* ── Dice tray ── */
.dice-tray { width: 100%; max-width: 460px; }
.die-face {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 10px; font-family: var(--mono); font-weight: 700; font-size: 20px;
  background: var(--panel-2); border: 1px solid var(--line); position: relative;
}
.die-face.crit { border-color: var(--good); color: var(--good); box-shadow: 0 0 0 1px var(--good); }
.die-face.fail { border-color: var(--bad); color: var(--bad); }
.die-face .dt { position: absolute; top: -7px; right: -7px; font-size: 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; color: var(--faint); }
.dice-result { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; min-height: 46px; }
.dice-total { font-family: var(--mono); font-size: var(--fs-xl); font-weight: 700; }
.dice-verdict { font-weight: 800; padding: 4px 10px; border-radius: 999px; }
.dice-verdict.pass { background: var(--good); color: #06130c; }
.dice-verdict.miss { background: var(--bad); color: #fff; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
.dice-log { max-height: 180px; overflow: auto; font-size: var(--fs-sm); }
.dice-log-row { display: flex; justify-content: space-between; gap: var(--space-2); padding: 6px 0; border-bottom: 1px solid var(--line-soft); color: var(--muted); }
.dice-log-row b { color: var(--text); font-family: var(--mono); }

/* ── Map ── */
.map-wrap { position: relative; display: inline-block; margin: 0 auto; }
.map-board { position: relative; width: min(1100px, 96vw); }
.map-img { width: 100%; display: block; border-radius: var(--radius); border: 1px solid var(--line); }
.map-node {
  position: absolute; transform: translate(-50%, -50%); z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  background: none; border: 0; padding: 0;
}
/* While the annotation layer is active, city nodes go inert so drawing never selects a city. */
.map-board.anno-active .map-node { pointer-events: none; }
/* Marker = dark ring (visibility + control glow) with a coloured centre (category). */
.node-dot {
  position: relative; width: 22px; height: 22px; border-radius: 50%;
  background: #10151d; border: 2px solid #05070b;
  box-shadow: 0 0 0 2px #0e1116cc, var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; transition: .12s;
}
.map-node.major .node-dot { width: 28px; height: 28px; }
/* Centre core — coloured by category. Western = gold, Eastern = blue, Major = purple (wins). */
.node-core {
  width: 11px; height: 11px; border-radius: 50%; background: var(--gold);
  box-shadow: 0 0 3px rgba(0,0,0,.7) inset, 0 0 5px rgba(255,255,255,.15);
}
.map-node.major .node-core { width: 15px; height: 15px; }
.map-node.east .node-core  { background: var(--blue); }
.map-node.major .node-core { background: var(--purple); }
/* Control shown as a coloured glow around the (still-dark) ring. */
.map-node.roman    .node-dot { box-shadow: 0 0 0 2px #0e1116cc, 0 0 12px 1px var(--gold); }
.map-node.seleucid .node-dot { box-shadow: 0 0 0 2px #0e1116cc, 0 0 12px 1px var(--blue); }
.map-node.entry .node-dot { border-radius: 5px; }
.map-node.entry .node-core { border-radius: 2px; }
.map-node.selected .node-dot { outline: 3px solid #fff; outline-offset: 2px; }
.map-node.route-a .node-dot { outline: 3px solid var(--good); outline-offset: 2px; }
.map-node.route-b .node-dot { outline: 3px solid var(--accent); outline-offset: 2px; }
.node-label {
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000, 0 0 4px #000;
  white-space: nowrap; letter-spacing: .3px;
}
.map-node.major .node-label { font-size: 13px; }
.node-tokens { display: flex; gap: 2px; margin-top: 1px; }
.node-token { font-size: 12px; filter: drop-shadow(0 1px 2px #000); }
.node-siege { position: absolute; top: -6px; right: -6px; font-size: 10px; }
.map-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ── Map annotations (arrows / lines / markers) ── */
.anno-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 10px; }
.anno-tools { display: flex; gap: 4px; background: var(--bg-2); padding: 3px; border-radius: var(--radius); border: 1px solid var(--line-soft); }
.anno-tool {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 7px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; font-size: var(--fs-sm); font-weight: 600;
}
.anno-tool:hover { color: var(--text); background: var(--panel); }
.anno-tool[aria-pressed="true"] { color: var(--text); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); }
.anno-swatches { display: flex; gap: 5px; }
.anno-swatch {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line-soft);
}
.anno-swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 1px var(--line-soft), 0 0 0 3px var(--bg-2); }
.anno-sep { width: 1px; align-self: stretch; background: var(--line-soft); margin: 0 2px; }

.anno-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.anno-svg .anno-shape { cursor: pointer; }
.anno-svg .anno-hit { stroke: transparent; stroke-width: 3; fill: none; pointer-events: stroke; cursor: pointer; }
.anno-svg .anno-shape.selected { filter: drop-shadow(0 0 3px #fff); }

.anno-capture { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; z-index: 5; }

.map-marker {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  background: none; border: 0; padding: 0; z-index: 3;
}
.marker-badge {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-size: 14px;
  background: #10151d; border: 2px solid var(--m-color, var(--gold));
  box-shadow: 0 0 0 2px #0e1116cc, var(--shadow-sm);
}
.map-marker.selected .marker-badge { outline: 3px solid #fff; outline-offset: 2px; }
.map-marker .marker-label {
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000, 0 0 4px #000;
  white-space: nowrap; background: rgba(10,13,19,.65); padding: 1px 6px; border-radius: 6px;
}
.anno-handle {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); cursor: grab; z-index: 6; touch-action: none;
}
.anno-handle:active { cursor: grabbing; }

/* City side panel */
.city-panel { display: flex; flex-direction: column; gap: var(--space-4); }
.control-seg { display: flex; gap: 4px; }
.control-seg button { flex: 1; }

/* Campaign strip */
.camp-strip { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.spoils-box { display: flex; align-items: center; gap: var(--space-2); padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg-2); }
.spoils-num { font-family: var(--mono); font-size: var(--fs-xl); font-weight: 800; }

/* ── Roster / builder rows ── */
.roster-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--line-soft); }
.roster-row .name { font-weight: 600; }
.roster-row .cost { font-family: var(--mono); color: var(--muted); margin-left: auto; }
.catalog-row { display: flex; align-items: center; gap: var(--space-3); padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--line-soft); background: var(--bg-2); }
.catalog-row:hover { border-color: var(--line); }
/* multi-line rows (name + stat line + rule pills) read better top-aligned */
.catalog-row.top { align-items: flex-start; }

/* Builder grids — collapse to one column on narrow screens so the page never scrolls sideways */
.builder-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.builder-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
@media (max-width: 1000px) {
  .builder-cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .builder-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ── Reference cards ── */
.ref-layout { display: grid; grid-template-columns: 220px 1fr; gap: var(--space-4); }
.ref-cats { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; align-self: start; }
.ref-cat { text-align: left; padding: 10px 12px; border-radius: var(--radius); border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
.ref-cat:hover, .ref-cat.active { background: var(--panel-2); color: var(--text); }
.ref-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-4); align-content: start; }
.ref-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); }
.ref-card h3 { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-lg); margin-bottom: 6px; }
.ref-card .short { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--space-3); }
.ref-card ul { margin: var(--space-2) 0; padding-left: 18px; }
.ref-card li { margin: 3px 0; }
.ref-card .mods { margin-top: var(--space-2); }
.ref-card .mods .badge { margin: 2px 2px 0 0; }
.cat-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); }

/* ── Search palette ── */
.search-box { width: 100%; }
.search-input { height: 48px; font-size: var(--fs-lg); }
.search-results { margin-top: var(--space-3); max-height: 56vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.search-hit { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; }
.search-hit:hover, .search-hit.active { background: var(--panel-2); border-color: var(--line); }
.search-hit .h-title { font-weight: 600; }
.search-hit .h-short { font-size: var(--fs-sm); color: var(--muted); }
.search-hit mark { background: var(--gold-dim); color: var(--gold-2); border-radius: 3px; padding: 0 2px; }

/* ── Battle tracker ── */
.battle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }
.combatant { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); }
.combatant.sunk { opacity: .5; filter: grayscale(1); }
.combatant h4 { display: flex; align-items: center; gap: 6px; margin-bottom: var(--space-2); }
.counter { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 4px 0; }
.counter .lbl { font-size: var(--fs-sm); color: var(--muted); }
.pips { display: flex; gap: 3px; }
.pip { width: 14px; height: 14px; border-radius: 3px; background: var(--panel-3); border: 1px solid var(--line); cursor: pointer; }
.pip.on { background: var(--good); border-color: var(--good); }
.pip.hull.on { background: var(--gold); border-color: var(--gold); }

/* ── Misc ── */
.empty { text-align: center; color: var(--muted); padding: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.hr { height: 1px; background: var(--line-soft); border: 0; margin: var(--space-3) 0; }
.note-block { background: var(--bg-2); border: 1px solid var(--line-soft); border-left: 3px solid var(--gold); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-size: var(--fs-sm); }

@media (max-width: 760px) {
  .ref-layout { grid-template-columns: 1fr; }
  .ref-cats { flex-direction: row; overflow-x: auto; position: static; }
}
