/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0a0a0a;
  --surface:    #1a1a18;
  --border:     #2a2a28;
  --text:       #e8e5df;
  --muted:      #555;
  --accent:     #5DCAA5;
  --danger:     #e05252;
  --warn:       #f5a623;
  --gold-color: #f5c842;

  --human:  #4A90D9;
  --orc:    #c0392b;
  --elf:    #27ae60;
  --dwarf:  #e67e22;

  --touch: 44px;
  --tile:  32px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Courier New', Courier, monospace;
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── SCREENS ── */
.screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
}
.screen.active { display: flex; }

/* ── TITLE SCREEN ── */
#screen-title {
  align-items: center; justify-content: center;
  background: var(--bg);
  gap: 0;
}
.title-logo {
  font-size: clamp(36px, 10vw, 80px);
  font-weight: 900; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 60px rgba(93,202,165,0.35);
  margin-bottom: 6px;
}
.title-sub {
  font-size: 10px; color: var(--muted); letter-spacing: 0.22em;
  text-transform: uppercase; margin-bottom: 52px;
}
.menu-btn {
  width: 260px; min-height: var(--touch);
  padding: 12px 24px; margin-bottom: 10px;
  border-radius: 10px; border: 0.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 12px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
}
.menu-btn.primary { border-color: var(--accent); color: var(--accent); }

/* ── GAME SCREEN ── */
#screen-game { background: var(--bg); }

#hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  height: 46px; display: flex; align-items: center;
  padding: 0 8px; gap: 6px;
  background: linear-gradient(to bottom, rgba(10,10,10,0.9), transparent);
  pointer-events: none;
}
.hud-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 6px;
  background: rgba(26,26,24,0.88); border: 0.5px solid var(--border);
  font-size: 11px; pointer-events: all;
}
.hud-chip .lbl { color: var(--muted); }
.hud-chip .val { font-weight: 700; }
#hud-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
#btn-settings { transition: color 0.15s, border-color 0.15s; }
#btn-settings:hover { color: var(--accent) !important; border-color: var(--accent) !important; }

#map-container {
  position: absolute;
  top: 46px; bottom: 58px; left: 0; right: 0;
  overflow: hidden; touch-action: none;
}
#game-canvas {
  position: absolute; top: 0; left: 0;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
#minimap {
  position: absolute; bottom: 8px; right: 8px;
  border: 0.5px solid var(--border); border-radius: 4px;
  opacity: 0.75; pointer-events: none;
}

#action-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 58px; z-index: 10;
  display: flex; align-items: center; padding: 0 6px; gap: 5px;
  background: rgba(10,10,10,0.96); border-top: 0.5px solid var(--border);
}
.act-btn {
  flex: 1; min-height: var(--touch);
  border-radius: 8px; border: 0.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 9px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; padding: 3px;
}
.act-btn .ico { font-size: 17px; line-height: 1; }
.act-btn.end  { border-color: var(--accent); color: var(--accent); }
.act-btn:disabled { opacity: 0.3; pointer-events: none; }

/* ── MODALS ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.72);
  display: none; align-items: flex-end; justify-content: center;
}
.modal-bg.open { display: flex; }
.modal-sheet {
  width: 100%; max-width: 520px; position: relative;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 0.5px solid var(--border); border-bottom: none;
  padding: 18px 16px 36px;
  max-height: 82vh; overflow-y: auto;
}
.modal-handle { width: 34px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 14px; }
.modal-title  { font-size: 13px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 14px; }
.modal-row    { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 0.5px solid var(--border); font-size: 12px; }
.modal-row .k { color: var(--muted); }
.modal-row .v { font-weight: 600; }
.modal-close  { position: absolute; top: 10px; right: 10px; width: var(--touch); height: var(--touch); border: none; background: none; color: var(--muted); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.prod-select {
  width: 100%; min-height: var(--touch);
  background: var(--bg); border: 0.5px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 12px;
  padding: 8px 12px; margin-top: 6px; cursor: pointer;
}
.unit-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 5px; margin-top: 8px; }
.unit-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 2px; border-radius: 7px; border: 0.5px solid var(--border);
  background: var(--bg); font-size: 9px; color: var(--muted); text-align: center;
}
.unit-chip .uico { font-size: 18px; }
.unit-chip .uhp  { color: var(--accent); }
.art-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.art-tag  { padding: 3px 9px; border-radius: 20px; border: 0.5px solid var(--gold-color); color: var(--gold-color); font-size: 10px; }

/* ── PRODUCTION PROGRESS ── */
.prod-bar-wrap { width: 100%; height: 6px; background: var(--bg); border-radius: 3px; margin: 5px 0 2px; overflow: hidden; }
.prod-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.25s; }

