/* Dai Chien Robot 3D - giao dien khoi vuong, nut day, mau tuoi cho tre 6-15 */

:root {
  --bg: #0b1220;
  --panel: rgba(16, 26, 46, 0.90);
  --panel-solid: #101a2e;
  --ink: #eef4ff;
  --muted: #93a4c4;
  --line: rgba(255, 255, 255, 0.12);

  --blue: #3b82f6;
  --blue-dark: #1d4ed8;
  --red: #ef4444;
  --red-dark: #b91c1c;
  --green: #22c55e;
  --green-dark: #15803d;
  --gold: #fbbf24;
  --gold-dark: #b45309;
  --purple: #a855f7;

  --r: 18px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-weight: 600;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#ui {
  position: fixed;
  inset: 0;
  display: grid;
  pointer-events: none;
}

.screen {
  grid-area: 1 / 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  background: radial-gradient(120% 90% at 50% 0%, rgba(11, 18, 32, 0.55), rgba(11, 18, 32, 0.88));
  backdrop-filter: blur(3px);
  animation: fade 0.22s ease both;
}

.screen.show { display: flex; }
.screen.no-bg { background: none; backdrop-filter: none; pointer-events: none; }

@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ─────────────────────────────────────────────────────────── panel & bar ── */

.panel {
  width: min(560px, 100%);
  margin: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  width: min(1000px, 100%);
  margin: 0 auto 14px;
  flex: none;
}

.bar h2 { margin: 0; font-size: clamp(18px, 3.4vw, 26px); letter-spacing: 0.02em; }

