* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #2b2118;
  color: #f5ecd9;
  overflow: hidden;
}

.screen { display: none; height: 100%; }
.screen.active { display: flex; align-items: center; justify-content: center; }
#game.active { display: block; position: relative; }

.card {
  width: min(560px, 94vw);
  max-height: 96vh;
  overflow-y: auto;
  background: #3d2f22;
  border: 2px solid #6b5238;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.card.small { width: min(360px, 90vw); text-align: center; }

h1 { margin: 0 0 4px; font-size: 2rem; color: #ffcf6e; }
h2 { margin: 0 0 8px; font-size: 1.05rem; }
.tagline, .hint { color: #c9b89a; margin: 4px 0 16px; }
label { display: block; margin: 12px 0 6px; font-size: 0.9rem; color: #e0cfae; }

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #6b5238;
  background: #2b2118;
  color: #f5ecd9;
  font-size: 1rem;
}

button {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: #8a6a45;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.primary { background: #d9822b; margin-top: 16px; }
button.ghost { background: transparent; border: 1px solid #6b5238; color: #c9b89a; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.panel { background: #33271c; border-radius: 12px; padding: 12px; }
.panel input { margin-bottom: 4px; }
@media (max-width: 480px) { .split { grid-template-columns: 1fr; } }

.code { font-size: 1.2rem; margin: 8px 0 0; }
.code strong { color: #ffcf6e; letter-spacing: 4px; font-size: 1.6rem; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team { border-radius: 12px; padding: 12px; min-height: 140px; }
.team.red { background: rgba(214, 69, 65, 0.25); border: 1px solid #d64541; }
.team.blue { background: rgba(52, 120, 219, 0.25); border: 1px solid #3478db; }
.team ul { list-style: none; padding: 0; margin: 0 0 8px; min-height: 60px; }
.team li { padding: 4px 0; }
.team li.me { font-weight: 700; color: #ffcf6e; }

.error { color: #ff7b6b; min-height: 1.2em; margin: 8px 0 0; }

#canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#hud { position: absolute; top: 10px; left: 10px; right: 10px; pointer-events: none; }
#hpWrap {
  position: relative;
  width: 200px;
  height: 22px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 11px;
  overflow: hidden;
}
#hpBar { height: 100%; width: 100%; background: #4cd964; transition: width 0.15s, background 0.15s; }
#hpText { position: absolute; inset: 0; text-align: center; font-size: 0.8rem; line-height: 22px; font-weight: 700; }

#killFeed {
  position: absolute;
  top: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 60vw;
  text-align: right;
  font-size: 0.85rem;
}
#killFeed li {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
}

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.plabel {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}
.plabel .pname {
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
}
.plabel.me .pname { color: #ffcf6e; }
.plabel .php { width: 40px; height: 5px; background: rgba(0, 0, 0, 0.6); border-radius: 3px; overflow: hidden; }
.plabel .php div { height: 100%; background: #4cd964; }
.plabel.dead .php { display: none; }

.bubble {
  max-width: 200px;
  white-space: normal;
  text-align: center;
  background: #fffbea;
  color: #2b2118;
  border: 2px solid #3a2a1a;
  border-radius: 10px;
  padding: 5px 9px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
  animation: pop 0.2s ease-out;
}
.bubble.victim { background: #e8eef8; }

.floater {
  position: absolute;
  transform: translate(-50%, -100%);
  font-weight: 900;
  font-size: 20px;
  text-shadow: 0 2px 3px #000;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

#crosshair {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 4px #000;
  pointer-events: none;
}
#crosshair::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  background: #fff;
  border-radius: 50%;
}
#powerFill {
  position: absolute;
  left: 40px;
  bottom: 0;
  width: 6px;
  height: 0;
  background: #ffcf6e;
  border-radius: 3px;
}

#centerText {
  position: absolute;
  top: 40%;
  width: 100%;
  text-align: center;
  font-size: 72px;
  font-weight: 900;
  color: #ffcf6e;
  -webkit-text-stroke: 2px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
#centerText.small { font-size: 26px; }

#dpad {
  position: absolute;
  left: 16px;
  bottom: 36px;
  width: 150px;
  height: 150px;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  touch-action: none;
}
#dpad button {
  margin: 0;
  padding: 0;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.4);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#dpad button.on { background: rgba(255, 207, 110, 0.6); }
#dpad [data-dir="up"] { grid-area: 1 / 2; }
#dpad [data-dir="left"] { grid-area: 2 / 1; }
#dpad [data-dir="right"] { grid-area: 2 / 3; }
#dpad [data-dir="down"] { grid-area: 3 / 2; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

#controlsHint {
  position: absolute;
  bottom: 6px;
  width: 100%;
  text-align: center;
  margin: 0;
  font-size: 0.8rem;
  color: rgba(245, 236, 217, 0.7);
  pointer-events: none;
}

.hidden { display: none !important; }
