:root {
  --bg: #151a12; --card: rgba(18, 22, 16, 0.92); --text: #f4efe4;
  --muted: #c5bba8; --accent: #e8d48b; --border: rgba(230, 220, 180, 0.18);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; height: 100dvh; background: var(--bg); color: var(--text); overflow: hidden; touch-action: manipulation; }
.screen {
  position: fixed; inset: 0; display: grid; place-items: center; align-content: safe center;
  direction: rtl; padding: 16px; overflow-x: hidden; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.hidden, .hidden { display: none !important; }
.screen.full {
  display: block; position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh;
  place-items: stretch; align-content: stretch;
  padding: 0; direction: ltr; overflow: hidden;
}
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; width: min(520px, 100%); max-width: 100%; margin: auto; text-align: center;
}
.card.wide { width: min(520px, 100%); }
.card h1, .card h2 { color: var(--accent); margin: 0 0 8px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.list { text-align: right; max-height: 40vh; overflow: auto; }
.list > div { padding: 8px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
input, select, button { border: 0; border-radius: 8px; padding: 10px 12px; font-size: 15px; }
input, select { background: #2a261c; color: var(--text); width: 100%; margin: 8px 0; }
button { background: #3a3328; color: var(--text); cursor: pointer; }
button:disabled { opacity: 0.4; }
#game {
  position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh;
  display: block; cursor: crosshair; touch-action: none; z-index: 0;
}
#countdown {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  font-size: 96px; color: var(--accent); pointer-events: none; text-shadow: 0 4px 20px #000;
}
#hud-top, #hud-bottom {
  position: fixed; z-index: 5;
  display: flex; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px; direction: rtl; pointer-events: none;
}
#hud-top {
  top: 10px; left: 216px; right: 248px;
  align-items: center; flex-wrap: wrap; min-height: 52px; overflow: visible;
}
#hud-bottom {
  left: 160px; right: 248px; bottom: 10px;
  pointer-events: auto; align-items: flex-end; flex-wrap: wrap;
}
.hud-player { display: flex; gap: 8px; align-items: center; flex: 0 1 auto; min-width: 0; max-width: 42%; }
.hud-stats { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.hud-stats > div { white-space: nowrap; font-size: 13px; }
.swatch { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff8; }
#money-wrap { display: flex; align-items: center; gap: 8px; }
#bank-count { color: #f7dc6f; }
#invest-pop {
  color: #2ecc71; font-weight: 700; font-size: 16px;
  text-shadow: 0 0 8px rgba(46, 204, 113, 0.45);
  animation: investPop 3.4s ease forwards;
}
@keyframes investPop {
  0% { opacity: 0; transform: translateY(6px); }
  12% { opacity: 1; transform: translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}
.muted, #selection-info { font-size: 13px; color: var(--muted); }
#player-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-meta {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#hud-top button, #hud-bottom button, #right-dock { pointer-events: auto; }
#hud-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#econ-box {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%);
  z-index: 6; width: min(460px, calc(100vw - 32px));
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; direction: rtl; pointer-events: auto;
}
#econ-box .econ-row, #invest-box .econ-row {
  display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px;
}
#econ-box strong, #invest-box strong { color: var(--accent); }
#econ-box .row.tight, #invest-box .row.tight { margin: 4px 0; }
#econ-box input, #invest-box input { width: 88px; margin: 0; padding: 8px; }
#econ-box button, #invest-box button { padding: 8px 10px; min-height: 38px; }
#invest-box .row.tight { margin: 3px 0; }
#invest-box button { padding: 6px 8px; min-height: 32px; font-size: 13px; }
#invest-box input { padding: 6px 8px; }
#right-dock {
  position: fixed; right: 10px; top: 10px; width: 228px; z-index: 6;
  height: calc(100dvh - 20px); max-height: calc(100dvh - 20px);
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
  overflow: hidden;
}
#invest-box {
  pointer-events: auto; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; direction: rtl;
  flex: 1 1 0; overflow-x: hidden; overflow-y: auto; min-height: 0;
}
#invest-box .send-head { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
#invest-box select { margin: 4px 0; }
#player-board {
  position: fixed; left: 10px; top: 10px; z-index: 6; width: 196px;
  max-height: calc(100vh - 260px); overflow: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; direction: rtl; pointer-events: none;
}
#player-board strong { color: var(--accent); font-size: 13px; display: block; margin-bottom: 6px; }
.roster-row {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--border);
}
.roster-row:last-child { border-bottom: 0; }
.roster-row.me { color: var(--accent); }
.roster-row.out { opacity: 0.45; }
.roster-who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.roster-who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 88px; }
.roster-stats { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.xp-mark { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: #f8f4ea; }
.xp-mark.gold { color: #f7dc6f; }
.xp-feather {
  display: inline-block; width: 7px; height: 14px; border-radius: 50% 50% 40% 40%;
  background: #f5e6c8; transform: rotate(-18deg); box-shadow: inset -2px 0 #c9b48a;
}
.xp-feather.long {
  width: 8px; height: 22px; background: linear-gradient(#fff6a3, #d4ac0d);
  transform: rotate(-8deg); box-shadow: inset -2px 0 #b7950b;
}
#minimap-wrap { position: fixed; left: 10px; bottom: 92px; z-index: 5; background: var(--card); padding: 4px; border-radius: 8px; border: 1px solid var(--border); }
#minimap { display: block; width: 140px; height: 140px; cursor: pointer; }
#chat-box {
  pointer-events: auto; flex: 0 0 auto; min-height: 0; max-height: 38%;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; direction: rtl; overflow: hidden;
}
#chat-box select, #chat-box .row { flex: 0 0 auto; margin: 4px 0 0; }
#chat-box input { margin: 0; min-width: 0; }
#chat-log {
  flex: 1 1 72px; min-height: 48px; overflow: auto; font-size: 12px; text-align: right;
  word-break: break-word; overflow-wrap: anywhere;
}
#chat-log > div { padding: 3px 0; border-bottom: 1px solid rgba(230, 220, 180, 0.08); }
#notify {
  position: fixed; top: 68px; left: 50%; transform: translateX(-50%);
  z-index: 40; pointer-events: none; max-width: min(360px, calc(100vw - 24px));
}
#notify div { background: var(--card); border: 1px solid var(--accent); padding: 6px 10px; border-radius: 8px; margin: 4px; direction: rtl; }
.cmd-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.cmd-bar button { min-height: 40px; padding: 8px 12px; font-size: 15px; }
.btn-danger, #build-cancel, #btn-cancel-builds {
  background: #8b241c;
  color: #fff8f4;
  font-weight: 700;
  border: 1px solid #e74c3c;
}
#hud-actions .btn-danger, #btn-cancel-builds {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 16px;
}
#btn-econ { display: none; }
@media (max-width: 1100px) {
  #hud-top { left: 10px; right: 248px; }
  #hud-bottom { left: 160px; right: 248px; }
}
@media (max-width: 900px) {
  #right-dock {
    width: min(228px, calc(100vw - 16px)); top: auto; bottom: 92px; right: 6px; left: auto;
    max-height: 55vh; display: none;
  }
  #right-dock.open { display: flex; }
  #hud-top, #hud-bottom { left: 10px; right: 10px; }
  #notify { max-width: calc(100vw - 24px); }
  #btn-econ { display: inline-block; }
}
@media (max-width: 700px) {
  #minimap-wrap { bottom: auto; top: 72px; left: 6px; }
  #minimap { width: 88px; height: 88px; }
  #player-board { left: 6px; top: 72px; width: min(168px, calc(100vw - 160px)); font-size: 11px; max-height: 40vh; }
  #hud-top, #hud-bottom { left: 6px; right: 6px; font-size: 12px; }
  #countdown { font-size: 72px; }
  #econ-box { width: calc(100vw - 12px); bottom: 78px; left: 6px; transform: none; }
}
#econ-summary {
  font-size: 12px; line-height: 1.45; margin-bottom: 6px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
#army-panel {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%);
  z-index: 7; width: min(420px, calc(100vw - 20px)); max-height: 62vh;
  overflow: auto; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px; direction: rtl; pointer-events: auto;
}
#army-list { font-size: 13px; }
.army-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.modal-overlay {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: rgba(8, 10, 6, 0.72); direction: rtl; pointer-events: auto;
}
.modal-overlay .card { min-width: min(340px, calc(100vw - 32px)); }
.modal-overlay p { color: var(--muted); margin: 0 0 8px; }
#defeat-overlay h2 { color: #e74c3c; }
#bank-withdraw-overlay h2 { color: var(--accent); }
#bank-withdraw-overlay input { width: 100%; margin: 8px 0; }
#spectate-banner {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
  z-index: 8; background: var(--card); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px 14px; direction: rtl; pointer-events: none;
}
#screen-game.spectating #econ-box,
#screen-game.spectating #hud-bottom .cmd-bar,
#screen-game.spectating #hud-actions { display: none; }
