/* Age of Supremacy — mobile-first dark theme */
:root {
  --bg: #0b0f1a;
  --bg2: #131a2b;
  --panel: #1d2740;
  --panel2: #283450;
  --text: #edf0f8;
  --dim: #a3adc6;
  --gold: #e8b64c;
  --gold-hi: #f7dc96;
  --gold-lo: #b8863a;
  --accent: #4a9eff;
  --danger: #e05555;
  --ok: #58c47c;
  --hairline-gold: rgba(232, 182, 76, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* iOS ignores user-scalable=no; this kills double-tap-to-zoom on buttons/sheets.
     #map keeps its own touch-action: none for pan. */
  touch-action: manipulation;
}

button { font-family: inherit; }
button:focus-visible { outline: 2px solid rgba(232, 182, 76, 0.75); outline-offset: 1px; }

#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- top HUD ---------- */
#hud {
  padding-top: var(--safe-top);
  background: linear-gradient(180deg, #182034 0%, #131a2b 100%);
  border-bottom: 1px solid var(--hairline-gold);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  z-index: 20;
}
#res-bar {
  display: flex;
  justify-content: space-around;
  padding: 6px 4px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
#res-bar .res { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
#res-bar .res b { font-weight: 600; letter-spacing: 0.2px; }
#res-bar .res .rate { color: var(--dim); font-size: 11px; }
#ctrl-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 8px;
  font-size: 13px;
  color: var(--dim);
}
#ctrl-bar .age {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-shadow: 0 0 12px rgba(232, 182, 76, 0.35);
}
#ctrl-bar .spacer { flex: 1; }
#ctrl-bar button {
  min-width: 44px; min-height: 32px;
  background: linear-gradient(180deg, #2a3554, #202944);
  color: var(--text);
  border: 1px solid #3a4770;
  border-radius: 8px;
  font-size: 15px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease, border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
#ctrl-bar button:active { transform: translateY(1px); filter: brightness(0.9); }
#ctrl-bar button.active {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 0 10px rgba(232, 182, 76, 0.3);
}

/* ---------- map ---------- */
#map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(130% 90% at 50% -10%, rgba(74, 158, 255, 0.08), rgba(74, 158, 255, 0) 55%),
    radial-gradient(120% 100% at 50% 115%, rgba(4, 6, 12, 0.85), rgba(4, 6, 12, 0) 50%),
    linear-gradient(180deg, #151d31 0%, #0e1424 48%, #080c16 100%);
}
#map { width: 100%; height: 100%; display: block; touch-action: none; }

.hex { stroke: #0a0d16; stroke-width: 1.5; cursor: pointer; transition: fill 0.25s; }
.hex.selected {
  stroke: var(--gold);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 5px rgba(232, 182, 76, 0.55));
}
#map.targeting .hex { stroke: #5a6a95; }
.hex-label {
  fill: #e6ecf8;
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
  paint-order: stroke;
  stroke: rgba(10, 13, 22, 0.8);
  stroke-width: 2.5px;
}
.hex-terrain { font-size: 12px; text-anchor: middle; pointer-events: none; }
.hex-capital { font-size: 13px; text-anchor: middle; pointer-events: none; }

.army-badge circle { stroke: rgba(255,255,255,0.85); stroke-width: 1.5; }
.army-badge.moving circle { stroke-dasharray: 3 2; }
.army-badge text {
  fill: #fff;
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}
.move-path {
  fill: none;
  stroke: rgba(255, 255, 255, 0.65);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  pointer-events: none;
}

/* ---------- banner (move / cast targeting) ---------- */
#banner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, #d9a83e);
  color: #20180a;
  padding: 10px 18px;
  border-radius: 24px;
  font-weight: 700;
  font-size: 14px;
  z-index: 35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  white-space: nowrap;
}
#banner button {
  margin-left: 10px;
  background: #20180a;
  color: var(--gold);
  border: none;
  border-radius: 14px;
  padding: 4px 12px;
  font-weight: 700;
  transition: transform 0.08s ease, filter 0.15s ease;
}
#banner button:active { transform: scale(0.94); filter: brightness(1.15); }

