/* ============ Reset & base ============ */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: #0c0d12;
  color: #f4f1e8;
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  overscroll-behavior: none;
}

.game-root {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  background: #0c0d12;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ============ Screens ============ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ============ Character select ============ */
.screen-select {
  background: radial-gradient(circle at 50% 20%, #2a2035 0%, #16121f 55%, #0c0d12 100%);
  gap: 18px;
  padding: 24px 16px;
}
.title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  letter-spacing: 0.06em;
  margin: 0;
  color: #ffd23f;
  text-shadow: 3px 3px 0 #b3251d, 6px 6px 0 rgba(0,0,0,0.4);
  font-weight: 900;
  text-align: center;
}
.subtitle {
  margin: 0 0 6px;
  color: #d9d2c4;
  font-size: 1rem;
  text-align: center;
}
.select-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 520px;
}
@media (min-width: 640px) {
  .select-grid { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
}
.char-card {
  position: relative;
  background: #1c1826;
  border: 3px solid #3a3350;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s ease, border-color 0.12s ease;
  min-height: 44px;
}
.char-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5));
}
.char-card .char-name {
  font-weight: 800;
  font-size: 0.95rem;
  color: #ffd23f;
  text-align: center;
}
.char-card .char-blurb {
  font-size: 0.72rem;
  color: #b8b0c8;
  text-align: center;
  line-height: 1.25;
}
.char-card.selected {
  border-color: #ffd23f;
  transform: translateY(-4px);
  box-shadow: 0 0 0 3px rgba(255,210,63,0.25);
}
.char-card:active { transform: scale(0.97); }

