:root {
  --bg-color: #0d0d12;
  --wall-color: #2a2a3e;
  --path-color: #1a1a27;
  --panel-bg: linear-gradient(180deg, rgba(16, 22, 33, 0.9), rgba(7, 12, 20, 0.94));
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-highlight: rgba(90, 203, 255, 0.22);

  --player-color: #00f0ff;
  --monster-color: #ff003c;
  --exit-color: #ffea00;

  --cell-size: 30px;
  --columns: 21;
  --rows: 21;
  --board-width: 630px;
  --board-height: 630px;
  --board-scale: 1;
  --wall-texture: none;
  --path-glow: rgba(0, 120, 95, 0.35);
  --path-shade: rgba(0, 80, 60, 0.95);

  /* Used by JS to read safe-area value */
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  /* Safe-area padding with minimum fallback */
  padding: max(10px, env(safe-area-inset-top))
           max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom))
           max(10px, env(safe-area-inset-left));
  background-color: var(--bg-color);
  color: white;
  font-family: 'Outfit', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* Fill viewport precisely — 100dvh accounts for mobile browser chrome */
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

#game-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 10px;
  box-sizing: border-box;
}

/* Status Bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 16px;
  padding: 14px 18px;
  background:
    radial-gradient(circle at top left, rgba(79, 190, 255, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 44px rgba(0,0,0,0.34);
  backdrop-filter: blur(14px);
  flex: 0 0 auto;
}

#left-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 320px;
  min-width: 0;
}

#status-center {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.stat-icon {
  font-size: 18px;
  flex: 0 0 auto;
}

.control-chip,
.overlay-settings {
  background: rgba(255, 255, 255, 0.06);
}

.control-chip {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  color: white;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  backdrop-filter: blur(10px);
  cursor: pointer;
}

.control-chip.is-off {
  opacity: 0.45;
}

#overlay-settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
}

#health-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

#health-icon {
  font-size: 24px;
}

#health-bar-bg {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  height: 16px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255,255,255,0.16);
}

#health-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff007a, #ff003c);
  width: 100%;
  transition: width 0.3s ease-out;
  box-shadow: 0 0 10px #ff003c;
}

#health-text {
  font-weight: 700;
  min-width: 76px;
  font-size: 14px;
  text-align: right;
  flex: 0 0 auto;
}

#exp-bar-bg {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  height: 16px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.3);
  position: relative;
}

#exp-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #00d2ff, #3a7bd5);
  transition: width 0.3s;
  box-shadow: 0 0 10px rgba(58, 123, 213, 0.55);
}

#exp-text {
  font-weight: 700;
  min-width: 44px;
  text-align: right;
  flex: 0 0 auto;
}

#status-text {
  font-weight: 700;
  font-size: 14px;
  color: var(--exit-color);
  text-shadow: 0 0 8px rgba(255, 234, 0, 0.5);
  text-align: center;
}

#player-attrs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.78);
  letter-spacing: 0.03em;
}
#player-attrs span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#player-attrs strong {
  font-weight: 800;
  color: white;
}

#right-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  font-weight: 700;
  font-size: 13px;
  flex: 0 0 auto;
}

#level-text {
  color: var(--exit-color);
  text-shadow: 0 0 8px rgba(255, 234, 0, 0.4);
}

#kill-text {
  color: var(--monster-color);
  text-shadow: 0 0 8px rgba(255, 0, 60, 0.4);
}

/* Game Board */
#board-stage {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
}

#board-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.8), 0 0 0 4px var(--wall-color);
  width: var(--board-width);
  height: var(--board-height);
  transform-origin: top left;
  transition: transform 0.11s linear;
  will-change: transform;
}

.combat-text {
  position: absolute;
  transform: translate(-50%, 0);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 90;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
  animation: combat-float 0.75s ease-out forwards;
  white-space: nowrap;
}

.combat-text-hit {
  color: #ffffff;
}

.combat-text-crit {
  color: #ffd84d;
  text-shadow: 0 0 10px rgba(255, 216, 77, 0.85), 0 0 20px rgba(255, 120, 0, 0.6);
}

.combat-text-miss {
  color: #8fd3ff;
  text-shadow: 0 0 10px rgba(80, 180, 255, 0.65);
}

@keyframes combat-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px) scale(0.8);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -2px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -28px) scale(1.04);
  }
}

