* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { width: 100%; height: 100%; background: #07060f; overflow: hidden; }

body {
  display: grid;
  place-items: center;
  font-family: 'Nunito', 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
  font-weight: 700;
  color: #f6ecd2;
  user-select: none;
}

#game {
  --px: 3px;
  position: relative;
  width: calc(384 * var(--px));
  height: calc(216 * var(--px));
  overflow: hidden;
  background: #000;
  font-size: calc(var(--px) * 7);
  line-height: 1.35;
}

canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; }
.hidden { display: none !important; }
#ui { position: absolute; inset: 0; pointer-events: none; }

.panel {
  background: #1a1030;
  border: var(--px) solid #f3e2b0;
  box-shadow:
    0 0 0 var(--px) #0c0914,
    0 0 0 calc(var(--px) * 2) #3ec8b4,
    0 calc(var(--px) * 3) 0 calc(var(--px) * 2) rgba(0, 0, 0, 0.35);
}

.key {
  display: inline-block;
  padding: 0 calc(var(--px) * 1.5);
  margin-right: calc(var(--px) * 1.5);
  background: #f3e2b0;
  color: #1a1030;
  border-radius: var(--px);
  line-height: 1.2;
}

#hud {
  position: absolute;
  top: calc(var(--px) * 6);
  left: calc(var(--px) * 6);
  right: calc(var(--px) * 6);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: calc(var(--px) * 4);
}
.hud-left, .hud-right { display: flex; gap: calc(var(--px) * 4); flex-wrap: wrap; }
.chip {
  display: flex;
  align-items: center;
  gap: calc(var(--px) * 3);
  padding: calc(var(--px) * 2) calc(var(--px) * 4);
  font-size: calc(var(--px) * 7);
  line-height: 1.15;
  white-space: nowrap;
}
#hud-role.caught { color: #ff8aa0; }
#hud-timer.low { color: #ffb15a; }
#hud-online { color: #8fd8ff; }
#hud-sound.off #hud-sound-icon { opacity: 0.35; text-decoration: line-through; }
.tap { pointer-events: auto; cursor: pointer; }

#monster-chip {
  position: absolute;
  top: calc(var(--px) * 28);
  left: 50%;
  transform: translateX(-50%);
  color: #ff8aa0;
  background: #2a1020;
}

#toast {
  position: absolute;
  top: calc(var(--px) * 64);
  left: 50%;
  transform: translateX(-50%);
  padding: calc(var(--px) * 3) calc(var(--px) * 6);
  font-size: calc(var(--px) * 7.5);
  white-space: nowrap;
  color: #ffd27a;
  max-width: calc(100% - var(--px) * 16);
  overflow: hidden;
  text-overflow: ellipsis;
}

#banner {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Pixelify Sans', 'Nunito', sans-serif;
  font-size: calc(var(--px) * 36);
  color: #ffe08a;
  text-shadow:
    calc(var(--px) * 2) calc(var(--px) * 2) 0 #2a1238,
    calc(var(--px) * 3) calc(var(--px) * 3) 0 #2a1238;
  white-space: nowrap;
}
#banner.small {
  font-family: 'Nunito', sans-serif;
  font-size: calc(var(--px) * 8);
  top: calc(var(--px) * 32);
  padding: calc(var(--px) * 2) calc(var(--px) * 5);
  background: rgba(18, 10, 32, 0.88);
  border: var(--px) solid #f3e2b0;
  text-shadow: none;
  color: #ffe7b0;
}

#action, #hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: calc(var(--px) * 2) calc(var(--px) * 5);
  font-size: calc(var(--px) * 6.5);
  white-space: nowrap;
}
#action { bottom: calc(var(--px) * 22); color: #fff6dc; }
#hint { bottom: calc(var(--px) * 6); transition: opacity 1.2s; }
#hint.fade { opacity: 0; }