.btn-back {
  border: 0;
  background: rgba(255, 255, 255, 0.10);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.btn-back:hover { background: rgba(255, 255, 255, 0.18); }

.coins {
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  color: #2b1a00;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

/* ─────────────────────────────────────────────────────────────── man chinh ── */

.title {
  margin: 0;
  text-align: center;
  font-size: clamp(34px, 8vw, 60px);
  line-height: 0.92;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.45);
  background: linear-gradient(180deg, #fff, #93c5fd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title span {
  display: block;
  background: linear-gradient(180deg, #fde68a, #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle { text-align: center; color: var(--muted); margin: 6px 0 18px; font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input,
.join-row input {
  width: 100%;
  padding: 13px 15px;
  border-radius: 13px;
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
}
.field input:focus, .join-row input:focus { outline: 3px solid var(--blue); border-color: transparent; }

.btn-stack { display: grid; gap: 11px; }

.btn {
  border: 0;
  border-radius: 15px;
  padding: 14px 18px;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  text-align: left;
  transition: transform 0.08s ease, filter 0.15s ease;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35);
}
.btn b { display: block; font-size: 18px; }
.btn small { display: block; font-weight: 600; opacity: 0.85; font-size: 13px; margin-top: 3px; }
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: linear-gradient(180deg, #60a5fa, var(--blue-dark)); }
.btn-secondary { background: linear-gradient(180deg, #4ade80, var(--green-dark)); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  text-align: center;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.16); }
.btn-ghost.small { padding: 7px 12px; font-size: 13px; box-shadow: none; }
.btn-ghost.danger { color: #fca5a5; margin-top: 20px; }
.btn.big { font-size: 21px; padding: 17px; text-align: center; }

.stats-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}
.stats-strip span {
  background: rgba(255, 255, 255, 0.07);
  padding: 6px 11px;
  border-radius: 999px;
}

/* ────────────────────────────────────────────────────────────── cua hang ── */

.shop-grid, .pick-grid {
  width: min(1000px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  padding-bottom: 20px;
}

.rcard {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 15px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.rcard:hover { transform: translateY(-3px); }
.rcard.owned { border-color: rgba(34, 197, 94, 0.55); }
.rcard.selected { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.28); }
.rcard.locked { opacity: 0.62; }
.rcard.disabled { cursor: not-allowed; }

.rcard .rhead { display: flex; align-items: center; gap: 8px; }
.rcard .remoji { font-size: 30px; line-height: 1; }
.rcard .rname { font-size: 16px; font-weight: 800; }
.rcard .rtier { font-size: 11px; color: var(--muted); font-weight: 700; }

.rstats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.rstats b { color: var(--ink); font-variant-numeric: tabular-nums; }

.rperk {
  font-size: 11.5px;
  background: rgba(168, 85, 247, 0.20);
  border: 1px solid rgba(168, 85, 247, 0.42);
  color: #e9d5ff;
  padding: 5px 8px;
  border-radius: 9px;
  line-height: 1.35;
}
.rperk.none { background: rgba(255, 255, 255, 0.05); border-color: var(--line); color: var(--muted); }

.rprice {
  margin-top: auto;
  text-align: center;
  padding: 9px;
  border-radius: 11px;
  font-weight: 800;
  font-size: 14px;
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  color: #2b1a00;
}
.rprice.have { background: rgba(34, 197, 94, 0.22); color: #86efac; }
.rprice.sel { background: linear-gradient(180deg, #fde68a, #f59e0b); color: #2b1a00; }
.rprice.cant { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

.powerbar { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.powerbar i { display: block; height: 100%; background: linear-gradient(90deg, #4ade80, #fbbf24, #ef4444); }

/* ─────────────────────────────────────────────────────────── chon robot ── */

.versus {
  width: min(1000px, 100%);
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  flex: none;
}
.vs-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.vs-side.right { flex-direction: row-reverse; text-align: right; }
.vs-emoji { font-size: 38px; }
.vs-name { font-size: 17px; font-weight: 800; }
.vs-meta { font-size: 12px; color: var(--muted); }
.vs-tag { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.vs-tag.blue { background: rgba(59, 130, 246, 0.28); color: #bfdbfe; }
.vs-tag.red { background: rgba(239, 68, 68, 0.28); color: #fecaca; }
.vs-mid { font-size: 22px; font-weight: 900; color: var(--gold); }

.pick-actions {
  width: min(1000px, 100%);
  margin: 6px auto 0;
  position: sticky;
  bottom: 0;
  padding: 10px 0;
  background: linear-gradient(180deg, transparent, rgba(11, 18, 32, 0.92) 40%);
  flex: none;
}
.pick-actions .btn { width: 100%; }
.pick-grid { padding-bottom: 96px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 8px 0 0; min-height: 18px; }
.hint.err { color: #fca5a5; }

/* ────────────────────────────────────────────────────────── phong 2 nguoi ── */

.mp-panel { display: grid; gap: 14px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.join-row input {
  text-transform: uppercase;
  letter-spacing: 0.28em;
  text-align: center;
  font-size: 24px;
  font-weight: 900;
}

.room-code {
  text-align: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 15px;
  padding: 15px;
}
.room-code span { display: block; font-size: 12px; color: var(--muted); }
.room-code strong {
  display: block;
  font-size: clamp(40px, 12vw, 62px);
  letter-spacing: 0.16em;
  font-weight: 900;
  color: var(--gold);
  margin: 4px 0 10px;
}

.lobby-players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.lobby-slot {
  background: rgba(255, 255, 255, 0.07);
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  min-height: 96px;
  display: grid;
  align-content: center;
  gap: 4px;
}
.lobby-slot.filled { border-style: solid; border-color: rgba(34, 197, 94, 0.5); }
.lobby-slot .ls-name { font-size: 16px; font-weight: 800; }
.lobby-slot .ls-sub { font-size: 12px; color: var(--muted); }
.lobby-slot .ls-emoji { font-size: 30px; }
.lobby-vs { font-weight: 900; color: var(--gold); font-size: 18px; }

/* ───────────────────────────────────────────────────────────── HUD tran ── */

.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: start;
  width: min(1000px, 100%);
  margin: 0 auto;
  padding-right: 46px;   /* chua cho nut Thoat o goc phai, khong de de len ten robot */
  pointer-events: auto;
}

.fighter-hud { background: rgba(9, 15, 28, 0.72); border-radius: 14px; padding: 9px 12px; min-width: 0; }
.fighter-hud.right { text-align: right; }
.fh-name { font-size: 14px; font-weight: 800; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hp-bar {
  position: relative;
  height: 20px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.14);
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #4ade80, var(--green-dark));
  transition: width 0.18s ease;
}
.hp-fill.low { background: linear-gradient(180deg, #fbbf24, #d97706); }
.hp-fill.crit { background: linear-gradient(180deg, #f87171, var(--red-dark)); }
.hp-bar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  font-variant-numeric: tabular-nums;
}

.hud-clock { text-align: center; }
.clock {
  background: rgba(9, 15, 28, 0.78);
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.hud-sub { font-size: 11px; color: var(--muted); margin-top: 4px; min-height: 14px; }

.quit-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: rgba(9, 15, 28, 0.75);
  color: var(--ink);
  font-size: 17px; font-weight: 800;
  cursor: pointer; pointer-events: auto;
  z-index: 6;
}
.quit-btn:hover { background: rgba(239, 68, 68, 0.8); }

.key-hint {
  position: absolute;
  left: 50%; bottom: 16px;
  transform: translateX(-50%);
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
  background: rgba(9, 15, 28, 0.6);
  padding: 8px 16px; border-radius: 999px;
  font-size: 12.5px; color: var(--muted);
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.key-hint b { color: var(--ink); }
.key-hint.fade { opacity: 0; }

.countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: clamp(70px, 22vw, 170px);
  font-weight: 900; color: #fff;
  text-shadow: 0 8px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown span { display: block; animation: cdPop 0.8s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes cdPop {
  from { transform: scale(2.2); opacity: 0; }
  45% { transform: scale(1); opacity: 1; }
  to { transform: scale(0.86); opacity: 0; }
}

.net-stall {
  position: absolute;
  left: 50%; top: 42%;
  transform: translateX(-50%);
  background: rgba(9, 15, 28, 0.92);
  border: 2px solid var(--line);
  padding: 12px 22px; border-radius: 14px;
  font-size: 16px; font-weight: 800;
  pointer-events: none;
}

/* ────────────────────────────────────────────── can dieu khien ao ──────── */

#touch-controls { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

.stick-zone {
  position: absolute;
  bottom: 0;
  width: 42%;
  height: 56%;
  pointer-events: auto;
  touch-action: none;
}
.stick-zone.left { left: 0; }
.stick-zone.right { right: 0; }

.stick-label {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  white-space: nowrap;
}

.stick-base {
  position: absolute;
  width: 116px; height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  border: 2px solid rgba(255, 255, 255, 0.22);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.stick-base.aim { border-color: rgba(251, 191, 36, 0.45); background: rgba(251, 191, 36, 0.10); }
.stick-base.active { opacity: 1; }

.stick-nub {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.stick-nub.aim { background: rgba(251, 191, 36, 0.75); border-color: #fde047; }

.action-buttons {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  gap: 12px;
  pointer-events: auto;
  touch-action: none;
}
.abtn {
  width: 66px; height: 66px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.3);
  font-size: 27px;
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, filter 0.1s ease;
}
.abtn.down { transform: scale(0.9); filter: brightness(1.4); }
.abtn.blk { background: rgba(59, 130, 246, 0.55); }
.abtn.dsh { background: rgba(34, 197, 94, 0.55); }

.help-panel table.keys { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.help-panel table.keys td { padding: 5px 8px 5px 0; vertical-align: top; font-size: 14px; }
.help-panel table.keys td:first-child { white-space: nowrap; color: var(--gold); width: 42%; }

/* ────────────────────────────────────────────────────────────── ket qua ── */

.result-panel { text-align: center; }
.result-banner {
  font-size: clamp(32px, 9vw, 54px);
  font-weight: 900;
  letter-spacing: 0.03em;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.4);
  animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.result-banner.win { background: linear-gradient(180deg, #fde68a, #f59e0b); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-banner.lose { color: #94a3b8; }
.result-banner.draw { color: #a5b4fc; }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.result-sub { color: var(--muted); font-size: 14px; margin: 4px 0 16px; }

.chest-area { margin: 6px 0 14px; }
.chest {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  position: relative;
  width: 120px;
  height: 96px;
  margin: 0 auto;
  display: block;
  animation: chestIdle 1.6s ease-in-out infinite;
}
.chest-box {
  position: absolute;
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 56px;
  background: linear-gradient(180deg, #b45309, #7c2d12);
  border: 3px solid #451a03;
  border-radius: 6px;
}
.chest-lid {
  position: absolute;
  top: 12px;
  left: 4px;
  right: 4px;
  height: 40px;
  background: linear-gradient(180deg, #f59e0b, #b45309);
  border: 3px solid #451a03;
  border-radius: 10px 10px 4px 4px;
  transform-origin: bottom center;
  transition: transform 0.45s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.chest.open { animation: none; }
.chest.open .chest-lid { transform: rotateX(-125deg) translateY(-6px); }
@keyframes chestIdle { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-7px) rotate(1.5deg); } }
.chest-hint { font-size: 13px; color: var(--gold); margin: 10px 0 0; }

.reward-list { display: grid; gap: 8px; margin-bottom: 14px; }
.reward {
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 12px;
  padding: 11px;
  font-size: 15px;
  font-weight: 800;
  animation: pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.reward.robot { background: rgba(168, 85, 247, 0.16); border-color: rgba(168, 85, 247, 0.45); }

.result-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
}
.result-stats span { background: rgba(255, 255, 255, 0.07); padding: 5px 10px; border-radius: 999px; }

/* ─────────────────────────────────────────────────────────────── cach choi ── */

.help-panel { text-align: left; line-height: 1.62; font-weight: 500; }
.help-panel h3 { margin: 18px 0 7px; font-size: 17px; color: var(--gold); font-weight: 800; }
.help-panel h3:first-child { margin-top: 0; }
.help-panel ul { padding-left: 20px; margin: 0; }
.help-panel li { margin-bottom: 6px; }
.help-panel p { margin: 0 0 8px; color: #cbd5e1; }
.help-panel b { color: var(--ink); }

/* ───────────────────────────────────────────────────────────────── toast ── */

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(24px);
  background: rgba(9, 15, 28, 0.96);
  border: 2px solid var(--line);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .panel { padding: 17px; }
  .shop-grid, .pick-grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 9px; }
  .versus { grid-template-columns: 1fr; text-align: center; }
  .vs-side, .vs-side.right { flex-direction: column; text-align: center; }
  /* Man dung: dong ho len tren, hai thanh mau nam canh nhau cho do ton chieu cao */
  .hud-top { grid-template-columns: 1fr 1fr; gap: 6px; }
  .hud-clock { grid-column: 1 / -1; order: -1; }
  .clock { font-size: 18px; padding: 4px 12px; display: inline-block; }
  .key-hint { display: none; }
  .quit-btn { width: 34px; height: 34px; }
  .fighter-hud { padding: 6px 9px; }
  .fh-name { font-size: 11px; margin-bottom: 4px; }
  .hp-bar { height: 16px; }
  .hp-bar span { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
