/* Pháo Thủ. The menu and lobby are cards on a sky; the match is a full-screen
   canvas with the HUD on top and the controls along the bottom. */
:root {
  --ink: #16324a;
  --muted: #4d6b84;
  --card: rgba(255, 255, 255, 0.86);
  --edge: rgba(255, 255, 255, 0.9);
  --blue: #2f7fd8;
  --green: #3fa34d;
  --red: #e2483d;
  --soft: 0 8px 24px rgba(20, 60, 100, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100dvh;
  background: linear-gradient(180deg, #5fb4ee 0%, #a9dcf7 55%, #dff3d6 80%, #8fd07a 100%) fixed;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- menu and lobby ---------- */
.menu, .lobby {
  max-width: 460px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.title { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 8px; }
.title .logo svg { display: block; width: 64px; height: 64px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2)); }
.title h1 { margin: 0; font-size: 38px; letter-spacing: -0.5px; color: #fff; text-shadow: 0 2px 0 #1f5f9e, 0 4px 14px rgba(0, 0, 0, 0.25); }
.tagline { margin: 0; text-align: center; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
.card { padding: 14px; border: 1px solid var(--edge); border-radius: 20px; background: var(--card); box-shadow: var(--soft); }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card p { margin: 0 0 10px; font-size: 14px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }
.btn { padding: 11px 14px; border: 0; border-radius: 14px; background: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.08); font-weight: 700; font-size: 16px; }
.btn.primary { background: linear-gradient(180deg, #4b9cf0, var(--blue)); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
input { font: inherit; font-size: 16px; padding: 11px 14px; border: 2px solid rgba(255, 255, 255, 0.9); border-radius: 14px; background: #fff; color: var(--ink); }
.join { display: flex; gap: 8px; margin-top: 10px; }
.join input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; font-weight: 800; text-align: center; }
.how summary { font-weight: 700; cursor: pointer; }
/* The account: a name typed in, or who's logged in. */
.account .field { color: var(--ink); text-shadow: none; }
.account .field input { border-color: #d7e6f2; }
.link.dark { color: var(--blue); text-shadow: none; padding: 8px 0 0; }
.account .me { display: flex; align-items: center; gap: 10px; }
.account .avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 20px; flex: 0 0 auto; }
.account .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account .who small { color: var(--muted); }
.account .who b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .me .link.dark { padding: 0; }
.screen-title { margin: 24px 0 0; text-align: center; font-size: 26px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 14px; }
.form input { border-color: #d7e6f2; }
.form .switch { margin: 0; text-align: center; font-size: 14px; }
.or { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }
.error { margin: 0; padding: 10px 14px; border-radius: 14px; background: #fee2e2; color: #991b1b; font-weight: 700; text-align: center; }
.note { margin: 0; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
.how ul { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.4; }
.foot { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; align-items: center; }
.link { padding: 4px 2px; border: 0; background: none; font-weight: 700; color: #fff; text-decoration: underline; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); font-size: 15px; }
.foot .muted { color: #fff; opacity: 0.8; font-size: 13px; }
.lobby h2 { margin: 24px 0 0; text-align: center; font-size: 22px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
.lobby > .muted { margin: 0; text-align: center; color: #fff; }
.code { display: inline-block; padding: 2px 12px; border-radius: 12px; background: #fff; color: var(--ink); letter-spacing: 6px; text-shadow: none; }
.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.players-list li, .standings li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px; background: var(--card); box-shadow: var(--soft); font-weight: 700; }
.players-list li small { margin-left: auto; color: var(--muted); }
.players-list li.me, .standings li.me { outline: 2px solid #fde047; }
.players-list .remove { border: 0; background: none; color: var(--muted); font-size: 16px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2); }

/* ---------- the match ---------- */
.game { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.top {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 0;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.players { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.chip { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; background: var(--card); box-shadow: var(--soft); font-size: 13px; max-width: 100%; }
.chip b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.chip .dot { width: 10px; height: 10px; }
.chip .hp { width: 38px; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.15); overflow: hidden; }
.chip .hp span { display: block; height: 100%; background: #4ade80; }
.chip.now { outline: 2px solid #fde047; }
.chip.out { opacity: 0.45; }
.wind { display: grid; grid-template-columns: auto auto auto; align-items: center; gap: 0 4px; padding: 5px 10px; border-radius: 14px; background: var(--card); box-shadow: var(--soft); font-size: 13px; }
.wind .label { font-weight: 700; }
.wind .arrow { display: inline-block; font-size: 16px; color: var(--blue); }
.wind .meter { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.12); overflow: hidden; margin-top: 3px; }
.wind .meter span { display: block; height: 100%; background: var(--blue); }
.clock { min-width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--card); box-shadow: var(--soft); font-weight: 800; font-size: 16px; }
.clock:empty { visibility: hidden; }
.clock.low { background: #fee2e2; color: var(--red); }
.quit { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--card); box-shadow: var(--soft); font-size: 16px; }
.banner {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(20, 50, 80, 0.78);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
.banner.show { animation: banner 1.6s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -40%) scale(0.9); } 12%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; } }

/* Controls: walk, weapons, angle, and a big Fire button with the power bar. */
.controls {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'walk aim' 'weapons weapons' 'fire fire';
  gap: 8px;
  padding: 8px;
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--soft);
  transition: opacity 200ms;
}
.controls.waiting { opacity: 0.55; }
.pad { display: flex; align-items: center; gap: 4px; }
.pad button { width: 46px; height: 46px; border: 0; border-radius: 14px; background: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); font-size: 18px; touch-action: none; }
.pad button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.walk { grid-area: walk; }
.walk-meter { flex: 1; max-width: 80px; }
.aim { grid-area: aim; }
.aim b { min-width: 42px; text-align: center; font-size: 17px; }
.walk-meter { width: 30px; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.12); overflow: hidden; }
.walk-meter span { display: block; height: 100%; background: var(--green); }
.weapons { grid-area: weapons; display: flex; gap: 4px; justify-content: center; min-width: 0; }
.weapon { flex: 1; max-width: 130px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 2px; border: 2px solid transparent; border-radius: 12px; background: #fff; font-size: 11px; line-height: 1.15; }
.weapon .icon { font-size: 16px; line-height: 1.1; }
.weapon b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.weapon small { color: var(--muted); font-size: 10px; }
.weapon.on { border-color: #f59e0b; background: #fff7e0; }
.weapon:disabled { opacity: 0.5; }
.fire {
  grid-area: fire;
  position: relative;
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #f06548, var(--red));
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 3px 0 #a72f25;
  overflow: hidden;
  touch-action: none;
}
.fire b { position: relative; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.fire .power { position: absolute; inset: 0; }
.fire .power span { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, rgba(255, 220, 90, 0.75), rgba(255, 255, 160, 0.9)); }
.fire .power i { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: rgba(255, 255, 255, 0.9); }
.fire:disabled { filter: grayscale(0.6); }

/* Wide screens: one row of controls. */
@media (min-width: 760px) {
  .controls { left: 50%; right: auto; transform: translateX(-50%); width: min(980px, calc(100% - 24px)); grid-template-columns: auto 1fr auto 220px; grid-template-areas: 'walk weapons aim fire'; }
  .weapon { font-size: 12px; }
}

/* ---------- sheets and pop-ups ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 30, 50, 0.4); }
.sheet .panel { width: min(420px, 100%); max-height: 86dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 18px; border-radius: 22px; background: #fff; box-shadow: var(--soft); }
.sheet h2 { margin: 0; text-align: center; font-size: 24px; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; }
.standings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.standings li { box-shadow: none; background: #f2f7fb; }
.standings li b { margin-left: auto; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 40, 60, 0.88);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- a new version is ready ---------- */
.update-banner {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  z-index: 45;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--soft);
  font-weight: 700;
}
.update-banner .link.dark { padding: 4px 2px; }
.btn.small { padding: 7px 12px; font-size: 14px; }

/* Five or six players: smaller chips, so they fit along the top of a phone. */
.players.many { gap: 4px; }
.players.many .chip { padding: 4px 7px; gap: 4px; font-size: 12px; }
.players.many .chip b { max-width: 64px; }
.players.many .chip .hp { width: 28px; }

/* ---------- open rooms ---------- */
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--blue); flex: none; }
.toggle span { display: flex; flex-direction: column; }
.toggle small { font-size: 13px; }
.open-rooms li .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.open-rooms li .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.open-rooms li .who small { color: var(--muted); margin: 0; }
.ask-banner { z-index: 46; }

/* ---------- room chat ---------- */
.chat-open { position: relative; }
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}
.chat-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--kb, 0px) + env(safe-area-inset-bottom));
  background: rgba(10, 30, 50, 0.35);
}
.chat-card {
  width: min(460px, 100%);
  max-height: min(70dvh, 560px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 12px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.chat-head { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; }
.chat-head h2 { margin: 0 0 0 4px; font-size: 18px; }
.chat-head .close { border: 0; background: none; font-size: 18px; color: var(--muted); padding: 4px 8px; }
.chat-empty { margin: 4px; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0 2px; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.chat-log:empty { display: none; }
.chat-log li { align-self: flex-start; max-width: 85%; padding: 7px 11px; border-radius: 14px; background: #eef4fa; overflow-wrap: anywhere; font-size: 15px; }
.chat-log li b { display: block; font-size: 12px; color: var(--muted); }
.chat-log li.mine { align-self: flex-end; background: #dcebfb; }
.chat-log li.system { align-self: center; background: none; padding: 2px 8px; font-size: 13px; color: var(--muted); text-align: center; }
.chat-quick { flex-shrink: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chat-quick .quick { flex: 0 0 auto; padding: 6px 12px; border: 1px solid #d6e2ee; border-radius: 999px; background: none; font-size: 14px; }
.chat-form { flex-shrink: 0; display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid #d6e2ee; border-radius: 12px; background: #f5f9fc; font-size: 16px; }
.chat-form .btn { padding: 10px 16px; font-size: 15px; border-radius: 12px; }
.chat-toast {
  position: fixed;
  z-index: 35;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--soft);
}
