:root {
  --bg: #11161c;
  --panel: #1a222b;
  --panel-2: #222c37;
  --text: #e8edf2;
  --muted: #8b98a6;
  --gold: #f5b700;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
}

#app {
  display: flex;
  gap: 12px;
  height: 100%;
  padding: 12px;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #2c3846, 0 10px 40px #0008;
  image-rendering: auto;
}

#feed {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

#feed div {
  background: #000a;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  animation: fade 4s forwards;
}

@keyframes fade {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

#side {
  width: 270px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  padding: 12px;
}

#lobbybar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

#side h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  color: var(--gold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#lobbybar button {
  border: 0;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 14px;
  cursor: pointer;
}

#lobbybar button:hover { background: #2d3a48; }

#board {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

#board li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 2px 8px;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
}

#board li.me { background: var(--panel-2); }
#board li.dead { opacity: 0.45; }
#board canvas { grid-row: span 2; }
#board .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .score { font-weight: 700; color: var(--gold); }
#board .buffs { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
#board .msg {
  grid-column: 2 / 4;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chatbox { margin-top: 8px; }

#chat {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #334050;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

#chat:focus { outline: 2px solid var(--gold); }

#footer {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#mute {
  border: 0;
  background: var(--panel-2);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 16px;
  cursor: pointer;
}

#rtt {
  font-size: 12px;
  color: var(--muted);
}

/* --- Touch controls --- */
#touch[hidden] { display: none; }

#stickzone, #bombbtn {
  position: fixed;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 5;
}

/* thumb can land anywhere in here, the stick follows it */
#stickzone {
  left: 0;
  bottom: 0;
  width: 55vw;
  height: 230px;
}

#bombbtn { bottom: max(20px, env(safe-area-inset-bottom)); }

#stick {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  pointer-events: none;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: #ffffff14;
  border: 2px solid #ffffff30;
}

#stick.active { background: #ffffff22; border-color: #ffffff55; }

#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: #ffffff55;
  box-shadow: 0 4px 12px #0006;
  pointer-events: none;
}

#bombbtn {
  right: max(24px, env(safe-area-inset-right));
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid #ffe27a;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f5b700 55%, #9b6200);
  font-size: 40px;
  box-shadow: 0 6px 18px #0008;
  opacity: 0.85;
}

#bombbtn.down { transform: scale(0.92); opacity: 1; }

body.touch { touch-action: manipulation; overscroll-behavior: none; }
body.touch #chat { font-size: 16px; } /* avoids iOS zoom on focus */

#join {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  background: #0009;
  backdrop-filter: blur(3px);
  z-index: 10;
}

#join.hidden { display: none; }

#menu {
  width: min(440px, 100%);
  margin: auto 0;
  background: var(--panel);
  padding: 24px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px #000a;
}

#menu h2 { margin: 0; color: var(--gold); font-size: 28px; }
#menu h3 { margin: 0 0 8px; font-size: 15px; }
#menu section, #createform { display: flex; flex-direction: column; }
#createform { gap: 10px; border-top: 1px solid #2c3846; padding-top: 14px; }
#createform h3 { margin: 0; }

.hint { margin: 0; color: var(--muted); }
.hint.small { font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.field output { color: var(--text); font-weight: 700; }

.field input:not([type=range]), #menu button {
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
}

.field input:not([type=range]) { border: 1px solid #334050; background: var(--bg); color: var(--text); }
.field input[type=range] { accent-color: var(--gold); }
.field input.invalid { outline: 2px solid #e5484d; }

.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

#menu button {
  border: 0;
  background: var(--gold);
  color: #241a00;
  font-weight: 700;
  cursor: pointer;
}

#menu button:disabled { background: #3a4350; color: var(--muted); cursor: default; }

#menu-error {
  background: #e5484d22;
  color: #ff8a8d;
  padding: 8px 10px;
  border-radius: 8px;
}

#lobbies { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
#lobbies li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 10px;
  background: var(--panel-2);
  padding: 8px 10px;
  border-radius: 8px;
}
#lobbies li.invited { outline: 2px solid var(--gold); }
#lobbies li.empty { display: block; color: var(--muted); background: none; padding: 0; }
#lobbies .lname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lobbies .meta { grid-column: 1; font-size: 12px; color: var(--muted); }
#lobbies button { grid-row: 1 / 3; grid-column: 2; padding: 8px 14px; font-size: 14px; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 10px; }

@media (max-width: 800px) and (orientation: portrait) {
  #app { flex-direction: column; height: auto; }
  #side { width: 100%; }
  body.touch #app { padding-bottom: 190px; }
}

/* Phone in landscape: slim sidebar, controls overlay the screen edges */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  #app { padding: 6px; gap: 6px; }
  #side { width: 180px; padding: 8px; font-size: 12px; }
  #side h1 { font-size: 14px; }
  #lobbybar { margin-bottom: 4px; }
  #board li { grid-template-columns: 28px 1fr auto; padding: 3px; }
  #board canvas { width: 28px; height: 28px; }
  #stickzone { width: 45vw; height: 100%; }
  #stick { width: 120px; height: 120px; opacity: 0.8; }
  #bombbtn { width: 80px; height: 80px; font-size: 32px; right: 200px; }
}
