:root {
  --bg: #12101c;
  --panel: #1d1a2e;
  --panel2: #27233d;
  --text: #f2eefc;
  --muted: #9a93b8;
  --accent: #ff8a3d;
  --accent2: #ffcf3d;
  --danger: #ff4d6d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #2a2145 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
}
.screen { display: none; height: 100%; width: 100%; align-items: center; justify-content: center; padding: 16px; }
.screen.active { display: flex; }
.card {
  background: var(--panel); border: 1px solid #ffffff14; border-radius: 18px;
  padding: 28px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px #0008; display: flex; flex-direction: column; gap: 14px;
}
.card.wide { max-width: 520px; }
.logo { margin: 0; font-size: 52px; letter-spacing: -1px; text-align: center; font-weight: 900; }
.logo span { color: var(--accent); text-shadow: 0 0 24px #ff8a3d88; }
.tagline { margin: -6px 0 6px; text-align: center; color: var(--muted); }
h2 { margin: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  background: var(--panel2); border: 1px solid #ffffff1a; color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 16px; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }
#code { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 700; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid #ffffff22;
  padding: 12px 16px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button.primary { background: linear-gradient(135deg, var(--accent), #ff5d3d); border: none; color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; }
.row > input { flex: 1; min-width: 0; }
.or { text-align: center; color: var(--muted); font-size: 13px; position: relative; }
.or::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid #ffffff1a; }
.or span { background: var(--panel); padding: 0 10px; position: relative; }
.error { color: var(--danger); min-height: 1em; margin: 0; font-size: 14px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.8; border-top: 1px solid #ffffff12; padding-top: 12px; }
kbd { background: var(--panel2); border: 1px solid #ffffff22; border-radius: 5px; padding: 1px 6px; font-size: 12px; color: var(--text); }
.code { color: var(--accent2); letter-spacing: 3px; }
.banner { margin: 0; font-weight: 700; color: var(--accent2); min-height: 0; }
.banner:empty { display: none; }

#playerList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#playerList li {
  display: flex; align-items: center; gap: 12px; background: var(--panel2);
  padding: 10px 14px; border-radius: 10px;
}
#playerList .dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset -3px -3px 0 #0003; flex: none; }
#playerList .pname { flex: 1; font-weight: 600; }
#playerList .tag { font-size: 11px; color: var(--muted); border: 1px solid #ffffff22; border-radius: 6px; padding: 2px 6px; }
#playerList .score { font-weight: 800; color: var(--accent2); }
#playerList li.empty { color: var(--muted); font-style: italic; justify-content: center; }
#hostControls button { flex: 1; }

.chat { border-top: 1px solid #ffffff12; padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
#chatLog { height: 90px; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
#chatLog b { margin-right: 6px; }

/* Game */
#game { flex-direction: column; gap: 10px; padding: 10px; }
#hud { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 980px; min-width: 0; }
#hudPlayers { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.hp {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 10px;
  padding: 6px 10px; font-size: 13px; border: 2px solid transparent;
}
.hp.me { border-color: #ffffff55; }
.hp.dead { opacity: .35; filter: grayscale(1); }
.hp .dot { width: 14px; height: 14px; border-radius: 50%; }
.hp .stats { color: var(--muted); font-size: 12px; }
#timer { font-size: 22px; font-weight: 800; background: var(--panel); padding: 6px 14px; border-radius: 10px; font-variant-numeric: tabular-nums; }
#timer.low { color: var(--danger); }
#stage { position: relative; flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; overflow: hidden; }
#overlay > div { max-width: 92%; }
canvas { border-radius: 12px; box-shadow: 0 10px 50px #000a; image-rendering: auto; }
#overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-size: clamp(28px, 7vw, 72px); font-weight: 900; text-align: center; text-shadow: 0 4px 0 #0008, 0 0 30px #000;
}
#overlay .sub { display: block; font-size: .35em; font-weight: 600; color: var(--muted); margin-top: 8px; }
.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#touch { display: none; width: 100%; max-width: 520px; justify-content: space-between; align-items: center; padding: 0 10px 10px; }
body.touch #touch { display: flex; }
.dpad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); gap: 4px; }
.dpad button { font-size: 22px; padding: 0; border-radius: 12px; user-select: none; -webkit-user-select: none; }
.dpad [data-dir=up] { grid-column: 2; grid-row: 1; }
.dpad [data-dir=left] { grid-column: 1; grid-row: 2; }
.dpad [data-dir=right] { grid-column: 3; grid-row: 2; }
.dpad [data-dir=down] { grid-column: 2; grid-row: 3; }
.dpad button.on, #bombBtn.on { background: var(--accent); }
#bombBtn { width: 96px; height: 96px; border-radius: 50%; font-size: 40px; padding: 0; user-select: none; -webkit-user-select: none; }

/* Lobby: bigger rooms + monster setting */
.card.wide { max-height: calc(100vh - 32px); overflow-y: auto; }
#playerList { display: grid; grid-template-columns: 1fr 1fr; }
#playerList li { padding: 8px 10px; gap: 8px; min-width: 0; }
#playerList .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) { #playerList { grid-template-columns: 1fr; } }
.listhead { display: flex; justify-content: space-between; align-items: baseline; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel2); padding: 8px 10px 8px 14px; border-radius: 10px; font-weight: 600; }
.seg { display: flex; gap: 4px; }
.seg button { padding: 7px 14px; font-size: 13px; }
.seg button.active { background: linear-gradient(135deg, #9b5cff, #ff3b3b); border-color: transparent; color: #fff; opacity: 1; }
.seg button:disabled:not(.active) { opacity: .4; }
.hp.compact { padding: 4px 8px; font-size: 12px; gap: 6px; }
.hp.compact .dot { width: 10px; height: 10px; }
#hudPlayers { gap: 6px; }

/* Scoring, kill feed, info bar */
.hp .pts { font-weight: 800; color: var(--accent2); font-variant-numeric: tabular-nums; }
#infobar { display: flex; gap: 14px; width: 100%; max-width: 980px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
#infobar b { color: var(--text); }
#pingInfo { margin-left: auto; }
#feed { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; pointer-events: none; max-width: 60%; }
.feedline { background: #000a; padding: 4px 10px; border-radius: 8px; font-size: 13px; transition: opacity .8s; animation: slidein .25s ease-out; }
.feedline i { color: var(--accent2); font-style: normal; font-weight: 700; }
.feedline .warn { color: #ff8a3d; }
.feedline.fade { opacity: 0; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
#banner { position: absolute; top: 18%; left: 0; right: 0; text-align: center; font-size: clamp(22px, 5vw, 44px); font-weight: 900; color: #ff8a3d; text-shadow: 0 3px 0 #000a, 0 0 30px #ff3b3b; opacity: 0; pointer-events: none; }
#banner.show { animation: bannerAnim 2.2s ease-out; }
@keyframes bannerAnim { 0% { opacity: 0; transform: scale(1.8); } 15% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }
table.board { margin: 14px auto 0; border-collapse: collapse; font-size: clamp(11px, 1.6vw, 15px); font-weight: 600; text-shadow: none; background: #120f1ee6; border-radius: 12px; overflow: hidden; }
table.board th, table.board td { padding: 6px 10px; text-align: center; }
table.board th { color: var(--muted); font-weight: 600; background: #ffffff0d; }
table.board td:nth-child(2) { text-align: left; white-space: nowrap; }
table.board tr.me td { background: #ffffff14; }
table.board .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* Settings panel, lock, volume, kick */
details#settingsBox { background: var(--panel2); border-radius: 12px; padding: 10px 12px; }
details#settingsBox summary { cursor: pointer; font-weight: 700; }
#settingsGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
#settingsGrid .opt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
#settingsGrid .opt.wide { grid-column: 1 / -1; }
@media (max-width: 480px) { #settingsGrid { grid-template-columns: 1fr; } }
select {
  background: var(--panel); color: var(--text); border: 1px solid #ffffff22; border-radius: 8px;
  padding: 8px 10px; font-size: 14px; width: 100%;
}
select:disabled { opacity: .75; }
select:focus { outline: none; border-color: var(--accent); }
.mapdesc { margin-top: 8px; font-style: italic; }
.lockrow { flex-direction: row; align-items: center; gap: 8px; margin-top: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.lockrow input { width: auto; }
.volrow { display: flex; align-items: center; gap: 8px; }
.volrow input[type=range] { flex: 1; padding: 0; accent-color: var(--accent); background: transparent; border: none; }
.volrow.small input[type=range] { width: 90px; flex: none; }
.volicon { padding: 4px 8px; font-size: 16px; background: transparent; border: none; }
#playerList .kick { padding: 2px 8px; font-size: 12px; background: transparent; border-color: #ff4d6d66; color: var(--danger); }