#game-board {
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  background-color: #081018;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.3);
}

/* Base cell */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #07121a;
  background-image: var(--wall-texture);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: inset 0 0 5px rgba(255,255,255,0.02);
  overflow: hidden;
}

.cell.path {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.26)),
    linear-gradient(180deg, var(--path-glow), var(--path-shade)),
    var(--wall-texture),
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0));
  background-size: cover, cover, cover, cover;
  background-position: center, center, center, center;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
  border-color: rgba(255,255,255,0.12);
  box-shadow:
    inset 0 0 12px rgba(255,255,255,0.08),
    inset 0 0 24px rgba(0,0,0,0.16);
}

/* Player */
.player::after {
  content: '';
  position: absolute;
  left: 6%;
  bottom: 2%;
  width: 88%;
  height: 88%;
  background-image: var(--player-sprite);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.35));
  z-index: 10;
}

.player::before {
  display: none;
}

.player.invincible::after {
  animation: blink 0.18s infinite alternate;
  filter: hue-rotate(90deg) drop-shadow(0 0 8px var(--player-color));
}

.follower::after {
  content: '';
  position: absolute;
  left: 10%;
  bottom: 4%;
  width: 80%;
  height: 80%;
  background-image: var(--follower-sprite);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  filter: drop-shadow(0 0 5px rgba(255, 215, 120, 0.6));
  z-index: 9;
}

/* Sprite-facing rules: keep character upright, only mirror when facing left */
.player.dir-up,
.player.dir-right,
.player.dir-down,
.follower.dir-up,
.follower.dir-right,
.follower.dir-down {
  transform: none;
}

.player.dir-left,
.follower.dir-left {
  transform: scaleX(-1);
}

@keyframes blink {
  0%   { opacity: 1; }
  100% { opacity: 0.25; }
}

/* Monster */
.monster::after {
  content: '';
  position: absolute;
  left: 8%;
  bottom: 4%;
  width: 84%;
  height: 84%;
  background-image: var(--monster-sprite);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  filter: drop-shadow(0 0 6px var(--monster-color));
  z-index: 8;
}

.monster.dir-right::after,
.monster.dir-up::after,
.monster.dir-down::after {
  transform: scaleX(1);
}

.monster.dir-left::after {
  transform: scaleX(-1);
}
.monster.boss {
  transform: scale(1.6);
  z-index: 20;
}
.monster.boss::after {
  filter: drop-shadow(0 0 15px red);
}

.trap::before {
  content: '';
  position: absolute;
  inset: 6%;
  background-image: var(--trap-sprite);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(0 0 6px rgba(255, 160, 80, 0.5));
  z-index: 6;
}

.projectile-follower::before {
  content: '';
  position: absolute;
  top: 30%; left: 30%;
  width: 40%; height: 40%;
  background: #7bdbff;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(123,219,255,0.8), inset 0 0 6px rgba(255,255,255,0.8);
  z-index: 11;
  animation: proj-follower-pulse 0.2s linear infinite alternate;
}

@keyframes proj-follower-pulse {
  0%   { transform: scale(1); }
  100% { transform: scale(1.2); }
}

.monster::before {
  content: '';
  position: absolute;
  top: -4px; left: 10%; width: 80%; height: 3px;
  background: #440000;
  border-radius: 2px;
  z-index: 10;
}
.monster-hp-fill {
  position: absolute; top: -4px; left: 10%; height: 3px;
  background: #ff003c;
  border-radius: 2px;
  z-index: 11;
  width: calc(80% * var(--hp-pct, 1));
  transition: width 0.1s;
}

@keyframes pulse-monster {
  0%   { transform: scale(1);   box-shadow: 0 0 15px var(--monster-color); }
  100% { transform: scale(1.1); box-shadow: 0 0 30px var(--monster-color), inset 0 0 10px white; }
}

/* Frozen monster */
.monster.frozen::after {
  background-color: #66ccff;
  box-shadow: 0 0 15px #66ccff, 0 0 30px #0088cc;
  animation: none;
  transform: scale(0.9);
}

/* Exit */
.exit::after {
  content: '';
  position: absolute;
  top: 15%; left: 15%;
  width: 70%; height: 70%;
  background-color: var(--exit-color);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  box-shadow: 0 0 20px var(--exit-color);
  animation: pulse-exit 1s infinite alternate;
  z-index: 8;
}

