/* Thủ Thành — nền tối neon, cùng phong cách Tròn Sinh Tồn */
:root {
  --bg: #0c0f1c;
  --panel: #171b2e;
  --panel2: #20263d;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef1fb;
  --muted: #9aa3c4;
  --gold: #ffcf33;
  --accent: #3ec6ff;
  --pink: #ff5d8f;
  --green: #4dff88;
  --red: #ff4d5e;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(ellipse at 50% 30%, #161c34, #0a0c17 75%);
}

/* ---------- nút chung ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 14px;
  transition:
    transform 0.08s,
    filter 0.15s;
}
.btn:hover {
  filter: brightness(1.15);
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(180deg, #4fd2ff, #2b8fe0);
  border-color: transparent;
  color: #06142a;
  box-shadow: 0 6px 22px rgba(62, 198, 255, 0.3);
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
}
.btn.danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(255, 77, 94, 0.4);
  font-size: 13px;
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
  transform: none;
}
.icon-btn {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(23, 27, 46, 0.8);
  font-size: 16px;
}
.icon-btn.txt {
  font-weight: 900;
  font-size: 14px;
}
.back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}
.gold {
  color: var(--gold);
}
.close {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  font-size: 20px;
  line-height: 1;
}

/* ---------- thanh trên ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  flex: none;
}
.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 18, 32, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 900;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.stat.lives.hit {
  animation: shake 0.35s;
  border-color: var(--red);
}
@keyframes shake {
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}
.stat.gold b {
  color: var(--gold);
}
.top-r {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

/* ---------- sân ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* bảng tháp đang chọn */
.tpanel {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 8px;
  translate: -50% 0;
  width: min(360px, calc(100% - 16px));
  background: rgba(23, 27, 46, 0.96);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  animation: pop 0.18s ease-out;
}
.tpanel.at-top {
  bottom: auto;
  top: 8px;
}
.tpanel.at-left,
.tpanel.at-right {
  bottom: auto;
  top: 6px;
  translate: none;
  width: min(300px, 46%);
}
.tpanel.at-left {
  left: 6px;
}
.tpanel.at-right {
  left: auto;
  right: 6px;
}
@keyframes pop {
  from {
    transform: scale(0.94);
    opacity: 0;
  }
}
.tp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 34px;
}
.tp-ic {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 900;
}
.tp-head b {
  font-size: 16px;
}
.tp-lv {
  font-size: 12px;
  color: var(--gold);
  font-weight: 800;
}
.tp-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 8px 0;
  font-size: 12.5px;
  color: var(--muted);
}
.tp-stats b {
  color: var(--text);
}
.tp-stats i {
  font-style: normal;
  color: var(--green);
}
.tp-modes {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.tp-modes button {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.tp-modes button.on {
  background: var(--panel2);
  color: var(--text);
  border-color: var(--accent);
}
.tp-btns {
  display: flex;
  gap: 8px;
}
.tp-btns .btn {
  flex: 1;
  padding: 9px 8px;
}

/* ---------- thanh xây ---------- */
.bar {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 6px 8px 8px;
  align-items: stretch;
}
.towers {
  flex: 1;
  display: flex;
  gap: 6px;
  min-width: 0;
}
.tw,
.act {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  transition:
    transform 0.08s,
    border-color 0.15s,
    background 0.15s;
}
.tw:active,
.act:active {
  transform: scale(0.95);
}
.tw .sw {
  width: 30px;
  height: 30px;
}
.tw b {
  font-size: 12px;
  line-height: 1.2;
}
.tw small,
.act small {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.tw.on {
  border-color: var(--accent);
  background: var(--panel2);
  box-shadow: 0 0 0 2px rgba(62, 198, 255, 0.25);
}
.tw.poor small {
  color: var(--red);
}
.tw.poor .sw,
.tw.poor b {
  opacity: 0.5;
}
.tw.locked {
  opacity: 0.4;
}
.tw.locked small {
  color: var(--muted);
}
.tw kbd {
  position: absolute;
  left: 6px;
  top: 3px;
  font-family: inherit;
  font-size: 10px;
  color: var(--muted);
}
.act {
  flex: 0 0 86px;
}
.act .ic {
  font-size: 20px;
  line-height: 1.2;
}
.act small {
  color: var(--text);
}
.act.next {
  background: linear-gradient(180deg, #2c3a6a, #212a4d);
  border-color: rgba(62, 198, 255, 0.4);
}
.act.next.early small {
  color: var(--gold);
}
.act.next.busy {
  opacity: 0.6;
}
.act.meteor.on {
  border-color: #ff8a3d;
  background: #3a2620;
}
.act.meteor i {
  position: absolute;
  inset: auto 0 0 0;
  height: 0;
  border-radius: 0 0 14px 14px;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.act.meteor.cool {
  opacity: 0.65;
}

/* ---------- màn phủ ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
}
.sheet-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(8, 10, 20, 0.6);
  backdrop-filter: blur(3px);
}
.sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: pop 0.22s ease-out;
}
.sheet.wide {
  width: min(760px, 100%);
}
.sheet h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 900;
}
.sub {
  color: var(--muted);
  margin: 0 0 14px;
  font-size: 14px;
}
.btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}
.help-list {
  text-align: left;
  padding-left: 18px;
  margin: 8px 0 16px;
  font-size: 14px;
  line-height: 1.55;
}
.help-list li {
  margin-bottom: 4px;
}

/* ---------- sảnh ---------- */
.home {
  display: flex;
  flex-direction: column;
  overflow: auto;
  background:
    radial-gradient(ellipse 60% 40% at 50% 20%, rgba(62, 198, 255, 0.14), transparent 70%),
    radial-gradient(ellipse 40% 30% at 85% 90%, rgba(255, 154, 60, 0.1), transparent 70%),
    #0c0f1c;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.home-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.starbox {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: rgba(255, 207, 51, 0.12);
  border: 1px solid rgba(255, 207, 51, 0.35);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 900;
  color: var(--gold);
}
.starbox small {
  color: var(--muted);
  font-size: 12px;
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 4px 16px 28px;
  text-align: center;
}
.logo {
  margin: 6px 0 0;
  font-size: clamp(40px, 8vw, 66px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1px;
  text-shadow: 0 4px 30px rgba(62, 198, 255, 0.45);
}
.logo span {
  color: #ff9a3c;
  text-shadow: 0 4px 30px rgba(255, 154, 60, 0.5);
}
.tag {
  margin: 0;
  color: var(--muted);
  max-width: 480px;
  font-size: 15px;
}
.maps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: min(940px, 100%);
}
.map {
  position: relative;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
  text-align: left;
  transition:
    transform 0.12s,
    border-color 0.15s;
}
.map:hover:not(.locked) {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.map canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}
.map .mi {
  padding: 8px 10px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.map .mi b {
  font-size: 14px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.map .mi small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.map .st {
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--gold);
}
.map .st .off {
  color: rgba(255, 255, 255, 0.18);
}
.map.locked canvas {
  filter: grayscale(1) brightness(0.45);
}
.map .lock {
  position: absolute;
  inset: 0 0 auto 0;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  font-size: 28px;
}
.map .new-tw {
  position: absolute;
  left: 8px;
  top: 8px;
  font-size: 10px;
  font-weight: 900;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--gold);
}
.home-btns {
  display: flex;
  gap: 10px;
}
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-size: 12px;
  margin-left: 4px;
}

/* ---------- nâng cấp ---------- */
.upg-list {
  display: grid;
  gap: 8px;
  text-align: left;
  margin-bottom: 12px;
}
.urow {
  display: grid;
  grid-template-columns: 120px repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  background: var(--panel2);
  border-radius: 14px;
  padding: 8px 10px;
}
.urow .who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 14px;
}
.urow .who canvas {
  width: 30px;
  height: 30px;
  flex: none;
}
.unode {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 11px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  align-items: center;
}
.unode em {
  font-style: normal;
  color: var(--gold);
  font-weight: 900;
  white-space: nowrap;
}
.unode.own {
  border-color: rgba(77, 255, 136, 0.5);
  background: rgba(77, 255, 136, 0.1);
}
.unode.own em {
  color: var(--green);
}
.unode:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- kết thúc ---------- */
.res-title {
  font-size: 32px !important;
}
.res-title.win {
  color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 207, 51, 0.5);
}
.res-title.lose {
  color: var(--red);
}
.res-stars {
  font-size: 46px;
  letter-spacing: 6px;
  margin: 4px 0 6px;
}
.res-stars span {
  display: inline-block;
  color: rgba(255, 255, 255, 0.15);
}
.res-stars span.on {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 207, 51, 0.6);
  animation: starIn 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
}
@keyframes starIn {
  from {
    transform: scale(0) rotate(-90deg);
  }
}
.toast {
  position: absolute;
  left: 50%;
  top: 64px;
  translate: -50% 0;
  z-index: 30;
  background: rgba(15, 18, 32, 0.94);
  border: 1px solid var(--line);
  padding: 9px 16px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- điện thoại ---------- */
@media (max-width: 760px) {
  .maps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .urow {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .urow .who {
    grid-column: 1 / -1;
  }
  .unode {
    flex-direction: column;
    align-items: flex-start;
    font-size: 11.5px;
  }
  .stat {
    font-size: 13px;
    padding: 4px 9px;
    gap: 4px;
  }
  .top {
    gap: 5px;
    padding: 6px 8px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  .tw b {
    display: none;
  }
  .tw .sw {
    width: 28px;
    height: 28px;
  }
  .tw kbd {
    display: none;
  }
  .act {
    flex-basis: 62px;
  }
  .act small {
    font-size: 10px;
  }
}
@media (max-height: 480px) {
  .top {
    padding: 4px 8px;
  }
  .bar {
    padding: 4px 8px 6px;
  }
  .tw,
  .act {
    flex-direction: row;
    gap: 5px;
    padding: 4px 6px;
  }
  .tw .sw {
    width: 24px;
    height: 24px;
  }
  .tw b {
    display: none;
  }
  .act .ic {
    font-size: 16px;
  }
  .act {
    flex-basis: 96px;
  }
  .home-body {
    gap: 8px;
  }
  .logo {
    font-size: 36px;
  }
  .tag {
    display: none;
  }
  .maps {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .tpanel {
    bottom: 4px;
    padding: 8px 12px;
  }
  .tp-stats {
    margin: 4px 0;
  }
  .tp-modes {
    margin-bottom: 6px;
  }
}
