/* css/game.css */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #faf8f2; font-family: 'Cinzel', serif; overflow: hidden; height: 100vh; height: 100svh; width: 100vw; }

/* ── SCREENS ── */
#screen-faction-picker { display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; height:100svh; background:#faf8f2; }
#screen-game { display:none; flex-direction:column; height:100vh; height:100svh; }

/* ── FACTION PICKER ── */
.picker-title { font-size:36px; font-weight:900; letter-spacing:6px; color:#3a3028; margin-bottom:8px; }
.picker-sub { font-size:12px; letter-spacing:3px; color:#a09080; margin-bottom:40px; }
.faction-cards { display:flex; gap:16px; flex-wrap:wrap; justify-content:center; }
.faction-card {
  width:180px; padding:24px 16px; border-radius:16px; cursor:pointer;
  background:#fff; border:2px solid #e0d8c8;
  transition:all 0.2s; text-align:center;
}
.faction-card:hover { transform:translateY(-4px); box-shadow:0 8px 24px rgba(0,0,0,0.12); }
.faction-card.selected { border-width:3px; }
.faction-card-name { font-size:14px; font-weight:700; letter-spacing:2px; margin-bottom:12px; }
.faction-card-dot { width:20px; height:20px; border-radius:50%; margin:0 auto 12px; }
.faction-card-pros { font-size:10px; color:#27ae60; line-height:1.8; margin-bottom:8px; font-family:Georgia,serif; }
.faction-card-cons { font-size:10px; color:#c0392b; line-height:1.8; font-family:Georgia,serif; }
.start-btn {
  margin-top:32px; padding:14px 48px; background:#3a3028; color:#faf8f2;
  border:none; border-radius:12px; font-family:'Cinzel',serif; font-size:14px;
  letter-spacing:3px; font-weight:700; cursor:pointer; transition:all 0.15s;
}
.start-btn:hover { background:#2a2018; transform:scale(1.03); }

/* ── TOP BAR ── */
.top-bar {
  position:fixed; top:12px; left:50%; transform:translateX(-50%);
  background:rgba(255,252,245,0.94); backdrop-filter:blur(8px);
  border-radius:14px; padding:10px 24px;
  box-shadow:0 2px 20px rgba(0,0,0,0.12);
  display:flex; align-items:center; gap:20px;
  border:1px solid rgba(200,185,160,0.4); z-index:100;
}
.game-title { font-size:16px; font-weight:900; letter-spacing:4px; color:#3a3028; }
.round-badge { font-size:11px; letter-spacing:2px; color:#a09080; }
.phase-badge { font-size:12px; font-weight:700; letter-spacing:2px; background:#f0e878; color:#8a7a10; padding:4px 14px; border-radius:20px; }
.divider { width:1px; height:20px; background:#e0d8c8; }
.opponents { display:flex; gap:10px; }
.opp { display:flex; align-items:center; gap:6px; background:rgba(255,255,255,0.7); border-radius:20px; padding:4px 12px; font-size:10px; letter-spacing:1px; }
.opp-dot { width:10px; height:10px; border-radius:50%; }

/* ── BOARD ── */
#board-wrap {
  position:fixed; inset:58px 0 118px 0;
  background:radial-gradient(ellipse at center, #f1e4c3 0%, #e8d8b0 55%, #c8a878 100%);
  overflow:hidden; cursor:grab;
}
#board-transform { transform-origin:0 0; }
#board {
  display:grid;
  grid-template-columns:repeat(21, 1fr);
  grid-template-rows:repeat(21, 1fr);
  gap:2px; padding:2px;
}
.tile {
  /* Softer octagon — 18% corners instead of 29%. ~18% less parchment clipped,
     so more of the painterly art shows through inside the tile shape. */
  clip-path:polygon(18% 0%,82% 0%,100% 18%,100% 82%,82% 100%,18% 100%,0% 82%,0% 18%);
  display:flex; align-items:center; justify-content:center;
  font-size:10px; transition:filter 0.15s; user-select:none; cursor:pointer;
  position:relative; overflow:visible;
}
.tile:hover { filter:brightness(1.15); }

/* Tile content layers */
.tile-icon { font-size:10px; line-height:1; pointer-events:none; }

/* Unit badge — faction-coloured pill bottom-right of tile */
.tile-unit-badge {
  position:absolute; bottom:1px; right:1px;
  font-size:7px; font-weight:900; line-height:1;
  color:#fff; padding:1px 3px; border-radius:3px;
  border:1px solid rgba(0,0,0,0.35);
  pointer-events:none; letter-spacing:0;
  text-shadow:0 1px 2px rgba(0,0,0,0.6);
  z-index:2;
}

/* Leader badge — styled in parchment.css as a per-faction background-image */


/* Fortification shield — top-right */
.tile-fort-badge {
  position:absolute; top:0px; right:1px;
  font-size:7px; line-height:1; pointer-events:none; z-index:2;
}

/* Structure badge — top-left (resource/influence structures). Stacks
   multiple structure icons into a small bar. */
.tile-structure-badge {
  position:absolute; top:0px; left:1px;
  font-size:7px; line-height:1; pointer-events:none; z-index:2;
  background:rgba(255,250,240,0.65); border-radius:3px; padding:1px 2px;
}

/* Pending build (under construction) — bottom-right, with turns remaining */
.tile-pending-badge {
  position:absolute; bottom:1px; right:1px;
  font-size:8px; line-height:1; pointer-events:none; z-index:3;
  background:rgba(255,225,160,0.85); border-radius:3px; padding:1px 3px;
  font-weight:bold; color:#603;
}

/* ── BOTTOM PANEL ── */
.bottom-panel {
  position:fixed; bottom:12px; left:12px; right:12px;
  background:rgba(255,252,245,0.95); backdrop-filter:blur(10px);
  border-radius:16px; padding:0 20px 14px;
  box-shadow:0 -2px 24px rgba(0,0,0,0.1);
  border:1px solid rgba(200,185,160,0.4);
  display:flex; flex-direction:column; gap:0; z-index:100;
}
/* Phase guide strip — top of bottom panel */
.phase-guide {
  display:flex; align-items:center; gap:10px;
  padding:8px 4px 8px;
  border-bottom:1px solid #e8e0d0;
  margin-bottom:10px;
}
#phase-guide-icon { font-size:14px; flex-shrink:0; }
#phase-guide-text {
  font-size:10px; letter-spacing:1.2px; color:#5a4a38;
  font-family:Georgia,serif; line-height:1.5;
}
/* The horizontal HUD row */
.bottom-row {
  display:flex; align-items:center; gap:24px; width:100%;
}
/* Dim action buttons when not in action phase */
.bottom-panel.upkeep-mode .action-phase-only {
  opacity:0.25; pointer-events:none;
}
.faction-info { display:flex; align-items:center; gap:10px; }
.faction-dot-lg { width:14px; height:14px; border-radius:50%; }
.faction-label { font-size:14px; font-weight:700; letter-spacing:2px; }
.stat-group { display:flex; gap:16px; }
.stat { text-align:center; }
.stat-val { font-size:18px; font-weight:700; color:#3a3028; }
.stat-lbl { font-size:8px; letter-spacing:2px; color:#a09080; margin-top:2px; }
.culture-pill { padding:5px 14px; border-radius:20px; font-size:11px; font-weight:700; letter-spacing:2px; }

/* ── UNIT ACTION MENU ── */
.unit-menu {
  position:fixed; z-index:150;
  background:rgba(255,252,245,0.97); backdrop-filter:blur(10px);
  border:1.5px solid rgba(200,185,160,0.6); border-radius:16px;
  padding:14px 16px; min-width:210px;
  box-shadow:0 8px 32px rgba(0,0,0,0.22);
}
.um-header { margin-bottom:12px; padding-bottom:10px; border-bottom:1px solid #e8e0d0; }
.um-name { font-size:13px; font-weight:700; letter-spacing:2px; color:#3a3028; margin-bottom:4px; }
.um-stats { font-size:10px; letter-spacing:0.5px; color:#a09080; font-family:Georgia,serif; line-height:1.6; }
.um-actions { display:flex; flex-direction:column; gap:6px; }
.um-btn {
  width:100%; padding:9px 14px; border:none; border-radius:9px;
  font-family:'Cinzel',serif; font-size:11px; letter-spacing:1px; font-weight:700;
  cursor:pointer; text-align:left; transition:all 0.12s;
}
.um-move   { background:#e4f2e4; color:#2a6a2a; border:1px solid #b8d8b8; }
.um-move:hover   { background:#c8e4c8; }
.um-attack { background:#f2e4e4; color:#7a2020; border:1px solid #d8b8b8; }
.um-attack:hover { background:#e4c8c8; }
.um-fort   { background:#e4e8f4; color:#2a307a; border:1px solid #b8c0d8; }
.um-fort:hover   { background:#c8cce4; }
.um-build  { background:#e4e8f4; color:#2a307a; border:1px solid #b8c0d8; }
.um-build:hover  { background:#c8cce4; }
.um-disband { background:#f0ece8; color:#7a6a50; border:1px solid #d4c8b4; }
.um-disband:hover { background:#e0d4c8; }
.um-btn:disabled { opacity:0.35; cursor:not-allowed; }

/* Leader menu — ability rows */
.um-abilities {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e8e0d0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.um-ability-row {
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #5a4a38;
  font-family: Georgia, serif;
  line-height: 1.4;
  padding: 4px 8px;
  background: #f5efdf;
  border-radius: 4px;
  border-left: 2px solid #a09080;
}
.um-ability-row.active {
  border-left-color: #d4a020;
  background: #faf3d8;
  cursor: pointer;
}
.um-ability-row.active:hover {
  background: #f0e8b8;
}
.um-ability-row.used {
  opacity: 0.4;
  text-decoration: line-through;
}
.um-ability-tag {
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #a09080;
  margin-right: 6px;
}

/* ── VICTORY TRACKER ── */
.victory-track { display:flex; flex-direction:column; gap:5px; min-width:110px; }
.vt-title { font-size:7px; letter-spacing:2px; color:#c0b0a0; }
.vt-row { display:flex; align-items:center; gap:6px; }
.vt-icon { font-size:9px; width:14px; text-align:center; line-height:1; }
.vt-track { flex:1; height:5px; background:#e8e0d0; border-radius:3px; overflow:hidden; }
.vt-fill { height:100%; border-radius:3px; width:0%; transition:width 0.4s ease; }
.vt-fill-mil { background:#e07070; }
.vt-fill-inf { background:#60a8d8; }
.vt-fill-res { background:#50a850; }
.vt-fill-dom { background:#2a7a3a; }
.vt-val { font-size:8px; letter-spacing:1px; color:#a09080; width:28px; text-align:right; }

.actions { display:flex; gap:8px; margin-left:auto; }
.action-btn { padding:9px 18px; border-radius:10px; border:none; cursor:pointer; font-family:'Cinzel',serif; font-size:11px; letter-spacing:1px; font-weight:700; transition:all 0.15s; }
.btn-primary { background:#3a3028; color:#faf8f2; }
.btn-primary:hover { background:#2a2018; transform:scale(1.03); }
.btn-secondary { background:#f0e8d8; color:#7a6a50; border:1px solid #d4c8b0; }

/* ── TILE TOOLTIP ── */
.tile-tip {
  position:fixed; top:80px; right:16px;
  background:rgba(255,252,245,0.95); backdrop-filter:blur(8px);
  border-radius:14px; padding:16px 18px; min-width:180px;
  box-shadow:0 4px 20px rgba(0,0,0,0.1);
  border:1px solid rgba(200,185,160,0.4); z-index:100; display:none;
}
.tile-tip-terrain { font-size:13px; font-weight:700; letter-spacing:1px; color:#3a3028; margin-bottom:4px; }
.tile-tip-owner { font-size:10px; letter-spacing:1px; margin-bottom:10px; }
.tile-tip-stat { display:flex; justify-content:space-between; font-size:10px; letter-spacing:1px; color:#a09080; padding:4px 0; border-bottom:1px solid #f0e8d8; }
.tile-tip-stat:last-child { border-bottom:none; }

/* ── EVENT LOG ── */
.log {
  position:fixed; bottom:148px; left:16px;
  background:rgba(255,252,245,0.88); backdrop-filter:blur(6px);
  border-radius:10px; padding:10px 14px; width:280px;
  box-shadow:0 2px 12px rgba(0,0,0,0.08);
  border:1px solid rgba(200,185,160,0.3); z-index:100;
}
.log-title { font-size:8px; letter-spacing:3px; color:#c0b0a0; margin-bottom:8px; }
.log-entry { font-size:10px; color:#7a6a58; line-height:1.7; border-bottom:1px solid #f0e8d8; padding-bottom:3px; margin-bottom:3px; font-family:Georgia,serif; }
.log-entry:last-child { border-bottom:none; }

/* ── ZOOM CONTROLS ── */
.zoom-controls { position:fixed; bottom:148px; right:16px; display:flex; flex-direction:column; gap:6px; z-index:100; }
.zoom-btn { width:36px; height:36px; background:rgba(255,252,245,0.95); border:1px solid rgba(200,185,160,0.4); border-radius:8px; font-family:'Cinzel',serif; font-size:16px; cursor:pointer; display:flex; align-items:center; justify-content:center; }
.zoom-pct { font-size:9px; letter-spacing:1px; text-align:center; color:#a09080; }

/* ── GAME OVER ── */
#gameover-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.7); z-index:200; align-items:center; justify-content:center; flex-direction:column; gap:16px; }
#gameover-winner { font-size:48px; font-weight:900; letter-spacing:6px; }

/* ── TILE HIGHLIGHTS ── */
.tile-selected          { outline: 3px solid #f0e040; outline-offset: -3px; filter: brightness(1.3) !important; }
.tile-movable           { outline: 3px solid #40c040; outline-offset: -3px; }
.tile-attack            { outline: 3px solid #e04040; outline-offset: -3px; }
.tile-preview           { outline: 2px dashed rgba(64,192,64,0.6); outline-offset: -2px; }
.tile-preview-selected  { outline: 2px dashed rgba(240,224,64,0.6); outline-offset: -2px; }

/* ── LEADER ON TILE ── */
.tile.has-leader {
  box-shadow: inset 0 0 0 2px rgba(248, 210, 60, 0.9);
}
@keyframes leader-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(248,210,60,0.9); }
  50%       { box-shadow: inset 0 0 0 3px rgba(248,210,60,1), 0 0 8px rgba(248,210,60,0.6); }
}
.tile.has-leader { animation: leader-pulse 2s ease-in-out infinite; }

/* ── GARRISON TILE NEUTRAL PULSE ── */
@keyframes garrison-neutral-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(220, 60, 60, 0.7); }
  50%       { box-shadow: inset 0 0 0 3px rgba(220, 60, 60, 1), 0 0 10px rgba(220,60,60,0.5); }
}
.tile-garrison-neutral { animation: garrison-neutral-pulse 1.4s ease-in-out infinite; }

/* ── VISUAL FEEDBACK ANIMATIONS ── */
@keyframes tile-flash-hit {
  0%   { filter: brightness(3) saturate(0) !important; }
  40%  { filter: brightness(2) saturate(2) sepia(1) !important; }
  100% { filter: brightness(1) !important; }
}
@keyframes tile-flash-move {
  0%   { filter: brightness(2) saturate(2) !important; }
  100% { filter: brightness(1) !important; }
}
@keyframes tile-pulse-garrison {
  0%, 100% { filter: brightness(1) !important; }
  50%       { filter: brightness(1.8) sepia(1) saturate(3) !important; }
}
@keyframes tile-capture {
  0%   { filter: brightness(2.5) saturate(0) !important; }
  50%  { filter: brightness(1.5) saturate(3) !important; }
  100% { filter: brightness(1) !important; }
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px); }
}

.fx-hit      { animation: tile-flash-hit      400ms ease-out forwards; }
.fx-move     { animation: tile-flash-move     300ms ease-out forwards; }
.fx-garrison { animation: tile-pulse-garrison 600ms ease-in-out 3; }
.fx-capture  { animation: tile-capture        500ms ease-out forwards; }

/* Dice "thunk down" — small bounce + flash when the roll locks in */
@keyframes die-thunk {
  0%   { transform: scale(1.4) rotate(-12deg); filter: brightness(2); }
  35%  { transform: scale(0.85) rotate(3deg); }
  70%  { transform: scale(1.08) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); filter: brightness(1); }
}
.die.die-locked { animation: die-thunk 360ms cubic-bezier(0.34, 1.56, 0.64, 1); display:inline-block; }

/* Critical-hit screen shake */
@keyframes screen-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, 4px); }
  20% { transform: translate(7px, -6px); }
  30% { transform: translate(-6px, -3px); }
  40% { transform: translate(5px, 5px); }
  50% { transform: translate(-4px, 2px); }
  60% { transform: translate(4px, -4px); }
  70% { transform: translate(-3px, 3px); }
  80% { transform: translate(2px, -2px); }
  90% { transform: translate(-1px, 1px); }
}
body.fx-screen-shake { animation: screen-shake 600ms ease-out; }

/* ── DICE ROLL MODAL ── */
#dice-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  z-index: 300; display: flex; align-items: center; justify-content: center;
}
.dice-modal {
  background: rgba(255,252,245,0.97); border-radius: 24px;
  padding: 32px 40px; min-width: 380px; text-align: center;
  box-shadow: 0 8px 48px rgba(0,0,0,0.4);
  border: 2px solid rgba(200,185,160,0.5);
  font-family: 'Cinzel', serif;
  animation: diceModalIn 0.2s ease-out;
}
@keyframes diceModalIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.dice-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.dice-side-label {
  font-size: 11px; font-weight: 700; letter-spacing: 3px; padding: 4px 12px;
  border-radius: 20px;
}
.dice-side-label.atk { background: #fde8e8; color: #c0392b; }
.dice-side-label.def { background: #e8f4e8; color: #27ae60; }
.dice-vs { font-size: 13px; font-weight: 900; color: #a09080; letter-spacing: 2px; }
.dice-arena {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin-bottom: 16px;
}
.dice-side { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.dice-divider { width: 1px; height: 80px; background: #e0d8c8; margin: 0 16px; }
.dice-pair { display: flex; gap: 10px; }
.die {
  font-size: 42px; line-height: 1;
  animation: dieSpin 0.08s ease-in-out;
  display: inline-block;
}
@keyframes dieSpin {
  0%   { transform: rotate(-15deg) scale(0.9); }
  50%  { transform: rotate(8deg) scale(1.05); }
  100% { transform: rotate(0deg) scale(1); }
}
.dice-total {
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  padding: 4px 10px; border-radius: 8px; min-height: 24px;
}
.atk-total { color: #c0392b; background: #fde8e8; }
.def-total { color: #27ae60; background: #e8f4e8; }
.dice-result {
  font-size: 16px; font-weight: 900; letter-spacing: 3px;
  min-height: 32px; padding: 8px 0;
  transition: all 0.3s;
}
.dice-atk-win { color: #c0392b; }
.dice-def-win { color: #27ae60; }
.dice-critical { color: #e67e22; animation: criticalPulse 0.4s ease-in-out 2; }
@keyframes criticalPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

/* ── RECRUIT MODAL ── */
#recruit-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.65);
  z-index:300; display:flex; align-items:center; justify-content:center;
}
.recruit-modal {
  background:rgba(255,252,245,0.97); border-radius:20px;
  padding:28px 32px; min-width:340px; max-width:420px;
  box-shadow:0 8px 48px rgba(0,0,0,0.35);
  border:2px solid rgba(200,185,160,0.5);
  font-family:'Cinzel',serif;
  animation:diceModalIn 0.18s ease-out;
}
.modal-title {
  font-size:14px; font-weight:900; letter-spacing:4px;
  color:#3a3028; margin-bottom:6px; text-align:center;
}
.modal-sub {
  font-size:10px; letter-spacing:2px; color:#a09080;
  text-align:center; margin-bottom:20px;
}
.recruit-list { display:flex; flex-direction:column; gap:8px; margin-bottom:20px; }
.recruit-row {
  display:flex; align-items:center; justify-content:space-between;
  background:#faf8f2; border:1px solid #e0d8c8; border-radius:10px;
  padding:10px 14px; cursor:pointer; transition:all 0.15s;
}
.recruit-row:hover:not(.disabled) { background:#f0e8d8; border-color:#c8b898; transform:translateX(2px); }
.recruit-row.disabled { opacity:0.4; cursor:not-allowed; }
.recruit-row-name { font-size:12px; font-weight:700; letter-spacing:2px; color:#3a3028; }
.recruit-row-stats { font-size:9px; letter-spacing:1px; color:#a09080; margin-top:2px; }
.recruit-row-cost {
  font-size:13px; font-weight:700; color:#27ae60;
  background:#e8f4e8; border-radius:8px; padding:4px 10px;
}
.recruit-row-cost.too-expensive { color:#c0392b; background:#fde8e8; }
.modal-close-btn {
  width:100%; padding:10px; background:#3a3028; color:#faf8f2;
  border:none; border-radius:10px; font-family:'Cinzel',serif;
  font-size:11px; letter-spacing:2px; font-weight:700; cursor:pointer;
}
.modal-close-btn:hover { background:#2a2018; }

/* ── BUILD MODAL ── */
#build-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.65);
  z-index:300; display:flex; align-items:center; justify-content:center;
}
.build-modal {
  background:rgba(255,252,245,0.97); border-radius:20px;
  padding:28px 32px; min-width:360px; max-width:460px;
  box-shadow:0 8px 48px rgba(0,0,0,0.35);
  border:2px solid rgba(200,185,160,0.5);
  font-family:'Cinzel',serif;
  animation:diceModalIn 0.18s ease-out;
}
.build-list { display:flex; flex-direction:column; gap:8px; margin-bottom:20px; }
.build-row { /* reuses .recruit-row layout */ }
.build-empty {
  text-align:center; padding:14px; color:#a09080;
  font-size:11px; letter-spacing:2px;
}

/* ── CARDS MODAL ── */
#cards-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.65);
  z-index:300; display:flex; align-items:center; justify-content:center;
}
.cards-modal {
  background:rgba(255,252,245,0.97); border-radius:20px;
  padding:24px 28px; width:460px; max-height:80vh;
  box-shadow:0 8px 48px rgba(0,0,0,0.35);
  border:2px solid rgba(200,185,160,0.5);
  font-family:'Cinzel',serif;
  display:flex; flex-direction:column; gap:12px;
  animation:diceModalIn 0.18s ease-out;
}
/* Victory progress */
.cards-progress { display:flex; flex-direction:column; gap:5px; }
.cards-progress-row { display:flex; align-items:center; gap:8px; }
.cards-prog-label { font-size:9px; letter-spacing:1px; color:#7a6a58; width:80px; }
.cards-prog-bar { flex:1; height:6px; background:#e8e0d0; border-radius:3px; overflow:hidden; }
.cards-prog-fill { height:100%; border-radius:3px; transition:width 0.3s; }
.cards-prog-fill.mil { background:#c0392b; }
.cards-prog-fill.inf { background:#8e44ad; }
.cards-prog-fill.res { background:#27ae60; }
.cards-prog-count { font-size:10px; font-weight:700; color:#3a3028; width:32px; text-align:right; }
/* Tabs */
.cards-tabs { display:flex; gap:6px; }
.cards-tab {
  flex:1; padding:7px; border-radius:8px; border:1px solid #d4c8b0;
  background:#f0e8d8; color:#7a6a50; font-family:'Cinzel',serif;
  font-size:10px; letter-spacing:1px; font-weight:700; cursor:pointer; transition:all 0.15s;
}
.cards-tab.active { background:#3a3028; color:#faf8f2; border-color:#3a3028; }
/* Content area */
.cards-content { flex:1; overflow-y:auto; min-height:200px; max-height:320px; display:flex; flex-direction:column; gap:6px; }
.cards-empty { text-align:center; color:#a09080; font-size:10px; letter-spacing:1px; padding:24px 0; font-family:Georgia,serif; }
/* Hand tab */
.cards-convert-btn {
  width:100%; padding:10px; background:#27ae60; color:#fff;
  border:none; border-radius:10px; font-family:'Cinzel',serif;
  font-size:11px; letter-spacing:2px; font-weight:700; cursor:pointer; margin-bottom:8px;
}
.cards-convert-btn:hover { background:#219a52; }
.cards-hand-grid { display:flex; flex-wrap:wrap; gap:6px; }
.card-chip { display:flex; flex-direction:column; align-items:center; justify-content:center; width:54px; height:54px; border-radius:10px; border:1px solid #d4c8b0; }
.resource-chip { background:#f0fce8; }
.chip-icon { font-size:18px; }
.chip-val { font-size:9px; letter-spacing:1px; color:#3a7a30; font-weight:700; }
/* Buy tab */
.cards-section-heading { font-size:9px; letter-spacing:2px; color:#a09080; padding:6px 0 2px; border-bottom:1px solid #e8e0d0; }
.buy-card-row {
  display:flex; align-items:center; gap:10px;
  background:#faf8f2; border:1px solid #e0d8c8; border-radius:10px;
  padding:10px 12px; cursor:pointer; transition:all 0.15s;
}
.buy-card-row:hover:not(.disabled) { background:#f0e8d8; border-color:#c8b898; }
.buy-card-row.disabled { opacity:0.4; cursor:not-allowed; }
.buy-card-icon { font-size:20px; width:28px; text-align:center; }
.buy-card-info { flex:1; }
.buy-card-name { font-size:11px; font-weight:700; letter-spacing:1px; color:#3a3028; }
.buy-card-desc { font-size:9px; color:#a09080; margin-top:2px; font-family:Georgia,serif; line-height:1.5; }
.buy-card-cost { font-size:12px; font-weight:700; color:#27ae60; background:#e8f4e8; border-radius:8px; padding:4px 8px; text-align:center; white-space:nowrap; }
.buy-card-cost.too-expensive { color:#c0392b; background:#fde8e8; }
/* Held tab */
.held-card-row { display:flex; align-items:center; gap:10px; padding:8px 12px; background:#faf8f2; border:1px solid #e0d8c8; border-radius:8px; flex-wrap:wrap; }
.held-card-icon { font-size:16px; }
.held-card-info { flex:1; display:flex; flex-direction:column; gap:2px; }
.held-card-name { font-size:11px; letter-spacing:1px; color:#3a3028; }
.held-card-upkeep { font-size:9px; color:#c0392b; background:#fde8e8; border-radius:6px; padding:2px 6px; align-self:flex-start; }
.held-card-play-btn {
  padding:4px 10px; border-radius:6px; border:none; cursor:pointer;
  background:#27ae60; color:#fff; font-family:'Cinzel',serif; font-size:9px;
  letter-spacing:1px; font-weight:700; white-space:nowrap;
  transition:background 0.15s;
}
.held-card-play-btn:hover { background:#219a52; }
.held-card-phase-tag { font-size:8px; color:#a09080; letter-spacing:1px; white-space:nowrap; }
.scandal-target-picker { display:flex; align-items:center; gap:6px; flex-wrap:wrap; width:100%; margin-top:4px; }
.scandal-label { font-size:9px; color:#8a7028; letter-spacing:1px; }
.scandal-target-btn {
  padding:3px 8px; border-radius:6px; border:none; cursor:pointer;
  background:#e07030; color:#fff; font-family:'Cinzel',serif; font-size:8px;
  letter-spacing:1px; font-weight:700; text-transform:capitalize;
  transition:background 0.15s;
}
.scandal-target-btn:hover { background:#c05820; }
.scandal-cancel { background:#888; }
.scandal-cancel:hover { background:#666; }

/* ── UPKEEP MODAL ── */
#upkeep-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.65);
  z-index:300; display:flex; align-items:center; justify-content:center;
}
.upkeep-modal {
  background:rgba(255,252,245,0.97); border-radius:20px;
  padding:28px 32px; min-width:380px; max-width:480px; width:100%;
  box-shadow:0 8px 48px rgba(0,0,0,0.35);
  border:2px solid rgba(200,185,160,0.5);
  font-family:'Cinzel',serif;
  animation:diceModalIn 0.18s ease-out;
  max-height:85vh; overflow-y:auto;
}
/* Token balance strip */
.upkeep-tokens {
  display:flex; gap:0; margin:12px 0 10px;
  background:#f0e8d8; border-radius:10px; overflow:hidden;
}
.upkeep-token-row {
  flex:1; display:flex; flex-direction:column; align-items:center;
  padding:8px 4px; border-right:1px solid #e0d8c8;
}
.upkeep-token-row:last-child { border-right:none; }
.upkeep-lbl { font-size:8px; letter-spacing:2px; color:#a09080; }
.upkeep-val { font-size:16px; font-weight:900; color:#3a3028; }
.upkeep-after { font-size:15px; font-weight:900; }
.upkeep-green { color:#27ae60; }
.upkeep-red   { color:#c0392b; }
/* Shortfall banner */
.upkeep-shortfall {
  background:#fde8e8; border:1px solid #e07070; border-radius:8px;
  padding:8px 14px; font-size:10px; letter-spacing:1px; color:#c0392b;
  text-align:center; margin-bottom:10px; font-weight:700;
}
/* Card rows */
.upkeep-list { display:flex; flex-direction:column; gap:6px; margin-bottom:16px; }
.upkeep-row {
  display:flex; align-items:center; gap:12px;
  background:#faf8f2; border:1px solid #e0d8c8; border-radius:10px;
  padding:10px 14px; transition:background 0.12s;
}
.upkeep-row-skipped { background:#fff8f0; border-color:#e8c8a0; }
.upkeep-row-seize   { background:#fff0f0; border-color:#e07070; }
.upkeep-row-info { flex:1; }
.upkeep-row-name { font-size:12px; font-weight:700; letter-spacing:1px; color:#3a3028; }
.upkeep-row-sub  { font-size:9px; letter-spacing:1px; color:#a09080; margin-top:2px; }
/* Status tags */
.upkeep-tag {
  display:inline-block; margin-top:4px; font-size:8px; font-weight:700;
  letter-spacing:1px; border-radius:4px; padding:2px 6px;
}
.upkeep-tag-clear { background:#e8f4e8; color:#27ae60; }
.upkeep-tag-skip  { background:#fff4e0; color:#c0892b; }
.upkeep-tag-warn  { background:#fde8e8; color:#c0392b; }
.upkeep-tag-seize { background:#c0392b; color:#fff; animation:criticalPulse 0.8s ease-in-out infinite; }
.upkeep-debt-badge {
  font-size:8px; font-weight:700; letter-spacing:1px; color:#c0892b;
  background:#fff4e0; border-radius:4px; padding:1px 5px; margin-left:4px;
}
/* Pay / Skip toggles */
.upkeep-toggle {
  padding:7px 14px; border-radius:8px; border:none; cursor:pointer;
  font-family:'Cinzel',serif; font-size:10px; letter-spacing:1px; font-weight:700;
  transition:all 0.12s; white-space:nowrap;
}
.upkeep-toggle-pay  { background:#e8f4e8; color:#27ae60; border:1px solid #b0d8b0; }
.upkeep-toggle-skip { background:#fff4e0; color:#c0892b; border:1px solid #e8c8a0; }
.upkeep-toggle-pay:hover  { background:#d0f0d0; }
.upkeep-toggle-skip:hover { background:#fde8c0; }
/* Confirm */
.upkeep-actions { display:flex; flex-direction:column; gap:8px; }
.upkeep-confirm-btn {
  width:100%; padding:12px; border:none; border-radius:10px;
  font-family:'Cinzel',serif; font-size:12px; letter-spacing:2px;
  font-weight:700; cursor:pointer; background:#3a3028; color:#faf8f2;
  transition:all 0.15s;
}
.upkeep-confirm-btn:hover { background:#2a2018; }
.upkeep-btn-warn { background:#c0392b !important; }
.upkeep-btn-warn:hover { background:#a02a20 !important; }

/* ── End-turn warning modal ── */
#end-turn-warning-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.55);
  display:flex; align-items:center; justify-content:center; z-index:9000;
}
.end-turn-warning-modal {
  background:#faf3e6; border:2px solid #c0392b; border-radius:14px;
  padding:24px 28px; max-width:420px; width:90%;
  box-shadow:0 8px 32px rgba(0,0,0,0.3);
}
.end-turn-warning-modal .modal-title { color:#c0392b; }
.etw-list {
  max-height:240px; overflow-y:auto; margin:14px 0; padding:8px 12px;
  background:#fff8f0; border:1px solid #e8c8a0; border-radius:8px;
  font-size:12px; line-height:1.6; color:#3a3028;
}
.etw-list-item { display:flex; align-items:center; gap:8px; }
.etw-list-item .etw-bullet { color:#c0392b; font-weight:700; }
.etw-buttons { display:flex; gap:10px; justify-content:flex-end; margin-top:8px; }

/* Pulsing outline for tiles with unmoved units (end-turn warning highlight) */
@keyframes etw-pulse {
  0%, 100% { box-shadow:0 0 0 0 rgba(192,57,43,0.0), inset 0 0 0 3px rgba(192,57,43,0.9); }
  50%      { box-shadow:0 0 14px 4px rgba(192,57,43,0.55), inset 0 0 0 3px rgba(255,80,60,1); }
}
.tile-etw-warn { animation: etw-pulse 1s ease-in-out infinite; z-index:5; }

/* ── Army composite badge ── */
.tile-unit-army {
  /* Stack of mini shields rendered via ::before/::after for visual layering */
  position:absolute; bottom:6px; right:6px; width:34px; height:34px;
  background:radial-gradient(circle at 35% 30%, #fff8e0 0%, #d4a04a 60%, #8a6028 100%);
  border:2px solid #3a2818; border-radius:6px;
  display:flex; align-items:center; justify-content:center;
  font-family:'Cinzel',serif; font-weight:700; color:#3a2818;
  box-shadow: 2px 2px 0 #1a1008, -3px -3px 0 #faf3e6, -5px -5px 0 #8a6028;
  z-index:3;
}
.tile-army-strength {
  position:absolute; top:-8px; right:-8px;
  background:#3a2818; color:#fff3a0; font-size:10px;
  border-radius:50%; padding:2px 5px; line-height:1;
  border:1px solid #d4a04a; font-weight:700;
}
.tile-army-count {
  font-size:9px; letter-spacing:0; line-height:1; text-align:center;
}
.tile-army-label { font-size:8px; opacity:0.85; }

/* ──────────────── MULTIPLAYER SCREENS ──────────────── */
#screen-mode-picker,
#screen-hotseat-setup,
#screen-hotseat-handoff,
#screen-online-mode,
#screen-online-lobby {
  display:none; flex-direction:column; align-items:center; justify-content:center;
  min-height:100vh; min-height:100svh; padding:40px 20px; box-sizing:border-box;
  background:#faf8f2;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(180,150,100,0.18), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(180,150,100,0.12), transparent 60%);
  font-family:'Cinzel',serif;
}
.mode-grid {
  display:flex; gap:24px; flex-wrap:wrap; justify-content:center; margin-top:20px;
}
.mode-card {
  width:240px; min-height:260px;
  background:#fffaf0; border:2px solid #d4c4a0; border-radius:10px;
  padding:28px 18px; cursor:pointer; text-align:center;
  transition:transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  display:flex; flex-direction:column; align-items:center; justify-content:flex-start;
  box-shadow: 0 4px 16px rgba(60,40,20,0.08);
}
.mode-card:hover { transform:translateY(-6px); border-color:#a08050;
  box-shadow:0 10px 28px rgba(60,40,20,0.16); }
.mode-icon { font-size:56px; margin-bottom:14px; line-height:1; }
.mode-name { font-size:20px; font-weight:900; letter-spacing:4px; color:#3a2818; margin-bottom:8px; }
.mode-desc { font-size:11px; color:#705840; letter-spacing:1px; line-height:1.5; font-family:Georgia,serif; }
.code-input {
  margin-top:14px; padding:10px 14px; font-size:18px; letter-spacing:3px;
  font-family:'Courier New',monospace; text-align:center; text-transform:uppercase;
  border:2px solid #d4c4a0; border-radius:6px; background:#fffaf0; color:#3a2818;
  width:80%;
}
.count-row { display:flex; gap:18px; margin-top:24px; }
.count-btn {
  padding:22px 36px; font-family:'Cinzel',serif; font-size:18px; letter-spacing:3px;
  background:#fffaf0; border:2px solid #d4c4a0; color:#3a2818; cursor:pointer;
  border-radius:8px; font-weight:700;
  transition:transform .15s ease, border-color .15s ease;
}
.count-btn:hover { transform:translateY(-3px); border-color:#a08050; }

.faction-taken {
  position:absolute; top:50%; left:50%; transform:translate(-50%,-50%) rotate(-12deg);
  background:rgba(140,40,40,0.92); color:#fff3a0; padding:6px 18px;
  font-weight:900; letter-spacing:4px; border-radius:4px;
}
.faction-card { position:relative; }

/* Hot-seat handoff */
.handoff-card {
  background:#fffaf0; border:3px solid #a08050; border-radius:14px;
  padding:48px 60px; text-align:center;
  box-shadow:0 20px 60px rgba(0,0,0,0.25);
  max-width:520px;
}
.handoff-pass { font-size:14px; letter-spacing:5px; color:#705840; margin-bottom:24px; }
.handoff-name { font-size:38px; font-weight:900; letter-spacing:6px; margin-bottom:10px; }
.handoff-sub { font-size:12px; color:#a09080; letter-spacing:2px; font-family:Georgia,serif; margin-bottom:8px; }
.handoff-ready { font-size:16px; padding:14px 36px; }

/* Lobby */
.lobby-code-box {
  background:#fffaf0; border:2px dashed #a08050; border-radius:10px;
  padding:18px 26px; margin:14px 0 24px; text-align:center;
}
.lobby-code-label { font-size:11px; letter-spacing:3px; color:#705840; margin-bottom:6px; }
.lobby-code-row { display:flex; align-items:center; justify-content:center; gap:6px; }
.lobby-code { font-family:'Courier New',monospace; font-size:32px; letter-spacing:6px;
  font-weight:900; color:#3a2818; }
.lobby-slots { display:flex; gap:14px; margin-bottom:24px; flex-wrap:wrap; justify-content:center; }
.lobby-slot {
  width:160px; min-height:160px; padding:14px;
  background:#fffaf0; border:2px solid #d4c4a0; border-radius:10px;
  text-align:center; font-family:Georgia,serif;
}
.lobby-slot.self { border-color:#3a7030; box-shadow:0 0 0 2px rgba(58,112,48,0.2); }
.lobby-name { font-family:'Cinzel',serif; font-weight:700; font-size:13px;
  letter-spacing:2px; color:#3a2818; margin-bottom:6px; }
.lobby-faction { font-size:11px; letter-spacing:2px; font-weight:700; }
.lobby-faction.muted { color:#a09080; }
.lobby-ready { font-size:10px; letter-spacing:1px; color:#705840; margin-top:8px; }
.lobby-controls { width:100%; max-width:780px; text-align:center; }

/* ──────────────────────────────────────────────────────────────────────
   CODEX — in-game rulebook (js/codex.js)
   ────────────────────────────────────────────────────────────────────── */
:root { --text-scale: 1; }

#codex-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(20, 16, 10, 0.78);
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.codex-modal {
  width: min(960px, 92vw);
  height: min(680px, 88vh);
  background: #f4ead4;
  border: 3px solid #3a2818;
  border-radius: 6px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.codex-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(180deg, #3a2818 0%, #2a1a10 100%);
  color: #f4ead4;
  border-bottom: 2px solid #1a1008;
}
.codex-title-strip {
  font-family: 'Cinzel', serif; font-weight: 900;
  letter-spacing: 4px; font-size: calc(18px * var(--text-scale));
}
.codex-close {
  background: transparent; color: #f4ead4; border: 1px solid #f4ead4;
  width: 32px; height: 32px; border-radius: 4px; cursor: pointer;
  font-size: 14px; line-height: 1;
}
.codex-close:hover { background: #f4ead4; color: #3a2818; }
.codex-body { display: flex; flex: 1; overflow: hidden; }
.codex-sidebar {
  width: 240px; min-width: 240px;
  background: #ebe0c4; border-right: 2px solid #c8b890;
  display: flex; flex-direction: column;
  padding: 10px;
}
.codex-search {
  width: 100%; padding: 8px 10px; border: 1px solid #b8a878;
  background: #fff8e4; border-radius: 4px;
  font-family: inherit; font-size: calc(13px * var(--text-scale));
  margin-bottom: 10px;
}
.codex-list { flex: 1; overflow-y: auto; }
.codex-cat {
  font-family: 'Cinzel', serif; font-weight: 700;
  letter-spacing: 2px; font-size: calc(10px * var(--text-scale));
  color: #705840; margin: 10px 0 4px 4px;
  text-transform: uppercase;
}
.codex-item {
  display: block; width: 100%; text-align: left;
  padding: 6px 10px; margin: 1px 0;
  background: transparent; border: none; border-radius: 3px;
  font-family: inherit; font-size: calc(12px * var(--text-scale));
  color: #3a2818; cursor: pointer;
}
.codex-item:hover { background: #d8c898; }
.codex-item.active {
  background: #3a2818; color: #f4ead4;
  font-weight: 700;
}
.codex-empty { padding: 12px; color: #a09080; font-style: italic; font-size: calc(12px * var(--text-scale)); }
.codex-content {
  flex: 1; overflow-y: auto; padding: 18px 28px;
  font-size: calc(14px * var(--text-scale));
  color: #2a1a10;
  outline: none;
}
.codex-breadcrumb {
  font-family: 'Cinzel', serif; font-size: calc(10px * var(--text-scale));
  letter-spacing: 2px; color: #806848;
  text-transform: uppercase; margin-bottom: 8px;
}
.codex-article h1 {
  font-family: 'Cinzel', serif; font-weight: 900;
  font-size: calc(22px * var(--text-scale)); color: #3a2818;
  border-bottom: 2px solid #c8b890; padding-bottom: 6px; margin: 0 0 14px 0;
}
.codex-article h2 {
  font-family: 'Cinzel', serif; font-size: calc(16px * var(--text-scale));
  color: #3a2818; margin: 16px 0 6px 0;
}
.codex-article h3 { font-size: calc(14px * var(--text-scale)); margin: 12px 0 4px 0; color: #3a2818; }
.codex-article p { margin: 0 0 10px 0; line-height: 1.5; }
.codex-article ul { margin: 0 0 10px 18px; padding: 0; }
.codex-article li { margin: 3px 0; line-height: 1.45; }
.codex-article code {
  background: #e8dcb0; padding: 1px 5px; border-radius: 3px;
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.92em;
}
.codex-article strong { color: #1a0e08; }
.codex-article a.codex-link {
  color: #8a4818; text-decoration: underline;
  text-decoration-style: dotted; cursor: pointer;
}
.codex-article a.codex-link:hover { color: #c04020; background: #f0e0b0; }
.codex-table {
  width: 100%; border-collapse: collapse;
  margin: 10px 0; font-size: calc(12px * var(--text-scale));
}
.codex-table th, .codex-table td {
  border: 1px solid #c8b890; padding: 5px 8px; text-align: left;
}
.codex-table th { background: #d8c898; font-weight: 700; }
.codex-table tr:nth-child(even) td { background: #f0e4c4; }

/* ──────────────────────────────────────────────────────────────────────
   SMART TOOLTIPS (js/tooltips.js)
   ────────────────────────────────────────────────────────────────────── */
.k-tip {
  position: fixed; z-index: 9999;
  max-width: 280px;
  background: #2a1a10; color: #f4ead4;
  border: 1px solid #f4ead4;
  border-radius: 4px;
  padding: 8px 12px;
  font-family: inherit; font-size: calc(12px * var(--text-scale));
  line-height: 1.4;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  pointer-events: auto;
}
.k-tip-body { white-space: normal; }
.k-tip-link {
  color: #f0c060; text-decoration: underline;
  text-decoration-style: dotted; cursor: pointer;
}
.k-tip-link:hover { color: #f8d880; }
.k-tip-lock {
  position: absolute; top: 4px; right: 6px;
  font-size: 11px; opacity: 0.85;
}

/* ──────────────────────────────────────────────────────────────────────
   VICTORY BANNER
   ────────────────────────────────────────────────────────────────────── */
#victory-banner {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(232, 200, 64, 0.12);
  border: 1px solid rgba(232, 200, 64, 0.45);
  color: #5a4818;
  font-family: inherit; font-size: calc(10px * var(--text-scale));
  letter-spacing: 1px;
  padding: 3px 10px; border-radius: 12px;
  cursor: pointer;
  margin: 0 8px;
}
#victory-banner:hover { background: rgba(232, 200, 64, 0.22); }

/* ──────────────────────────────────────────────────────────────────────
   UNDO BUTTON
   ────────────────────────────────────────────────────────────────────── */
#btn-undo {
  background: linear-gradient(180deg, #d8c898 0%, #b8a878 100%);
  border: 1px solid #806840;
  color: #2a1a10;
}
#btn-undo[disabled] { opacity: 0.4; cursor: not-allowed; }
.undo-hint {
  display: inline-block; margin-left: 8px;
  font-size: calc(9px * var(--text-scale)); color: #806840;
  font-style: italic;
}

/* ──────────────────────────────────────────────────────────────────────
   FACTION PATTERNS (accessibility — colorblind-safe ownership marks)
   Layered ON TOP of the existing color tint defined in parchment.css.
   ────────────────────────────────────────────────────────────────────── */
.tile[data-owner="iron_veil"]::after {
  background-image:
    repeating-linear-gradient(45deg,
      rgba(0,0,0,0.18) 0 2px,
      transparent 2px 7px),
    linear-gradient(rgba(122, 30, 30, 0.32), rgba(122, 30, 30, 0.32));
}
.tile[data-owner="tidal_accord"]::after {
  background-image:
    repeating-radial-gradient(circle at 3px 3px,
      rgba(255,255,255,0.20) 0 1.2px,
      transparent 1.2px 7px),
    linear-gradient(rgba(26, 58, 106, 0.32), rgba(26, 58, 106, 0.32));
}
.tile[data-owner="root_council"]::after {
  background-image:
    radial-gradient(circle at 50% 50%, rgba(0,0,0,0.22) 1px, transparent 1.4px),
    linear-gradient(rgba(42, 90, 42, 0.32), rgba(42, 90, 42, 0.32));
  background-size: 6px 6px, 100% 100%;
}
.tile[data-owner="dust_compact"]::after {
  background-image:
    repeating-linear-gradient(45deg, rgba(0,0,0,0.16) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,0.16) 0 1px, transparent 1px 6px),
    linear-gradient(rgba(168, 104, 32, 0.32), rgba(168, 104, 32, 0.32));
}

/* ──────────────────────────────────────────────────────────────────────
   FONT SCALER — scale top-level interface text (not codex tables/etc which
   already use var(--text-scale) directly).
   ────────────────────────────────────────────────────────────────────── */
html { font-size: calc(16px * var(--text-scale)); }

/* ──────────────────────────────────────────────────────────────────────
   REDUCED MOTION — disabled animations/transitions for a11y.
   Applies if OS preference set OR body has .reduce-motion (manual toggle).
   ────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* ── WILL CHECK MODAL ────────────────────────────────────────────────── */
#will-check-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  z-index: 320; display: flex; align-items: center; justify-content: center;
}
.will-modal {
  background: rgba(255,252,245,0.97);
  border-radius: 24px; padding: 28px 36px; min-width: 420px; text-align: center;
  box-shadow: 0 8px 48px rgba(0,0,0,0.4);
  border: 2px solid rgba(196,165,90,0.6);
  font-family: 'Cinzel', serif;
  animation: diceModalIn 0.2s ease-out;
}
.will-title {
  font-size: 14px; font-weight: 900; letter-spacing: 5px;
  color: #6a4f9a; margin-bottom: 18px;
}
.will-arena {
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
}
.will-side { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.will-vs { font-size: 13px; font-weight: 900; color: #a09080; letter-spacing: 2px; margin: 0 18px; }
.will-faction { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: #2c1810; }
.will-sub { font-size: 11px; color: #8c7a5c; letter-spacing: 1px; }
.will-roll { font-size: 28px; margin: 6px 0; }
.will-total { font-size: 13px; font-weight: 800; color: #2c1810; }
.will-result {
  font-size: 16px; font-weight: 900; letter-spacing: 3px;
  min-height: 32px; padding: 8px 0;
}
.will-success { color: #6a4f9a; }
.will-fail    { color: #27ae60; }

/* ──────────────────────────────────────────────────────────────────────
   MOBILE / TOUCH UI — hamburger, mobile drawer, HUD collapse, responsive
   breakpoints. The desktop UI is left untouched; rules below kick in only
   on small viewports OR when body.is-touch is set.
   ────────────────────────────────────────────────────────────────────── */

/* Hamburger button — hidden on desktop, shown on phones. */
.hamburger-btn {
  display: none;
  background: rgba(255,252,245,0.95);
  border: 1px solid rgba(200,185,160,0.4);
  border-radius: 8px;
  width: 40px; height: 40px;
  font-size: 18px; color: #3a3028;
  cursor: pointer; margin-left: 6px;
}
.hamburger-btn:hover { background: #f0e8d8; }

/* Mobile drawer (right-side slide-in) */
.mobile-drawer {
  position: fixed; inset: 0;
  background: rgba(20, 16, 10, 0);
  display: none;
  z-index: 9000;
  transition: background 0.18s ease;
}
.mobile-drawer.drawer-open { display: block; background: rgba(20, 16, 10, 0.55); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(320px, 86vw);
  background: #fffaf0;
  border-left: 2px solid #a08050;
  box-shadow: -8px 0 32px rgba(0,0,0,0.35);
  padding: 18px 16px 24px;
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}
.mobile-drawer.drawer-open .drawer-panel { transform: translateX(0); }
.drawer-close {
  align-self: flex-end;
  width: 44px; height: 44px;
  background: transparent; border: 1px solid #d4c4a0; border-radius: 8px;
  font-size: 18px; cursor: pointer; color: #3a2818;
}
.drawer-title {
  font-family: 'Cinzel', serif; font-weight: 900; letter-spacing: 5px;
  font-size: 18px; color: #3a2818; text-align: center;
  margin: 4px 0 10px;
}
.drawer-item {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px; text-align: left;
  background: #faf3e0; border: 1px solid #d4c4a0; border-radius: 10px;
  font-family: 'Cinzel', serif; font-size: 13px; letter-spacing: 2px;
  font-weight: 700; color: #3a2818; cursor: pointer;
}
.drawer-item:active { background: #ebe0c4; }

/* HUD collapse chevron — hidden on desktop. */
.hud-collapse {
  display: none;
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  width: 44px; height: 28px;
  background: rgba(255,252,245,0.95);
  border: 1px solid rgba(200,185,160,0.5);
  border-radius: 14px 14px 0 0; border-bottom: none;
  font-size: 14px; cursor: pointer; line-height: 1;
}
.bottom-panel { position: fixed; }
.bottom-panel.hud-collapsed .phase-guide,
.bottom-panel.hud-collapsed .faction-info,
.bottom-panel.hud-collapsed .victory-track,
.bottom-panel.hud-collapsed .culture-pill,
.bottom-panel.hud-collapsed .stat-group .stat:nth-child(n+3),
.bottom-panel.hud-collapsed .actions .action-btn:not(#btn-endturn):not(#btn-undo) {
  display: none;
}

/* Touch device: suppress hover-only :hover artefacts on tiles + hide kbd hint */
body.is-touch #kbd-hint { display: none !important; }
body.is-touch .tile:hover { filter: none; }

/* ── TABLET (< 768px) ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .top-bar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 14px;
    max-width: 96vw;
    font-size: 11px;
  }
  .game-title { font-size: 14px; letter-spacing: 3px; }
  .top-bar .divider { display: none; }
  #victory-banner { font-size: 9px; padding: 2px 8px; max-width: 100%; }
  .opponents { gap: 6px; flex-wrap: wrap; }
  .opp { padding: 3px 8px; font-size: 9px; }

  .bottom-panel { left: 8px; right: 8px; padding: 0 12px 10px; }
  .bottom-row { flex-wrap: wrap; gap: 12px 18px; }
  .stat-group { gap: 12px; }
  .actions { gap: 6px; margin-left: 0; flex-wrap: wrap; }
  .action-btn { padding: 10px 14px; font-size: 10px; min-height: 40px; }

  .log { width: 220px; bottom: 200px; padding: 8px 10px; }
  .zoom-controls { bottom: 200px; }

  /* Modals: take more of the viewport */
  .recruit-modal, .build-modal, .cards-modal, .dice-modal, .upkeep-modal,
  .end-turn-warning-modal, .will-modal, .handoff-card {
    max-width: 95vw !important;
    min-width: 0 !important;
    width: 95vw !important;
  }

  #mini-map-wrap { transform: scale(0.7); transform-origin: top right; }
}

/* ── PHONE (< 480px) ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Bigger tap targets everywhere */
  button, .action-btn, .modal-close-btn, .zoom-btn, .um-btn, .drawer-item,
  .faction-card, .mode-card {
    min-height: 44px;
  }

  /* Top bar: compress to a small badge row + hamburger */
  .top-bar {
    top: 6px;
    padding: 6px 10px;
    gap: 6px;
    border-radius: 10px;
  }
  .top-bar .game-title { display: none; }
  .top-bar #victory-banner { display: none; }
  .top-bar .opponents { display: none; }
  .top-bar #btn-mute, .top-bar #btn-settings { display: none; }
  .hamburger-btn { display: inline-flex; align-items: center; justify-content: center; }

  .round-badge { font-size: 10px; }
  .phase-badge { font-size: 10px; padding: 3px 8px; }

  /* Board: tile floor handled in board.js (48px) */
  #board-wrap { inset: 52px 0 96px 0; }

  /* Hide ancillary panels by default; user can still pan/zoom freely. */
  .log { display: none; }
  #mini-map-wrap { display: none; }
  #kbd-hint { display: none; }

  /* Zoom controls remain but smaller and tucked above HUD */
  .zoom-controls { bottom: 110px; right: 8px; gap: 4px; }
  .zoom-btn { width: 40px; height: 40px; }

  /* Bottom panel — compact + collapse chevron visible */
  .bottom-panel { left: 6px; right: 6px; bottom: 6px; padding: 4px 10px 8px; border-radius: 12px; }
  .hud-collapse { display: block; }
  .phase-guide { padding: 6px 2px; margin-bottom: 6px; }
  #phase-guide-text { font-size: 9px; letter-spacing: 0.8px; }
  .bottom-row { gap: 8px; row-gap: 6px; }
  .faction-info { gap: 6px; }
  .faction-label { font-size: 11px; letter-spacing: 1px; }
  .stat-group { gap: 10px; }
  .stat-val { font-size: 14px; }
  .stat-lbl { font-size: 7px; letter-spacing: 1px; }
  .culture-pill { font-size: 10px; padding: 4px 10px; }
  .victory-track { display: none; }   /* hidden on phone; expand via tap-future */
  .actions { gap: 4px; }
  .action-btn { padding: 8px 10px; font-size: 9px; letter-spacing: 0.5px; }
  /* Dividers in bottom-row look awkward when wrapped — hide them */
  .bottom-row > div[style*="background:#e8e0d0"] { display: none; }

  /* Modals: full-screen with sticky close */
  .recruit-modal, .build-modal, .cards-modal, .dice-modal, .upkeep-modal,
  .end-turn-warning-modal, .will-modal {
    width: 100vw !important; max-width: 100vw !important;
    min-width: 0 !important;
    height: 100vh !important; max-height: 100vh !important;
    height: 100svh !important; max-height: 100svh !important;
    border-radius: 0 !important;
    padding: 56px 16px 16px !important;
    overflow-y: auto;
  }
  .modal-close-btn {
    position: sticky; top: 8px; right: 8px;
    width: auto; padding: 10px 16px;
    z-index: 10;
  }
  .codex-modal { width: 100vw !important; height: 100vh !important; height: 100svh !important; max-width:100vw; border-radius: 0 !important; }

  /* Lobby slots wrap on phone */
  .lobby-slots { gap: 8px; }
  .lobby-slot { width: 46%; min-width: 0; min-height: 0; padding: 10px; }

  /* Faction picker cards smaller */
  .faction-card { width: 44%; padding: 14px 8px; }
  .faction-card-name { font-size: 12px; }

  /* Unit menu near tap — narrower */
  .unit-menu { min-width: 180px; padding: 10px 12px; }
}

/* iOS safe-area awareness for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 480px) {
    .top-bar { top: calc(6px + env(safe-area-inset-top)); }
    .bottom-panel { bottom: calc(6px + env(safe-area-inset-bottom)); }
  }
}

/* ──────────────────────────────────────────────────────────────────────
   MOBILE POLISH v2 — gesture isolation, full-screen modals, bottom sheets,
   orientation hint, perf hints. Desktop UX is untouched.
   ────────────────────────────────────────────────────────────────────── */

/* ---- Gesture isolation (prevents browser hijacking pinch/scroll on board) */
html { overscroll-behavior: none; }
body { overscroll-behavior: none; }
#board-wrap { touch-action: none; }
/* Individual tiles: manipulation prevents iOS double-tap-zoom on fast taps */
.tile { touch-action: manipulation; }
/* Modal bodies still need to scroll on touch */
.modal-scroll, .cards-content, .recruit-list, .build-list,
.upkeep-modal, .codex-content, .codex-list, .etw-list,
#cards-overlay, #recruit-overlay, #build-overlay, #upkeep-overlay,
#settings-overlay, #codex-overlay {
  touch-action: pan-y;
}

/* GPU acceleration for board pan/zoom */
#board-transform { will-change: transform; transform: translateZ(0); }
.tile { transform: translateZ(0); }

/* ---- Floating End-Turn FAB (only visible on phones, hidden by default) */
.fab-endturn {
  display: none;
  position: fixed;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 250;
  padding: 14px 22px;
  background: #3a3028; color: #faf8f2;
  border: 2px solid #2a2018; border-radius: 999px;
  font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 2px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  cursor: pointer;
}
.fab-endturn:active { transform: translateY(1px); }

/* ---- Orientation hint card (phone portrait, one-time) */
.orientation-hint {
  position: fixed; inset: 0; z-index: 9500;
  background: rgba(20,16,10,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.orientation-hint .oh-card {
  background: #fffaf0; border: 2px solid #a08050; border-radius: 16px;
  padding: 24px 22px; max-width: 320px; text-align: center;
  box-shadow: 0 12px 36px rgba(0,0,0,0.5);
}
.orientation-hint .oh-icon { font-size: 40px; margin-bottom: 10px; }
.orientation-hint .oh-title {
  font-family: 'Cinzel', serif; font-weight: 900; letter-spacing: 3px;
  font-size: 14px; color: #3a2818; margin-bottom: 8px;
}
.orientation-hint .oh-sub {
  font-family: Georgia, serif; font-size: 12px; color: #5a4838; line-height: 1.5;
  margin-bottom: 16px;
}
.orientation-hint .oh-dismiss {
  padding: 12px 28px; border-radius: 10px; border: none;
  background: #3a2818; color: #faf3e0;
  font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 2px; font-weight: 700;
  cursor: pointer; min-height: 44px; min-width: 60%;
}

/* ---- Larger settings slider thumb (phones) */
@media (max-width: 480px) {
  .settings-slider { height: 36px; background: transparent; }
  .settings-slider::-webkit-slider-runnable-track {
    height: 8px; border-radius: 4px; background: #e8e0d0;
  }
  .settings-slider::-moz-range-track {
    height: 8px; border-radius: 4px; background: #e8e0d0;
  }
  .settings-slider::-webkit-slider-thumb {
    width: 28px; height: 28px; margin-top: -10px;
  }
  .settings-slider::-moz-range-thumb { width: 28px; height: 28px; }
  input[type=range] { width: 100%; }
}

/* ──────────────────────────────────────────────────────────────────────
   PHONE-ONLY: full-screen modal pattern with sticky header + footer.
   Applied broadly; each modal opts in via its container class.
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* All modal *containers* (the overlay) flex top-aligned so the scrollable
     body works correctly. */
  #cards-overlay, #recruit-overlay, #build-overlay, #upkeep-overlay,
  #end-turn-warning-overlay, #settings-overlay {
    align-items: stretch !important;
    padding: 0 !important;
  }

  /* Common full-screen sheet for inner modal */
  .cards-modal, .recruit-modal, .build-modal, .upkeep-modal,
  .end-turn-warning-modal, .settings-modal {
    width: 100vw !important; max-width: 100vw !important; min-width: 0 !important;
    height: 100vh !important; max-height: 100vh !important;
    height: 100svh !important; max-height: 100svh !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important; flex-direction: column !important;
    overflow: hidden !important;
  }

  /* Title becomes sticky header bar with X */
  .cards-modal .modal-title,
  .recruit-modal .modal-title,
  .build-modal .modal-title,
  .upkeep-modal .modal-title,
  .end-turn-warning-modal .modal-title,
  .settings-modal .settings-title,
  .settings-modal h2 {
    position: sticky; top: 0; z-index: 5;
    background: #faf3e0;
    margin: 0 !important;
    padding: 14px 56px 14px 18px !important;
    border-bottom: 1px solid #d4c4a0;
    text-align: left !important;
    font-size: 14px !important; letter-spacing: 3px !important;
  }
  .cards-modal .modal-sub,
  .recruit-modal .modal-sub,
  .build-modal .modal-sub,
  .upkeep-modal .modal-sub,
  .end-turn-warning-modal .modal-sub {
    padding: 8px 18px;
    margin: 0 !important;
    border-bottom: 1px solid #efe6d4;
    background: #fffaf0;
    text-align: left !important;
  }

  /* The close X — floated as 44x44 tap target in top-right of the modal */
  .cards-modal .modal-close-btn,
  .recruit-modal .modal-close-btn,
  .build-modal .modal-close-btn,
  .upkeep-modal .modal-close-btn,
  .end-turn-warning-modal .modal-close-btn,
  .settings-modal .modal-close-btn {
    position: absolute; top: 8px; right: 8px;
    width: 44px; height: 44px; min-height: 44px;
    padding: 0 !important; border-radius: 50% !important;
    z-index: 10;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
  }
  /* Hide the textual "✕ Close" label visually; the X is enough on mobile.
     We do it by emptying via CSS only when the parent has class `is-mobile-close`. */

  /* Scrollable body region for each modal */
  .recruit-modal .recruit-list,
  .build-modal .build-list,
  .cards-modal .cards-content,
  .upkeep-modal .upkeep-list,
  .end-turn-warning-modal .etw-list,
  .settings-modal > div,
  .settings-modal form,
  .settings-modal .settings-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    max-height: none !important;
    min-height: 0 !important;
  }

  /* The cards tabs sit just below the header — make them sticky too */
  .cards-modal .cards-tabs {
    position: sticky; top: 48px; z-index: 4;
    background: #fffaf0;
    padding: 8px 12px;
    border-bottom: 1px solid #efe6d4;
    margin: 0 !important;
  }
  .cards-modal .cards-tab { min-height: 44px; padding: 12px; font-size: 11px; }
  .cards-modal .cards-progress { padding: 8px 14px; background: #fffaf0; border-bottom: 1px solid #efe6d4; }
  .cards-modal .cards-progress + .cards-tabs { top: auto; }

  /* Buttons in the rows: bigger tap targets */
  .recruit-row, .buy-card-row, .upkeep-row {
    min-height: 56px;
    padding: 12px 14px !important;
  }

  /* Sticky bottom action bar — primary buttons */
  .upkeep-actions, .etw-buttons {
    position: sticky; bottom: 0;
    background: #fffaf0; border-top: 1px solid #d4c4a0;
    padding: 12px 16px calc(12px + var(--mobile-safe-bottom));
    margin: 0 !important;
    flex-direction: column !important;
  }
  .etw-buttons { flex-direction: row !important; }
  .etw-buttons .modal-close-btn {
    position: static !important; width: 50% !important; height: auto !important;
    border-radius: 10px !important; min-height: 48px;
  }

  /* AI summary popup: slide from TOP, full width */
  #ai-summary-overlay {
    top: 0 !important; right: 0 !important; left: 0 !important;
    width: 100vw !important; border-radius: 0 0 16px 16px !important;
    border-left: none !important; border-right: none !important; border-top: none !important;
    padding-top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    animation: aiSummaryInTop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both !important;
  }
  @keyframes aiSummaryInTop {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
  }

  /* Event popup: slide from top, full width */
  #event-overlay {
    top: 0 !important; left: 0 !important; right: 0 !important;
    transform: none !important;
    width: 100vw !important; max-width: 100vw !important; min-width: 0 !important;
    border-radius: 0 0 16px 16px !important;
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  }

  /* Floating End-Turn FAB visible only when HUD is collapsed */
  .bottom-panel.hud-collapsed ~ .fab-endturn { display: none; } /* end-turn already in collapsed HUD */
}

/* ──────────────────────────────────────────────────────────────────────
   FACTION PICKER — vertical stack on phone
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #screen-faction-picker {
    justify-content: flex-start;
    padding: 24px 12px 100px;
    overflow-y: auto;
  }
  .picker-title { font-size: 26px; margin-top: 16px; }
  .picker-sub { margin-bottom: 18px; }
  .faction-cards {
    flex-direction: column;
    width: 100%; max-width: 360px; gap: 10px;
  }
  .faction-card {
    width: 100% !important;
    min-height: 0;
    padding: 14px 16px !important;
    display: flex; align-items: center; gap: 12px;
    text-align: left;
  }
  .faction-card .faction-card-crest,
  .faction-card .faction-card-dot {
    margin: 0 !important;
    width: 44px; height: 44px;
    flex-shrink: 0;
  }
  .faction-card-name { margin-bottom: 4px !important; flex: 1; }
  .faction-card-pros, .faction-card-cons { line-height: 1.4; }
  .start-btn {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--mobile-safe-bottom));
    margin: 0; width: auto;
  }
}

/* ──────────────────────────────────────────────────────────────────────
   HOT-SEAT HANDOFF — keep crest reasonable on small screens
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .handoff-card { padding: 32px 20px !important; max-width: 92vw !important; }
  .handoff-card [class*="crest"], .handoff-card .gameover-crest {
    width: 40vw !important; height: 40vw !important;
    max-width: 200px; max-height: 200px;
  }
  .handoff-name { font-size: 26px !important; letter-spacing: 4px !important; }
  .handoff-ready { width: 60% !important; min-height: 48px; }
}

/* ──────────────────────────────────────────────────────────────────────
   CODEX — collapsible sidebar at <480px
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .codex-body { flex-direction: column !important; }
  .codex-sidebar {
    width: 100% !important; min-width: 0 !important;
    border-right: none !important;
    border-bottom: 2px solid #c8b890;
    max-height: 50vh;
    padding: 8px !important;
  }
  /* Collapse mode: hide sidebar entirely; show "Browse" header */
  .codex-modal.codex-mobile-content .codex-sidebar { display: none; }
  .codex-modal.codex-mobile-browse .codex-content { display: none; }
  .codex-modal .codex-mobile-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: #ebe0c4; border-bottom: 1px solid #c8b890;
  }
  .codex-modal .codex-mobile-bar button {
    min-height: 40px; padding: 8px 14px;
    border-radius: 8px; border: 1px solid #b8a878;
    background: #fff8e4; font-family: 'Cinzel', serif;
    font-size: 11px; letter-spacing: 2px; font-weight: 700;
    color: #3a2818; cursor: pointer;
  }
  .codex-modal .codex-mobile-title {
    flex: 1; font-family: 'Cinzel', serif; font-size: 12px;
    color: #3a2818; font-weight: 700; letter-spacing: 1.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .codex-item { min-height: 44px; display: flex !important; align-items: center; }
}
/* Hide the mobile codex bar on desktop */
.codex-mobile-bar { display: none; }

/* ──────────────────────────────────────────────────────────────────────
   UNIT / LEADER MENU — bottom sheet on phones
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .unit-menu {
    /* Override the JS-set inline left/top via !important — slide in from bottom */
    left: 0 !important; right: 0 !important; top: auto !important;
    bottom: 0 !important;
    width: 100vw !important;
    min-width: 0 !important; max-width: 100vw !important;
    border-radius: 18px 18px 0 0 !important;
    border-bottom: none !important;
    padding: 14px 16px calc(14px + var(--mobile-safe-bottom)) !important;
    max-height: 80vh;
    overflow-y: auto;
    animation: unitMenuSlideUp 220ms cubic-bezier(0.34, 1.4, 0.64, 1);
    z-index: 9999;
  }
  .unit-menu::before {
    content: ''; display: block; width: 40px; height: 4px;
    background: #c8b898; border-radius: 2px; margin: -4px auto 12px;
  }
  .um-btn { padding: 14px 16px !important; min-height: 48px; font-size: 13px !important; }
  @keyframes unitMenuSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
}

/* ──────────────────────────────────────────────────────────────────────
   ONLINE LOBBY MOBILE
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .lobby-slots { flex-direction: column; align-items: stretch; }
  .lobby-slot { width: 100%; min-width: 0; padding: 12px; }
  .code-input {
    width: 100%; font-size: 22px; letter-spacing: 6px;
    min-height: 56px; padding: 14px;
  }
  .count-row { flex-direction: column; width: 100%; }
  .count-btn { width: 100%; padding: 18px; min-height: 56px; }
  .lobby-code { font-size: 26px; letter-spacing: 4px; }
}

/* ──────────────────────────────────────────────────────────────────────
   TOOLTIP CLOSE BUTTON (touch users) — small X in corner of locked tip
   ────────────────────────────────────────────────────────────────────── */
body.is-touch .k-tip-close {
  position: absolute; top: 2px; right: 4px;
  width: 22px; height: 22px;
  background: transparent; color: #f4ead4;
  border: none; cursor: pointer; font-size: 14px; line-height: 1;
  padding: 0;
}
.k-tip-close { display: none; }
body.is-touch .k-tip .k-tip-close { display: inline-flex; align-items: center; justify-content: center; }
.k-tip { position: fixed; }

/* ──────────────────────────────────────────────────────────────────────
   MOBILE BOTTOM TAB BAR (phone primary nav; replaces hamburger discovery)
   ────────────────────────────────────────────────────────────────────── */
:root {
  --mobile-nav-height: 56px;
  /* Use this for any phone-context bottom-anchored element so it never gets
     cut off by the mobile bottom nav. Equals safe-area-inset on desktop
     (where the nav is hidden) and (nav + safe-area) on phones. */
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
}
body.has-mobile-nav {
  --mobile-safe-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
}

#mobile-bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 400;
  height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #2a2018;
  border-top: 2px solid #1a120c;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.35);
  display: flex; flex-direction: row;
}
#mobile-bottom-nav .mbn-tab {
  flex: 1 1 25%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  border-top: 3px solid transparent;
  color: #c8b898;
  font-family: 'Cinzel', serif;
  font-size: 10px; letter-spacing: 1.2px; font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#mobile-bottom-nav .mbn-tab .mbn-ico { font-size: 20px; line-height: 1; }
#mobile-bottom-nav .mbn-tab .mbn-lbl { font-size: 10px; }
#mobile-bottom-nav .mbn-tab.mbn-active {
  color: #faf3e0;
  border-top-color: #c89858;
  font-weight: 800;
}
#mobile-bottom-nav .mbn-tab:active { background: rgba(255,255,255,0.06); }

/* Show only on phones. On wider, the hamburger + top bar stays primary. */
@media (max-width: 480px) {
  #mobile-bottom-nav { display: flex; }
  body.has-mobile-nav .bottom-panel { bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px)) !important; }
  body.has-mobile-nav .fab-endturn { bottom: calc(var(--mobile-nav-height) + 14px + env(safe-area-inset-bottom, 0px)); }
  /* Hide hamburger on phones since bottom nav has More tab */
  body.has-mobile-nav #btn-hamburger { display: none; }
}

/* Mobile map overlay (the mini-map is hidden on phones; this is its modal twin) */
#mobile-map-overlay {
  position: fixed; inset: 0; z-index: 9600;
  background: rgba(20,16,10,0.78);
  align-items: center; justify-content: center;
  display: none;
}
#mobile-map-overlay.open { display: flex; }
.mobile-map-card {
  background: #fffaf0; border: 2px solid #a08050; border-radius: 14px;
  padding: 18px 18px 14px; max-width: 92vw;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.5);
}
.mobile-map-card canvas {
  width: min(340px, 80vw); height: min(340px, 80vw);
  background: #f4ead4; border: 1px solid #c8b890; border-radius: 6px;
}

/* ──────────────────────────────────────────────────────────────────────
   LOW-POWER MODE — set when prefers-reduced-motion OR Save-Data OR manual
   ────────────────────────────────────────────────────────────────────── */
body.low-power *,
body.low-power *::before,
body.low-power *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}
body.low-power .faction-rim-glow,
body.low-power .fog-cloud,
body.low-power .ambient-fog,
body.low-power .decoration-anim { display: none !important; }
body.low-power .fade-in,
body.low-power .fade { opacity: 1 !important; }

/* ──────────────────────────────────────────────────────────────────────
   VIEW TRANSITIONS — soft cross-fade for screen swaps (supported browsers)
   ────────────────────────────────────────────────────────────────────── */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 250ms;
}
body.low-power ::view-transition-old(root),
body.low-power ::view-transition-new(root) {
  animation-duration: 1ms;
}