#lobby, #result {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.card {
  pointer-events: auto;
  width: min(92%, calc(var(--px) * 250));
  padding: calc(var(--px) * 8) calc(var(--px) * 8) calc(var(--px) * 6);
  text-align: center;
  background: rgba(18, 10, 32, 0.92);
}
.logo { font-family: 'Pixelify Sans', 'Nunito', sans-serif; line-height: 0.9; }
.logo .l1 {
  display: block;
  font-size: calc(var(--px) * 22);
  letter-spacing: calc(var(--px) * 2);
  color: #f6ecd2;
}
.logo .l2 {
  display: block;
  margin-top: calc(var(--px) * 2);
  font-size: calc(var(--px) * 14);
  color: #7ef0dc;
}
#lobby-msg, #result-next {
  margin: calc(var(--px) * 5) 0;
  font-size: calc(var(--px) * 7);
  color: #ffe7b0;
}
.choices { display: flex; gap: calc(var(--px) * 6); justify-content: center; }
.choices button, .texty {
  pointer-events: auto;
  font: 800 calc(var(--px) * 8) 'Nunito', sans-serif;
  color: #1a1030;
  background: #f3e2b0;
  border: var(--px) solid #0c0914;
  box-shadow: 0 0 0 var(--px) #3ec8b4;
  padding: calc(var(--px) * 3) calc(var(--px) * 6);
  cursor: pointer;
}
.choices button.on { background: #7ef0dc; }
.texty {
  margin-top: calc(var(--px) * 4);
  background: transparent;
  color: #f3e2b0;
  box-shadow: none;
  border-color: transparent;
}
#roster { list-style: none; margin-top: calc(var(--px) * 4); font-size: calc(var(--px) * 6.5); color: #d7c8ea; }
#roster li { margin-top: calc(var(--px) * 1); }
#result h2 {
  font-family: 'Pixelify Sans', 'Nunito', sans-serif;
  font-size: calc(var(--px) * 16);
  color: #ffe08a;
}
#result h3 { margin-top: calc(var(--px) * 3); font-size: calc(var(--px) * 7); color: #7ef0dc; }
#result ul { list-style: none; font-size: calc(var(--px) * 6.5); }
#result .monster-line { margin-top: calc(var(--px) * 3); color: #ff8aa0; }

html, body, body * { touch-action: none; }
html, body { overscroll-behavior: none; -webkit-user-select: none; }
body.touch .kb { display: none !important; }
body:not(.touch) .tc { display: none !important; }

#touch {
  --stick: clamp(110px, 30vmin, 170px);
  --btn: clamp(72px, 20vmin, 120px);
  --edge: 22px;
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
#stick-zone { position: absolute; left: 0; top: 0; width: 50%; height: 100%; pointer-events: auto; }
#stick {
  position: absolute;
  left: calc(max(var(--edge), env(safe-area-inset-left)) + var(--stick) / 2);
  top: calc(100% - max(var(--edge), env(safe-area-inset-bottom)) - var(--stick) / 2);
  width: var(--stick);
  height: var(--stick);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(26, 16, 48, 0.4);
  border: 3px solid rgba(243, 226, 176, 0.5);
  opacity: 0.6;
}
#stick.active { opacity: 1; }
#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 44%; height: 44%;
  margin: -22% 0 0 -22%;
  border-radius: 50%;
  background: #f3e2b0;
  border: 3px solid #3ec8b4;
}
#stick.run #stick-knob { background: #ffb15a; }
.tbtn {
  position: absolute;
  right: max(var(--edge), env(safe-area-inset-right));
  bottom: max(var(--edge), env(safe-area-inset-bottom));
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
  pointer-events: auto;
  font: 800 22px 'Nunito', sans-serif;
  color: #f3e2b0;
  background: #1a1030;
  border: 3px solid #f3e2b0;
  box-shadow: 0 0 0 3px #0c0914, 0 0 0 6px #3ec8b4;
}
.tbtn.down { transform: translateY(2px); }

#rotate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #07060f;
  text-align: center;
  font-size: 20px;
}
#rotate .phone {
  width: 48px; height: 84px;
  border: 4px solid #f3e2b0;
  border-radius: 8px;
  animation: turn 2s ease-in-out infinite;
}
@keyframes turn { 0%, 30% { transform: rotate(0); } 70%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 760px) {
  body.touch #rotate { display: flex; }
}
