@font-face {
  font-family: 'VT323';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/VT323-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/PressStart2P-latin.woff2') format('woff2');
}
:root {
  --p1: #00f0ff;
  --p2: #ff2a6d;
  --p3: #b388ff;
  --p4: #7af7a7;
  --ui-bg: #0a0518;
  --ui-border: #f4a261;
  --ui-text: #f4e3b2;
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
html, body {
  width: 100%; height: 100%; max-height: 100dvh;
  background: #000;
  color: var(--ui-text);
  font-family: 'VT323', ui-monospace, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}
body {
  display: flex;
  flex-direction: column;
  margin: 0;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  z-index: 300;
  padding: 8px 12px;
  background: var(--ui-border);
  color: #000;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  text-decoration: none;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  outline: 3px solid var(--p1);
  outline-offset: 2px;
}

.app {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Topbar overlays the top of the canvas. Translucent so action stays visible. */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  min-height: 32px;
  flex-wrap: wrap;
  background: linear-gradient(rgba(10, 5, 24, 0.78), rgba(10, 5, 24, 0));
  border-bottom: 1px solid rgba(244, 162, 97, 0.4);
  pointer-events: auto;
}
.hp-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  flex: 1 1 180px;
  min-width: 0;
}
.hp-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hp-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hp-label.p1 { color: var(--p1); }
.hp-label.p2 { color: var(--p2); }
.hp-label.p3 { color: var(--p3); }
.hp-label.p4 { color: var(--p4); }
.hp-label.cpu { color: #8a7baa; }
.hp-bar { height: 6px; background: #1f1330; border: 1px solid #444; }
.hp-fill { height: 100%; transition: width .25s; }
.hp-fill.p1 { background: var(--p1); box-shadow: 0 0 4px var(--p1); }
.hp-fill.p2 { background: var(--p2); box-shadow: 0 0 4px var(--p2); }
.hp-fill.p3 { background: var(--p3); box-shadow: 0 0 4px var(--p3); }
.hp-fill.p4 { background: var(--p4); box-shadow: 0 0 4px var(--p4); }
.hp-fill.dead { background: #333; box-shadow: none; width: 0% !important; }
.hp-fill.heal-flash { animation: hp-heal-flash 0.7s ease-out; }
@keyframes hp-heal-flash {
  0% { box-shadow: 0 0 14px #3df58a, 0 0 4px #3df58a; }
  100% { box-shadow: 0 0 4px currentColor; }
}
.center-info {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 96px;
}
.turn-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  padding: 3px 8px;
  border: 1px solid;
  background: #000;
  text-align: center;
  letter-spacing: 1px;
}
.turn-badge.p1 { color: var(--p1); border-color: var(--p1); text-shadow: 0 0 4px var(--p1); }
.turn-badge.p2 { color: var(--p2); border-color: var(--p2); text-shadow: 0 0 4px var(--p2); }
.turn-badge.p3 { color: var(--p3); border-color: var(--p3); text-shadow: 0 0 4px var(--p3); }
.turn-badge.p4 { color: var(--p4); border-color: var(--p4); text-shadow: 0 0 4px var(--p4); }
.wind { font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--ui-border); }
.reset-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 8px;
  background: #2a1f3d;
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  cursor: pointer;
  flex-shrink: 0;
}
.reset-btn:active { background: var(--ui-border); color: #000; }
.reset-btn:focus-visible { outline: 2px solid var(--p1); outline-offset: 2px; }

.main {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

/* Dock overlays the bottom edge of the canvas, full-width and translucent so
 * tanks behind it stay readable. Sits above gameplay layers (z-index 40). */
.control-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 4px 8px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  background: linear-gradient(rgba(10, 5, 24, 0), rgba(10, 5, 24, 0.78));
  pointer-events: auto;
}
.control-dock.hidden { display: none; }

.dock-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.dock-hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 14px;
}

.weapon-group, .angle-group, .power-group, .util-group {
  display: flex;
  align-items: center;
  gap: 5px;
}
.util-group { gap: 6px; }

.weapon-group label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: var(--ui-border);
}
.weapon-select {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 15px;
  padding: 4px 6px;
  background: #000;
  color: var(--ui-text);
  border: 2px solid #4a3f6a;
  min-height: 36px;
  width: 9rem;
}
.weapon-select:focus { outline: 2px solid var(--p1); outline-offset: 2px; }