@keyframes pulse-exit {
  0%   { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.1); opacity: 1; filter: brightness(1.5); }
}

/* Items */
.item-health::after,
.item-speed::after,
.item-shield::after,
.item-bomb::after,
.item-freeze::after,
.item-ammo::after {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  animation: float-item 1.2s ease-in-out infinite alternate;
}

.item-health::after  { content: '+';  color: #00ff88; font-size: 22px; font-weight: 900; font-family: 'Outfit', sans-serif; text-shadow: 0 0 10px #00ff88, 0 0 20px #00ff88; line-height: 1; }
.item-speed::after   { content: '⚡'; font-size: 16px; }
.item-shield::after  { content: '🛡'; font-size: 14px; }
.item-bomb::after    { content: '💣'; font-size: 15px; }
.item-freeze::after  { content: '❄️'; font-size: 15px; }
.item-ammo::after    { content: '🔫'; font-size: 14px; }
.item-exp::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 78%;
  height: 78%;
  transform: translate(-50%, -50%);
  background-image: var(--item-sprite);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  z-index: 7;
  animation: float-item 1.2s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 10px rgba(120, 220, 255, 0.65));
}

@keyframes float-item {
  0%   { transform: translate(-50%, -60%); }
  100% { transform: translate(-50%, -40%); }
}

/* Projectile */
.projectile::before {
  content: '';
  position: absolute;
  top: 25%; left: 25%;
  width: 50%; height: 50%;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 8px #fff, 0 0 18px #ffff66;
  z-index: 11;
  animation: proj-pulse 0.1s linear infinite alternate;
}

.projectile.has-sprite::before {
  top: 10%;
  left: 10%;
  width: 80%;
  height: 80%;
  background: transparent;
  background-image: var(--projectile-sprite);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border-radius: 0;
  box-shadow: none;
}

@keyframes proj-pulse {
  0%   { transform: scale(1); }
  100% { transform: scale(1.3); }
}

.skill-effect {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  background-image: var(--skill-effect-sprite);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
  z-index: 30;
  animation: skill-effect-burst 0.45s ease-out forwards;
}

@keyframes skill-effect-burst {
  0% {
    opacity: 0.25;
    transform: translate(-50%, -50%) scale(0.7);
    filter: drop-shadow(0 0 4px rgba(255, 120, 0, 0.6));
  }
  40% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.45);
    filter: drop-shadow(0 0 16px rgba(255, 160, 40, 0.9));
  }
}

/* Fog Canvas */
#fog-canvas {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 50;
}

/* Overlay */
#overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  /* Outer wrapper must not scroll — inner panel handles it */
  overflow: hidden;
  padding: 0;
  background:
    radial-gradient(circle at top, rgba(0, 185, 255, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(255, 183, 0, 0.16), transparent 28%),
    rgba(0,0,0,0.85);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  opacity: 1;
  transition: opacity 0.5s;
  /* Let the inner panel control touch panning */
  touch-action: none;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay .overlay-shell {
  width: min(1080px, 100%);
  /* Scroll container: this is the element that actually scrolls on iOS */
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 24px;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
}

.overlay-hero-panel {
  width: 100%;
  padding: 30px;
  margin: auto 0;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.12);
  background:
    radial-gradient(circle at top left, rgba(255, 234, 0, 0.1), transparent 30%),
    radial-gradient(circle at bottom right, rgba(0, 195, 255, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(10, 16, 27, 0.95), rgba(5, 9, 16, 0.98));
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  text-align: center;
}

.overlay-eyebrow {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
}

#overlay-title {
  font-size: 64px;
  margin: 0;
  text-transform: uppercase;
  text-shadow: 0 0 20px currentColor;
}

.title-gold { color: var(--exit-color); }
.title-red  { color: var(--monster-color); }

#overlay-msg {
  font-size: 22px;
  margin: 10px auto 24px;
  color: #ccc;
  text-align: center;
  max-width: 720px;
  padding: 0 20px;
  white-space: pre-line;
}

#overlay.settings-mode #overlay-msg {
  margin-bottom: 18px;
}

#overlay-settings.hidden {
  display: none;
}

.overlay-start-panel {
  display: none;
}

