/* Xe Tăng Mê Cung — hoạt hình tươi sáng: nền trời pastel, nút kẹo bo tròn */
:root {
  --bg1: #bfe6ff;
  --bg2: #ffe3f0;
  --ink: #3b2a5a;
  --muted: #7a6b98;
  --panel: #ffffff;
  --panel2: #f4efff;
  --line: rgba(59, 42, 90, 0.12);
  --accent: #8e7bff;
  --red: #ff6b6b;
  --blue: #4d9dff;
  --green: #45d483;
  --yellow: #ffc93c;
  --shadow: 0 6px 0 rgba(59, 42, 90, 0.12), 0 14px 30px rgba(59, 42, 90, 0.12);
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
h1,
h2,
h3 {
  font-family: "Baloo 2", "Be Vietnam Pro", sans-serif;
}
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.grow {
  flex: 1;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- nút ---------- */
.btn {
  border: 0;
  background: var(--panel2);
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 0 rgba(59, 42, 90, 0.14);
  transition: transform 0.08s;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(59, 42, 90, 0.14);
}
.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 0 #5f4fd1;
}
.btn.big {
  width: 100%;
  padding: 14px;
  font-size: 18px;
}
.btn.danger {
  background: transparent;
  color: #e04545;
  box-shadow: none;
  border: 2px dashed rgba(224, 69, 69, 0.4);
}
.icon-btn {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  border: 0;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(59, 42, 90, 0.12);
  font-size: 18px;
  font-weight: 900;
  display: grid;
  place-items: center;
}
.back {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(59, 42, 90, 0.12);
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  flex: none;
}
.bar h2 {
  margin: 0;
  font-size: 24px;
}
.pill {
  font-weight: 900;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 3px 0 rgba(59, 42, 90, 0.12);
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--panel2);
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-weight: 800;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
}
.seg button.on {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 0 #5f4fd1;
}

/* ---------- sảnh ---------- */
.home {
  overflow: auto;
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 0 16px 28px;
  text-align: center;
}
.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}
.hero-tank {
  flex: none;
  animation: bob 2.4s ease-in-out infinite;
}
.hero-tank.r {
  transform: scaleX(-1);
  animation-delay: -1.2s;
}
@keyframes bob {
  50% {
    translate: 0 -6px;
  }
}
.logo {
  margin: 0;
  font-size: clamp(38px, 8vw, 66px);
  line-height: 0.95;
  font-weight: 800;
  color: var(--ink);
  text-shadow: 0 4px 0 rgba(255, 255, 255, 0.8);
}
.logo span {
  display: block;
  color: var(--accent);
}
.tag {
  margin: 0;
  max-width: 520px;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
}
.modes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: min(820px, 100%);
}
.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 18px 8px 16px;
  border: 0;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.mode:hover {
  transform: translateY(-4px) rotate(-1deg);
}
.mode .mi {
  font-size: 38px;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  margin-bottom: 4px;
}
.m-pvp .mi {
  background: #ffe0e0;
}
.m-ai .mi {
  background: #dcebff;
}
.m-brawl .mi {
  background: #fff1cc;
}
.m-camp .mi {
  background: #dcf7e8;
}
.mode b {
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  line-height: 1.1;
}
.mode small {
  color: var(--muted);
  font-weight: 700;
  font-size: 12.5px;
}
.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}
.k {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(59, 42, 90, 0.15);
}

