:root {
  --hot: #ff3b30;
  --gold: #ffd60a;
  --ink: #1a1a1a;
  --paper: #fff8e7;
  --brick: #b34b3a;
  --char-shirt: #d83a3a;
  --char-pants: #2b4a8b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: 'Space Mono', monospace;
  color: var(--paper);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
}
#game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — accounts for mobile browser chrome */
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: none;
}
/* Overlays themselves get a normal cursor. Don't cascade to all children — that
   breaks iOS Safari tap hit-testing. */
.overlay { cursor: default; }
.overlay button, .overlay .btn {
  cursor: pointer;
  /* Override the body's `touch-action: none` so iOS delivers tap events */
  touch-action: manipulation;
  pointer-events: auto;
  /* Larger touch hitbox without changing visual size */
  -webkit-tap-highlight-color: rgba(255, 214, 10, 0.4);
}
.swap-btn {
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
}

/* HUD */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
  font-family: 'Rubik Mono One', sans-serif;
  gap: 10px;
}
.hud-block {
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  border: 3px solid var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  line-height: 1.2;
}
.hud-block .label { font-size: 9px; opacity: 0.7; display: block; margin-bottom: 2px; }
.hud-block .val { font-size: 20px; color: var(--gold); }
.hud-block.swap .val { color: #7ad7f0; }
.hud-block.swap.ready { animation: pulse-blue 1.2s infinite; }
@keyframes pulse-blue {
  0%, 100% { box-shadow: 4px 4px 0 var(--ink); }
  50% { box-shadow: 4px 4px 0 var(--ink), 0 0 14px #7ad7f0; }
}
.hud-block.swap.spent .val { color: #555; }
.hud-right { text-align: right; }

/* Mobile HUD — compact, tighter spacing, smaller text */
@media (max-width: 600px) {
  .hud {
    padding: 8px 8px;
    gap: 5px;
  }
  .hud-block {
    padding: 5px 7px;
    font-size: 10px;
    border-width: 2px;
    box-shadow: 2px 2px 0 var(--ink);
    letter-spacing: 0.04em;
  }
  .hud-block .label {
    font-size: 7px;
    margin-bottom: 1px;
  }
  .hud-block .val { font-size: 14px; }
  .hud-block.swap.ready {
    animation: pulse-blue-mobile 1.2s infinite;
  }
  @keyframes pulse-blue-mobile {
    0%, 100% { box-shadow: 2px 2px 0 var(--ink); }
    50% { box-shadow: 2px 2px 0 var(--ink), 0 0 10px #7ad7f0; }
  }
}

/* Boss bar */
.boss-bar-wrap {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 80vw);
  z-index: 9;
  pointer-events: none;
  display: none;
}
@media (max-width: 600px) {
  .boss-bar-wrap {
    top: 50px;
    width: 92vw;
  }
  .boss-name {
    font-size: 11px !important;
  }
  .boss-bar {
    height: 12px !important;
    border-width: 2px !important;
    box-shadow: 2px 2px 0 var(--ink) !important;
  }
}
.boss-bar-wrap.visible { display: block; animation: slide-down 0.4s ease-out; }
@keyframes slide-down {
  from { transform: translate(-50%, -30px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.boss-name {
  font-family: 'Rubik Mono One', sans-serif;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--ink);
  letter-spacing: 0.12em;
  font-size: 14px;
  text-align: center;
  margin-bottom: 4px;
}
.boss-bar {
  width: 100%;
  height: 18px;
  background: var(--ink);
  border: 3px solid var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  overflow: hidden;
}
.boss-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--hot), #ff8c2a, var(--gold));
  transition: width 0.25s;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.3);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  text-align: center;
  padding: 20px;
  overflow-y: auto;
}
.overlay.hidden { display: none; }

/* Start screen layout */
.start-grid {
  display: flex;
  align-items: center;
  gap: 30px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.start-left { text-align: left; }
@media (max-width: 600px) {
  .start-left { text-align: center; }
  .start-grid { gap: 12px; margin-bottom: 4px; }
  .overlay {
    padding: 12px;
    align-items: center;
    justify-content: flex-start;
  }
  .overlay.hidden { display: none !important; }
  /* iOS safe-area padding so content doesn't hide under the home indicator / notch */
  #start-screen, #gameover-screen, #pause-screen {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: calc(max(20px, env(safe-area-inset-bottom)) + 20px);
  }
  /* CRITICAL: reorder children of the start screen so START button sits high.
     Default visual stacking on mobile becomes:
       1. Title block (SHIT/SUM)
       2. Subtitle (Swap or Die)
       3. Character thumbnail
       4. START button         <- thumb-reachable!
       5. Controls card
       6. Best-wave/best-score line  */
  #start-screen { display: flex; flex-direction: column; }
  #start-screen > .start-grid { order: 1; }
  #start-screen > .controls-card { order: 3; }
  #start-screen > #start-btn    { order: 2; margin-bottom: 14px; }
  #start-screen > div:last-child { order: 4; } /* best wave/score line */

  .title {
    font-size: clamp(36px, 11vw, 64px) !important;
    text-shadow: 3px 3px 0 #5a3a1a, 5px 5px 0 var(--ink);
    margin-bottom: 4px;
  }
  .subtitle {
    font-size: 13px !important;
    padding: 5px 12px;
    box-shadow: 4px 4px 0 var(--ink);
    margin-bottom: 4px;
  }
  .locale-tag {
    font-size: 9px;
    margin-top: 6px;
    margin-bottom: 4px;
  }
}

.title {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(48px, 11vw, 120px);
  color: var(--gold);
  text-shadow: 4px 4px 0 #5a3a1a, 8px 8px 0 var(--ink);
  letter-spacing: 0.02em;
  line-height: 0.9;
  transform: rotate(-2deg);
  margin-bottom: 8px;
}
.subtitle {
  display: inline-block;
  font-family: 'Rubik Mono One', sans-serif;
  font-size: clamp(14px, 2.5vw, 22px);
  color: var(--paper);
  background: var(--hot);
  padding: 8px 18px;
  border: 3px solid var(--paper);
  box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(1deg);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.locale-tag {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  opacity: 0.7;
  letter-spacing: 0.1em;
  margin-top: 14px;
}

/* Character thumbnail — full body portrait card */
.char-thumb-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.char-thumb-frame {
  width: clamp(140px, 18vw, 200px);
  height: clamp(260px, 34vw, 380px);
  border-radius: 16px;
  overflow: hidden;
  border: 5px solid var(--gold);
  box-shadow: 6px 6px 0 var(--ink), inset 0 0 0 3px var(--ink);
  background: linear-gradient(180deg, #c4e4f0 0%, #f4dba6 70%, #b34b3a 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px 4px 0;
}
.char-thumb-frame img {
  width: auto;
  height: 96%;
  object-fit: contain;
  display: block;
}
.char-thumb-name {
  font-family: 'Bungee', sans-serif;
  background: var(--gold);
  color: var(--ink);
  padding: 4px 16px;
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--paper);
  letter-spacing: 0.1em;
  font-size: 14px;
  transform: rotate(-2deg);
}
@media (max-width: 600px) {
  .char-thumb-frame {
    width: 110px;
    height: 180px;
    border-width: 3px;
    box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 2px var(--ink);
  }
  .char-thumb-name {
    font-size: 11px;
    padding: 3px 10px;
    border-width: 2px;
  }
}

.controls-card {
  background: var(--paper);
  color: var(--ink);
  padding: 14px 20px;
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--gold);
  margin: 18px 0 20px;
  font-size: 12px;
  line-height: 1.6;
  max-width: 420px;
  text-align: left;
}
.controls-card strong {
  font-family: 'Rubik Mono One', sans-serif;
  color: var(--hot);
  display: block;
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  font-size: 11px;
  margin-top: 8px;
}
.controls-card strong:first-child { margin-top: 0; }
.controls-card .row { display: flex; justify-content: space-between; gap: 10px; }
.controls-card kbd {
  background: var(--ink);
  color: var(--paper);
  padding: 1px 7px;
  border-radius: 3px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
}
.controls-card .warn { color: #b34b3a; font-weight: bold; }
@media (max-width: 600px) {
  .controls-card {
    padding: 10px 14px;
    font-size: 10px;
    line-height: 1.5;
    margin: 10px 0 14px;
    box-shadow: 3px 3px 0 var(--gold);
    border-width: 2px;
    max-width: 100%;
  }
  .controls-card strong { font-size: 10px; margin-top: 6px; }
  .controls-card kbd { font-size: 9px; padding: 1px 5px; }
}

.btn {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(20px, 4vw, 32px);
  background: var(--gold);
  color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--paper);
  padding: 12px 32px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--paper); }
.btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--paper); }
.btn.danger { background: var(--hot); color: var(--paper); }
@media (max-width: 600px) {
  .btn {
    font-size: 22px;
    padding: 10px 24px;
    border-width: 3px;
    box-shadow: 4px 4px 0 var(--paper);
  }
}