#overlay.settings-mode .overlay-start-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.95fr);
  gap: 20px;
  align-items: stretch;
  margin: 0 auto 22px;
  text-align: left;
}

.overlay-feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.overlay-feature-card,
.overlay-preview-card {
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--panel-bg);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

.overlay-feature-card {
  padding: 18px;
}

.overlay-feature-card strong {
  display: block;
  font-size: 18px;
  margin-bottom: 8px;
}

.overlay-feature-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255,255,255,0.74);
}

.overlay-feature-kicker {
  display: inline-block;
  margin-bottom: 10px;
  color: #9ddfff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.overlay-preview-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
}

.preview-topline,
.overlay-device-tips,
.preview-bar {
  display: flex;
  align-items: center;
}

.preview-topline,
.overlay-device-tips {
  justify-content: space-between;
  gap: 12px;
}

.preview-topline {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.7);
}

.preview-bar {
  gap: 10px;
}

.preview-bar span,
.preview-bar strong {
  flex: 0 0 auto;
}

.preview-bar span {
  width: 36px;
  color: rgba(255,255,255,0.7);
}

.preview-bar strong {
  min-width: 72px;
  text-align: right;
  font-size: 13px;
}

.preview-bar-track {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14);
}

.preview-bar-fill {
  height: 100%;
  width: 76%;
  border-radius: inherit;
}

.preview-bar-hp .preview-bar-fill {
  background: linear-gradient(90deg, #ff4a86, #ff003c);
}

.preview-bar-exp .preview-bar-fill {
  width: 52%;
  background: linear-gradient(90deg, #00d2ff, #3a7bd5);
}

.overlay-device-tips {
  flex-wrap: wrap;
  margin-top: 4px;
}

.overlay-device-tips span {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.82);
  font-size: 12px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#overlay-btn, #overlay-btn2, #overlay-btn3, #overlay-btn4 {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

#overlay-btn {
  padding: 15px 40px;
  font-size: 20px;
  background: linear-gradient(135deg, #ffffff, #ffe28a);
  color: #071018;
  box-shadow: 0 12px 30px rgba(255,255,255,0.22);
}

#overlay-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 25px rgba(255,255,255,0.8);
}

#overlay-btn2,
#overlay-btn3,
#overlay-btn4 {
  padding: 10px 28px;
  font-size: 15px;
  background: transparent;
  color: rgba(255,255,255,0.6);
  border: 2px solid rgba(255,255,255,0.3);
  margin-top: 12px;
}

#overlay-btn2:hover,
#overlay-btn3:hover,
#overlay-btn4:hover {
  border-color: white;
  color: white;
  background: rgba(255,255,255,0.08);
}

#overlay-btn4 {
  color: rgba(123, 224, 255, 0.92);
  border-color: rgba(123, 224, 255, 0.45);
}

#overlay-btn4:hover {
  border-color: #7be0ff;
  color: #7be0ff;
}

#overlay-btn2.hidden,
#overlay-btn3.hidden,
#overlay-btn4.hidden {
  display: none;
}

/* ---- Hero Selection ---- */
#hero-selection {
  margin: 15px 0 25px;
}
.hero-cards {
  display: flex; gap: 15px; justify-content: center;
}
.hero-card {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  padding: 10px 15px;
  cursor: pointer;
  width: 80px;
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
}
.hero-card.active {
  background: rgba(0, 240, 255, 0.2);
  border-color: #00f0ff;
  transform: scale(1.05);
}
.hero-icon { font-size: 32px; filter: drop-shadow(0 0 5px currentColor); }
.hero-name { font-size: 16px; font-weight: bold; margin-top: 5px; color: #fff; }
.hero-desc { font-size: 11px; color: #ccc; margin-top: 2px; }

/* ---- Dual-player Iframe Overlay ---- */
#mp-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #071018;
  display: flex;
  flex-direction: column;
}

#mp-overlay.hidden {
  display: none;
}

#mp-close-btn {
  flex: 0 0 auto;
  align-self: flex-start;
  margin: 12px 16px 0;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.75);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

#mp-close-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: white;
}

#mp-frame {
  flex: 1 1 auto;
  width: 100%;
  border: none;
  display: block;
  min-height: 0;
}

/* ---- Level Up Overlay ---- */
#overlay-levelup {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
#overlay-levelup.hidden { display: none; }