/* ---------- god power bar ---------- */
#power-bar {
  position: absolute;
  right: 10px;
  bottom: calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 30;
}
.power-btn {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, #3c4a78, #1a2138 70%);
  border: 2px solid var(--gold);
  font-size: 24px;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.6),
    0 0 12px rgba(232, 182, 76, 0.22),
    inset 0 1px 1px rgba(255, 255, 255, 0.14);
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.power-btn:active { transform: scale(0.93); filter: brightness(1.1); }
.power-btn:disabled { opacity: 0.45; border-color: #556; box-shadow: 0 3px 10px rgba(0,0,0,0.55); }
.power-btn .cd {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(8,10,18,0.72);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.power-btn .cost {
  position: absolute; bottom: -6px; right: -4px;
  background: linear-gradient(180deg, #2c385c, #232e4c);
  border-radius: 10px;
  font-size: 10px;
  padding: 1px 5px;
  color: var(--gold);
  border: 1px solid #45528a;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* ---------- bottom sheet ---------- */
#sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 58%;
  background: linear-gradient(180deg, #161d30 0%, #111727 100%);
  border-top: 1px solid var(--hairline-gold);
  border-radius: 16px 16px 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.6);
  padding-bottom: var(--safe-bottom);
  animation: sheet-in 0.18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0.4; } }
#sheet::before {
  content: "";
  position: absolute;
  top: 5px; left: 50%;
  width: 38px; height: 4px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: rgba(163, 173, 198, 0.3);
  pointer-events: none;
}
#sheet .sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 6px;
}
#sheet .sheet-head h2 { font-size: 17px; flex: 1; letter-spacing: 0.3px; }
#sheet .sheet-head .owner-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.5); box-shadow: 0 0 6px rgba(0,0,0,0.4); }
#sheet .close-btn {
  min-width: 44px; min-height: 36px;
  background: none; border: none;
  color: var(--dim); font-size: 22px;
  transition: color 0.15s ease;
}
#sheet .close-btn:active { color: var(--text); }
#sheet .tabs { display: flex; gap: 4px; padding: 0 14px 8px; }
#sheet .tabs button {
  flex: 1;
  min-height: 44px;
  background: rgba(29, 39, 64, 0.6);
  border: 1px solid #303d63;
  border-radius: 10px;
  color: var(--dim);
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.2px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}
#sheet .tabs button:active { transform: translateY(1px); }
#sheet .tabs button.active {
  color: var(--gold);
  border-color: rgba(232, 182, 76, 0.55);
  background: linear-gradient(180deg, rgba(232, 182, 76, 0.16), rgba(232, 182, 76, 0.05));
  box-shadow: 0 0 10px rgba(232, 182, 76, 0.18), inset 0 1px 0 rgba(247, 220, 150, 0.12);
}
#sheet .sheet-body { overflow-y: auto; padding: 0 14px 14px; -webkit-overflow-scrolling: touch; }
#sheet .sheet-body::-webkit-scrollbar { width: 4px; }
#sheet .sheet-body::-webkit-scrollbar-thumb { background: rgba(163, 173, 198, 0.3); border-radius: 2px; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #212b47, #1c2440);
  border: 1px solid #303c60;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s ease, transform 0.08s ease;
}
.row .icon { font-size: 22px; width: 30px; text-align: center; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.row .info { flex: 1; min-width: 0; }
.row .info .name { font-size: 14px; font-weight: 600; letter-spacing: 0.15px; }
.row .info .sub { font-size: 12px; color: var(--dim); margin-top: 2px; }
.row .pips { letter-spacing: 2px; font-size: 11px; color: var(--gold); text-shadow: 0 0 6px rgba(232,182,76,0.35); }
.row .pips .off { color: #3a4468; text-shadow: none; }
.row button.act {
  min-width: 64px; min-height: 44px;
  background: linear-gradient(180deg, #5aa8ff, #3f8ef2);
  border: none; border-radius: 10px;
  color: #fff; font-weight: 700; font-size: 13px;
  padding: 0 12px;
  box-shadow: 0 2px 8px rgba(74, 158, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.row button.act:active { transform: translateY(1px) scale(0.98); filter: brightness(0.92); }
.row button.act:disabled {
  background: #2c385c;
  color: #6c7899;
  box-shadow: none;
  text-shadow: none;
}
.cost { font-size: 12px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cost .lack { color: var(--danger); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  background: linear-gradient(180deg, #2b3656, #242e4c);
  border: 1px solid #3d4a76;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--dim);
  margin: 12px 0 6px;
}

.army-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #232c48; font-size: 14px; flex-wrap: wrap; }
.army-line:last-child { border-bottom: none; }
.army-line .who { font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.army-line .units { color: var(--text); }
.army-line .note { color: var(--dim); font-size: 12px; width: 100%; }

/* ---------- toasts ---------- */
#toasts {
  position: absolute;
  top: calc(86px + var(--safe-top));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 50; pointer-events: none;
  width: min(92vw, 420px);
}
.toast {
  background: rgba(19, 26, 43, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid #3a4770;
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: toast-in 0.2s ease-out;
}
.toast.capture { border-left-color: var(--gold); background: linear-gradient(90deg, rgba(232,182,76,0.14), rgba(19,26,43,0.92) 45%); }
.toast.power { border-left-color: #b06cff; background: linear-gradient(90deg, rgba(176,108,255,0.13), rgba(19,26,43,0.92) 45%); }
.toast.age { border-left-color: var(--ok); background: linear-gradient(90deg, rgba(88,196,124,0.13), rgba(19,26,43,0.92) 45%); }
.toast.battle { border-left-color: var(--danger); background: linear-gradient(90deg, rgba(224,85,85,0.14), rgba(19,26,43,0.92) 45%); }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }
.toast.out { opacity: 0; transition: opacity 0.4s; }

/* ---------- modal ---------- */
#modal {
  position: absolute; inset: 0;
  background: radial-gradient(130% 100% at 50% 0%, rgba(16, 22, 38, 0.9), rgba(5, 7, 12, 0.94));
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-card {
  background: linear-gradient(180deg, #1a2138 0%, #121829 100%);
  border: 1px solid rgba(232, 182, 76, 0.3);
  border-radius: 18px;
  padding: 24px 20px;
  width: min(94vw, 460px);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: modal-in 0.22s ease-out;
}
@keyframes modal-in { from { transform: translateY(14px) scale(0.97); opacity: 0; } }
.modal-card h1 {
  font-size: 26px;
  letter-spacing: 1px;
  margin-bottom: 4px;
  color: var(--gold);
  background: linear-gradient(180deg, var(--gold-hi) 0%, var(--gold) 55%, var(--gold-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.modal-card h1 .sub {
  display: block;
  font-size: 13px;
  color: var(--dim);
  -webkit-text-fill-color: var(--dim);
  letter-spacing: 3px;
  margin-top: 2px;
}
.modal-card p.tag { color: var(--dim); font-size: 13px; margin: 10px 0 18px; line-height: 1.5; }
.god-cards { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.god-card {
  background: linear-gradient(180deg, #212b47, #1b2340);
  border: 2px solid #36436e;
  border-radius: 14px;
  padding: 14px;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  min-height: 56px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.god-card:active {
  border-color: var(--gold);
  transform: scale(0.99);
  box-shadow: 0 0 16px rgba(232, 182, 76, 0.25);
}
.god-card .god-name { font-weight: 700; color: var(--gold); font-size: 15px; letter-spacing: 0.3px; }
.god-card .god-desc { color: var(--dim); font-size: 12.5px; margin-top: 4px; line-height: 1.45; }
.big-btn {
  width: 100%;
  min-height: 52px;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, #d9a83e);
  color: #20180a;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 800;
  letter-spacing: 0.5px;
  margin-top: 10px;
  box-shadow: 0 4px 14px rgba(232, 182, 76, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.big-btn:active { transform: translateY(1px) scale(0.99); filter: brightness(0.94); }
.big-btn.secondary {
  background: linear-gradient(180deg, #242e4e, #1c2440);
  color: var(--text);
  border: 1px solid #3a4770;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.big-btn:disabled { opacity: 0.4; box-shadow: none; }

.hidden { display: none !important; }

@media (hover: hover) {
  #ctrl-bar button:hover { border-color: #4d5b8a; }
  .row:hover { border-color: #42517e; }
  .god-card:hover {
    border-color: rgba(232, 182, 76, 0.55);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), 0 0 14px rgba(232, 182, 76, 0.15);
  }
  .big-btn:not(:disabled):hover { filter: brightness(1.05); }
  #sheet .tabs button:not(.active):hover { color: var(--text); border-color: #42517e; }
}

@media (min-width: 700px) {
  #res-bar { font-size: 16px; }
  #sheet { left: auto; width: 420px; border-left: 1px solid var(--hairline-gold); border-radius: 16px 0 0 0; }
}

/* === mapfx === */
/* Deep-ocean backdrop so empty map space isn't flat black. */
#map { background: radial-gradient(ellipse at 50% 38%, #17263f 0%, #0e1728 55%, #060a13 100%); }

/* Nation borders: mapview sets --hex-stroke / --hex-sw per hex owner.
   Later same-specificity rule wins here; .selected and #map.targeting still override. */
.hex { stroke: var(--hex-stroke, #0a0d16); stroke-width: var(--hex-sw, 1.5); }
.hex.selected { animation: sel-glow 1.3s ease-in-out infinite; }
@keyframes sel-glow { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: 0.4; } }

/* Static hex decorations. */
.hex-terrain { opacity: 0.6; }
.hex-capital {
  fill: var(--gold);
  paint-order: stroke;
  stroke: rgba(10, 13, 22, 0.8);
  stroke-width: 2px;
}

/* Marching-ants movement paths + arrowheads. */
.move-path { animation: ants 0.9s linear infinite; }
@keyframes ants { to { stroke-dashoffset: -9; } }
.move-arrow { pointer-events: none; stroke: rgba(10, 13, 22, 0.6); stroke-width: 0.75; }

/* Pulsing battle indicator above contested provinces. */
.battle-icon {
  font-size: 15px;
  text-anchor: middle;
  pointer-events: none;
  animation: battle-pulse 0.9s ease-in-out infinite;
}
@keyframes battle-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Richer army badges: contested red ring, unit + frozen mini-icons. */
.army-badge.contested circle { stroke: var(--danger); stroke-width: 2.2; }
.army-badge .unit-icon { font-size: 9px; }
.army-badge .frozen-icon { font-size: 10px; }

/* === army split === */
/* March + Split side by side under an army. */
.btn-row { display: flex; gap: 8px; align-items: stretch; }
.btn-row .big-btn { flex: 1 1 0; width: auto; min-width: 0; }
.btn-row .big-btn.secondary { flex: 0 0 auto; width: auto; min-width: 96px; }

/* Split panel steppers (− n + per stack). */
.split-panel { margin-top: 4px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .step {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid #3a4770;
  background: linear-gradient(180deg, #242e4e, #1c2440);
  color: var(--text);
  font-size: 20px; font-weight: 700;
  line-height: 1;
}
.stepper .step:disabled { opacity: 0.35; }
.stepper .step-val { min-width: 22px; text-align: center; font-weight: 700; font-size: 16px; }

/* === map sizes === */
/* Start-screen world-size picker. */
.size-row { display: flex; gap: 8px; margin-top: 12px; }
.size-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid #3a4770;
  background: linear-gradient(180deg, #242e4e, #1c2440);
  color: var(--dim);
  font-size: 14px; font-weight: 700;
}
.size-btn .size-dims { font-weight: 400; font-size: 12px; }
.size-btn.active { color: var(--gold); border-color: var(--gold); box-shadow: 0 0 10px rgba(232, 182, 76, 0.2); }

/* === army select === */
/* City marker at each hex center: the province's visible tap target now that
   army badges are offset and selectable on their own. Taps fall through to
   the hex below. */
.hex-city {
  stroke: rgba(10, 13, 22, 0.7);
  stroke-width: 1.5;
  pointer-events: none;
}

/* Army badges are tappable; the selected one gets a gold ring. */
.army-badge { cursor: pointer; }
.army-badge.selected circle {
  stroke: var(--gold);
  stroke-width: 3;
  filter: drop-shadow(0 0 4px rgba(232, 182, 76, 0.6));
}

/* === fog of war === */
/* Grey hue over hexes outside the human's vision; drawn on the topmost SVG
   layer so it dims terrain, labels and city markers too. Taps fall through. */
.fog-hex {
  fill: #4b5261;
  fill-opacity: 0.55;
  pointer-events: none;
}
