/* RBN war table. Dark walnut table, parchment ink.
   Meaning of color: ember = attack, steel = defence, brass = both / our marks / focus. */
:root {
  color-scheme: dark;
  /* surfaces: the table and the boards laid on it */
  --table: #15110e;
  --board: #1b1612;
  --board-up: #231d18;
  --board-hi: #2b241e;
  --well: #0f0c0a;
  /* ink on parchment */
  --ink: #ece2cb;
  --ink-2: #c3b69b;
  --ink-3: #908470;
  --ink-4: #5f574a;
  /* rules */
  --rule: rgba(236, 226, 203, 0.075);
  --rule-2: rgba(236, 226, 203, 0.13);
  --rule-3: rgba(236, 226, 203, 0.22);
  /* meaning */
  --ember: #e26c4b;
  --ember-wash: rgba(226, 108, 75, 0.13);
  --steel: #7eaad2;
  --steel-wash: rgba(126, 170, 210, 0.13);
  --brass: #cfa652;
  --brass-wash: rgba(207, 166, 82, 0.13);
  --alarm: #e8917a;
  /* type */
  --f-ui: 'Heebo', system-ui, 'Segoe UI', Arial, sans-serif;
  --f-ink: 'Frank Ruhl Libre', 'Heebo', serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  /* shape */
  --r-s: 5px;
  --r-m: 8px;
  --r-l: 12px;
  --bar-h: 60px;
  --nav-h: 64px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.detail > *, .block > *, .side > *, .near > * { min-width: 0; } /* let scroll wrappers (unit table, chips) shrink */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--table);
  color: var(--ink);
  font: 400 15px/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
ol { list-style: none; margin: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: var(--r-s); }

.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; letter-spacing: -0.01em; }
.num.nil { color: var(--ink-4); }
.xy { font-family: var(--f-mono); font-size: 0.92em; color: var(--ink-3); letter-spacing: -0.02em; white-space: nowrap; }
.muted { color: var(--ink-3); font-size: 13px; }
.is-error { color: var(--alarm); }

/* ---------------------------------------------------------------- boot / login */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-msg { color: var(--ink-3); font-size: 14px; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; }
.login-mark { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 12px; text-align: center; }
.login-mark .emblem { width: 112px; height: 112px; }
.login-mark .wordmark { font-size: 30px; }
.login-sub { color: var(--ink-3); margin-bottom: 28px; text-wrap: pretty; text-align: center; }
.login-form { display: grid; gap: 10px; padding: 20px; background: var(--board); border: 1px solid var(--rule); border-radius: var(--r-l); }
.login .empty { padding: 20px; background: var(--board); border: 1px solid var(--rule); border-radius: var(--r-l); }

/* ---------------------------------------------------------------- wordmark + emblem slot */
.mark { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.emblem { width: 32px; height: 32px; flex: none; display: grid; place-items: center; }
.emblem:not(.has-art)::before { /* placeholder until art/emblem.png exists */
  content: ''; width: 15px; height: 15px; transform: rotate(45deg);
  border: 1.5px solid var(--brass); box-shadow: inset 0 0 0 3px var(--table), inset 0 0 0 9px var(--brass-wash);
}
.emblem img { width: 100%; height: 100%; object-fit: contain; }
.wordmark { display: flex; align-items: baseline; gap: 8px; font-size: 21px; line-height: 1; white-space: nowrap; }
.wm-tag { font-family: var(--f-mono); font-weight: 600; color: var(--brass); letter-spacing: 0.06em; font-size: 0.86em; }
.wm-name { font-family: var(--f-ink); font-weight: 700; color: var(--ink); }

/* ---------------------------------------------------------------- shell */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: var(--bar-h); padding: 0 24px;
  background: var(--table); /* opaque: a backdrop-filter here would trap the fixed phone nav inside the bar */
  border-bottom: 1px solid var(--rule);
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 100%;
  color: var(--ink-3); font-weight: 500; font-size: 15px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 150ms var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brass); }