.util-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  width: 100%;
}
.util-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 6px 8px;
  background: #2a1f3d;
  color: #b388ff;
  border: 1px solid #b388ff;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 0 8px rgba(179, 136, 255, 0.25);
}
.util-btn:active { background: #b388ff; color: #000; }
.util-btn.armed {
  background: #b388ff;
  color: #000;
  box-shadow: 0 0 14px rgba(179, 136, 255, 0.6);
}
.util-btn[hidden] { display: none !important; }
.util-btn:focus-visible { outline: 2px solid #b388ff; outline-offset: 2px; }
.util-btn.jetpack {
  color: #ffb070;
  border-color: #ffb070;
  box-shadow: 0 0 8px rgba(255, 176, 112, 0.25);
}
.util-btn.jetpack:active { background: #ffb070; color: #000; }
.util-btn.jetpack.armed { background: #ffb070; color: #000; box-shadow: 0 0 14px rgba(255, 176, 112, 0.6); }
.util-btn.shop {
  color: #ffd166;
  border-color: #ffd166;
  box-shadow: 0 0 8px rgba(255, 209, 102, 0.25);
}
.util-btn.shop:active { background: #ffd166; color: #000; }
.util-btn.shop.armed { background: #ffd166; color: #000; box-shadow: 0 0 14px rgba(255, 209, 102, 0.6); }
.util-hint.jetpack { color: #ffb070; }
.util-hint {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 13px;
  color: #b388ff;
}
.util-hint[hidden] { display: none !important; }
.canvas-wrap.teleport-aim {
  cursor: crosshair;
}

.shop-modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 22, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}
.shop-modal[hidden] { display: none; }
.shop-card {
  background: #1a0f2e;
  border: 2px solid #ffd166;
  box-shadow: 0 0 32px rgba(255, 209, 102, 0.35);
  padding: 14px 16px;
  width: min(360px, 100%);
  max-height: 80vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.shop-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.shop-header h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: #ffd166;
  margin: 0;
  letter-spacing: 1px;
  flex: 1;
}
.shop-balance {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 16px;
  color: #ffd166;
}
.shop-close {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  background: transparent;
  color: #ffd166;
  border: 1px solid #ffd166;
  padding: 4px 8px;
  cursor: pointer;
}
.shop-close:active { background: #ffd166; color: #000; }
.shop-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #3a2a55;
  background: #221538;
}
.shop-item-name {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 15px;
  color: #e8ddff;
  flex: 1;
}
.shop-item-owned {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 13px;
  color: #b388ff;
  min-width: 28px;
  text-align: right;
}
.shop-buy {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: #2a1f3d;
  color: #ffd166;
  border: 1px solid #ffd166;
  padding: 6px 8px;
  cursor: pointer;
  letter-spacing: 0.5px;
  min-width: 60px;
}
.shop-buy:active { background: #ffd166; color: #000; }
.shop-buy:disabled {
  color: #5a4a78;
  border-color: #3a2a55;
  cursor: not-allowed;
  box-shadow: none;
}
.shop-hint {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 12px;
  color: #8a7aa8;
  text-align: center;
  margin: 0;
}

.chat-panel {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}
.chat-panel[hidden] { display: none; }
.chat-panel * { pointer-events: auto; }
.chat-toggle {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 16px;
  padding: 6px 10px;
  background: rgba(10, 5, 24, 0.85);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  cursor: pointer;
  position: relative;
  border-radius: 4px;
}
.chat-toggle:focus-visible { outline: 2px solid var(--p1); outline-offset: 2px; }
.chat-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--p2);
  color: #000;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-badge[hidden] { display: none; }
.chat-body {
  display: flex;
  flex-direction: column;
  width: min(36vw, 320px);
  height: min(40vh, 220px);
  background: rgba(10, 5, 24, 0.92);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  overflow: hidden;
}
.chat-body[hidden] { display: none; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.25;
  scrollbar-width: thin;
}
.chat-log .row { word-wrap: break-word; margin-bottom: 2px; }
.chat-log .row .name {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  margin-right: 4px;
}
.chat-log .row.system { color: #6a5b8a; font-style: italic; }
.chat-log .row.system .name { color: #6a5b8a; }
.chat-log .row.muted { display: none; }
.chat-log .name.p1 { color: var(--p1); }
.chat-log .name.p2 { color: var(--p2); }
.chat-log .name.p3 { color: var(--p3); }
.chat-log .name.p4 { color: var(--p4); }
.chat-log .row .mute-btn {
  background: transparent;
  border: 1px solid #4a3f6a;
  color: #6a5b8a;
  font-size: 9px;
  padding: 0 4px;
  margin-left: 4px;
  cursor: pointer;
}
.chat-log .row .mute-btn:hover { color: var(--ui-text); border-color: var(--ui-border); }
.chat-form {
  display: flex;
  border-top: 1px solid #2a1f3d;
}
.chat-input {
  flex: 1;
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 14px;
  padding: 6px 8px;
  background: #000;
  color: var(--ui-text);
  border: none;
  outline: none;
}
.chat-input:focus { background: #110820; }
.chat-send {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 0 12px;
  background: #2a1f3d;
  color: var(--ui-text);
  border: none;
  border-left: 1px solid #2a1f3d;
  cursor: pointer;
}
.chat-send:active { background: var(--ui-border); color: #000; }

.angle-label, .power-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: var(--ui-border);
  letter-spacing: 0.5px;
}
.angle-btn.slot0 { color: var(--p1); border-color: var(--p1); box-shadow: 0 0 10px rgba(0,240,255,0.15); }
.angle-btn.slot0:active { background: var(--p1); color: #000; }
.angle-btn.slot1 { color: var(--p2); border-color: var(--p2); box-shadow: 0 0 10px rgba(255,42,109,0.15); }
.angle-btn.slot1:active { background: var(--p2); color: #000; }
.angle-btn.slot2 { color: var(--p3); border-color: var(--p3); box-shadow: 0 0 10px rgba(179,136,255,0.15); }
.angle-btn.slot2:active { background: var(--p3); color: #000; }
.angle-btn.slot3 { color: var(--p4); border-color: var(--p4); box-shadow: 0 0 10px rgba(122,247,167,0.15); }
.angle-btn {
  width: 40px;
  height: 36px;
  font-size: 16px;
  background: #1a1430;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Press Start 2P', monospace;
  touch-action: none;
}
.angle-btn:focus-visible { outline: 2px solid var(--p1); outline-offset: 2px; }
.angle-display {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--ui-text);
  background: #000;
  border: 1px solid var(--ui-border);
  padding: 4px 3px;
  min-width: 44px;
  text-align: center;
}

.fire-btn {
  --charge: 0%;
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #2a0915;
  border: 2px solid var(--p2);
  color: var(--p2);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(255,42,109,0.4);
  touch-action: none;
}
.fire-btn::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--charge);
  background: linear-gradient(to top, #2a8c3a 0%, #ffd166 55%, #ff2a6d 100%);
  transition: height 0.04s linear;
  z-index: 0;
}
.fire-btn span {
  position: relative;
  z-index: 1;
  text-shadow: 0 0 4px #000, 0 0 4px #000, 0 0 4px #000;
  letter-spacing: 1px;
}
.fire-btn.p1 {
  border-width: 2px;
  border-color: var(--p1);
  color: var(--p1);
  background: #051820;
  box-shadow: 0 0 20px rgba(0,240,255,0.35);
}
.fire-btn.slot2 {
  border-width: 2px;
  border-color: var(--p3);
  color: var(--p3);
  background: #140a20;
  box-shadow: 0 0 20px rgba(179,136,255,0.35);
}
.fire-btn.slot3 {
  border-width: 2px;
  border-color: var(--p4);
  color: var(--p4);
  background: #062010;
  box-shadow: 0 0 20px rgba(122,247,167,0.3);
}
.fire-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.fire-btn:focus-visible:not(:disabled) {
  outline: 2px solid var(--p2);
  outline-offset: 2px;
}
.fire-btn.p1:focus-visible:not(:disabled) { outline-color: var(--p1); }
.fire-btn.slot2:focus-visible:not(:disabled) { outline-color: var(--p3); }
.fire-btn.slot3:focus-visible:not(:disabled) { outline-color: var(--p4); }
.power-readout {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--ui-text);
  background: #000;
  border: 1px solid var(--ui-border);
  padding: 3px 4px;
  min-width: 44px;
  text-align: center;
}
.hint {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #6a5b8a;
  letter-spacing: 0.5px;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #000;
}
canvas {
  width: 100%;
  height: 100%;
  /* No aspect-ratio cap: stretch to fill the viewport on any device. The
   * internal 900x420 drawing buffer is unaffected; only display dimensions
   * scale. Click-to-canvas math in input.ts already converts via
   * canvas.width / rect.width so coordinates stay consistent. */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  touch-action: none;
}

.rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--ui-bg);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  text-align: center;
  padding: 30px;
}
.rotate-hint .icon {
  font-size: 64px;
  animation: spin 2.4s ease-in-out infinite;
  transform-origin: center;
}
.rotate-hint .text {
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  color: var(--ui-border);
  line-height: 1.6;
}
@keyframes spin {
  0%, 40% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (max-width: 820px) {
  .rotate-hint { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  .rotate-hint .icon { animation: none; }
}
.netstat {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 12px;
  color: #8a7baa;
  text-align: center;
  max-width: 132px;
  line-height: 1.25;
}

.lobby {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 18px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background: rgba(10, 5, 24, 0.94);
  text-align: center;
}
.lobby.hidden { display: none; }
.lobby h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(11px, 2.8vw, 15px);
  color: var(--ui-border);
  letter-spacing: 2px;
  text-shadow: 0 0 12px rgba(244, 162, 97, 0.35);
}
.lobby p.lobby-lead {
  font-size: 18px;
  color: #8a7baa;
  max-width: 22rem;
  line-height: 1.35;
}
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 20rem);
}
.lobby-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 12px 14px;
  background: #2a1f3d;
  color: var(--ui-text);
  border: 2px solid var(--ui-border);
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
  min-height: 44px;
}
.lobby-btn:active { background: var(--ui-border); color: #000; }
.lobby-btn:focus-visible { outline: 2px solid var(--p1); outline-offset: 3px; }
.lobby-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
}
.lobby-row label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.lobby-input {
  flex: 1 1 140px;
  min-width: 0;
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 20px;
  padding: 10px 12px;
  background: #000;
  color: var(--ui-text);
  border: 2px solid #4a3f6a;
  min-height: 44px;
}
.lobby-input:focus {
  outline: none;
  border-color: var(--p1);
  box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.25);
}
.lobby-row .lobby-btn { flex: 0 0 auto; width: auto; min-width: 44px; }
.lobby-err {
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 17px;
  color: #ff6b8a;
  min-height: 1.35em;
  max-width: 22rem;
}
.lobby-hint {
  font-size: 15px;
  color: #5c4f78;
  min-height: 1.25em;
}
.lobby-legal {
  margin-top: 10px;
  text-align: center;
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 16px;
  color: #6a5b8a;
}
.lobby-legal a {
  color: var(--ui-border);
}
.lobby-legal a:focus-visible {
  outline: 2px solid var(--p1);
  outline-offset: 3px;
}