/* ---------- chiến dịch ---------- */
.camp {
  overflow: auto;
}
.lv-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 4px 14px 24px;
}
.lv {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 14px 8px 12px;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.lv .ln {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 15px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.lv b {
  font-size: 14.5px;
}
.lv .ls i {
  font-style: normal;
  color: rgba(59, 42, 90, 0.18);
  font-size: 16px;
}
.lv .ls i.on {
  color: var(--yellow);
}
.lv .lf {
  display: flex;
  gap: 2px;
  min-height: 26px;
}
.lv small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.lv.done .ln {
  background: var(--green);
}
.lv.locked {
  opacity: 0.55;
}
.lv.locked .ln {
  background: #b7aecb;
}

/* ---------- trong trận ---------- */
.play {
  padding: 0;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  translate: -50% 0;
  display: flex;
  gap: 6px;
  z-index: 3;
  pointer-events: none;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 120px);
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 0 rgba(59, 42, 90, 0.12);
  font-weight: 800;
  font-size: 14px;
}
.chip:not(.score) {
  padding: 6px 12px;
}
.chip b {
  font-family: "Baloo 2", sans-serif;
  font-size: 18px;
  line-height: 1;
}
.chip.dead {
  opacity: 0.45;
}
.chip.dim {
  color: var(--muted);
  font-size: 12px;
}
.chip.hearts {
  letter-spacing: 1px;
}
.pause-btn {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 4;
}

/* cần điều khiển ảo */
.touch {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.pad {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}
.pad .base,
.pad .knob {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  pointer-events: none;
}
.pad .base {
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px;
  background: rgba(255, 255, 255, 0.35);
  border: 3px solid rgba(255, 255, 255, 0.8);
}
.pad .knob {
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(59, 42, 90, 0.2);
}
.pad:not(.on) .base,
.pad:not(.on) .knob {
  opacity: 0.55;
}
.fire {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 0;
  font-size: 34px;
  background: var(--c);
  box-shadow: 0 5px 0 rgba(59, 42, 90, 0.25), inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}
.fire.on {
  transform: translateY(4px) scale(0.95);
}
/* 1 người, màn dọc: cần bên trái dưới, nút bắn bên phải dưới */
.touch.n1 .pad.p1 {
  left: 0;
  bottom: 0;
  width: 60%;
  height: 26%;
}
.touch.n1 .fire.p1 {
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
}
/* 2 người, màn dọc: người 1 dưới, người 2 trên (xoay ngược) */
.touch.n2 .pad.p1 {
  left: 0;
  bottom: 0;
  width: 60%;
  height: 20%;
}
.touch.n2 .fire.p1 {
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
}
.touch.n2 .pad.p2 {
  right: 0;
  top: 0;
  width: 60%;
  height: 20%;
}
.touch.n2 .fire.p2 {
  left: 18px;
  top: calc(18px + env(safe-area-inset-top));
  rotate: 180deg;
}
/* màn ngang */
.touch.land.n1 .pad.p1 {
  width: 40%;
  height: 70%;
}
.touch.land.n2 .pad.p1 {
  left: 0;
  top: 30%;
  bottom: 0;
  width: 18%;
  height: auto;
}
.touch.land.n2 .fire.p1 {
  left: 18px;
  right: auto;
  top: 60px;
  bottom: auto;
}
.touch.land.n2 .pad.p2 {
  right: 0;
  left: auto;
  top: 30%;
  bottom: 0;
  width: 18%;
  height: auto;
}
.touch.land.n2 .fire.p2 {
  right: 18px;
  left: auto;
  top: 60px;
  rotate: 0deg;
}

/* ---------- lớp phủ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(59, 42, 90, 0.32);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border-radius: 26px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  animation: pop 0.22s ease-out;
}
.sheet.wide {
  width: min(560px, 100%);
}
@keyframes pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}
.sheet h2 {
  margin: 0;
  text-align: center;
  font-size: 26px;
  line-height: 1.1;
}
.sheet h3 {
  margin: 4px 0 0;
  font-size: 18px;
}
.sheet ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
  font-size: 14px;
  line-height: 1.5;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.row > span {
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
}
.sub {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--panel2);
  font-size: 22px;
  line-height: 1;
}
.btns {
  display: grid;
  gap: 8px;
}
.res {
  text-align: center;
}
.res-ico {
  font-size: 60px;
  line-height: 1;
  animation: pop 0.45s ease-out;
}
.res-stars span {
  display: inline-block;
  font-size: 44px;
  color: rgba(59, 42, 90, 0.15);
}
.res-stars span.on {
  color: var(--yellow);
  animation: starIn 0.4s backwards;
}
@keyframes starIn {
  from {
    transform: scale(2.2) rotate(-30deg);
    opacity: 0;
  }
}
.res-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.res-board span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel2);
  font-weight: 800;
}
.res-board i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c);
}
.res-board b {
  font-family: "Baloo 2", sans-serif;
  font-size: 18px;
}
.pw-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.pw-list div {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--panel2);
}
.pw-list span {
  grid-row: span 2;
  font-size: 24px;
}
.pw-list b {
  font-size: 14px;
}
.pw-list small {
  font-size: 12px;
  color: var(--muted);
}
.toast {
  position: absolute;
  left: 50%;
  top: 64px;
  translate: -50% 0;
  z-index: 40;
  max-width: calc(100% - 32px);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

/* ---------- điện thoại ---------- */
@media (max-width: 720px) {
  .modes {
    grid-template-columns: 1fr 1fr;
  }
  .lv-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .row {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  .pw-list {
    grid-template-columns: 1fr;
  }
  .hero-tank {
    width: 48px !important;
    height: 48px !important;
  }
}
@media (max-height: 480px) {
  .home-body {
    gap: 10px;
  }
  .tag {
    display: none;
  }
  .mode {
    padding: 10px 6px;
  }
  .mode .mi {
    width: 44px;
    height: 44px;
    font-size: 26px;
  }
  .lv-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

body.playing .toast {
  top: auto;
  bottom: calc(14px + env(safe-area-inset-bottom));
  opacity: 0.94;
}
@media (max-width: 520px) {
  .chip.score span,
  .chip.dim {
    display: none;
  }
  .chip.score {
    padding-right: 10px;
  }
  .hud {
    flex-wrap: nowrap;
  }
}