/* Game-over */
.gameover-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}
.stat-box {
  background: var(--paper);
  color: var(--ink);
  padding: 12px 18px;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--hot);
  min-width: 110px;
}
.stat-box .label {
  font-family: 'Rubik Mono One', sans-serif;
  font-size: 10px;
  letter-spacing: 0.1em;
  opacity: 0.6;
}
.stat-box .num {
  font-family: 'Bungee', sans-serif;
  font-size: 30px;
  color: var(--hot);
  line-height: 1;
  margin-top: 4px;
}
@media (max-width: 600px) {
  .gameover-stats { gap: 8px; margin-bottom: 14px; }
  .stat-box {
    padding: 8px 12px;
    min-width: 80px;
    border-width: 2px;
    box-shadow: 2px 2px 0 var(--hot);
  }
  .stat-box .label { font-size: 8px; }
  .stat-box .num { font-size: 22px; }
}
.new-record {
  font-family: 'Rubik Mono One', sans-serif;
  color: var(--gold);
  background: var(--ink);
  padding: 6px 14px;
  border: 2px solid var(--gold);
  margin-bottom: 16px;
  font-size: 14px;
  animation: shake 0.4s infinite;
}
#splatter-canvas {
  width: 180px;
  height: 290px;
  margin: 0 auto 20px;
  display: block;
  background: linear-gradient(180deg, #c4e4f0 0%, #f4dba6 70%, #b34b3a 100%);
  border: 5px solid var(--gold);
  border-radius: 12px;
  box-shadow: 6px 6px 0 var(--ink), inset 0 0 0 3px var(--ink);
}
@media (max-width: 600px) {
  #splatter-canvas {
    width: 130px;
    height: 210px;
    margin: 0 auto 14px;
    border-width: 3px;
    box-shadow: 4px 4px 0 var(--ink), inset 0 0 0 2px var(--ink);
  }
}
@keyframes shake { 0%,100% { transform: rotate(-1deg); } 50% { transform: rotate(1deg); } }

