/* ============================================================
   TANK BATTLE — core layout & battlefield styling
   ============================================================ */
:root {
  --sky-top: #4aa7e8;
  --sky-mid: #7cc4f2;
  --sky-low: #b8e3fb;
  --ink: #0b1119;
  --panel: #16222f;
  --panel-2: #1d2d3e;
  --panel-edge: #2c4258;
  --text: #eaf4ff;
  --muted: #9db8cf;
  --accent: #ffb02e;
  --accent-2: #ffd23e;
  --green: #59b93c;
  --green-dark: #35771f;
  --red: #e8503a;
  --blue: #3f86e0;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-pop: 0 10px 30px rgba(4, 10, 18, .45);
  --font-stack: "Trebuchet MS", "Segoe UI", Verdana, Arial, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-stack);
  color: var(--text);
  background:
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-low) 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

#game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

/* ---------------- HUD ---------------- */
#hud {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 18px);
  padding: 8px clamp(8px, 1.5vw, 16px);
  background: linear-gradient(180deg, rgba(11, 17, 25, .92), rgba(15, 24, 34, .88));
  border-bottom: 3px solid var(--ink);
  box-shadow: 0 4px 14px rgba(4, 10, 18, .35);
  z-index: 20;
}

#hud.hud-hidden {
  display: none;
}

/* ---------------- Stage / battlefield ---------------- */
#stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: clamp(6px, 1.2vmin, 14px);
}

#stage {
  position: relative;
  /* exact size set from JS to preserve world aspect ratio */
  border-radius: 14px;
  border: 4px solid #101820;
  outline: 2px solid rgba(255, 255, 255, .18);
  box-shadow: 0 18px 44px rgba(4, 10, 18, .5), 0 4px 12px rgba(4, 10, 18, .35);
  overflow: hidden;
  background: #87a956;
  /* grass tone while loading */
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ---------------- Banner (round intro etc.) ---------------- */
#banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(1);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

#banner.banner-hidden {
  animation: bannerOut .45s ease forwards;
}

#banner.banner-show {
  animation: bannerIn 2s cubic-bezier(.2, 1.4, .4, 1) forwards;
}

@keyframes bannerIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.3);
  }

  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }

  20% {
    transform: translate(-50%, -50%) scale(1);
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(1.05);
  }
}

@keyframes bannerOut {
  to {
    opacity: 0;
  }
}

#banner-title {
  font-size: clamp(34px, 8vmin, 84px);
  font-weight: 900;
  letter-spacing: .06em;
  color: var(--accent-2);
  text-shadow:
    0 3px 0 #7a4a00, 0 6px 0 rgba(0, 0, 0, .55),
    -2px -2px 0 rgba(0, 0, 0, .35), 2px -2px 0 rgba(0, 0, 0, .35),
    -2px 2px 0 rgba(0, 0, 0, .35), 2px 2px 0 rgba(0, 0, 0, .35),
    0 14px 28px rgba(0, 0, 0, .5);
}

#banner-sub {
  margin-top: 4px;
  font-size: clamp(13px, 2.6vmin, 22px);
  font-weight: 700;
  letter-spacing: .35em;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6), 0 8px 18px rgba(0, 0, 0, .5);
}

/* ---------------- Dock (bottom bar) ---------------- */
#dock {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(13, 20, 29, .94), rgba(9, 14, 21, .96));
  border-top: 3px solid var(--ink);
}

#footer-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px clamp(10px, 2vw, 20px);
}

/* ---------------- On-screen drive pad (desktop friendly) ---------------- */
#drive-pad {
  display: grid;
  grid-template-columns: repeat(3, clamp(44px, 4vw, 54px));
  grid-template-rows: repeat(2, clamp(40px, 3.6vw, 48px));
  gap: 6px;
  padding: 8px clamp(12px, 2vw, 24px) 8px 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 3px solid rgba(255, 255, 255, .14);
  border-radius: 12px;
  background: linear-gradient(180deg, #35495f 0%, #1c2938 100%);
  color: #cfe6ff;
  cursor: pointer;
  box-shadow:
    0 4px 0 #0b1119,
    inset 0 2px 6px rgba(255, 255, 255, .18),
    0 8px 16px rgba(0, 0, 0, .4);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .05s ease, box-shadow .05s ease, background .05s ease;
}

.dp-btn svg {
  width: 42%;
  height: 42%;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .5));
}

.dp-btn.dp-active,
.dp-btn:active {
  transform: translateY(3px);
  border-color: #5e130a;
  background: linear-gradient(180deg, #ff8b3d 0%, #e2372a 55%, #b52117 100%);
  color: #fff;
  box-shadow:
    0 1px 0 #6d150c,
    inset 0 2px 6px rgba(255, 255, 255, .25);
}

.dp-up    { grid-column: 2; grid-row: 1; }
.dp-left  { grid-column: 1; grid-row: 2; }
.dp-down  { grid-column: 2; grid-row: 2; }
.dp-right { grid-column: 3; grid-row: 2; }

/* once real touch controls appear they take over the dock */
#touch-controls.touch-on~#footer-bar,
#touch-controls.touch-on~#drive-pad {
  display: none;
}

.hint-key {
  color: var(--muted);
  font-size: clamp(10px, 1.3vw, 13px);
  font-weight: 700;
  letter-spacing: .06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- Touch controls ---------------- */
#touch-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(12px, 3vw, 26px) 4px;
  touch-action: none;
}

#touch-controls.touch-on {
  display: flex;
}

#joy-zone {
  position: relative;
  width: min(46vw, 240px);
  height: clamp(120px, 20vh, 170px);
  touch-action: none;
}

#joy-base {
  position: absolute;
  left: 18px;
  bottom: 6px;
  width: clamp(104px, 30vw, 132px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .22), transparent 42%),
    repeating-conic-gradient(rgba(255, 255, 255, .05) 0 9deg, transparent 9deg 18deg),
    radial-gradient(circle at 50% 50%, #33475c, #1a2634 72%);
  border: 3px solid rgba(255, 255, 255, .16);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, .55), 0 6px 16px rgba(0, 0, 0, .4);
}

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 32% 26%, #9fdcff 0%, #4fa3d8 38%, #2a5f8a 78%);
  border: 3px solid rgba(255, 255, 255, .35);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .5), inset 0 -6px 10px rgba(0, 0, 0, .35);
  transition: transform .06s ease-out;
  will-change: transform;
}

#joy-base.joy-live {
  border-color: var(--accent);
}

#btn-fire {
  width: clamp(88px, 24vw, 116px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid #5e130a;
  color: #fff;
  font-family: inherit;
  font-weight: 900;
  font-size: clamp(16px, 4.4vw, 22px);
  letter-spacing: .12em;
  cursor: pointer;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, .5), transparent 36%),
    radial-gradient(circle at 50% 118%, #ff8b3d 8%, transparent 52%),
    linear-gradient(180deg, #ff6a3d 0%, #e2372a 46%, #a81d12 100%);
  box-shadow: 0 8px 0 #6d150c, 0 14px 24px rgba(0, 0, 0, .5), inset 0 2px 8px rgba(255, 255, 255, .35);
  touch-action: none;
  transition: transform .05s ease, box-shadow .05s ease;
}

#btn-fire:active,
#btn-fire.firing {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #6d150c, 0 6px 14px rgba(0, 0, 0, .5), inset 0 2px 8px rgba(255, 255, 255, .3);
}