:root {
  --bg0: #05040c;
  --bg1: #0b0a1c;
  --panel: rgba(16, 14, 38, 0.72);
  --panel-solid: #12102a;
  --line: rgba(140, 160, 255, 0.18);
  --text: #eaf2ff;
  --muted: #8d95bd;
  --cyan: #22e5ff;
  --magenta: #ff3fd8;
  --gold: #ffc83d;
  --red: #ff4d6a;
  --grad: linear-gradient(100deg, var(--cyan), #8d6bff 45%, var(--magenta) 75%, var(--gold));
  --cut: 14px;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: 'Segoe UI', system-ui, -apple-system, 'SF Pro Display', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font);
  font-size: clamp(12px, 2.1vh + 0.45vw, 18px);
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  display: block;
}

#bg,
#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
#game {
  visibility: hidden;
}
body.in-game #game {
  visibility: visible;
}
body.in-game #bg {
  visibility: hidden;
}

#touch-layer {
  position: fixed;
  inset: 0;
  display: none;
  touch-action: none;
}
body.in-game #touch-layer {
  display: block;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

button,
input,
select {
  font-family: inherit;
  color: inherit;
}

.muted {
  color: var(--muted);
  font-weight: 500;
}
.accent {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gold {
  color: var(--gold);
}
.cyan {
  color: var(--cyan);
}

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  padding: calc(1.1rem + var(--safe-t)) calc(1.4rem + var(--safe-r)) calc(1rem + var(--safe-b)) calc(1.4rem + var(--safe-l));
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: perspective(900px) rotateX(8deg) translateY(2%) scale(0.97);
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.35s;
  pointer-events: none;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
  pointer-events: auto;
}

.panel {
  position: relative;
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  padding: 0.9rem 1rem;
}
.panel::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1px;
  background: linear-gradient(135deg, rgba(34, 229, 255, 0.6), rgba(141, 107, 255, 0.15) 40%, rgba(255, 63, 216, 0.15) 70%, rgba(255, 200, 61, 0.5));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  clip-path: inherit;
}
.panel-title {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.6rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
  flex: none;
}
.screen-head h2 {
  margin: 0;
  flex: 1;
  font-size: 1.25rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 800;
}

/* ---------- buttons ---------- */
.btn {
  --sk: 10px;
  position: relative;
  border: 0;
  cursor: pointer;
  padding: 0.6rem 1.3rem;
  min-height: 2.6rem;
  background: rgba(120, 130, 255, 0.12);
  clip-path: polygon(var(--sk) 0, 100% 0, calc(100% - var(--sk)) 100%, 0 100%);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.85rem;
  transition: transform 0.12s ease, background 0.2s ease, filter 0.2s ease;
  outline: none;
}
.btn b {
  font-weight: 800;
}
.btn small {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  opacity: 0.7;
  text-transform: none;
  margin-top: 0.1rem;
  font-weight: 500;
}
.btn:hover {
  background: rgba(140, 150, 255, 0.24);
}
.btn:active {
  transform: scale(0.96);
}
.btn:focus-visible {
  filter: drop-shadow(0 0 6px var(--cyan));
}
.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}
.btn-primary {
  background: var(--grad);
  color: #090716;
}
.btn-primary:hover {
  background: var(--grad);
  filter: brightness(1.12);
}
.btn-accent {
  background: rgba(34, 229, 255, 0.2);
  color: #bdf6ff;
}
.btn-accent.on {
  background: linear-gradient(100deg, #24ffb0, #22e5ff);
  color: #04131a;
}
.btn-danger {
  background: rgba(255, 77, 106, 0.22);
  color: #ffd0d8;
}
.btn-ghost {
  background: transparent;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}
.btn-small {
  --sk: 6px;
  padding: 0.3rem 0.8rem;
  min-height: 1.9rem;
  font-size: 0.7rem;
}
.btn-xl {
  flex-direction: row;
  gap: 1rem;
  padding: 0.9rem 2rem;
  font-size: 1.15rem;
  text-align: left;
  align-items: center;
  justify-content: flex-start;
}
.btn-xl .btn-icon {
  font-size: 1.4rem;
}
.btn-xl small {
  font-size: 0.7rem;
}

.icon-btn,
.hud-btn {
  width: 2.6rem;
  height: 2.6rem;
  border: 0;
  cursor: pointer;
  background: rgba(120, 130, 255, 0.14);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  font-size: 1.05rem;
  font-weight: 800;
  transition: background 0.2s, transform 0.12s;
}
.icon-btn:hover,
.hud-btn:hover {
  background: rgba(140, 150, 255, 0.3);
}
.icon-btn:active,
.hud-btn:active {
  transform: scale(0.92);
}

/* ---------- home ---------- */
.home-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}
.home-left {
  flex: 1.2;
  min-width: 0;
}
.home-right {
  flex: 0.8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}
