html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #060606;
  height: 100%;
  min-height: 100dvh;
  width: 100%;
  font-family: system-ui, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100vw !important;
  height: 100vh !important;
  image-rendering: pixelated;
  touch-action: none;
}

#rotateHint {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(0,0,0,0.7);
  color: #ffd84a;
  border: 2px solid #777;
  padding: 7px 10px;
  font-weight: 800;
  font-size: 13px;
  display: none;
  text-align: center;
  pointer-events: none;
}

#topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
  pointer-events: none;
}

.badge {
  color: #ffd84a;
  background: #111;
  border: 3px solid #333;
  box-shadow: 0 0 0 2px #000;
  padding: 6px 10px;
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 2px 2px #000;
}

.hint {
  color: #fff;
  opacity: 0.85;
  background: rgba(0,0,0,0.45);
  padding: 6px 10px;
  border-radius: 3px;
  font-size: 13px;
}

#centerCrosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  text-shadow: 2px 2px #000;
  font-size: 30px;
  z-index: 4;
  pointer-events: none;
  opacity: 0.9;
}

#hud {
  position: fixed;
  left: env(safe-area-inset-left);
  right: env(safe-area-inset-right);
  bottom: env(safe-area-inset-bottom);
  height: 88px;
  background: linear-gradient(#3b3b3b, #111);
  border-top: 4px solid #6a6a6a;
  display: grid;
  grid-template-columns: 1fr 1fr 78px 1fr 1.3fr 1fr;
  gap: 4px;
  padding: 6px;
  box-sizing: border-box;
  z-index: 5;
  color: white;
  pointer-events: none;
}

.panel {
  border: 2px solid #777;
  background: #151515;
  text-align: center;
  min-width: 0;
}

.label {
  color: #eee;
  font-weight: 900;
  font-size: 13px;
  padding-top: 3px;
}

.big {
  font-weight: 900;
  font-size: 28px;
  line-height: 46px;
  text-shadow: 2px 2px #000;
}

.red { color: #ff3030; }
.green { color: #4fe64f; }
.yellow { color: #ffd83a; }

.face {
  border: 2px solid #777;
  background: #0c0c0c;
  display: grid;
  place-items: center;
  font-size: 42px;
}

.weapon #weaponName {
  color: #52e85c;
  font-weight: 900;
  font-size: 14px;
  padding-top: 10px;
}

#item {
  color: #ffd83a;
  font-weight: 900;
  font-size: 14px;
  padding-top: 10px;
}

#message {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(0,0,0,0.72);
  color: white;
  border: 2px solid #777;
  padding: 10px 14px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  font-weight: 800;
  max-width: 82vw;
  text-align: center;
  pointer-events: none;
}

#minimap {
  display: none;
  position: fixed;
  top: max(70px, calc(58px + env(safe-area-inset-top)));
  right: max(12px, env(safe-area-inset-right));
  z-index: 6;
  margin: 0;
  padding: 8px 10px;
  border: 2px solid #777;
  background: rgba(0,0,0,0.68);
  color: #d6f5b8;
  font: 900 11px/1.05 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 1px;
  text-shadow: 1px 1px #000;
  pointer-events: none;
  white-space: pre;
}

#fullscreenBtn {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  z-index: 11;
  display: none;
  border: 2px solid #bbb;
  background: rgba(20,20,20,0.82);
  color: #ffd84a;
  font-size: 12px;
  font-weight: 900;
  padding: 9px 11px;
  touch-action: none;
  pointer-events: auto;
}

#mobileControls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  touch-action: none;
}

#touchZoneDebug {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 1;
  font-size: 18px;
  font-weight: 900;
  color: rgba(255,255,255,0.58);
}

#touchZoneDebug.visible {
  display: grid;
  grid-template-columns: 42fr 58fr;
}

#moveZoneDebug,
#lookZoneDebug {
  display: grid;
  place-items: center;
  border: 2px dashed rgba(255,255,255,0.25);
  background: rgba(255,216,74,0.08);
}

#lookZoneDebug {
  background: rgba(82,232,92,0.07);
}

#stickBase {
  position: fixed;
  left: max(22px, env(safe-area-inset-left));
  bottom: calc(114px + env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  border: 3px solid rgba(255,255,255,0.32);
  pointer-events: auto;
  touch-action: none;
}

#stickKnob {
  position: absolute;
  left: 43px;
  top: 43px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: rgba(255,255,255,0.6);
  border: 3px solid rgba(0,0,0,0.45);
  pointer-events: none;
}

#attackBtn, #throwBtn, #useBtn {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  border-radius: 10px;
  border: 2px solid #bbb;
  color: white;
  font-weight: 900;
  background: rgba(110,20,20,0.86);
  pointer-events: auto;
  height: 56px;
  width: 104px;
  touch-action: none;
  font-size: 15px;
}

#useBtn { bottom: calc(204px + env(safe-area-inset-bottom)); background: rgba(40,40,100,0.86); }
#attackBtn { bottom: calc(144px + env(safe-area-inset-bottom)); }
#throwBtn { bottom: calc(84px + env(safe-area-inset-bottom)); background: rgba(50,70,30,0.86); }