/* ── CITY NAVIGATION ── */
.city-nav-header { display:flex; align-items:center; margin-bottom:14px; gap:6px; }
.city-nav-btn {
  width:30px; height:30px; border-radius:8px; border:0.5px solid var(--border);
  background:var(--bg); color:var(--text); font-size:18px; cursor:pointer; flex-shrink:0;
  display:flex; align-items:center; justify-content:center; line-height:1;
}
.city-nav-btn:disabled { opacity:0.2; pointer-events:none; }

/* ── PRODUCTION UNIT PICKER ── */
.prod-unit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; width: 100%; }
.prod-unit-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 8px; border: 0.5px solid var(--border);
  background: var(--bg); cursor: pointer; font-size: 9px; color: var(--muted);
  text-align: center;
}
.prod-unit-card .pu-ico  { font-size: 20px; }
.prod-unit-card .pu-name { color: var(--text); font-size: 10px; font-weight: 600; margin-top: 1px; }
.prod-unit-card .pu-cost { color: var(--gold-color); }
.prod-unit-card.selected { border-color: var(--accent); background: rgba(93,202,165,0.1); }

/* ── GARRISON ROWS ── */
.garr-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; border-bottom: 0.5px solid var(--border); font-size: 11px;
}
.garr-row:last-child { border-bottom: none; }
.garr-info { display: flex; align-items: center; gap: 8px; }
.garr-ico  { font-size: 16px; line-height: 1; }
.deploy-btn {
  padding: 3px 10px; border-radius: 6px; border: 0.5px solid var(--accent);
  background: none; color: var(--accent); font-family: inherit;
  font-size: 9px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; cursor: pointer;
}
.deploy-btn:disabled { opacity: 0.35; pointer-events: none; }

/* ── DELIVERY TARGET PICKER ── */
.deploy-target-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; padding: 7px 10px; border-radius: 8px;
  border: 0.5px solid var(--border); background: var(--bg);
  color: var(--text); font-family: inherit; font-size: 11px; font-weight: 600;
  cursor: pointer; text-align: left;
}
.deploy-target-btn.selected { border-color: var(--accent); background: rgba(93,202,165,0.1); }

#combat-log {
  font-size: 11px; color: var(--muted); line-height: 1.75;
  max-height: 220px; overflow-y: auto;
  padding: 8px; background: var(--bg);
  border-radius: 8px; border: 0.5px solid var(--border);
}
#combat-log .ca { color: var(--danger); }
#combat-log .cd { color: var(--human); }
#combat-log .cw { color: var(--accent); font-weight: 700; }
#combat-log .ci { color: #c8a010; font-style: italic; }
#combat-log .cx { color: var(--danger); font-weight: 700; }

/* ── COMBAT HISTORY ── */
#history-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 340px; overflow-y: auto;
  padding-right: 2px;
}
.hist-entry {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--bg); border: 0.5px solid var(--border);
  cursor: pointer; transition: border-color 0.12s, background 0.12s;
  font-size: 11px;
}
.hist-entry:hover { background: rgba(255,255,255,0.04); border-color: var(--accent); }
.hist-num {
  font-size: 10px; color: var(--muted); min-width: 20px; text-align: right; flex-shrink: 0;
}
.hist-badge {
  font-size: 14px; flex-shrink: 0;
}
.hist-body { flex: 1; min-width: 0; }
.hist-title {
  font-weight: 600; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.hist-meta { font-size: 10px; color: var(--muted); margin-top: 1px; }
.hist-result {
  font-size: 10px; font-weight: 700; flex-shrink: 0;
}
.hist-result.win  { color: var(--accent); }
.hist-result.loss { color: var(--danger); }
.hist-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 24px 0; }