/* Wave banner */
.wave-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.wave-banner.visible { opacity: 1; }
.wave-banner.boss .banner-main { color: var(--hot); animation: shake 0.18s infinite; }
.banner-small {
  font-family: 'Rubik Mono One', sans-serif;
  font-size: clamp(12px, 2vw, 18px);
  color: var(--paper);
  background: var(--ink);
  padding: 6px 14px;
  border: 2px solid var(--paper);
  letter-spacing: 0.12em;
  margin-bottom: 10px;
  text-transform: uppercase;
}
.banner-main {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(50px, 11vw, 110px);
  color: var(--gold);
  text-shadow: 3px 3px 0 #5a3a1a, 6px 6px 0 var(--ink);
  line-height: 0.9;
  transform: rotate(-1deg);
  text-align: center;
}

/* Flashes */
.danger-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 0 solid var(--hot);
  z-index: 5;
  transition: border-width 0.15s;
}
.doom-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 0%, rgba(255,40,180,0.35), transparent 60%);
  z-index: 6;
  opacity: 0;
  transition: opacity 0.4s;
}
.doom-flash.active { opacity: 1; }

.touch-hint {
  position: absolute;
  bottom: 30px;
  left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--paper);
  opacity: 0.5;
  pointer-events: none;
  font-family: 'Rubik Mono One', sans-serif;
  letter-spacing: 0.1em;
  z-index: 5;
  transition: opacity 0.4s;
}
@media (hover: hover) { .touch-hint { display: none; } }

.swap-btn {
  position: absolute;
  bottom: 30px;
  right: 24px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #7ad7f0;
  color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: 'Bungee', sans-serif;
  font-size: 16px;
  cursor: pointer;
  z-index: 11;
  display: none;
  letter-spacing: 0.05em;
}
.swap-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.swap-btn.spent { background: #555; color: #999; }
/* Show swap button on touch devices OR narrow viewports */
@media (hover: none), (max-width: 600px) {
  .swap-btn.show { display: block; }
}
@media (max-width: 600px) {
  .swap-btn {
    width: 70px;
    height: 70px;
    bottom: 16px;
    right: 12px;
    font-size: 14px;
    border-width: 3px;
    box-shadow: 3px 3px 0 var(--ink);
  }
}

.footer-credit {
  position: absolute;
  bottom: 10px;
  left: 14px;
  font-size: 10px;
  opacity: 0.5;
  font-family: 'Space Mono', monospace;
  z-index: 4;
  pointer-events: none;
}