#startScreen {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: radial-gradient(circle at center, rgba(50,60,30,0.9), #050505);
  display: grid;
  place-items: center;
  color: white;
}

.startCard {
  width: min(520px, 86vw);
  border: 4px solid #777;
  background: #111;
  padding: 24px;
  text-align: center;
  box-shadow: 0 0 0 5px #000;
}

.startCard h1 {
  color: #ffd84a;
  margin: 0 0 10px 0;
  font-size: 42px;
}

.startCard .small {
  color: #ccc;
  font-size: 14px;
}

#startBtn {
  background: #6b8f2c;
  color: white;
  border: 3px solid #cde58b;
  padding: 12px 20px;
  font-weight: 900;
  font-size: 18px;
  cursor: pointer;
}

/* Desktop */
@media (hover: hover) and (pointer: fine) {
  #mobileControls { display: none; }
}

/* Portrait phones */
@media (orientation: portrait) and (max-width: 900px) {
  #rotateHint { display: block; }
  .hint { display: none; }
  #hud {
    height: 78px;
    grid-template-columns: 1fr 1fr 58px 1fr 1.1fr 0.8fr;
    font-size: 10px;
  }
  .big { font-size: 22px; line-height: 38px; }
  .face { font-size: 32px; }
  .weapon #weaponName, #item { font-size: 11px; }
}

/* Landscape phones */
@media (orientation: landscape) and (max-height: 520px) {
  #hud {
    height: 64px;
    grid-template-columns: 1fr 1fr 60px 1fr 1.2fr 0.9fr;
    padding: 4px;
  }
  .badge { padding: 4px 8px; font-size: 18px; }
  .hint { display: none; }
  .label { font-size: 11px; }
  .big { font-size: 20px; line-height: 32px; }
  .face { font-size: 30px; }
  .weapon #weaponName, #item { font-size: 11px; padding-top: 6px; }
  #stickBase {
    width: 112px;
    height: 112px;
    bottom: calc(78px + env(safe-area-inset-bottom));
  }
  #stickKnob {
    left: 36px;
    top: 36px;
  }
  #useBtn, #attackBtn, #throwBtn {
    width: 92px;
    height: 44px;
    font-size: 13px;
  }
  #useBtn { bottom: calc(174px + env(safe-area-inset-bottom)); }
  #attackBtn { bottom: calc(126px + env(safe-area-inset-bottom)); }
  #throwBtn { bottom: calc(78px + env(safe-area-inset-bottom)); }
  #minimap {
    top: max(48px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    font-size: 8px;
    padding: 5px 6px;
  }
  #fullscreenBtn {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    padding: 7px 9px;
    font-size: 11px;
  }
}


#damageFlash {
  position: fixed;
  inset: 0;
  z-index: 7;
  background: rgba(190, 0, 0, 0.0);
  pointer-events: none;
  transition: background 0.16s;
}

#weaponCanvas {
  position: fixed;
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(38px + env(safe-area-inset-bottom));
  width: min(22vw, 176px);
  height: auto;
  z-index: 3;
  image-rendering: pixelated;
  pointer-events: none;
  transform-origin: 82% 88%;
}

#weaponCanvas.swing {
  animation: scytheSwing 0.22s steps(3, end);
}

@keyframes scytheSwing {
  0% { transform: rotate(0deg) translate(0, 0); }
  40% { transform: rotate(-18deg) translate(-20px, -16px); }
  100% { transform: rotate(5deg) translate(4px, 8px); }
}

.pickupNotice {
  color: #ffd84a;
}

@media (orientation: portrait) and (max-width: 900px) {
  #weaponCanvas {
    width: min(32vw, 168px);
    bottom: calc(58px + env(safe-area-inset-bottom));
    right: max(2px, env(safe-area-inset-right));
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #weaponCanvas {
    width: min(16vw, 150px);
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(86px + env(safe-area-inset-right));
  }
}


/* v0.8 unified low-resolution pixel viewport.
   The WebGL scene and all visible game UI are rendered/drawn at 480x270,
   then the viewport is upscaled with nearest-neighbor. HTML controls remain
   as invisible high-resolution hit zones only. */
#pixelViewport {
  position: fixed;
  left: 0;
  top: 0;
  width: 480px;
  height: 270px;
  overflow: hidden;
  background: #000;
  image-rendering: pixelated;
  z-index: 1;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  touch-action: none;
  z-index: 1;
}

#uiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 2;
}

/* Hide former high-res visual layers. Their DOM remains available for state,
   messages and input, but the visible version is drawn on #uiCanvas. */
#rotateHint,
#topbar,
#centerCrosshair,
#damageFlash,
#hud,
#message,
#minimap,
#weaponCanvas {
  display: none !important;
}

/* Keep mobile controls as invisible touch targets. */
#stickBase {
  background: transparent !important;
  border-color: transparent !important;
}

#stickKnob {
  background: transparent !important;
  border-color: transparent !important;
}