.logo {
  margin: 0;
  font-size: clamp(2.8rem, 9vh + 2vw, 6.4rem);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0.04em;
  font-style: italic;
  display: flex;
  flex-wrap: wrap;
}
.logo-wick {
  color: #fff;
  text-shadow: -0.04em 0 0 rgba(34, 229, 255, 0.75), 0.04em 0 0 rgba(255, 63, 216, 0.75);
}
.logo-sumo {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 63, 216, 0.35));
}
.tagline {
  margin: 0.4rem 0 1.4rem;
  color: var(--muted);
  letter-spacing: 0.4em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 30rem;
}
.btn-row {
  display: flex;
  gap: 0.6rem;
}
.btn-row .btn {
  flex: 1;
}
.join-inline {
  display: flex;
  gap: 0.6rem;
}
.code-input,
.name-input {
  flex: 1;
  min-width: 0;
  background: rgba(10, 10, 30, 0.6);
  border: 1px solid var(--line);
  padding: 0.55rem 1rem;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.code-input:focus,
.name-input:focus {
  border-color: var(--cyan);
  background: rgba(20, 30, 60, 0.7);
}
.name-input {
  flex: none;
  letter-spacing: 0.12em;
  text-align: center;
  width: 100%;
  margin-top: 0.5rem;
}

.profile-card {
  border: 0;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0;
}
.ball-preview {
  width: min(34vh, 13rem);
  height: min(34vh, 13rem);
}
.profile-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.profile-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}
.profile-class {
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
}
.profile-edit {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cyan);
}
.icon-row {
  display: flex;
  gap: 0.6rem;
}

