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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0e1622;
  font-family: "Rubik", "Arial Rounded MT Bold", "Trebuchet MS", Verdana, Arial, sans-serif;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#cv { position: fixed; inset: 0; display: block; }

#ui {
  position: fixed;
  left: 0; top: 0;
  width: 1600px; height: 900px;
  transform-origin: 0 0;
  pointer-events: none;
}
#ui > * { pointer-events: none; }
#ui button, #ui .modal, #ui #popup-block { pointer-events: auto; }

.hidden { display: none !important; }
.scr { position: absolute; inset: 0; }
.spacer { flex: 1; }

/* ---------- shared ---------- */
.btn {
  border: none; cursor: pointer;
  font-family: inherit; font-weight: 700;
  border-radius: 14px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
  box-shadow: 0 4px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.25);
  transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.2); }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: default; }

.btn-battle {
  font-size: 40px; font-weight: 900;
  padding: 18px 70px;
  background: linear-gradient(#ffb62e, #f08c1b 55%, #d97710);
  border: 3px solid #8a5106;
  border-radius: 20px;
  letter-spacing: 1px;
  animation: pulse 1.8s ease-in-out infinite;
}
.btn-battle.small { font-size: 26px; padding: 12px 36px; animation: none; }
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.045);} }

.btn-menu {
  font-size: 24px;
  padding: 14px 26px;
  background: linear-gradient(#5f9ff0, #3d78d4 60%, #2f61b4);
  border: 3px solid #1c3f7c;
  min-width: 210px;
  text-align: left;
}
.btn-gold {
  font-size: 20px;
  padding: 10px 28px;
  background: linear-gradient(#ffc95e, #eda42d 60%, #d68a17);
  border: 3px solid #8a5c0d;
  color: #4a2f05;
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
.btn-ghost {
  font-size: 20px;
  padding: 8px 18px;
  background: rgba(14, 25, 40, 0.55);
  border: 2px solid rgba(255,255,255,0.35);
}
.btn-up { font-size: 17px; padding: 8px 16px; background: linear-gradient(#67c460, #3f9a3c 60%, #2f7d2e); border: 2px solid #1d5a1e; width: 100%; }

.chip {
  display: flex; align-items: center; gap: 7px;
  background: rgba(12, 22, 36, 0.72);
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 999px;
  color: #fff; font-weight: 700; font-size: 21px;
  padding: 7px 18px 7px 10px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.chip.big { font-size: 30px; padding: 10px 26px 10px 14px; }
.chip-rank { padding-left: 14px; }

.ico-coin, .ico-troph {
  display: inline-block; width: 24px; height: 24px;
  border-radius: 50%;
  flex: none;
  vertical-align: -4px;
}
.ico-coin {
  background: radial-gradient(circle at 35% 30%, #ffe98a, #f5c531 55%, #c78d12);
  border: 2px solid #a06e0a;
  box-shadow: inset 0 0 0 3px rgba(255, 240, 170, 0.55);
}
.ico-troph {
  border-radius: 30% 30% 45% 45%;
  background: radial-gradient(circle at 35% 25%, #ffe27a, #f0a43a 60%, #c46d15);
  border: 2px solid #94540e;
  clip-path: polygon(0 0, 100% 0, 82% 62%, 66% 74%, 66% 84%, 84% 100%, 16% 100%, 34% 84%, 34% 74%, 18% 62%);
}
.chip.big .ico-coin, .chip.big .ico-troph { width: 32px; height: 32px; }

.top-bar {
  position: absolute; top: 16px; left: 20px; right: 20px;
  display: flex; gap: 12px; align-items: center;
}

/* ---------- home ---------- */
.game-title {
  position: absolute; top: 66px; left: 0; right: 0;
  text-align: center;
  font-size: 74px; font-weight: 900; letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 4px 0 #b06a10, 0 8px 18px rgba(0,0,0,0.45);
  -webkit-text-stroke: 2px #7c4a08;
  pointer-events: none;
}
.game-title span {
  color: #ffd257;
  margin-left: 18px;
}

.home-left {
  position: absolute; left: 26px; top: 220px;
  display: flex; flex-direction: column; gap: 16px;
}

.home-bottom {
  position: absolute; bottom: 8px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.opp-box {
  background: rgba(12, 22, 36, 0.72);
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 14px;
  padding: 8px 26px;
  text-align: center; color: #cfe0f2;
}
.opp-label { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.75; }
.opp-name { font-size: 24px; font-weight: 900; color: #fff; }
.opp-diff { color: #ff9d4d; font-size: 15px; letter-spacing: 3px; }
.home-tip { color: rgba(255,255,255,0.85); font-size: 16px; text-shadow: 0 1px 3px rgba(0,0,0,0.6); padding-bottom: 4px; }

/* ---------- build ---------- */
.build-hint {
  color: #fff; font-size: 18px; font-weight: 500;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  background: rgba(12,22,36,0.6);
  padding: 8px 18px; border-radius: 999px;
}

#popup-block {
  position: absolute;
  width: 250px;
  background: linear-gradient(#41546e, #2b3a4e);
  border: 3px solid #7f95b0;
  border-radius: 16px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.pop-title { color: #cfe0f2; font-size: 15px; font-weight: 700; }
.ub-row { display: flex; gap: 8px; }
.ub {
  width: 50px; height: 50px;
  border-radius: 12px;
  border: 3px solid rgba(255,255,255,0.25);
  background: rgba(10, 18, 30, 0.6);
  cursor: pointer;
  color: #fff; font-size: 22px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.08s;
}
.ub:active { transform: scale(0.92); }
.ub.on { border-color: #ffe14d; box-shadow: 0 0 12px rgba(255, 225, 77, 0.6); }
.ub canvas { pointer-events: none; }

/* ---------- battle ---------- */
.battle-top {
  position: absolute; top: 12px; left: 16px; right: 16px;
  display: flex; align-items: flex-start; gap: 14px;
}
.side-box { flex: 1; }
.side-box.right { text-align: right; }
.side-name {
  color: #fff; font-weight: 900; font-size: 20px;
  text-shadow: 0 2px 3px rgba(0,0,0,0.6);
  margin-bottom: 4px;
}
.hp-bar {
  position: relative;
  height: 30px;
  background: rgba(10, 16, 26, 0.75);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 999px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.hp-fill.player { background: linear-gradient(#7db9ff, #2e7ce0 60%, #1d5cb4); }
.hp-fill.enemy { background: linear-gradient(#ff9d8a, #e0452e 60%, #b42e1d); float: right; }
.hp-txt {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 900; font-size: 17px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.center-box { text-align: center; min-width: 130px; }
.vs {
  font-size: 30px; font-weight: 900; color: #ffd257;
  text-shadow: 0 3px 0 rgba(0,0,0,0.4);
  -webkit-text-stroke: 1px #7c4a08;
}
.round { color: #fff; font-weight: 700; font-size: 16px; text-shadow: 0 1px 2px rgba(0,0,0,0.7); }
.timer {
  color: #fff; font-weight: 900; font-size: 24px;
  text-shadow: 0 2px 2px rgba(0,0,0,0.7);
}
.timer.low { color: #ff5544; animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
.btn-flag { font-size: 22px; padding: 6px 14px; }

#banner {
  position: absolute; top: 200px; left: 0; right: 0;
  text-align: center;
  font-size: 52px; font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 8px 20px rgba(0,0,0,0.4);
  -webkit-text-stroke: 1.5px rgba(60, 30, 0, 0.7);
  opacity: 0;
  pointer-events: none;
}
#banner.pop { animation: bannerPop 1.7s ease forwards; }
@keyframes bannerPop {
  0% { opacity: 0; transform: scale(0.4); }
  12% { opacity: 1; transform: scale(1.12); }
  20% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(1) translateY(-20px); }
}

.battle-bottom {
  position: absolute; bottom: 10px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#aim-readout {
  display: flex; gap: 30px;
  color: #fff; font-size: 20px;
  background: rgba(12, 22, 36, 0.7);
  border-radius: 999px;
  padding: 6px 24px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
#aim-readout b { color: #ffd257; }

#unit-bar { display: flex; gap: 12px; }
.ub-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  width: 110px;
  padding: 8px 6px 7px;
  border-radius: 14px;
  border: 3px solid rgba(255,255,255,0.25);
  background: rgba(12, 22, 36, 0.78);
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  transition: transform 0.1s, border-color 0.15s;
}
.ub-card.sel {
  border-color: var(--uc, #ffe14d);
  box-shadow: 0 0 16px var(--uc, rgba(255,225,77,0.5));
  transform: translateY(-6px);
}
.ub-card.dead { filter: grayscale(1) brightness(0.5); cursor: default; }
.ubc-name { font-size: 13px; font-weight: 700; }
.ubc-lv { font-size: 12px; color: #ffd257; font-weight: 700; }

/* ---------- modals ---------- */
.modal {
  position: absolute; inset: 0;
  background: rgba(6, 12, 20, 0.6);
  display: flex; align-items: center; justify-content: center;
}
.modal-panel {
  background: linear-gradient(#41546e, #2b3a4e);
  border: 3px solid #7f95b0;
  border-radius: 22px;
  padding: 26px 30px;
  min-width: 500px; max-width: 900px;
  max-height: 92%;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
  align-items: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.55);
}
.modal-panel h2 {
  color: #fff; font-size: 34px; font-weight: 900;
  text-shadow: 0 3px 0 rgba(0,0,0,0.3);
}

#units-cards { display: flex; gap: 16px; }
.unit-card {
  width: 240px;
  background: rgba(10, 18, 30, 0.5);
  border: 3px solid var(--uc, #888);
  border-radius: 16px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 9px;
  color: #d8e4f2;
}
.uc-head { display: flex; gap: 10px; align-items: center; }
.uc-name { font-size: 19px; font-weight: 900; color: #fff; }
.uc-lv { font-size: 14px; color: #ffd257; font-weight: 700; }
.uc-desc { font-size: 13.5px; line-height: 1.35; min-height: 54px; opacity: 0.9; }
.uc-stats { font-size: 14px; display: flex; flex-direction: column; gap: 3px; }
.uc-stats b { color: #fff; }
.up-arrow { color: #74e07a; font-weight: 700; }
.uc-btn { margin-top: 4px; }

#rank-list { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.rank-row {
  display: flex; align-items: center; gap: 14px;
  background: rgba(10, 18, 30, 0.5);
  border-radius: 10px;
  padding: 8px 16px;
  color: #d8e4f2; font-size: 18px;
}
.rank-row.me {
  background: rgba(240, 164, 41, 0.25);
  border: 2px solid #f0a429;
  color: #fff; font-weight: 900;
}
.rr-pos { width: 34px; font-weight: 900; color: #ffd257; }
.rr-name { flex: 1; }
.rr-rank { opacity: 0.7; font-size: 15px; }
.rr-tr { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.rr-tr .ico-troph { width: 18px; height: 18px; }

.result-panel { min-width: 440px; }
#result-title { font-size: 58px; }
#result-title.win { color: #ffd257; text-shadow: 0 4px 0 #9a6108, 0 8px 24px rgba(0,0,0,0.5); }
#result-title.lose { color: #9fb2c8; }
.rewards-label { color: #cfe0f2; font-size: 18px; text-transform: uppercase; letter-spacing: 2px; }
.rewards-row { display: flex; gap: 20px; }
.result-btns { display: flex; gap: 16px; margin-top: 8px; align-items: center; }

/* ---------- toast ---------- */
#toast {
  position: absolute; top: 90px; left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(200, 60, 40, 0.92);
  color: #fff; font-weight: 700; font-size: 19px;
  border-radius: 999px;
  padding: 10px 28px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