#attackBtn,
#throwBtn,
#useBtn,
#fullscreenBtn {
  background: transparent !important;
  border-color: transparent !important;
  color: transparent !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

/* Start screen becomes an invisible hit layer. The pixel start menu is drawn
   on #uiCanvas while #startBtn remains tappable/clickable. */
#startScreen {
  background: transparent !important;
  pointer-events: none;
}

#startScreen .startCard {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  color: transparent !important;
}

#startScreen .startCard h1,
#startScreen .startCard p {
  color: transparent !important;
  text-shadow: none !important;
}

#startBtn {
  pointer-events: auto;
  background: transparent !important;
  border-color: transparent !important;
  color: transparent !important;
  text-shadow: none !important;
}

/* Desktop keeps controls hidden, but touch targets are not needed there. */
@media (hover: hover) and (pointer: fine) {
  #mobileControls {
    display: block;
    pointer-events: none;
  }
}


/* v0.1.9: make the whole start overlay tappable while keeping it visually invisible.
   The visible start menu/button is drawn on the low-res uiCanvas. */
#startScreen {
  pointer-events: auto !important;
  background: transparent !important;
}

#startScreen .startCard {
  pointer-events: none !important;
}

#startBtn {
  pointer-events: auto !important;
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  opacity: 0 !important;
  border: 0 !important;
  background: transparent !important;
  color: transparent !important;
}


/* v0.2.0 fullscreen retry target */
#fullscreenBtn {
  display: none;
  pointer-events: auto !important;
  opacity: 0 !important;
  position: fixed !important;
  right: max(8px, env(safe-area-inset-right)) !important;
  top: max(8px, env(safe-area-inset-top)) !important;
  width: 92px !important;
  height: 54px !important;
  z-index: 30 !important;
}


/* v0.2.1 fixed invisible touch targets matching the pixel-drawn controls */
#useBtn, #attackBtn, #throwBtn {
  display: block !important;
  pointer-events: auto !important;
  opacity: 0 !important;
  color: transparent !important;
  background: transparent !important;
  border-color: transparent !important;
  width: 92px !important;
  height: 54px !important;
  right: max(20px, env(safe-area-inset-right)) !important;
}

#useBtn {
  bottom: calc(200px + env(safe-area-inset-bottom)) !important;
}

#attackBtn {
  bottom: calc(140px + env(safe-area-inset-bottom)) !important;
}

#throwBtn {
  bottom: calc(80px + env(safe-area-inset-bottom)) !important;
}

@media (orientation: landscape) and (max-height: 520px) {
  #useBtn, #attackBtn, #throwBtn {
    width: 92px !important;
    height: 44px !important;
    right: max(18px, env(safe-area-inset-right)) !important;
  }

  #useBtn {
    bottom: calc(174px + env(safe-area-inset-bottom)) !important;
  }

  #attackBtn {
    bottom: calc(126px + env(safe-area-inset-bottom)) !important;
  }

  #throwBtn {
    bottom: calc(78px + env(safe-area-inset-bottom)) !important;
  }
}

#fullscreenBtn {
  display: none;
  pointer-events: auto !important;
  opacity: 0 !important;
  position: fixed !important;
  right: max(8px, env(safe-area-inset-right)) !important;
  top: max(8px, env(safe-area-inset-top)) !important;
  width: 120px !important;
  height: 70px !important;
  z-index: 50 !important;
}


/* v0.2.2: two-button mobile combat. ATTACK handles melee and ranged weapons. */
#throwBtn {
  display: none !important;
  pointer-events: none !important;
}

#useBtn, #attackBtn {
  display: block !important;
  pointer-events: auto !important;
  opacity: 0 !important;
  color: transparent !important;
  background: transparent !important;
  border-color: transparent !important;
  width: 104px !important;
  height: 64px !important;
  right: max(18px, env(safe-area-inset-right)) !important;
}

#useBtn {
  bottom: calc(150px + env(safe-area-inset-bottom)) !important;
}

#attackBtn {
  bottom: calc(78px + env(safe-area-inset-bottom)) !important;
}

@media (orientation: landscape) and (max-height: 520px) {
  #useBtn, #attackBtn {
    width: 104px !important;
    height: 56px !important;
    right: max(16px, env(safe-area-inset-right)) !important;
  }

  #useBtn {
    bottom: calc(140px + env(safe-area-inset-bottom)) !important;
  }

  #attackBtn {
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
  }
}


/* v0.2.9: invisible mobile pause button target; visible pixel button is drawn on uiCanvas */
#pauseBtn {
  display: block !important;
  position: fixed !important;
  top: max(8px, env(safe-area-inset-top)) !important;
  right: max(76px, calc(env(safe-area-inset-right) + 76px)) !important;
  width: 86px !important;
  height: 54px !important;
  z-index: 50 !important;
  pointer-events: auto !important;
  opacity: 0 !important;
  background: transparent !important;
  border: 0 !important;
  color: transparent !important;
}


/* v0.3.3: controls are handled by virtual 480x270 hit testing, not DOM button geometry. */
#pauseBtn {
  pointer-events: none !important;
}
