/* ============================================================================
   CROWN & CONQUEST — a medieval war table.
   Charcoal + oak frame, parchment map, warm gold economy, teal / crimson houses.
   ==========================================================================*/

@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700&family=Source+Sans+3:wght@400;500;600;700&display=swap");

:root {
  /* Frame — charcoal and oak */
  --ink: #14100c;
  --oak-1: #241b13;
  --oak-2: #33261a;
  --oak-3: #4a3725;
  --char-1: #1b1815;
  --char-2: #262220;
  --rule: #4b3d2e;
  --rule-soft: #3a2f24;

  /* Parchment — the map itself */
  --parch-1: #ece0c6;
  --parch-2: #e2d3b4;
  --parch-3: #d6c5a1;
  --parch-ink: #2f2618;
  --parch-mute: #6d6047;

  /* Fog */
  --fog-remember: #b6ab93;
  --fog-unseen: #2c2b2c;
  --fog-unseen-2: #3a3839;

  /* Economy */
  --gold: #d9a441;
  --gold-deep: #a9741e;
  --gold-ink: #3d2a06;

  /* Houses */
  --a: #2f7d8c;
  --a-deep: #17505d;
  --a-lite: #8fd3d8;
  --b: #a33440;
  --b-deep: #6e1b26;
  --b-lite: #f0a9a0;

  --danger: #c0453f;
  --ok: #6f9a53;

  --text: #f2e9da;
  --text-mute: #b2a288;
  --text-dim: #8a7c66;

  --serif: "Cinzel", "Trajan Pro", Georgia, "Times New Roman", serif;
  --sans:
    "Source Sans 3", "Segoe UI", system-ui, -apple-system, "Helvetica Neue",
    sans-serif;

  --r-sm: 3px;
  --r-md: 5px;
  --r-lg: 8px;

  --shadow-panel: 0 2px 0 #0000004d, 0 18px 44px #00000059;
  --shadow-token: 0 2px 4px #1a120a5c;

  --cell-h: clamp(78px, 12.4vh, 132px);
  --tap: 44px;
}

* {
  box-sizing: border-box;
}
/* `display` declarations below would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
}
html {
  background: var(--ink);
  -webkit-text-size-adjust: 100%;
}
body {
  min-height: 100vh;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
  background:
    radial-gradient(120% 70% at 50% -10%, #3a2c1e 0%, transparent 60%),
    radial-gradient(90% 60% at 50% 110%, #241a12 0%, transparent 60%),
    repeating-linear-gradient(
      92deg,
      #1b1611 0px,
      #1b1611 3px,
      #1e1812 3px,
      #1e1812 7px
    ),
    var(--ink);
}

/* Tabular numerals everywhere a number can be compared or read at a glance. */
.num,
.cp,
.income-badge,
.stat-value,
input[type="number"],
.turn-chip,
.coord {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ------------------------------------------------------------- primitives */

button,
input,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 2px;
}