.hint { font-size: 0.8rem; color: #8f88a3; text-align: center; margin: 4px 0 0; }

/* ============ Buttons ============ */
.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  min-height: 44px;
  min-width: 44px;
  color: #221a08;
  background: linear-gradient(180deg, #ffe37a, #ffb92e);
  box-shadow: 0 5px 0 #a5660b, 0 8px 14px rgba(0,0,0,0.35);
  transition: transform 0.08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a5660b; }
.btn:disabled { opacity: 0.4; box-shadow: none; }
.btn-secondary {
  background: linear-gradient(180deg, #4b4560, #2c2740);
  color: #f4f1e8;
  box-shadow: 0 5px 0 #1a1729, 0 8px 14px rgba(0,0,0,0.35);
}
.btn-secondary:active { box-shadow: 0 2px 0 #1a1729; }

/* ============ How to play ============ */
.screen-howto {
  background: #16121f;
  gap: 16px;
  padding: 24px;
}
.screen-howto h2 { color: #ffd23f; margin: 0; }
.howto-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.howto-list li {
  background: #221d33;
  border-left: 4px solid #ffd23f;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.92rem;
  line-height: 1.35;
}

/* ============ Game screen ============ */
.screen-game {
  padding: 0;
  background: #000;
  align-items: stretch;
  justify-content: stretch;
}
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
}

/* ============ HUD ============ */
.hud {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 0 calc(env(safe-area-inset-left) + 10px);
  pointer-events: none;
  z-index: 20;
}
.hud-left { display: flex; gap: 8px; align-items: center; }
.portrait {
  width: 46px; height: 46px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  border: 2px solid #ffd23f;
  box-shadow: 0 3px 6px rgba(0,0,0,0.5);
  flex-shrink: 0;
}
.bars { display: flex; flex-direction: column; gap: 2px; width: 120px; }
.bar-label { font-size: 0.55rem; letter-spacing: 0.05em; color: #d9d2c4; text-shadow: 1px 1px 2px #000; }
.health-word { color: #7effc8; font-weight: 700; letter-spacing: 0.08em; }
.bar-track {
  height: 9px;
  background: rgba(0,0,0,0.5);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}
.bar-fill { height: 100%; width: 0%; transition: width 0.15s ease; }
.bar-health { background: linear-gradient(90deg, #ff5b4d, #ff8a3d); }
.bar-power { background: linear-gradient(90deg, #4dc6ff, #7effc8); }
.hud-center { text-align: center; }
.hud-level { font-weight: 800; font-size: 0.85rem; color: #ffd23f; text-shadow: 1px 1px 2px #000; }
.hud-goal { font-size: 0.72rem; color: #f4f1e8; text-shadow: 1px 1px 2px #000; }
.hud-right { text-align: right; }
.hud-score { font-weight: 800; font-size: 1.1rem; color: #fff; text-shadow: 1px 1px 2px #000; }
.hud-score-label { font-size: 0.55rem; color: #d9d2c4; }

.btn-icon {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 10px);
  z-index: 25;
  pointer-events: auto;
}
.btn-pause {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(20,16,30,0.7);
  color: #ffd23f;
  border: 2px solid rgba(255,210,63,0.5);
  font-weight: 900;
}

/* ============ Dialog bubbles & subtitles ============ */
.dialog-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}
.speech-bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #fdfaf0;
  color: #221a08;
  border: 2.5px solid #221a08;
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  max-width: 150px;
  text-align: center;
  line-height: 1.2;
  box-shadow: 0 3px 6px rgba(0,0,0,0.35);
  animation: bubble-pop 0.18s ease-out;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  border-width: 9px 7px 0 7px;
  border-style: solid;
  border-color: #221a08 transparent transparent transparent;
}
.speech-bubble.cop { background: #d9ecff; border-color: #10508c; }
.speech-bubble.cop::after { border-color: #10508c transparent transparent transparent; }
.speech-bubble.victim { background: #fff2d6; border-color: #a5660b; }
.speech-bubble.victim::after { border-color: #a5660b transparent transparent transparent; }

@keyframes bubble-pop {
  from { opacity: 0; transform: translate(-50%, -80%) scale(0.7); }
  to { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}

.subtitle-bar {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 78px);
  transform: translateX(-50%);
  width: min(92%, 620px);
  background: rgba(10, 8, 16, 0.82);
  border: 2px solid #ffd23f;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  display: flex;
  gap: 8px;
  align-items: baseline;
  z-index: 30;
  pointer-events: none;
}
/* Short mobile browser viewports: keep subtitle clear of controls. */
@media (max-height: 480px) {
  .subtitle-bar {
    bottom: auto;
    top: calc(env(safe-area-inset-top) + 58px);
    width: min(70%, 480px);
  }
}
.subtitle-name { color: #ffd23f; font-weight: 900; flex-shrink: 0; }
.subtitle-text { color: #fff; font-weight: 600; }

/* ============ Touch controls ============ */
.touch-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(env(safe-area-inset-right) + 10px) calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 10px);
  z-index: 25;
  pointer-events: none;
}
.touch-dpad, .touch-actions { pointer-events: auto; }
.touch-dpad {
  position: relative;
  width: 148px;
  height: 148px;
}
.dpad-btn {
  position: absolute;
  width: 50px; height: 50px;
  border-radius: 12px;
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.35);
  color: #fff;
  font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
  user-select: none;
}
.dpad-btn:active, .dpad-btn.active { background: rgba(255,210,63,0.55); border-color: #ffd23f; }
.dpad-left { left: 0; top: 49px; }
.dpad-right { left: 98px; top: 49px; }
.dpad-up { left: 49px; top: 0; }
.dpad-down { left: 49px; top: 98px; }

.touch-actions {
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
}
.action-btn {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  font-weight: 900;
  font-size: 0.7rem;
  color: #221a08;
  touch-action: none;
  user-select: none;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  line-height: 1.05;
}
.action-punch { width: 72px; height: 72px; background: radial-gradient(circle, #ff8a3d, #d94f1f); color: #2a1000; }
.action-power1 { width: 60px; height: 60px; background: radial-gradient(circle, #4dc6ff, #1a7fc4); color: #04202f; }
.action-power2 { width: 60px; height: 60px; background: radial-gradient(circle, #ffe37a, #d9a300); color: #2a1c00; }
.action-btn:active { transform: scale(0.92); }
.action-power1.charging { opacity: 0.45; filter: grayscale(0.5); }
.action-power2.disabled { opacity: 0.35; filter: grayscale(0.7); }

/* ============ Pause / overlays ============ */
.screen-pause, .screen-level-complete, .screen-gameover {
  background: rgba(8, 6, 14, 0.92);
  gap: 18px;
  z-index: 40;
}
.screen-pause h2, .screen-level-complete h2, .screen-gameover h2 {
  color: #ffd23f;
  font-size: 1.8rem;
  margin: 0;
  text-align: center;
}
.big-score {
  font-size: 2.4rem;
  font-weight: 900;
  color: #fff;
  margin: 0;
}

/* ============ Small screens: tighten HUD/select ============ */
@media (max-width: 700px), (max-height: 520px) {
  .hud {
    padding-top: calc(env(safe-area-inset-top) + 6px);
    padding-left: calc(env(safe-area-inset-left) + 6px);
    padding-right: calc(env(safe-area-inset-right) + 6px);
  }
  .bars { width: 88px; }
  .portrait { width: 38px; height: 38px; }
  .hud-center { max-width: 46%; }
  .hud-level { font-size: 0.75rem; }
  .hud-goal { font-size: 0.62rem; line-height: 1.15; }
  .hud-score { font-size: 0.92rem; }
  .touch-controls {
    padding: 0 calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 8px);
    align-items: flex-end;
  }
  .touch-dpad {
    width: 126px;
    height: 126px;
  }
  .dpad-btn {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    font-size: 1.05rem;
    background: rgba(255,255,255,0.1);
  }
  .dpad-left { left: 0; top: 42px; }
  .dpad-right { left: 84px; top: 42px; }
  .dpad-up { left: 42px; top: 0; }
  .dpad-down { left: 42px; top: 84px; }
  .touch-actions { gap: 7px; }
  .action-punch { width: 60px; height: 60px; }
  .action-power1, .action-power2 { width: 50px; height: 50px; }
  .action-btn { font-size: 0.62rem; }
  .subtitle-bar {
    bottom: calc(env(safe-area-inset-bottom) + 130px);
    width: min(86%, 520px);
    font-size: 0.72rem;
    padding: 6px 10px;
  }
  .btn-pause {
    width: 38px;
    height: 38px;
    bottom: calc(env(safe-area-inset-bottom) + 8px);
    right: 50%;
    transform: translateX(50%);
  }
}

@media (max-height: 520px) {
  .touch-dpad {
    width: 108px;
    height: 108px;
    opacity: 0.72;
  }
  .dpad-btn {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }
  .dpad-left { left: 0; top: 36px; }
  .dpad-right { left: 72px; top: 36px; }
  .dpad-up { left: 36px; top: 0; }
  .dpad-down { left: 36px; top: 72px; }
  .touch-actions { opacity: 0.82; gap: 5px; }
  .action-punch { width: 54px; height: 54px; }
  .action-power1, .action-power2 { width: 44px; height: 44px; }
  .subtitle-bar {
    top: calc(env(safe-area-inset-top) + 48px);
    bottom: auto;
    width: min(64%, 460px);
  }
}

@media (max-width: 420px) {
  .bars { width: 78px; }
  .portrait { width: 34px; height: 34px; }
  .bar-label { font-size: 0.48rem; }
  .bar-track { height: 7px; }
}
