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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Mali', 'Prompt', system-ui, sans-serif;
  background: #87ceeb;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ===== overlays ===== */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, rgba(64,196,255,.35), rgba(255,110,199,.25));
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 16px;
}

.panel {
  background: #fffdf5;
  border: 4px solid #3b2f2f;
  border-radius: 24px;
  box-shadow: 0 10px 0 rgba(59,47,47,.35);
  padding: 26px 30px;
  width: min(420px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}

.title {
  font-size: 2.3rem; line-height: 1.15;
  color: #ff5252;
  text-shadow: 3px 3px 0 #ffd740, 5px 5px 0 rgba(59,47,47,.2);
  transform: rotate(-2deg);
}

.subtitle { color: #6d5d5d; font-size: 1.05rem; }

h2 { color: #3b2f2f; font-size: 1.5rem; }

input[type="text"] {
  font-family: inherit; font-size: 1.05rem;
  padding: 12px 16px;
  border: 3px solid #3b2f2f; border-radius: 14px;
  outline: none; text-align: center;
  background: #fff;
}
input[type="text"]:focus { border-color: #40c4ff; }

.btn {
  font-family: inherit; font-size: 1.05rem; font-weight: 700;
  padding: 12px 18px;
  border: 3px solid #3b2f2f; border-radius: 16px;
  background: #ffd740; color: #3b2f2f;
  cursor: pointer;
  box-shadow: 0 4px 0 #3b2f2f;
  transition: transform .06s, box-shadow .06s;
  flex: 1;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #3b2f2f; }
.btn-big { font-size: 1.35rem; padding: 15px 20px; background: #69f0ae; }
.btn-small { font-size: .9rem; padding: 8px 14px; flex: 0 auto; background: #eee; }

.row { display: flex; gap: 10px; }

.error { color: #ff5252; font-weight: 700; }
.hint { color: #9a8b8b; font-size: .92rem; }

.how-to { text-align: left; color: #5d4f4f; font-size: .92rem; }
.how-to summary { cursor: pointer; text-align: center; font-weight: 700; color: #40a4dd; }
.how-to p { margin: 7px 0; }

/* lobby */
.room-code-box {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: #6d5d5d;
}
.room-code {
  font-size: 2rem; font-weight: 700; letter-spacing: .35em;
  color: #3b2f2f; background: #fff3c4;
  border: 3px dashed #ffb300; border-radius: 12px;
  padding: 4px 10px 4px 20px;
}
.player-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  background: #f6f1e5; border-radius: 12px; padding: 8px 14px;
  font-weight: 700; color: #3b2f2f;
}
.player-list .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #3b2f2f; }
.player-list .host-tag { margin-left: auto; font-size: .8rem; color: #ff9800; }

/* ===== HUD ===== */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#scoreboard {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: .95rem;
}
.score-row {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,253,245,.88);
  border: 2px solid #3b2f2f; border-radius: 12px;
  padding: 3px 10px;
  color: #3b2f2f; font-weight: 700;
}
.score-row.dead { opacity: .45; text-decoration: line-through; }
.score-row .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #3b2f2f; }
.score-row .pct { margin-left: auto; color: #ff5252; }

#own-status {
  position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  pointer-events: none;
}
/* touch mode: lift own-status above the buttons */
body.touch-mode #own-status { bottom: 130px; }
#own-dmg {
  font-size: 2.4rem; font-weight: 700; color: #fff;
  -webkit-text-stroke: 2px #3b2f2f;
  text-shadow: 0 4px 0 rgba(59,47,47,.3);
}
#own-item { font-size: 1.6rem; background: rgba(255,253,245,.9); border: 2px solid #3b2f2f; border-radius: 12px; padding: 2px 10px; }

#banner {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%) rotate(-2deg);
  font-size: clamp(1.6rem, 5vw, 3rem); font-weight: 700;
  color: #fff; -webkit-text-stroke: 2px #3b2f2f;
  text-shadow: 4px 4px 0 rgba(59,47,47,.25);
  text-align: center; white-space: nowrap;
  animation: pop-in .4s cubic-bezier(.3,1.6,.6,1);
}
@keyframes pop-in { from { transform: translateX(-50%) scale(0) rotate(-20deg); } }

#feed {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: .9rem; max-width: 46vw;
}
.feed-item {
  background: rgba(59,47,47,.75); color: #fff;
  border-radius: 10px; padding: 3px 10px;
  animation: pop-in-l .3s ease-out;
}
@keyframes pop-in-l { from { opacity: 0; transform: translateX(-16px); } }

#shrink-warn {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  color: #fff; background: #ff5252;
  border: 3px solid #3b2f2f; border-radius: 14px;
  padding: 6px 18px; font-weight: 700;
  animation: blink 0.8s infinite;
}
@keyframes blink { 50% { opacity: .5; } }

/* ===== touch controls ===== */
#touch-ui { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#joystick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 45%; pointer-events: auto; }
#joystick {
  position: absolute; width: 120px; height: 120px;
  border-radius: 50%; background: rgba(255,255,255,.25);
  border: 3px solid rgba(255,255,255,.6);
  transform: translate(-50%, -50%);
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 3px solid #3b2f2f;
  transform: translate(-50%, -50%);
}
.touch-buttons {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; align-items: flex-end; gap: 12px;
  pointer-events: auto;
}
.tbtn {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid #3b2f2f;
  background: rgba(255,253,245,.85);
  font-size: 1.7rem;
  box-shadow: 0 4px 0 rgba(59,47,47,.5);
  touch-action: none;
}
.tbtn:active, .tbtn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 rgba(59,47,47,.5); background: #ffd740; }
.tbtn-big { width: 92px; height: 92px; font-size: 2.6rem; }