.levelup-box {
  background: rgba(20,20,40,0.95);
  border: 2px solid var(--exit-color);
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
  max-width: 90%;
  width: 320px;
}
.upgrade-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.upgrade-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  padding: 15px;
  color: white;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: transform 0.1s, background 0.1s;
}
.upgrade-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.02); }
.upg-icon { font-size: 28px; }
.upg-text { flex: 1; text-align: left; }
.upg-title { font-weight: bold; font-size: 18px; margin-bottom: 3px; display: block; }
.upg-desc { font-size: 12px; color: #aaa; }

#mobile-hint {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: rgba(255,255,255,0.72);
  text-align: center;
}

.action-btn-new { display: none; }

@media (max-width: 720px), (pointer: coarse) {
  .action-btn-new {
    display: flex;
    width: 90px; height: 90px;
    border-radius: 50%;
    background: rgba(0, 240, 255, 0.15);
    border: 2px solid rgba(0, 240, 255, 0.4);
    color: var(--player-color);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.25), inset 0 0 10px rgba(0,240,255,0.1);
    transition: transform 0.1s, background 0.1s;
    margin-top: 15px; 
    margin-bottom: 5px;
  }
  
  .action-btn-new:active {
    transform: scale(0.94);
    background: rgba(0, 240, 255, 0.3);
  }
}

.shoot-icon {
  font-size: 38px;
  line-height: 1;
}
.shoot-text {
  font-size: 16px;
  font-weight: 700;
  margin-top: 4px;
}

/* ---- Small screens: wrap status bar ---- */
@media (max-width: 600px) {
  #status-bar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }

  #left-stats {
    width: 100%;
    flex-wrap: wrap;
  }

  .stat-card {
    min-width: 0;
    width: 100%;
  }

  #status-center {
    order: 3;
    width: 100%;
    padding: 0;
  }

  #status-text {
    font-size: 13px;
  }

  #right-info {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  #health-bar-bg {
    min-width: 0;
  }

  #health-text,
  #exp-text {
    font-size: 12px;
    min-width: 0;
  }
}

/* ---- Touch / mobile layout ---- */
@media (max-width: 720px), (pointer: coarse) {
  body {
    position: fixed;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  #game-container {
    gap: 10px;
    padding: 6px;
    align-items: stretch;
  }

  #status-bar {
    align-items: flex-start;
    width: 100%;
  }

  #left-stats {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }

  .stat-card {
    flex: 1 1 100%;
  }

  #status-center {
    width: 100%;
    order: 3;
    padding: 0;
  }

  #player-attrs {
    justify-content: flex-start;
    gap: 8px 12px;
  }

  #player-attrs span {
    white-space: normal;
  }

  #right-info {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .control-chip {
    font-size: 12px;
    padding: 9px 12px;
  }

  #overlay .overlay-shell {
    padding: 14px;
  }

  .overlay-hero-panel {
    padding: 22px 16px 18px;
    border-radius: 22px;
  }

  #overlay.settings-mode .overlay-start-panel {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .overlay-feature-grid {
    grid-template-columns: 1fr;
  }

  #overlay-title {
    font-size: clamp(34px, 10vw, 42px);
  }

  #overlay-msg {
    font-size: 18px;
    padding: 0;
  }

  .preview-topline,
  .overlay-device-tips {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---- Landscape on touch devices: keep status bar single-line ---- */
@media (pointer: coarse) and (orientation: landscape) {
  body {
    overflow: auto;
  }

  #game-container {
    height: auto;
    min-height: 100%;
  }

  #status-bar {
    flex-wrap: wrap;
    padding: 8px 14px;
  }

  #status-center {
    order: 3;
    width: 100%;
  }

  #status-text {
    font-size: 12px;
  }

  #left-stats {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
  }

  .stat-card {
    min-width: 0;
  }

  #health-text,
  #exp-text {
    font-size: 11px;
  }

  #mobile-hint {
    display: none;
  }
}

@media (max-height: 760px) {
  body {
    overflow: auto;
  }

  #game-container {
    height: auto;
    min-height: 100%;
    justify-content: flex-start;
  }

  #status-bar {
    padding: 10px 12px;
    gap: 10px;
  }

  #mobile-hint {
    margin-top: 4px;
    font-size: 12px;
  }
}
