:root {
  --bg: #0b0b16;
  --panel: #151527;
  --panel2: #1d1d36;
  --line: #2c2c52;
  --text: #ece9ff;
  --dim: #9a96c2;
  --accent: #ff5a2a;
  --accent2: #ffb02e;
  --violet: #8d6bff;
  --p0: #44dcff;
  --p1: #ff4fa0;
  --p2: #9cff4a;
  --p3: #ffb23f;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

.screen { display: none; height: 100%; position: relative; }
.screen.active { display: flex; }

/* ---------- landing ---------- */
#screen-landing { align-items: center; justify-content: center; overflow: hidden; }
#title-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.landing-inner {
  position: relative;
  width: min(440px, 92vw);
  text-align: center;
  padding: calc(16px + var(--safe-t)) 0 calc(16px + var(--safe-b));
}
.logo {
  margin: 0 0 4px;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 0.9;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: clamp(44px, 13vw, 76px);
  text-transform: uppercase;
}
.logo .l1 {
  font-size: 0.55em;
  letter-spacing: 0.5em;
  margin-right: -0.5em;
  color: var(--violet);
  text-shadow: 0 0 18px #8d6bff88;
}
.logo .l2 {
  background: linear-gradient(180deg, #fff3c4 0%, #ffb02e 40%, #ff5a2a 75%, #b3122a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px #ff5a2a99) drop-shadow(0 4px 0 #3b0a14);
}
.tag { color: var(--dim); margin: 6px 0 18px; }
.card {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 40px #0008;
}
.field { display: block; text-align: left; color: var(--dim); font-size: 13px; margin-bottom: 12px; }
.field input, .join-row input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0c0c1a;
  color: var(--text);
  outline: none;
}
.field input:focus, .join-row input:focus { border-color: var(--violet); }
.row { display: flex; gap: 10px; justify-content: center; margin: 10px 0; }
.big {
  flex: 1;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-weight: 700;
  transition: transform 0.08s, background 0.15s;
}
.big:hover { background: #26264a; }
.big:active { transform: scale(0.97); }
.big.primary {
  background: linear-gradient(180deg, #ff7a3a, #e8401e);
  border-color: #ff8a4a;
  color: #fff;
  box-shadow: 0 4px 24px #ff5a2a55, inset 0 1px 0 #ffffff44;
}
.big.primary:hover { background: linear-gradient(180deg, #ff8a4a, #f04a24); }
.big:disabled { opacity: 0.5; cursor: default; }
/* the pad / arrow-key highlight (menunav.js) */
.padfocus { outline: 3px solid var(--accent2) !important; outline-offset: 3px; box-shadow: 0 0 22px #ffb02e88 !important; }
button:focus:not(.padfocus) { outline: none; }
.join-row input { margin: 0; text-transform: uppercase; letter-spacing: 0.2em; text-align: center; font-weight: 700; }
.join-row .big { flex: 0 0 auto; }
.seg { display: inline-flex; background: #0c0c1a; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; justify-content: center; }
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--dim);
  font-size: 14px;
  font-weight: 600;
}
.seg button.on { background: var(--violet); color: #fff; box-shadow: 0 0 12px #8d6bff66; }
.seg[aria-disabled="true"] button { cursor: default; }
.error { color: #ff7a7a; font-weight: 600; }
.ok { color: #7dff9a; font-size: 13px; }
.hint { color: var(--dim); font-size: 13px; }
.hint.keys { font-size: 12px; opacity: 0.8; }
.linkish { background: none; border: 0; color: var(--dim); text-decoration: underline; padding: 8px; }
.ghost {
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  color: var(--dim);
}
.ghost:hover { color: var(--text); border-color: var(--violet); }

/* ---------- lobby ---------- */
#screen-lobby { justify-content: center; overflow-y: auto; }
.lobby-inner { width: min(560px, 94vw); padding: calc(18px + var(--safe-t)) 0 calc(24px + var(--safe-b)); text-align: center; }
.lobby-head { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.lobby-head h2 { margin: 0; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.18em; color: var(--accent2); }
.share {
  border: 1px solid var(--accent2);
  background: #ffb02e18;
  color: var(--accent2);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
}
.seats { list-style: none; padding: 0; margin: 16px 0 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  min-height: 64px;
  text-align: left;
}
.seat canvas { width: 44px; height: 44px; flex: 0 0 auto; }
.seat .who { flex: 1; min-width: 0; }
.seat .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .sub { font-size: 12px; color: var(--dim); }
.seat input { width: 100%; background: #0c0c1a; border: 1px solid var(--line); border-radius: 7px; color: var(--text); padding: 4px 6px; font-weight: 700; }
.seat.empty { opacity: 0.55; border-style: dashed; }
.seat.mine { border-color: color-mix(in srgb, var(--c) 70%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--c) 25%, transparent); }
.seat .x { background: none; border: 0; color: var(--dim); font-size: 18px; padding: 4px; }
.settings { text-align: left; margin-top: 14px; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; flex-wrap: wrap; }
.set > span { color: var(--dim); font-size: 14px; }

/* ---------- game ---------- */
#screen-game { flex-direction: column; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l));
  min-height: 52px;
}
#hud-players { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; min-width: 0; }
.hp {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  border-radius: 10px;
  padding: 4px 8px;
  min-width: 0;
  transition: opacity 0.3s;
}
.hp.dead { opacity: 0.4; }
.hp .nm { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.hp .wins { display: flex; gap: 2px; flex: 0 0 auto; }
.hp .wins i { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--c); }
.hp .wins i.w { background: var(--c); box-shadow: 0 0 6px var(--c); }
.hp .stats { font-size: 11px; color: var(--dim); white-space: nowrap; flex: 0 0 auto; }
#hud-timer {
  font: 800 20px/1 ui-monospace, Menlo, monospace;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  min-width: 70px;
  text-align: center;
}
#hud-timer.hurry { color: #fff; background: #c41d3a; border-color: #ff4d6a; animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 22px #ff2a4a; } }
#arena-wrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
#arena { display: block; }
#banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: clamp(34px, 9vw, 84px);
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 0 24px currentColor, 0 4px 0 #0009;
  white-space: nowrap;
}
#banner.pop { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
#banner small { display: block; font-size: 0.32em; letter-spacing: 0.2em; opacity: 0.85; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; } }
#results {
  position: absolute;
  inset: auto;
  background: #11111fe8;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 22px;
  min-width: min(380px, 92vw);
  text-align: center;
  box-shadow: 0 20px 60px #000a;
  backdrop-filter: blur(4px);
}
#results h2 { margin: 0 0 10px; font-size: 26px; }
#results table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
#results td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; }
#results td:first-child, #results td:nth-child(2) { text-align: left; }
#results tr.win td { color: var(--accent2); font-weight: 800; }
#results .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

#game-menu { position: absolute; left: calc(8px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); display: flex; gap: 6px; z-index: 3; }
#game-menu button { background: #15152799; border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; }
body.touch #game-menu { bottom: auto; left: auto; right: calc(8px + var(--safe-r)); top: calc(62px + var(--safe-t)); }

/* ---------- touch ---------- */
@media (orientation: portrait) {
  body.touch #arena-wrap { padding-bottom: 190px; }
}
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 2; display: none; }
body.touch #touch { display: block; }
#stick-zone { position: absolute; left: 0; top: 30%; bottom: 0; width: 50%; pointer-events: auto; }
#stick-base {
  position: absolute;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  left: calc(90px + var(--safe-l));
  bottom: auto;
  top: calc(100% - 110px - var(--safe-b));
  border-radius: 50%;
  border: 2px solid #ffffff2a;
  background: radial-gradient(#ffffff10, #ffffff05);
  transition: opacity 0.2s;
  opacity: 0.6;
}
#stick-base.live { opacity: 1; transition: none; }
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffffaa, #8d6bff88);
  box-shadow: 0 0 18px #8d6bff88;
}
#touch-right { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); display: flex; align-items: flex-end; gap: 12px; pointer-events: auto; }
#btn-bomb {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 42px;
  border: 2px solid #ff8a4a;
  background: radial-gradient(circle at 40% 35%, #ff7a3acc, #b3201acc);
  box-shadow: 0 0 26px #ff5a2a88;
}
#btn-bomb.down { transform: scale(0.92); filter: brightness(1.3); }
#taunts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#taunts button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: #15152799; font-size: 18px; padding: 0; }

@media (max-width: 640px) {
  #hud { gap: 6px; }
  #hud-players { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .hp { padding: 2px 6px; }
  .hp .stats { display: none; }
  #hud-timer { font-size: 16px; min-width: 56px; padding: 6px 8px; }
  .seats { grid-template-columns: 1fr; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #hud { min-height: 40px; padding-top: calc(3px + var(--safe-t)); padding-bottom: 3px; }
  #hud-players { grid-template-columns: repeat(4, 1fr); }
  .hp .stats { display: none; }
  #btn-bomb { width: 84px; height: 84px; }
}