/* ── TOGGLE SWITCH ── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 0.5px solid var(--border); font-size: 12px;
}
.toggle-row .k { color: var(--muted); }
.toggle-wrap {
  position: relative; display: inline-block;
  width: 40px; height: 22px; cursor: pointer; flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 11px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  left: 3px; top: 3px; width: 16px; height: 16px;
  background: var(--text); border-radius: 50%;
  transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.toggle-wrap input:checked + .toggle-slider { background: var(--accent); }
.toggle-wrap input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── GAME OVER ── */
#screen-gameover {
  align-items: center; justify-content: center;
  background: var(--bg); text-align: center; gap: 0;
}
.go-title { font-size: clamp(28px,8vw,64px); font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 10px; }
.go-title.win  { color: var(--accent); }
.go-title.loss { color: var(--danger); }
.go-sub   { font-size: 12px; color: var(--muted); margin-bottom: 44px; }

/* ── TOASTS ── */
#toasts {
  position: fixed; top: 50px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 5px;
  pointer-events: none; align-items: center;
}
.toast {
  padding: 7px 16px; border-radius: 8px;
  background: rgba(26,26,24,0.96); border: 0.5px solid var(--border);
  font-size: 11px; letter-spacing: 0.05em; white-space: nowrap;
  animation: tin 0.18s ease, tout 0.28s ease 2.1s forwards;
}
@keyframes tin  { from { opacity:0; transform:translateY(-6px); } }
@keyframes tout { to   { opacity:0; transform:translateY(-6px); } }

/* ── SELECTION RING ── */
#sel-ring {
  position: absolute; pointer-events: none; z-index: 5;
  border: 2px solid var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(93,202,165,0.5);
  transition: left 0.12s, top 0.12s;
  display: none;
}

/* ── MOVE HINT OVERLAY ── */
#move-layer { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 4; }

/* ── FACTION SELECT (new game) ── */
#modal-newgame .faction-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;
}
.faction-card {
  min-height: var(--touch); padding: 10px 10px;
  border-radius: 10px; border: 0.5px solid var(--border);
  background: var(--bg); cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; font-weight: 600;
}
.faction-card .fac-header { display: flex; align-items: center; gap: 8px; }
.faction-card .fdot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.faction-card .fac-desc {
  font-size: 10px; font-weight: 400; color: var(--muted);
  line-height: 1.35; margin: 0;
}
.faction-card.selected { border-width: 1.5px; }

/* ── AI BATTLE REPORT ── */
#ai-report {
  position: fixed; bottom: 68px; right: 10px;
  min-width: 210px; max-width: 280px;
  background: rgba(20,20,18,0.97); border: 0.5px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  z-index: 150; display: none;
  animation: tin 0.2s ease;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
}
#ai-report.open { display: block; }
.air-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 7px;
}
.air-title { font-size: 11px; font-weight: 700; color: var(--text); letter-spacing: 0.04em; }
.air-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 0; line-height: 1;
}
.air-row {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 4px; margin: 0 -4px; font-size: 11px; color: var(--text);
  border-top: 0.5px solid rgba(255,255,255,0.05);
  border-radius: 5px; cursor: pointer;
  transition: background 0.12s;
}
.air-row:first-child { border-top: none; }
.air-row:hover { background: rgba(255,255,255,0.07); }
.air-row:hover .air-detail { opacity: 1; }
.air-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.air-vs { color: var(--muted); font-size: 10px; }
.air-won    { margin-left: auto; color: var(--danger);  font-size: 10px; font-weight: 700; }
.air-lost   { margin-left: auto; color: var(--accent); font-size: 10px; font-weight: 700; }
.air-detail { font-size: 9px; color: var(--muted); opacity: 0; transition: opacity 0.12s; margin-left: 3px; }

/* ── SPLIT TROOP PICKER ── */
.split-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
  margin: 6px 0 0; width: 100%;
}
.split-cell {
  aspect-ratio: 1; border-radius: 7px;
  border: 0.5px solid var(--border); background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 18px; gap: 1px; padding: 4px 2px;
}
.split-cell small { font-size: 8px; color: var(--muted); line-height: 1.3; display: block; text-align: center; }
.split-cell.sc-current { border-color: var(--muted); color: var(--muted); }
.split-cell.sc-valid   { border-color: var(--accent); cursor: pointer; }
.split-cell.sc-valid:hover { background: rgba(93,202,165,0.1); }
.split-cell.sc-selected { border-color: var(--accent); background: rgba(93,202,165,0.2); color: var(--accent); font-weight: 700; }
.split-cell.sc-blocked  { opacity: 0.28; pointer-events: none; }
.split-qty {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 2px;
}
.split-qty-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 0.5px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-family: inherit; line-height: 1;
}
.split-qty-val { font-size: 20px; font-weight: 700; min-width: 32px; text-align: center; }