.btn {
  min-height: var(--tap);
  padding: 10px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #3b2e21, #2a2017);
  color: var(--text);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  box-shadow:
    inset 0 1px 0 #ffffff14,
    0 1px 2px #0009;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #4a3928, #33271b);
  border-color: var(--oak-3);
}
.btn:active:not(:disabled) {
  box-shadow: inset 0 2px 4px #0009;
}
.btn-primary {
  background: linear-gradient(180deg, #e2b258, var(--gold-deep));
  border-color: #7d5613;
  color: var(--gold-ink);
  text-shadow: 0 1px 0 #ffffff40;
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f0c16b, #b8811f);
  border-color: #7d5613;
}
.btn-ghost {
  background: transparent;
  border-color: var(--rule-soft);
  color: var(--text-mute);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: #ffffff0a;
}
.btn-sm {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 0.07em;
}

.ico {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.13em;
  flex: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- masthead */

.masthead {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(12px, 3vw, 40px);
  background: linear-gradient(180deg, #2b2118, #1c1610);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 6px 22px #0009;
}
.masthead::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--gold-deep) 20%,
    var(--gold) 50%,
    var(--gold-deep) 80%,
    transparent
  );
  opacity: 0.55;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--gold);
  flex: none;
  filter: drop-shadow(0 1px 2px #0008);
}
.brand-text {
  min-width: 0;
}
.brand-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(17px, 2.4vw, 25px);
  letter-spacing: 0.16em;
  line-height: 1.05;
  color: #f6ecd8;
  text-shadow: 0 1px 0 #00000080;
  white-space: nowrap;
}
.brand-title em {
  font-style: normal;
  color: var(--gold);
}
.brand-sub {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mast-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.turn-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: #16120e;
  line-height: 1.1;
}
.turn-chip b {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.06em;
  color: var(--gold);
}
.turn-chip span {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ stage */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(322px, 26vw, 384px);
  gap: clamp(10px, 1.4vw, 20px);
  align-items: start;
  padding: clamp(10px, 1.6vw, 22px) clamp(10px, 3vw, 40px)
    clamp(18px, 3vw, 34px);
  max-width: 1720px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, #262019, #1d1813);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
}
.panel + .panel {
  margin-top: clamp(8px, 1vw, 14px);
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--rule-soft);
  background: linear-gradient(180deg, #2f2619, #241d15);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.panel-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: #e9dcc3;
}
.panel-head .ico {
  color: var(--gold);
  font-size: 15px;
}
.panel-head .head-note {
  margin-left: auto;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.panel-body {
  padding: 13px 14px;
}

/* ------------------------------------------------------------------ board */

/* The board is the primary surface: on wide screens it stays put while the
   command rail scrolls beside it. */
@media (min-width: 1081px) {
  .board-frame {
    position: sticky;
    top: clamp(8px, 1.4vw, 18px);
  }
}

.board-frame {
  position: relative;
  padding: clamp(9px, 1.1vw, 17px);
  border-radius: var(--r-lg);
  border: 1px solid var(--rule);
  background:
    linear-gradient(180deg, #3a2c1e, #241a12) padding-box,
    linear-gradient(180deg, #55402a, #241a12) border-box;
  box-shadow:
    inset 0 1px 0 #ffffff12,
    var(--shadow-panel);
}
.board-frame::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid #6c522f4d;
  border-radius: var(--r-md);
  pointer-events: none;
}

.board-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 2px 10px;
}
.board-title {
  font-family: var(--serif);
  font-size: clamp(14px, 1.5vw, 17px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #efe2c8;
}
.board-bar .spacer {
  flex: 1 1 auto;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: #191410;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
  white-space: nowrap;
}
.pill .ico {
  font-size: 13px;
}
.pill.a {
  color: var(--a-lite);
  border-color: #2f7d8c66;
}
.pill.b {
  color: var(--b-lite);
  border-color: #a3344066;
}
.pill.gold {
  color: var(--gold);
  border-color: #d9a44159;
}

.board-scroll {
  position: relative;
}
.board {
  position: relative;
  display: grid;
  gap: clamp(3px, 0.42vw, 6px);
  padding: 3px;
  border-radius: var(--r-md);
  background:
    radial-gradient(120% 90% at 50% 0%, #00000000, #00000040),
    linear-gradient(180deg, #6b5636, #4c3b25);
}

/* Rows exist for assistive tech; the grid tracks come from .board itself. */
.board-row {
  display: contents;
}

.coord {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(9px, 0.85vw, 11px);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #d8c49a;
  text-transform: uppercase;
  min-width: 0;
}
.coord.corner {
  font-size: 8px;
  color: #9a8460;
}

/* --- a tile.  NOTE: no z-index / transform / filter here on purpose, so the
   arrow overlay can slot between tile scenery and tile badges. --- */
.cell {
  position: relative;
  display: block;
  width: 100%;
  min-height: var(--cell-h);
  padding: 0;
  border: 0;
  border-radius: 2px;
  overflow: hidden;
  text-align: left;
  color: var(--parch-ink);
  background:
    radial-gradient(120% 100% at 30% 10%, #ffffff2e, transparent 60%),
    linear-gradient(160deg, var(--parch-1), var(--parch-2) 55%, var(--parch-3));
  box-shadow:
    inset 0 0 0 1px #00000026,
    inset 0 -8px 16px #8b724526;
  cursor: pointer;
  transition:
    box-shadow 0.14s ease,
    background-color 0.14s ease;
}
.cell:hover {
  box-shadow:
    inset 0 0 0 1px #00000026,
    inset 0 0 0 2px #d9a44173,
    inset 0 -8px 16px #8b724526;
}
.cell.is-locked,
.cell.is-over {
  cursor: default;
}

.terrain-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.62;
  pointer-events: none;
}

/* Fog tiers ------------------------------------------------------------- */
.cell.fog-remembered {
  background:
    repeating-linear-gradient(
      135deg,
      #00000012 0 6px,
      transparent 6px 12px
    ),
    linear-gradient(160deg, #cfc2a5, #b8ac91);
  filter: none;
}
.cell.fog-remembered .terrain-art {
  opacity: 0.24;
}
.cell.fog-unseen {
  background:
    radial-gradient(120% 110% at 50% 0%, #4a4744, transparent 70%),
    repeating-linear-gradient(45deg, #2b2a2a 0 7px, #313030 7px 14px);
  color: #6f6a63;
  box-shadow: inset 0 0 0 1px #0000004d;
}
.cell.fog-unseen:hover {
  box-shadow:
    inset 0 0 0 1px #0000004d,
    inset 0 0 0 2px #d9a44140;
}
.fog-mark {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  font-family: var(--serif);
  font-size: clamp(13px, 1.7vw, 19px);
  color: #5d5851;
  letter-spacing: 0.1em;
}

/* Badges — always the topmost thing on a tile. */
.income-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 19px;
  padding: 1px 5px 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--gold-deep);
  background: linear-gradient(180deg, #f2cd7c, #d9a441);
  color: var(--gold-ink);
  font-size: clamp(10px, 1.05vw, 12px);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px #00000059;
}
.income-badge .ico {
  font-size: 9px;
  color: #7a5a10;
}
.income-badge.unknown {
  background: #46433f;
  border-color: #5b5751;
  color: #a49c8f;
}
.income-badge.remembered {
  background: linear-gradient(180deg, #d3b276, #b08c3c);
  border-color: #8a6c22;
  color: #33240a;
}
.income-badge.castle-income {
  background: linear-gradient(180deg, #f6dc9d, #e0b352);
  top: 26px;
}

.coord-tag {
  position: absolute;
  left: 4px;
  bottom: 3px;
  z-index: 5;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #6f6247;
  opacity: 0.75;
  pointer-events: none;
}
.cell.fog-unseen .coord-tag {
  color: #6e6862;
}

/* Castle ---------------------------------------------------------------- */
.castle {
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  z-index: 4;
  width: clamp(52px, 6.2vw, 78px);
  height: clamp(38px, 4.6vw, 58px);
  pointer-events: none;
  filter: drop-shadow(0 2px 3px #00000047);
}
.castle-flag {
  position: absolute;
  left: 4px;
  right: 4px;
  justify-content: center;
  top: 4px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  border: 1px solid;
  box-shadow: 0 1px 2px #00000047;
}
.castle-flag.a {
  background: #17505d;
  border-color: #2f7d8c;
  color: #cdeef1;
}
.castle-flag.b {
  background: #6e1b26;
  border-color: #a33440;
  color: #fbd9d5;
}
.castle-flag.dead {
  background: #3a3733;
  border-color: #565049;
  color: #b3aa9c;
  text-decoration: line-through;
}

/* Armies ---------------------------------------------------------------- */
.army-row {
  position: relative;
  z-index: 4;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding: 17px 3px 3px;
  min-height: 100%;
}
/* On a castle tile the keep is the backdrop and the garrison stands in front
   of it, so both the illustration and every exact CP stay readable. */
.cell.has-castle .castle {
  bottom: auto;
  top: 15px;
  width: clamp(46px, 5.2vw, 66px);
  height: clamp(32px, 3.8vw, 46px);
  opacity: 0.92;
}
.cell.has-castle .army-row {
  align-items: flex-end;
  padding: 20px 3px 3px;
}

.unit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: clamp(38px, 4.2vw, 54px);
  flex: 0 1 54px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px #00000042);
  transition: transform 0.12s ease;
}
.unit:hover {
  transform: translateY(-2px);
}
.unit .army-art {
  display: block;
  width: 100%;
  height: clamp(30px, 3.4vw, 44px);
}
.unit.b .army-art {
  transform: scaleX(-1);
}
.cp {
  position: relative;
  z-index: 6;
  display: block;
  min-width: 26px;
  padding: 0 5px;
  border-radius: 3px;
  border: 1px solid;
  font-size: clamp(11.5px, 1.15vw, 14px);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px #00000059;
}
.cp.a {
  background: linear-gradient(180deg, #2f7d8c, #17505d);
  border-color: #0d3a45;
  color: #eafafb;
}
.cp.b {
  background: linear-gradient(180deg, #a33440, #6e1b26);
  border-color: #4d0f17;
  color: #fff0ee;
}
.unit.selected {
  filter: drop-shadow(0 0 4px var(--gold)) drop-shadow(0 0 10px #d9a44182);
}
.unit.selected .cp {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px #d9a44166;
}
.unit.ordered .cp::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  border: 1px solid #6a4711;
}

/* Selection / order state on the tile ----------------------------------- */
.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 2px;
  pointer-events: none;
  transition: box-shadow 0.14s ease;
}
.cell.is-selected::after {
  box-shadow:
    inset 0 0 0 3px var(--gold),
    inset 0 0 18px #d9a4413d;
}
.cell.is-target::after {
  box-shadow: inset 0 0 0 2px #d9a44199;
}
.cell.is-target {
  background:
    radial-gradient(120% 100% at 30% 10%, #ffffff2e, transparent 60%),
    linear-gradient(160deg, #efe0bd, #e5d4ab 55%, #d9c79e);
}
.cell.is-hold-target::after {
  box-shadow:
    inset 0 0 0 3px var(--gold),
    inset 0 0 0 6px #d9a4412e;
}
.cell.is-destination::after {
  box-shadow: inset 0 0 0 2px #2f7d8ccc;
}

/* Planned-order markers ------------------------------------------------- */
.hold-marker {
  position: absolute;
  right: 4px;
  bottom: 3px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid #0d3a45;
  background: linear-gradient(180deg, #3d8f9c, #1b5b69);
  color: #eafafb;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 1px 2px #00000059;
}
.hold-marker .ico {
  font-size: 10px;
}
.dest-ghost {
  position: absolute;
  left: 4px;
  top: 4px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px dashed #2f7d8c;
  background: #0d3a45e0;
  color: #d7f3f6;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 1px 2px #00000059;
}
.dest-ghost .ghost-count {
  color: #8fd3d8;
  font-weight: 600;
}

/* Arrow overlay — between tile scenery and tile badges, never interactive. */
.arrows {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.order-arrow-line {
  fill: none;
  stroke: #12424dcc;
  stroke-width: 5;
  stroke-linecap: round;
}
.order-arrow-head {
  fill: #12424dcc;
}
.order-arrow.selected .order-arrow-line {
  stroke: var(--gold);
  stroke-width: 6.5;
}
.order-arrow.selected .order-arrow-head {
  fill: var(--gold);
}
.order-arrow.hold .order-arrow-line {
  stroke-dasharray: 5 6;
}

/* ------------------------------------------------------------- side rail */

.rail {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1vw, 14px);
  min-width: 0;
}
.rail .panel + .panel {
  margin-top: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.stat {
  padding: 8px 9px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
  background: #16120e;
  min-width: 0;
}
.stat-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}
.stat-value {
  margin-top: 2px;
  font-family: var(--serif);
  font-size: clamp(19px, 2.1vw, 25px);
  font-weight: 700;
  line-height: 1.1;
  color: #f4ead7;
}
.stat.gold .stat-value {
  color: var(--gold);
}
.stat.gold .stat-label .ico {
  color: var(--gold);
}
.stat-note {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}

.defense-line {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid var(--rule-soft);
  border-left: 3px solid var(--a);
  border-radius: var(--r-sm);
  background: #16120e;
  font-size: 12.5px;
  color: var(--text-mute);
}
.defense-line b {
  color: #f4ead7;
}
.defense-sum {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-dim);
}
.defense-sum .eq {
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
}

.house-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--rule-soft);
  font-size: 13px;
}
.house-row:first-child {
  border-top: 0;
}
.house-swatch {
  width: 12px;
  height: 15px;
  border-radius: 2px 2px 4px 4px;
  flex: none;
  border: 1px solid #0006;
}
.house-swatch.a {
  background: linear-gradient(180deg, #2f7d8c, #17505d);
}
.house-swatch.b {
  background: linear-gradient(180deg, #a33440, #6e1b26);
}
.house-row .grow {
  flex: 1 1 auto;
  min-width: 0;
}
.tag {
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
  white-space: nowrap;
}
.tag.you {
  border-color: var(--gold-deep);
  color: var(--gold);
}
.tag.joined {
  border-color: #4d6f43;
  color: #a9cf94;
}
.tag.locked {
  border-color: #7d5613;
  background: #d9a4411f;
  color: var(--gold);
}
.tag.waiting {
  border-color: #5a5145;
  color: var(--text-dim);
}

/* Recruitment ----------------------------------------------------------- */
.recruit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.recruit-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #1d1811, #171310);
}
.recruit-card.active {
  border-color: var(--gold-deep);
  box-shadow: inset 0 0 0 1px #d9a4412e;
}
.recruit-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.recruit-preview {
  position: relative;
  height: 60px;
  border-radius: var(--r-sm);
  border: 1px solid #00000040;
  background:
    radial-gradient(100% 100% at 50% 0%, #ffffff1a, transparent 70%),
    linear-gradient(160deg, var(--parch-2), var(--parch-3));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}
.recruit-preview .army-art {
  width: 88%;
  height: 100%;
}
.recruit-preview.empty::after {
  content: "No levy";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7d7059;
  background: repeating-linear-gradient(
    45deg,
    #00000010 0 6px,
    transparent 6px 12px
  );
}
.recruit-tier {
  font-family: var(--serif);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #e7d9bd;
  text-align: center;
  min-height: 15px;
}
.recruit-input {
  display: flex;
  align-items: center;
  gap: 6px;
}
.recruit-input input[type="number"] {
  width: 100%;
  min-height: var(--tap);
  padding: 6px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: #100d0a;
  color: #f4ead7;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
}
.recruit-input input[type="number"]:disabled {
  opacity: 0.5;
}
.step {
  min-height: var(--tap);
  min-width: 30px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: #241d15;
  color: var(--text-mute);
  font-size: 18px;
  line-height: 1;
}
.step:hover:not(:disabled) {
  color: var(--gold);
  border-color: var(--gold-deep);
}
.recruit-cost {
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-align: center;
}
.budget-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-sm);
  background: #16120e;
  font-size: 12.5px;
  color: var(--text-mute);
}
.budget-line b {
  font-size: 16px;
  color: var(--gold);
  font-family: var(--serif);
}
.budget-line.over {
  border-color: var(--danger);
  background: #c0453f1a;
  color: #f3c3bf;
}
.budget-line.over b {
  color: #f0a9a0;
}
.recruit-note {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-dim);
}
.recruit-note b {
  color: var(--text-mute);
}

/* Selected army panel --------------------------------------------------- */
.selected-empty {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.selected-body {
  display: flex;
  gap: 11px;
  align-items: flex-start;
}
.selected-art {
  width: 78px;
  height: 62px;
  flex: none;
  border-radius: var(--r-sm);
  border: 1px solid #00000040;
  background: linear-gradient(160deg, var(--parch-2), var(--parch-3));
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.selected-meta {
  min-width: 0;
  flex: 1 1 auto;
}
.selected-cp {
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.selected-cp b {
  font-family: var(--serif);
  font-size: 27px;
  line-height: 1;
  color: #f4ead7;
}
.selected-cp span {
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.selected-tier {
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.05em;
  color: var(--gold);
}
.selected-facts {
  margin: 7px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--text-mute);
}
.selected-facts li {
  display: flex;
  gap: 6px;
  padding: 2px 0;
}
.selected-facts .k {
  color: var(--text-dim);
  min-width: 62px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
  padding-top: 2px;
}
.selected-facts .v {
  color: #f0e5d0;
  font-weight: 600;
}
.selected-actions {
  display: flex;
  gap: 7px;
  margin-top: 11px;
  flex-wrap: wrap;
}
.selected-actions .btn {
  flex: 1 1 0;
  min-width: 96px;
}

/* Roster ---------------------------------------------------------------- */
.roster-group {
  margin-bottom: 11px;
}
.roster-group:last-child {
  margin-bottom: 0;
}
.roster-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0 6px;
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--rule-soft);
}
.roster-head .ico {
  color: var(--gold);
  font-size: 12px;
}
.roster-head .count {
  margin-left: auto;
  color: var(--text-mute);
}
.roster-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 7px;
}
.garrison-entry {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: var(--tap);
  padding: 6px 8px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #1e1811, #17130f);
  text-align: left;
  transition:
    border-color 0.14s ease,
    background 0.14s ease;
}
.garrison-entry:hover {
  border-color: var(--oak-3);
  background: #241d15;
}
.garrison-entry.selected {
  border-color: var(--gold);
  background: #2a2116;
  box-shadow: inset 0 0 0 1px #d9a4413d;
}
.entry-art {
  width: 40px;
  height: 34px;
  border-radius: 2px;
  background: linear-gradient(160deg, var(--parch-2), var(--parch-3));
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  flex: none;
}
.entry-art .army-art {
  width: 100%;
  height: 100%;
}
.entry-main {
  min-width: 0;
}
.entry-name {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  color: #f0e5d0;
}
.entry-name .idx {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--gold);
}
.entry-name .tier {
  font-size: 11px;
  color: var(--text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-order {
  margin-top: 1px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.entry-order.move {
  color: var(--a-lite);
}
.entry-order.hold {
  color: var(--gold);
}
.entry-cp {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  color: #f4ead7;
  padding-left: 4px;
}
.entry-tools {
  display: flex;
  gap: 5px;
  margin: 5px 0 0 49px;
}
.entry-tools .btn {
  flex: 0 0 auto;
}
.roster-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 0;
}

/* Status / actions ------------------------------------------------------ */
.status-note {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule-soft);
  border-left: 3px solid var(--text-dim);
  background: #16120e;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-mute);
}
.status-note.live {
  border-left-color: var(--a);
  color: #d6ecef;
}
.status-note.wait {
  border-left-color: var(--gold);
  color: #eeddb6;
}
.status-note.win {
  border-left-color: var(--ok);
  color: #cfe6bd;
}
.status-note.lose {
  border-left-color: var(--danger);
  color: #f2c8c4;
}
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.action-grid .wide {
  grid-column: 1 / -1;
}
.invite {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}
.invite input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  padding: 8px 10px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-sm);
  background: #100d0a;
  color: var(--text-dim);
  font-size: 11.5px;
}

/* Legend ---------------------------------------------------------------- */
.legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 8px 12px;
  font-size: 11.5px;
  color: var(--text-mute);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.legend-key {
  width: 24px;
  height: 18px;
  border-radius: 2px;
  flex: none;
  border: 1px solid #0006;
}
.legend-key.visible {
  background: linear-gradient(160deg, var(--parch-1), var(--parch-3));
}
.legend-key.remembered {
  background:
    repeating-linear-gradient(135deg, #00000014 0 4px, transparent 4px 8px),
    linear-gradient(160deg, #cfc2a5, #b8ac91);
}
.legend-key.unseen {
  background: repeating-linear-gradient(45deg, #2b2a2a 0 5px, #313030 5px 10px);
}
.legend-key.gold {
  background: linear-gradient(180deg, #f2cd7c, #d9a441);
}
.legend-key.teal {
  background: linear-gradient(180deg, #2f7d8c, #17505d);
}
.legend-key.crimson {
  background: linear-gradient(180deg, #a33440, #6e1b26);
}
.legend-key.arrow {
  background: none;
  border: 0;
  display: grid;
  place-items: center;
  color: var(--gold);
}
.tier-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--rule-soft);
}
.tier-chip {
  text-align: center;
}
.tier-chip .art {
  height: 40px;
  border-radius: 2px;
  background: linear-gradient(160deg, var(--parch-2), var(--parch-3));
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.tier-chip .art .army-art {
  width: 100%;
  height: 100%;
}
.tier-chip .name {
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 10px;
  letter-spacing: 0.03em;
  color: #e7d9bd;
  line-height: 1.25;
}
.tier-chip .range {
  font-size: 9.5px;
  color: var(--text-dim);
}

.rules-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-mute);
}
.rules-list li {
  padding: 5px 0;
  border-top: 1px solid var(--rule-soft);
}
.rules-list li:first-child {
  border-top: 0;
}
.rules-list b {
  color: #eadfc8;
  font-weight: 600;
}

/* --------------------------------------------------------------- overlays */

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -180%);
  max-width: min(560px, calc(100vw - 24px));
  padding: 11px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--rule);
  background: linear-gradient(180deg, #33271b, #201a13);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: 0 14px 40px #000000a6;
  transition: transform 0.22s ease;
}
.toast.show {
  transform: translate(-50%, 0);
}
.toast.error {
  border-color: var(--danger);
  color: #f6d3cf;
}
.toast.good {
  border-color: #4d6f43;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #0c0906cc;
  backdrop-filter: blur(3px);
}
.scrim[hidden] {
  display: none;
}
.dialog {
  width: min(460px, 100%);
  border-radius: var(--r-lg);
  border: 1px solid var(--rule);
  background: linear-gradient(180deg, #2b2219, #1c1712);
  box-shadow: 0 30px 80px #000000b8;
  overflow: hidden;
}
.dialog-crest {
  height: 76px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #3a2c1e, #241a12);
  border-bottom: 1px solid var(--rule);
  color: var(--gold);
}
.dialog-crest svg {
  width: 44px;
  height: 44px;
}
.dialog-body {
  padding: 18px 20px 20px;
  text-align: center;
}
.dialog-body h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #f6ecd8;
}
.dialog-body h2.win {
  color: var(--gold);
}
.dialog-body h2.lose {
  color: var(--b-lite);
}
.dialog-body p {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-mute);
  line-height: 1.5;
}
.dialog-actions {
  display: flex;
  gap: 9px;
  justify-content: center;
  flex-wrap: wrap;
}
.dialog-actions .btn {
  min-width: 130px;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 62vh;
  gap: 14px;
  text-align: center;
  padding: 24px;
}
.boot-crest {
  width: 62px;
  height: 62px;
  color: var(--gold);
  animation: pulse 1.9s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}
.boot h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #eadfc8;
}
.boot p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.footer {
  padding: 0 16px 26px;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6b6151;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1080px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
  }
  .rail {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    align-items: start;
  }
  :root {
    --cell-h: clamp(76px, 12vw, 104px);
  }
}

@media (max-width: 720px) {
  :root {
    --cell-h: 78px;
  }
  body {
    font-size: 14px;
  }
  .stage {
    padding: 8px 8px 20px;
    gap: 9px;
  }
  .rail {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }
  .masthead {
    padding: 10px 10px;
    gap: 8px;
  }
  .brand {
    min-width: 0;
    flex: 1 1 auto;
  }
  .brand-mark {
    width: 24px;
    height: 24px;
  }
  .brand-title {
    font-size: clamp(14px, 4.4vw, 19px);
    letter-spacing: 0.08em;
    white-space: normal;
    text-wrap: balance;
    line-height: 1.12;
  }
  .brand-sub {
    display: none;
  }
  .turn-chip {
    padding: 5px 9px;
  }
  .turn-chip b {
    font-size: 15px;
  }
  .turn-chip span {
    font-size: 9px;
    letter-spacing: 0.1em;
  }
  .board-frame {
    padding: 7px;
  }
  .board {
    gap: 3px;
  }
  .board-bar {
    padding-bottom: 7px;
    gap: 6px;
  }
  .unit {
    width: clamp(30px, 8.4vw, 40px);
  }
  .unit .army-art {
    height: 26px;
  }
  .cp {
    min-width: 22px;
    font-size: 11.5px;
    padding: 0 3px;
  }
  .castle {
    width: 46px;
    height: 34px;
  }
  .income-badge {
    top: 2px;
    right: 2px;
    font-size: 11.5px;
    padding: 0 3px;
    min-height: 19px;
  }
  .income-badge .ico {
    display: none;
  }
  .income-badge.castle-income {
    top: 20px;
    font-size: 10px;
  }
  .castle-flag {
    left: 2px;
    right: 2px;
    top: 2px;
    font-size: 8px;
    letter-spacing: 0;
    padding: 0 1px;
  }
  .coord-tag {
    display: none;
  }
  .hold-marker {
    right: 2px;
    bottom: 2px;
    font-size: 8.5px;
    padding: 0 3px;
  }
  .hold-marker .ico {
    display: none;
  }
  .dest-ghost {
    left: 2px;
    top: 2px;
    font-size: 9.5px;
    padding: 0 3px;
  }
  .army-row {
    padding: 15px 1px 2px;
    gap: 1px;
  }
  /* Three fresh/veteran garrison armies remain individually selectable.
     Compact vertical power tags preserve exact values on narrow screens;
     their full formations remain visible in the roster. */
  .has-castle .army-row:has(.unit:nth-child(3)) {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 1px;
    padding: 18px 3px 3px;
  }
  .has-castle .army-row:has(.unit:nth-child(3)) .unit {
    flex: none;
    width: auto;
  }
  .has-castle .army-row:has(.unit:nth-child(3)) .army-art {
    display: none;
  }
  .stat-value {
    font-size: 20px;
  }
  .selected-art {
    width: 62px;
    height: 52px;
  }
  .tier-legend {
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  }
  .toast {
    top: auto;
    bottom: 12px;
    transform: translate(-50%, 200%);
  }
  .toast.show {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 400px) {
  :root {
    --cell-h: 74px;
  }
  .recruit-grid {
    gap: 6px;
  }
  .recruit-card {
    padding: 6px;
  }
  .recruit-preview {
    height: 50px;
  }
  .unit {
    width: 28px;
  }
  .garrison-entry {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 7px;
    padding: 5px 6px;
  }
  .entry-art {
    width: 34px;
    height: 30px;
  }
  .entry-tools {
    margin-left: 41px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (prefers-contrast: more) {
  .cell {
    box-shadow: inset 0 0 0 1px #000;
  }
  .income-badge,
  .cp {
    border-width: 2px;
  }
}