.tab-ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.ledger { margin-inline-start: auto; display: flex; align-items: stretch; gap: 0; }
.stat { display: flex; flex-direction: column; justify-content: center; padding: 0 16px; border-inline-start: 1px solid var(--rule); min-width: 96px; }
.stat:first-child { border-inline-start: 0; }
.stat-label { font-size: 11px; font-weight: 500; color: var(--ink-3); line-height: 1.2; }
.stat-val { font-size: 19px; font-weight: 600; line-height: 1.25; }
.stat.off .stat-val { color: var(--ember); }
.stat.def .stat-val { color: var(--steel); }
.stat.rep .stat-val { color: var(--ink-2); font-weight: 500; }

.view { padding: 0; }

/* ---------------------------------------------------------------- shared controls */
.field {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--well); border: 1px solid var(--rule-2); border-radius: var(--r-m);
  color: var(--ink); outline: none;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.field::placeholder { color: var(--ink-4); }
.field:hover { border-color: var(--rule-3); }
.field:focus { border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-wash); }
.field[aria-invalid="true"] { border-color: var(--alarm); }
.field[dir="ltr"] { text-align: left; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field-search { background-image: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  background: var(--board-up); color: var(--ink);
  border: 1px solid var(--rule-2); border-radius: var(--r-m);
  font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--board-hi); border-color: var(--rule-3); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary { background: var(--brass); border-color: var(--brass); color: #1a140c; }
.btn-primary:hover { background: #dbb463; border-color: #dbb463; }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; }
.link { color: var(--brass); text-decoration: underline; text-decoration-color: rgba(207, 166, 82, 0.4); text-underline-offset: 3px; }
.link:hover { text-decoration-color: var(--brass); }

.form-error { color: var(--alarm); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }
.form-status { color: var(--ink-3); font-size: 13px; }
.hint { color: var(--ink-3); font-size: 13px; }

.seg { display: flex; gap: 2px; padding: 3px; background: var(--well); border: 1px solid var(--rule); border-radius: var(--r-m); overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg-opt {
  flex: 1 0 auto; min-height: 36px; padding: 0 12px; border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--ink-3); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.seg-opt:hover { color: var(--ink); }
.seg-opt[aria-pressed="true"] { background: var(--board-hi); color: var(--ink); box-shadow: 0 0 0 1px var(--rule-2); }
.seg-opt[data-k="off"][aria-pressed="true"] { color: var(--ember); }
.seg-opt[data-k="def"][aria-pressed="true"] { color: var(--steel); }

.section-title { font-family: var(--f-ink); font-weight: 700; font-size: 19px; line-height: 1.3; display: flex; align-items: baseline; gap: 8px; }
.count { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.eyebrow { font-size: 12px; font-weight: 500; color: var(--brass); margin-bottom: 2px; }
.badge { display: inline-block; margin-inline-start: 8px; padding: 1px 7px; font: 500 11px/1.6 var(--f-ui); color: var(--brass); background: var(--brass-wash); border-radius: 999px; vertical-align: 2px; }

.empty { padding: 28px 16px; text-align: center; }
.empty-title { font-family: var(--f-ink); font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.empty-body { color: var(--ink-3); font-size: 14px; max-width: 42ch; margin: 0 auto 14px; text-wrap: pretty; }

/* column headers shared by roster, village list, nearest list */
.cols { display: grid; gap: 12px; padding: 0 16px 6px; font-size: 11px; font-weight: 500; color: var(--ink-4); }
.col-off, .col-def { text-align: left; }
.col-off { color: rgba(226, 108, 75, 0.75); }
.col-def { color: rgba(126, 170, 210, 0.8); }
.cell-off, .cell-def { text-align: left; font-size: 15px; font-weight: 500; }
.cell-off .num:not(.nil) { color: var(--ember); }
.cell-def .num:not(.nil) { color: var(--steel); }

/* ---------------------------------------------------------------- players */
.players-view { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: calc(100vh - var(--bar-h)); }
.roster {
  position: sticky; top: var(--bar-h); align-self: start;
  height: calc(100vh - var(--bar-h)); overflow-y: auto;
  border-inline-end: 1px solid var(--rule);
  padding-bottom: 24px;
}
.roster-head { display: grid; gap: 10px; padding: 20px 16px 14px; position: sticky; top: 0; background: var(--table); z-index: 2; }
.roster-cols, .vl-cols { grid-template-columns: minmax(0, 1fr) 72px 72px; }
.prow {
  display: grid; grid-template-columns: minmax(0, 1fr) 72px 72px; gap: 12px; align-items: center;
  min-height: 60px; padding: 10px 16px;
  border-top: 1px solid var(--rule);
  transition: background-color 120ms var(--ease);
}
.prow:hover { background: var(--board); }
.prow[aria-current="true"] { background: var(--board-up); box-shadow: inset -3px 0 0 var(--brass); }
.prow-main { display: grid; gap: 2px; min-width: 0; }
.prow-name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-meta { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pips { display: flex; gap: 3px; margin-top: 3px; flex-wrap: wrap; }
.pip { display: inline-block; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--ink-4); }
.pip.on { background: var(--brass); border-color: var(--brass); }

.detail-wrap { min-width: 0; }
.detail { padding: 24px 32px 48px; max-width: 980px; display: grid; gap: 24px; align-content: start; }
.back { display: none; color: var(--ink-3); font-size: 14px; min-height: 44px; align-items: center; }
.dhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px solid var(--rule); }
.dtitle { min-width: 0; }
.dname { font-family: var(--f-ink); font-weight: 700; font-size: 34px; line-height: 1.15; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.dsub { color: var(--ink-3); font-size: 14px; margin-top: 4px; }

.totals { display: flex; gap: 28px; }
.tot { display: grid; gap: 0; }
.tot-label { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.tot-val { font-size: 34px; font-weight: 600; line-height: 1.1; }
.tot.off .tot-val:not(.nil) { color: var(--ember); }
.tot.def .tot-val:not(.nil) { color: var(--steel); }
.totals.mid .tot-val { font-size: 24px; }

.overview .callout { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 20px; background: var(--board); border: 1px solid var(--rule); border-radius: var(--r-l); color: var(--ink-2); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px;
  background: var(--board); border: 1px solid var(--rule-2); border-radius: 999px;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
.chip:hover { border-color: var(--rule-3); background: var(--board-up); }
.chip[aria-current="true"] { background: var(--brass-wash); border-color: var(--brass); }
.chip-name { font-weight: 600; font-size: 14px; max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-sub { font-size: 12px; color: var(--ink-3); font-family: var(--f-mono); }
.chip-all .chip-sub { background: var(--board-hi); border-radius: 999px; padding: 0 7px; }

.block { display: grid; gap: 10px; }

/* units per type on the player profile */
.ut-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r-l); background: var(--board); }
.unit-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.unit-table th, .unit-table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.unit-table tbody tr:last-child > * { border-bottom: 0; }
.unit-table thead th { font-size: 12px; font-weight: 500; color: var(--ink-3); background: var(--board-up); }
.unit-table thead .ut-v { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; }
.unit-table tbody th { font-weight: 600; border-inline-start: 3px solid transparent; line-height: 1.25; white-space: normal; width: 1%; min-width: 8ch; }
.unit-table thead .ut-v, .unit-table thead .ut-total { width: 1%; }
@media (max-width: 760px) { .unit-table th, .unit-table td { padding-inline: 8px; font-size: 13px; } .unit-table thead .ut-v { max-width: 9ch; } }
.unit-table .ut-name { display: block; }
.unit-table .ut-role { display: block; }
.unit-table th, .unit-table td { padding-inline: 10px; }
.unit-table tr.r-off th[scope="row"] { border-inline-start-color: var(--ember); }
.unit-table tr.r-def th[scope="row"] { border-inline-start-color: var(--steel); }
.unit-table tr.r-both th[scope="row"] { border-inline-start-color: var(--brass); }
.ut-role { font-size: 11px; font-weight: 400; color: var(--ink-3); }
.unit-table .num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.unit-table td.ut-total { font-weight: 600; color: var(--ink); }
.unit-table td.ut-v { color: var(--ink-2); }
.unit-table tr.is-zero td { color: var(--ink-4); }
.vlist { border-bottom: 1px solid var(--rule); }
.vlist .prow { padding-inline: 12px; }
.vlist .prow-meta { white-space: normal; }

/* village card + troop form */
.vcard { display: grid; gap: 18px; padding: 20px; background: var(--board); border: 1px solid var(--rule); border-radius: var(--r-l); }
.vcard-head { display: flex; justify-content: space-between; gap: 16px; }
.vname { font-family: var(--f-ink); font-weight: 700; font-size: 22px; line-height: 1.25; overflow-wrap: anywhere; }
.vmeta { color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.units { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.unit { display: grid; gap: 6px; padding: 10px; background: var(--board-up); border-radius: var(--r-m); border-top: 2px solid var(--ink-4); }
.unit.r-off { border-top-color: var(--ember); }
.unit.r-def { border-top-color: var(--steel); }
.unit.r-both { border-top-color: var(--brass); }
.unit.r-none { border-top-color: var(--rule-2); }
.unit-top { display: grid; gap: 0; min-width: 0; }
.unit-name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-role { font-size: 11px; color: var(--ink-3); }
.unit.r-off .unit-role { color: var(--ember); }
.unit.r-def .unit-role { color: var(--steel); }
.unit.r-both .unit-role { color: var(--brass); }
.unit-in { font-family: var(--f-mono); font-size: 17px; font-weight: 500; text-align: left; padding: 8px 10px; }
.unit.r-none .unit-in { color: var(--ink-2); }
.troops { display: grid; gap: 14px; }
.troops-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.live { display: flex; gap: 18px; align-items: baseline; font-size: 14px; color: var(--ink-3); }
.live-item .num { font-size: 17px; font-weight: 600; margin-inline-start: 4px; }
.live-item.off .num { color: var(--ember); }
.live-item.def .num { color: var(--steel); }
.live-bad { color: var(--alarm); font-size: 13px; }
.troops-actions { display: flex; gap: 8px; }
.troops-actions .btn-primary { min-width: 120px; }

/* ---------------------------------------------------------------- nearest list (the signature) */
.near { display: grid; gap: 12px; }
.near-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.near-from { color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.near-from b { color: var(--ink-2); font-weight: 600; }
.near-count { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.near-controls { display: flex; gap: 12px 20px; align-items: center; flex-wrap: wrap; }
.near-controls .seg { flex: 0 1 auto; }
.filters { display: flex; gap: 8px 20px; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.check input { width: 18px; height: 18px; accent-color: var(--brass); margin: 0; }
.maxd { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.field-num { width: 76px; min-height: 40px; padding: 6px 10px; font-family: var(--f-mono); }

.near-cols { grid-template-columns: 64px minmax(0, 1fr) 76px 76px; padding-inline: 12px; }
.near-list { border-bottom: 1px solid var(--rule); }
.nrow {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) 76px 76px; gap: 12px; align-items: center;
  min-height: 58px; padding: 8px 12px; border-top: 1px solid var(--rule);
  transition: background-color 120ms var(--ease);
}
.nrow:hover { background: var(--board); }
.compass { display: flex; align-items: center; gap: 6px; }
.arrow { width: 22px; height: 22px; flex: none; }
.arrow-ring { fill: none; stroke: var(--rule-3); stroke-width: 1; }
.arrow-head { fill: var(--brass); }
.arrow-dot { fill: var(--brass); }
.dist { font-size: 14px; font-weight: 600; color: var(--ink); }
.nmain { display: grid; gap: 1px; min-width: 0; }
.nname { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nmeta { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowner { color: var(--ink-2); }
.tribe-tag { font-weight: 400; color: var(--ink-3); font-size: 0.82em; white-space: nowrap; }
.dname .tribe-tag { font-family: var(--f-ui); font-size: 0.5em; letter-spacing: 0; }
.nfrom { color: var(--ink-4); }

/* ---------------------------------------------------------------- war table view */
.table-view { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, 1fr); gap: 32px; padding: 24px 32px 48px; align-items: start; }
.board-col { position: sticky; top: calc(var(--bar-h) + 24px); display: grid; gap: 10px; }
.board { position: relative; aspect-ratio: 1 / 1; width: 100%; max-height: calc(100vh - var(--bar-h) - 90px); max-width: calc(100vh - var(--bar-h) - 90px); margin-inline: auto; border-radius: var(--r-l); overflow: hidden; border: 1px solid var(--rule-2); background: #110e0b url(art/table.jpg) center / 512px repeat; }
.wartable { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; direction: ltr; user-select: none; -webkit-user-select: none; }
.wartable .sea { fill: rgba(8, 6, 5, 0.55); }
.wartable .frame { fill: rgba(21, 17, 14, 0.35); stroke: rgba(207, 166, 82, 0.35); stroke-width: 1; vector-effect: non-scaling-stroke; }
.wartable .grid line { vector-effect: non-scaling-stroke; stroke-width: 1; }
.wartable .g-minor { stroke: rgba(236, 226, 203, 0.035); }
.wartable .g-major { stroke: rgba(236, 226, 203, 0.08); }
.wartable .g-axis { stroke: rgba(207, 166, 82, 0.22); }
.wartable .grid { pointer-events: none; }
.vmark .vdot { fill: transparent; stroke: var(--brass); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.vmark.is-in .vdot { fill: var(--brass); }
.vmark.is-cap .vdot { stroke-width: 2.5; }
.vlabel { fill: var(--ink-2); font-family: var(--f-ui); font-weight: 500; paint-order: stroke; stroke: #17130f; stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.links line { stroke: var(--brass); stroke-opacity: 0.55; stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.pmark { pointer-events: none; }
.pmark circle { fill: rgba(236, 226, 203, 0.08); stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.pmark line { stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.map-ctl { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; }
.map-btn {
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: var(--r-m);
  background: rgba(27, 22, 18, 0.92); border: 1px solid var(--rule-2); color: var(--ink);
  font-size: 18px; font-weight: 500; cursor: pointer;
  transition: background-color 120ms var(--ease), transform 120ms var(--ease);
}
.map-btn:hover { background: var(--board-hi); }
.map-btn:active { transform: scale(0.95); }
.map-btn-text { font-size: 13px; }
.readout { position: absolute; bottom: 10px; left: 10px; padding: 2px 8px; border-radius: var(--r-s); background: rgba(21, 17, 14, 0.85); font: 500 12px/1.6 var(--f-mono); color: var(--ink-2); pointer-events: none; }
.readout:empty { display: none; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; font-size: 12.5px; color: var(--ink-3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--brass); display: inline-block; }
.lg-in { background: var(--brass); }
.lg-pt { border-color: var(--ink); border-radius: 50%; background: rgba(236, 226, 203, 0.1); width: 11px; height: 11px; }

.side { display: grid; gap: 24px; min-width: 0; }
.pointform { display: grid; gap: 8px; }
.pf-row { display: flex; gap: 8px; }
.field-coord { font-family: var(--f-mono); font-size: 17px; font-weight: 500; letter-spacing: 0.02em; }
.side .empty { border: 1px dashed var(--rule-2); border-radius: var(--r-l); }

/* ---------------------------------------------------------------- settings */
.settings { max-width: 1040px; padding: 24px 32px 64px; }
.page-head { padding-bottom: 8px; }
.page-title { font-family: var(--f-ink); font-weight: 700; font-size: 30px; }
.set-sec { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 32px; padding: 28px 0; border-top: 1px solid var(--rule); }
.set-sec:first-of-type { border-top: 0; }
.set-intro { display: grid; gap: 8px; align-content: start; }
.set-intro p { color: var(--ink-3); font-size: 14px; text-wrap: pretty; }
.set-body { display: grid; gap: 14px; align-content: start; min-width: 0; }
.tag-form { display: grid; gap: 8px; max-width: 360px; }
.field-tag { font-family: var(--f-mono); font-weight: 600; letter-spacing: 0.04em; }
.set-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; z-index: 3; padding: 12px 0; background: var(--table); border-top: 1px solid var(--rule); }
.tribe { margin: 0; padding: 4px 0 8px; border: 0; }
.tribe legend { padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 16px; }
.legend-en { font-size: 12px; font-weight: 500; color: var(--ink-4); margin-inline-start: 4px; }
.role-row { display: grid; grid-template-columns: minmax(0, 170px) minmax(0, 1fr); gap: 12px; align-items: center; padding: 6px 0; border-top: 1px solid var(--rule); }
.role-row .unit-name { font-size: 14px; }
.roles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 3px; background: var(--well); border: 1px solid var(--rule); border-radius: var(--r-m); }
.role-opt { position: relative; display: flex; align-items: center; justify-content: center; min-height: 38px; border-radius: var(--r-s); font-size: 13.5px; font-weight: 500; color: var(--ink-3); cursor: pointer; transition: background-color 120ms var(--ease), color 120ms var(--ease); }
.role-opt:hover { color: var(--ink); }
.role-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.role-opt:has(input:focus-visible) { outline: 2px solid var(--brass); outline-offset: 1px; }
.role-opt:has(input:checked) { background: var(--board-hi); color: var(--ink); box-shadow: 0 0 0 1px var(--rule-2); }
.role-opt.r-off:has(input:checked) { background: var(--ember-wash); color: var(--ember); box-shadow: 0 0 0 1px rgba(226, 108, 75, 0.35); }
.role-opt.r-def:has(input:checked) { background: var(--steel-wash); color: var(--steel); box-shadow: 0 0 0 1px rgba(126, 170, 210, 0.35); }
.role-opt.r-both:has(input:checked) { background: var(--brass-wash); color: var(--brass); box-shadow: 0 0 0 1px rgba(207, 166, 82, 0.35); }
.default-mark { position: absolute; top: 5px; left: 6px; width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); }
.default-mark.inline { position: static; display: inline-block; vertical-align: middle; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; z-index: 50;
  padding: 10px 16px; border-radius: var(--r-m);
  background: var(--board-hi); color: var(--ink); border: 1px solid var(--rule-2);
  font-size: 14px; font-weight: 500;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- tablet */
@media (max-width: 1100px) {
  .ledger .stat { min-width: 0; padding: 0 12px; }
  .table-view { grid-template-columns: minmax(0, 1fr); }
  .board-col { position: static; }
  .board { max-height: none; max-width: 640px; }
  .set-sec { grid-template-columns: minmax(0, 1fr); gap: 16px; }
}
@media (max-width: 1000px) {
  .units { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------------------------------------------------------------- phone */
@media (max-width: 760px) {
  :root { --bar-h: 56px; }
  body { font-size: 15px; }
  .bar { gap: 12px; padding: 0 16px; }
  .wordmark { font-size: 18px; }
  .bar .wm-name { display: none; }
  .ledger .stat { padding: 0 10px; }
  .stat-val { font-size: 16px; }
  .stat-label { font-size: 10.5px; }

  .tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(21, 17, 14, 0.97); border-top: 1px solid var(--rule-2);
    gap: 0;
  }
  .tab { flex: 1; flex-direction: column; justify-content: center; gap: 2px; padding: 0; font-size: 12px; border-bottom: 0; border-top: 2px solid transparent; margin: 0; }
  .tab[aria-current="page"] { border-top-color: var(--brass); color: var(--brass); }
  .tab-ico { width: 22px; height: 22px; }
  .view { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
  .toast { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
  .sticky-actions { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

  .players-view { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .roster { position: static; height: auto; overflow: visible; border: 0; padding-bottom: 0; }
  .roster-head { position: static; padding: 16px 16px 12px; }
  .players-view.has-player .roster { display: none; }
  .players-view:not(.has-player) .detail-wrap { display: none; }
  .roster-cols, .vl-cols, .prow { grid-template-columns: minmax(0, 1fr) 64px 64px; gap: 8px; }
  .detail { padding: 4px 16px 24px; gap: 20px; }
  .back { display: inline-flex; }
  .dhead { align-items: flex-start; flex-direction: column; gap: 14px; padding-bottom: 16px; }
  .dname { font-size: 28px; }
  .totals { width: 100%; gap: 0; }
  .tot { flex: 1; padding: 10px 12px; background: var(--board); border: 1px solid var(--rule); }
  .tot.off { border-start-start-radius: var(--r-m); border-end-start-radius: var(--r-m); }
  .tot.def { border-start-end-radius: var(--r-m); border-end-end-radius: var(--r-m); border-inline-start: 0; }
  .tot-val { font-size: 26px; }
  .totals.mid .tot { background: var(--board-up); }
  .totals.mid .tot-val { font-size: 20px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin-inline: -16px; padding: 2px 16px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .vcard { padding: 14px; gap: 14px; margin-inline: -4px; }
  .vcard-head { flex-direction: column; gap: 4px; }
  .units { gap: 8px; }
  .troops-foot { flex-direction: column; align-items: stretch; }
  .troops-actions { justify-content: stretch; }
  .troops-actions .btn { flex: 1; }

  .near-controls { flex-direction: column; align-items: stretch; gap: 4px; }
  .near-controls .seg { width: 100%; }
  .seg-opt { padding: 0 8px; }
  .near-cols, .nrow { grid-template-columns: 58px minmax(0, 1fr) 54px 54px; gap: 8px; }
  .nrow { padding-inline: 4px; }
  .near-cols { padding-inline: 4px; }
  .cell-off, .cell-def { font-size: 14px; }
  .arrow { width: 20px; height: 20px; }
  .dist { font-size: 13px; }

  .table-view { padding: 12px 16px 24px; gap: 20px; }
  .table-view .side { display: contents; }
  .table-view .pointform { order: -1; }
  .table-view .side > .near, .table-view .side > .empty { order: 1; }
  .settings { padding: 16px 16px 32px; }
  .set-sec { padding: 20px 0; }
  .role-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 10px 0; }
}

@media (max-width: 380px) {
  .ledger .stat { padding: 0 7px; }
  .stat-val { font-size: 15px; }
}

/* ================================================================ round 2: manual villages, travel time */
.btn-small { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn-danger { background: #b9533d; border-color: #b9533d; color: #fff4ee; }
.btn-danger:hover { background: #c95e47; border-color: #c95e47; }
.btn-danger-text { color: var(--alarm); }
.btn-danger-text:hover { color: #f2a593; }
.badge-manual { color: var(--ink-2); background: transparent; border: 1px dashed var(--rule-3); }

select.field, .field-select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-inline-start: 12px; padding-inline-end: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23908470' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center;
}
select.field option, select.field optgroup { background: var(--board); color: var(--ink); }

.roster-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dactions { display: flex; gap: 8px; margin-top: 10px; }
.chip-manual { font-style: normal; font-size: 11px; color: var(--ink-3); border: 1px dashed var(--rule-3); border-radius: 999px; padding: 0 6px; }
.chip-add { border-style: dashed; color: var(--ink-2); }
.chip-add:hover { color: var(--ink); }

/* village card: tournament square + footer */
.vcard-head { align-items: flex-start; }
.ts { display: flex; align-items: center; gap: 10px; flex: none; }
.ts-label { display: grid; font-size: 13px; font-weight: 500; color: var(--ink-2); text-align: end; }
.ts-hint { font-size: 11px; font-weight: 400; color: var(--ink-3); }
.ts .field-num { width: 64px; text-align: center; font-size: 16px; }
.ts-msg { font-size: 12px; color: var(--ink-3); min-width: 3ch; }
.vcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--rule); }
.vcard-foot .muted { max-width: 60ch; text-wrap: pretty; }

/* confirm dialog */
.dlg {
  width: min(440px, calc(100vw - 32px)); padding: 22px; margin: auto;
  background: var(--board-up); color: var(--ink);
  border: 1px solid var(--rule-2); border-radius: var(--r-l);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.dlg::backdrop { background: rgba(8, 6, 5, 0.72); }
.dlg[open] { animation: dlg-in 180ms var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.dlg-title { font-family: var(--f-ink); font-weight: 700; font-size: 21px; line-height: 1.3; margin-bottom: 10px; overflow-wrap: anywhere; }
.dlg-body { display: grid; gap: 8px; color: var(--ink-2); font-size: 14.5px; text-wrap: pretty; margin-bottom: 20px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-actions .btn { min-width: 110px; }

/* nearest: travel-time controls */
.timebox { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 14px; background: var(--board); border: 1px solid var(--rule); border-radius: var(--r-l); }
.tb-row { display: flex; align-items: flex-end; gap: 10px 18px; flex-wrap: wrap; }
.tb-field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.tb-row > * { min-width: 0; }
.field-select { max-width: 100%; }
.tb-field .field-select { min-width: 240px; }
.tb-arrival { display: flex; gap: 8px; align-items: center; }
.field-time { width: 120px; font-family: var(--f-mono); font-size: 17px; text-align: center; letter-spacing: 0.02em; }
.field-day { width: 96px; min-width: 0 !important; }
.arr-note { font-size: 13px; color: var(--brass); padding-bottom: 12px; }
.tb-row:has(.field-time[aria-invalid="true"]) .arr-note { color: var(--alarm); }
.arr-note:empty { display: none; }
.timebox .hint { font-size: 12.5px; }
.timebox .check { min-height: 40px; }

/* nearest: time column */
.near-cols, .nrow { grid-template-columns: 64px minmax(0, 1fr) 128px 76px 76px; }
.table-view .near-cols, .table-view .nrow { grid-template-columns: 56px minmax(0, 1fr) 112px 64px 64px; gap: 10px; }
.ntime { display: grid; gap: 1px; min-width: 0; }
.nt-dur { display: flex; align-items: baseline; gap: 6px; }
.nt-dur .num { font-size: 15px; font-weight: 600; color: var(--ink); }
.nt-est { font-size: 10.5px; font-weight: 500; color: var(--brass); border: 1px solid rgba(207, 166, 82, 0.4); border-radius: 999px; padding: 0 5px; line-height: 1.5; }
.nt-unit { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nt-send { font-size: 12.5px; color: var(--brass); font-weight: 500; white-space: nowrap; }
.nt-send .num { font-weight: 600; }
.nt-send.is-late { color: var(--alarm); }
.nt-none { font-size: 12px; color: var(--ink-4); }
.nrow.is-late { opacity: 0.45; }
.nrow.is-late:hover { opacity: 0.75; }
.nname .badge { vertical-align: 1px; }

/* add village */
.add-view .detail { max-width: 760px; }
.page-sub { color: var(--ink-3); font-size: 14px; margin-top: 6px; max-width: 62ch; text-wrap: pretty; }
.back-always { display: inline-flex; }
.addform { gap: 16px; }
.add-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.add-field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.add-new { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; padding: 14px; border: 1px dashed var(--rule-3); border-radius: var(--r-m); }
.add-new[hidden] { display: none; }
.add-new .seg-opt { min-height: 40px; }
.opt { font-weight: 400; color: var(--ink-3); }
.add-actions { display: flex; gap: 8px; justify-content: flex-end; }
.add-actions .btn-primary { min-width: 150px; }
.addform .field-num { width: 120px; }
.hint.is-error { color: var(--alarm); }

/* settings: speed + hidden villages */
.mult { align-self: center; font-family: var(--f-mono); color: var(--ink-3); font-size: 18px; }
#spd { width: 90px; font-size: 17px; text-align: center; }
.hidden-list { border-top: 1px solid var(--rule); }
.hrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.hrow-main { display: grid; gap: 2px; min-width: 0; }
.hrow .prow-meta { white-space: normal; }

/* map: manual villages */
.vmark.is-manual .vdot { stroke-dasharray: 2 2; }

@media (max-width: 760px) {
  .near-cols, .table-view .near-cols { grid-template-columns: 58px minmax(0, 1fr) 54px 54px; }
  .near-cols .col-time { display: none; }
  .nrow, .table-view .nrow {
    grid-template-columns: 58px minmax(0, 1fr) 54px 54px; gap: 8px;
    grid-template-areas: "c m o d" ". t t t";
    row-gap: 4px;
  }
  .nrow .compass { grid-area: c; }
  .nrow .nmain { grid-area: m; }
  .nrow .cell-off { grid-area: o; }
  .nrow .cell-def { grid-area: d; }
  .nrow .ntime { grid-area: t; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
  .nt-dur .num { font-size: 14px; }
  .tb-field, .tb-field .field-select { width: 100%; min-width: 0; }
  .tb-row { gap: 8px; }
  .tb-arrival { width: 100%; }
  .tb-arrival .field-time { flex: 1; width: auto; min-width: 0; }
  .tb-arrival .field-day { flex: none; width: 96px; }
  .arr-note { padding-bottom: 0; }
  .add-grid, .add-new { grid-template-columns: minmax(0, 1fr); }
  .add-actions .btn { flex: 1; }
  .vcard-head { flex-direction: column; }
  .ts { width: 100%; justify-content: space-between; padding: 10px 12px; background: var(--board-up); border-radius: var(--r-m); }
  .ts-label { text-align: start; }
  .vcard-foot { flex-direction: column; align-items: stretch; }
  .roster-title .btn-small { min-height: 40px; }
  .dlg-actions .btn { flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