/* ---------- character select ---------- */
.char-wrap {
  flex: 1;
  display: flex;
  gap: 1rem;
  min-height: 0;
}
.char-stage {
  flex: 0.9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.char-stage .ball-preview {
  width: min(52vh, 18rem);
  height: min(52vh, 18rem);
}
.char-config {
  flex: 1.3;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.field label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.field label .accent {
  font-size: 0.95rem;
  letter-spacing: 0.15em;
}
.color-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.color-heading label {
  margin-bottom: 0;
}
.custom-color {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 46px;
  padding: 0.2rem 0.65rem 0.2rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.custom-color:hover,
.custom-color.sel {
  border-color: var(--cyan);
}
.custom-color:focus-within {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}
.custom-color-wheel {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: conic-gradient(#ff5278, #ffcb3d, #8cff4a, #22e5ff, #9b6bff, #ff5278);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  text-shadow: 0 1px 3px #000;
}
.custom-color input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
}
.swatch {
  position: relative;
  aspect-ratio: 1.1;
  border: 0;
  cursor: pointer;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
  transition: transform 0.15s;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}
.swatch:hover {
  transform: scale(1.06);
}
.swatch:focus-visible {
  box-shadow: inset 0 0 0 4px #fff;
}
.swatch.sel {
  transform: scale(1.12);
}
.swatch.sel::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #0b0a1c;
  font-weight: 900;
  font-size: 1.1rem;
}
.swatch.taken {
  opacity: 0.25;
  pointer-events: none;
}
.swatch.taken::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #000;
  font-weight: 900;
}
.weight-scale {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.scale-end {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-align: center;
  color: var(--muted);
  line-height: 1.1;
}
.stats {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.8rem;
  align-items: center;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.stat-bar {
  height: 0.55rem;
  background: rgba(255, 255, 255, 0.07);
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  overflow: hidden;
}
.stat-bar i {
  display: block;
  height: 100%;
  background: var(--grad);
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 2.2rem;
  background: transparent;
  cursor: pointer;
  touch-action: pan-x;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 0.45rem;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
}
input[type='range']::-moz-range-track {
  height: 0.45rem;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: -0.53rem;
  background: #fff;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
input[type='range']::-moz-range-thumb {
  width: 1.4rem;
  height: 1.4rem;
  border: 0;
  border-radius: 0;
  background: #fff;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
input[type='range']:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- lobby ---------- */
.room-code {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.room-label {
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
}
.room-code-value {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-user-select: text;
  user-select: text;
}
.lobby-cta {
  display: flex;
  gap: 0.5rem;
}
.lobby-wrap {
  flex: 1;
  display: flex;
  gap: 1rem;
  min-height: 0;
}
.lobby-players {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.lobby-settings {
  flex: 1.15;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  touch-action: pan-y;
}
.player-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  animation: rowIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.player-row.me {
  background: rgba(34, 229, 255, 0.1);
}
.player-row.offline {
  opacity: 0.5;
}
@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
}
.p-dot {
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
}
.p-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.p-name {
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.p-sub {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}
.tag {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  background: rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}
.tag.host {
  background: var(--gold);
  color: #1a1200;
}
.tag.ready {
  background: #24ffb0;
  color: #002a1a;
}
.tag.easy {
  background: #3dffb0;
  color: #002a1a;
}
.tag.medium {
  background: #ffc83d;
  color: #2a1a00;
}
.tag.hard {
  background: #ff4d6a;
  color: #2a0008;
}
.tag.spec {
  background: rgba(141, 107, 255, 0.4);
}
button.tag {
  border: 0;
  cursor: pointer;
}
.row-x {
  border: 0;
  background: rgba(255, 77, 106, 0.2);
  width: 1.7rem;
  height: 1.7rem;
  cursor: pointer;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  font-weight: 900;
}
.row-edit {
  border: 0;
  background: rgba(34, 229, 255, 0.18);
  padding: 0.2rem 0.6rem;
  cursor: pointer;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 800;
  clip-path: polygon(5px 0, 100% 0, calc(100% - 5px) 100%, 0 100%);
}
.add-bot {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}
.add-bot .muted {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-right: 0.3rem;
}

.settings-form {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.9rem;
  align-items: center;
  align-content: start;
  touch-action: pan-y;
  padding-right: 0.3rem;
}
.set-group {
  grid-column: 1 / -1;
  margin-top: 0.9rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--cyan);
}
.set-group:first-child {
  margin-top: 0;
}
.set-label {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.seg {
  display: flex;
  gap: 2px;
}
.seg button {
  flex: 1;
  border: 0;
  cursor: pointer;
  padding: 0.38rem 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  transition: background 0.15s;
}
.seg button:first-child {
  clip-path: polygon(6px 0, 100% 0, 100% 100%, 0 100%);
}
.seg button:last-child {
  clip-path: polygon(0 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}
.seg button.on {
  background: var(--grad);
  color: #0a0716;
}
.seg button:disabled {
  cursor: default;
}
.seg button:disabled:not(.on) {
  opacity: 0.45;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.slider-row output {
  min-width: 3.2rem;
  text-align: right;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.toggle-row .slider-row {
  flex: 1;
  min-width: 0;
}
.toggle-row .slider-row.off {
  opacity: 0.5;
}
.set-hint {
  grid-column: 1 / -1;
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: -0.25rem;
  letter-spacing: 0.04em;
}

/* toggles */
.toggle {
  -webkit-appearance: none;
  appearance: none;
  width: 3rem;
  height: 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 0.2rem;
  left: 0.35rem;
  width: 1.1rem;
  height: 1.1rem;
  background: #fff;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  transition: transform 0.2s;
}
.toggle:checked {
  background: var(--grad);
}
.toggle:checked::after {
  transform: translateX(1.4rem);
}

/* ---------- results ---------- */
.results-wrap {
  flex: 1;
  display: flex;
  gap: 1.2rem;
  align-items: center;
  min-height: 0;
}
.results-hero {
  flex: 0.6;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.results-title {
  font-size: clamp(2rem, 8vh, 4rem);
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: pop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.results-title.lose {
  background: linear-gradient(100deg, #8d95bd, #ff4d6a);
  -webkit-background-clip: text;
  background-clip: text;
}
@keyframes pop {
  from {
    transform: scale(0.4) rotate(-6deg);
    opacity: 0;
  }
}
.results-sub {
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.results-table-wrap {
  flex: 1.7;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  min-height: 0;
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  overflow: auto;
  display: block;
  flex: 1;
  min-height: 0;
}
.results-table th {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  padding: 0.2rem 0.3rem;
  font-weight: 700;
}
.results-table td {
  padding: 0.35rem 0.3rem;
  text-align: center;
  border-top: 1px solid var(--line);
}
.results-table td.name {
  text-align: left;
  font-weight: 800;
  white-space: nowrap;
  width: 100%;
}
.results-table tr.me td {
  background: rgba(34, 229, 255, 0.08);
}
.results-table .place {
  font-weight: 900;
  font-size: 1rem;
}
.results-table .p1 {
  color: var(--gold);
}
.results-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}
body.in-game .hud {
  display: block;
}
.hud-top {
  position: absolute;
  top: calc(0.4rem + var(--safe-t));
  left: calc(0.6rem + var(--safe-l));
  right: calc(0.6rem + var(--safe-r));
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.hud-top .hud-btn {
  pointer-events: auto;
  flex: none;
  width: 2.3rem;
  height: 2.3rem;
}
.hud-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
}
.ping {
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
}
#btn-emote {
  display: none;
}
body.online #btn-emote {
  display: block;
}
.chips {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.chip {
  --c: #fff;
  position: relative;
  min-width: 5.6rem;
  max-width: 9rem;
  padding: 0.2rem 0.75rem 0.25rem 0.95rem;
  background: rgba(14, 12, 36, 0.85);
  background: linear-gradient(100deg, color-mix(in srgb, var(--c) 30%, rgba(10, 8, 30, 0.8)), rgba(10, 8, 30, 0.75));
  clip-path: polygon(9px 0, 100% 0, calc(100% - 9px) 100%, 0 100%);
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  transition: opacity 0.3s, transform 0.2s;
}
.chip::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--c);
  clip-path: polygon(9px 0, 100% 0, calc(100% - 9px) 100%, 0 100%);
}
.chip.me {
  box-shadow: inset 0 -2px 0 var(--c);
}
.chip.out {
  opacity: 0.38;
  filter: grayscale(0.8);
}
.chip.hit {
  animation: chipHit 0.3s;
}
@keyframes chipHit {
  30% {
    transform: translateY(2px) scale(1.06);
  }
}
.chip-name {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.9;
}
.chip-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}
.chip-dmg {
  font-size: 1.2rem;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
.chip-dmg small {
  font-size: 0.6em;
}
.chip-lives {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 3.4rem;
  justify-content: flex-end;
}
.chip-lives i {
  width: 0.45rem;
  height: 0.45rem;
  background: var(--c);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.chip-lives i.lost {
  background: rgba(255, 255, 255, 0.15);
}
.chip-place {
  font-size: 1rem;
  font-weight: 900;
}
.chip-by {
  position: absolute;
  right: 4px;
  top: 2px;
  font-size: 0.55rem;
  color: var(--gold);
  font-weight: 900;
}

.banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s;
  text-shadow: 0 0 14px rgba(0, 0, 0, 0.9);
}
.banner.show {
  opacity: 1;
}
.banner.warn {
  color: #ffb547;
}
.banner.danger {
  color: var(--red);
}
.banner.gold {
  color: var(--gold);
}
.countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(4rem, 22vh, 10rem);
  font-weight: 900;
  font-style: italic;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 30px rgba(255, 63, 216, 0.5));
  pointer-events: none;
}
.countdown.pulse {
  animation: cd 0.8s ease-out;
}
@keyframes cd {
  from {
    transform: translate(-50%, -50%) scale(1.8) rotate(-8deg);
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
}
.killfeed {
  position: absolute;
  right: calc(0.7rem + var(--safe-r));
  top: calc(3.6rem + var(--safe-t));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}
.kf {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.6rem;
  background: rgba(8, 6, 24, 0.7);
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  animation: kfIn 0.3s ease-out;
  transition: opacity 0.6s;
}
.kf.fade {
  opacity: 0;
}
@keyframes kfIn {
  from {
    transform: translateX(30px);
    opacity: 0;
  }
}
.spectate {
  position: absolute;
  bottom: calc(1rem + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem 0.9rem;
  background: rgba(8, 6, 24, 0.75);
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
  pointer-events: auto;
}
.spectate.show {
  display: flex;
}
.spectate .btn.on {
  background: var(--grad);
  color: #0a0716;
}

.joystick {
  position: absolute;
  width: 8rem;
  height: 8rem;
  margin: -4rem 0 0 -4rem;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
  background: radial-gradient(circle, rgba(34, 229, 255, 0.05), rgba(34, 229, 255, 0.16));
  opacity: 0;
  transition: opacity 0.15s;
}
.joystick.on {
  opacity: 1;
}
.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3.2rem;
  height: 3.2rem;
  margin: -1.6rem 0 0 -1.6rem;
  background: linear-gradient(135deg, rgba(34, 229, 255, 0.85), rgba(255, 63, 216, 0.75));
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
}

.by-button {
  position: absolute;
  right: calc(1.6rem + var(--safe-r));
  bottom: calc(5.2rem + var(--safe-b));
  width: 7.2rem;
  height: 7.2rem;
  border: 0;
  background: none;
  pointer-events: auto;
  touch-action: none;
  display: none;
  cursor: pointer;
  filter: drop-shadow(0 0 18px rgba(255, 200, 61, 0.55));
  animation: byIn 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.by-button.show {
  display: block;
}
@keyframes byIn {
  from {
    transform: scale(0.3) rotate(-30deg);
    opacity: 0;
  }
}
.by-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.by-ring polygon {
  fill: rgba(30, 20, 0, 0.75);
  stroke: var(--gold);
  stroke-width: 4;
  stroke-dasharray: 290;
  stroke-dashoffset: var(--dash, 0);
  stroke-linejoin: round;
}
.by-button.aiming .by-ring polygon {
  fill: rgba(255, 200, 61, 0.35);
  stroke: #fff;
}
.by-label {
  position: relative;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  line-height: 1.1;
  color: var(--gold);
}
.by-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #ffe9a8;
  opacity: 0.8;
}
.action-btns {
  position: absolute;
  right: calc(1.6rem + var(--safe-r));
  bottom: calc(1rem + var(--safe-b));
  display: none;
  gap: 0.7rem;
  pointer-events: none;
}
.action-btns.show {
  display: flex;
}
.act-btn {
  position: relative;
  width: 3.4rem;
  height: 3.4rem;
  border: 0;
  padding: 0;
  overflow: hidden;
  color: #fff;
  background: rgba(14, 12, 40, 0.78);
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  --c: var(--cyan);
}
.act-dodge {
  --c: var(--mint, #3dffb0);
}
.act-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--c);
  opacity: 0.2;
}
.act-btn.ready::before {
  opacity: 0.38;
}
.act-btn:active::before,
.act-btn.pressed::before {
  opacity: 0.7;
}
.act-cd {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: rgba(4, 3, 12, 0.72);
  transform-origin: bottom;
  transform: scaleY(var(--cd, 0));
  pointer-events: none;
}
.act-charge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: linear-gradient(0deg, rgba(34, 229, 255, 0.85), rgba(180, 250, 255, 0.55));
  transform-origin: bottom;
  transform: scaleY(var(--ch, 0));
  pointer-events: none;
  opacity: 0;
}
.act-btn.charging .act-charge {
  opacity: 1;
}
.act-btn.full .act-charge {
  animation: chargeFull 0.28s ease-in-out infinite alternate;
}
@keyframes chargeFull {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.7);
  }
}
.act-label {
  position: relative;
  display: block;
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--c);
}
.act-key {
  position: relative;
  display: block;
  margin-top: 0.1rem;
  font-size: 0.55rem;
  font-weight: 800;
  opacity: 0.85;
}
.action-btns[data-mode='touch'] {
  gap: 0.9rem;
}
.action-btns[data-mode='touch'] .act-btn {
  width: 4.4rem;
  height: 4.4rem;
}
.action-btns[data-mode='touch'] .act-label {
  font-size: 0.7rem;
}
.action-btns[data-mode='touch'] .act-key {
  display: none;
}
.action-btns[data-mode='touch'] ~ .by-button {
  bottom: calc(6.2rem + var(--safe-b));
}
.controls-hint {
  position: absolute;
  bottom: calc(0.7rem + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.6s;
  white-space: nowrap;
}
.controls-hint.show {
  opacity: 0.9;
}
.emote-bar {
  position: absolute;
  top: calc(3.2rem + var(--safe-t));
  right: calc(0.6rem + var(--safe-r));
  display: none;
  gap: 0.3rem;
  pointer-events: auto;
}
.emote-bar.show {
  display: flex;
}
.emote-bar button {
  border: 0;
  background: rgba(20, 16, 50, 0.85);
  padding: 0.45rem 0.7rem;
  font-weight: 900;
  cursor: pointer;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 3, 12, 0.6);
  pointer-events: auto;
  z-index: 10;
}
.overlay.show {
  display: flex;
  animation: fadeIn 0.25s;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
}
.modal {
  min-width: min(24rem, 90vw);
  max-width: 92vw;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.2rem 1.5rem;
  animation: modalIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-wide {
  width: min(52rem, 94vw);
}
@keyframes modalIn {
  from {
    transform: perspective(700px) rotateX(-14deg) scale(0.92);
    opacity: 0;
  }
}
.modal h2 {
  margin: 0 0 0.8rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-size: 1.1rem;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}
#pause .modal-actions {
  flex-direction: column;
}
.prefs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.pref {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}
.pref input[type='range'] {
  max-width: 12rem;
}
.pref select {
  background: rgba(10, 10, 30, 0.8);
  border: 1px solid var(--line);
  padding: 0.35rem 0.6rem;
}
.howto-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem 1.2rem;
  font-size: 0.8rem;
  line-height: 1.4;
}
.howto-grid b {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.howto-grid p {
  margin: 0.25rem 0 0;
  color: #c6cde8;
}
.kbd {
  display: inline-block;
  padding: 0 0.35rem;
  font-size: 0.65rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.12);
  letter-spacing: 0.06em;
}
.spinner {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 0.8rem;
  background: var(--grad);
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
#connecting p {
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-b));
  transform: translate(-50%, 150%);
  background: rgba(16, 14, 40, 0.92);
  padding: 0.55rem 1.2rem;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  transform: translate(-50%, 0);
}
.toast.error {
  color: #ffc2cd;
}
.fps {
  position: absolute;
  left: calc(0.5rem + var(--safe-l));
  bottom: calc(0.3rem + var(--safe-b));
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- rotate prompt ---------- */
.rotate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg0);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  text-align: center;
  font-size: 16px;
}
.rotate p {
  margin: 0;
  font-weight: 900;
  letter-spacing: 0.25em;
  text-transform: uppercase;
}
.rotate small {
  color: var(--muted);
  letter-spacing: 0.15em;
}
.rotate-phone {
  width: 54px;
  height: 92px;
  border: 3px solid var(--cyan);
  border-radius: 10px;
  animation: rot 2s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(34, 229, 255, 0.4);
}
@keyframes rot {
  0%,
  20% {
    transform: rotate(0);
  }
  60%,
  100% {
    transform: rotate(-90deg);
  }
}
@media (orientation: portrait) and (pointer: coarse) {
  .rotate {
    display: flex;
  }
}

/* ---------- compact layouts (phones in landscape) ---------- */
@media (max-height: 460px) {
  .screen {
    padding-top: calc(0.6rem + var(--safe-t));
    padding-bottom: calc(0.5rem + var(--safe-b));
  }
  .screen-head {
    margin-bottom: 0.45rem;
  }
  .panel {
    padding: 0.6rem 0.75rem;
  }
  .tagline {
    margin-bottom: 0.8rem;
  }
  .howto-grid {
    font-size: 0.72rem;
  }
}
@media (max-width: 700px) {
  .howto-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .screen-head h2 {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .screen,
  .screen.active {
    transition: opacity 0.2s;
    transform: none;
  }
}
