:root {
  color-scheme: dark;
  --bg: #0a0810;
  --panel: #12101c;
  --accent: #5ce1e6;
  --accent-2: #f59e42;
  --text: #e8e6f2;
  --muted: #9b97ad;
  --border: rgba(255, 255, 255, 0.08);
  font-family: "Fira Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #1a1530, var(--bg) 55%);
  color: var(--text);
}

#shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 8, 16, 0.85);
  backdrop-filter: blur(8px);
}

.brand { display: flex; gap: 0.75rem; align-items: center; }
.brand p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.brand-mark { font-size: 1.5rem; color: var(--accent); }

.actions, .row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

button {
  --btn-lift: 0px;
  --btn-glow: 0;
  appearance: none;
  border: 1px solid var(--border);
  background: #1b1728;
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.45rem 0.8rem;
  font: inherit;
  cursor: pointer;
  transform: translateY(var(--btn-lift));
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) calc(var(--btn-glow) * 1%), transparent);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.18s ease,
    filter 0.15s ease,
    opacity 0.15s ease;
}
button:hover:not(:disabled):not(.is-disabled) {
  --btn-lift: -1px;
  --btn-glow: 28;
  border-color: var(--accent);
  color: #fff;
}
button:active:not(:disabled):not(.is-disabled) {
  --btn-lift: 1px;
  --btn-glow: 18;
  filter: brightness(1.08);
  transition-duration: 0.06s;
}
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 75%, #fff);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
button[aria-pressed="true"],
button.is-active {
  background: #173238;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}
button[aria-pressed="true"]:hover:not(:disabled):not(.is-disabled),
button.is-active:hover:not(:disabled):not(.is-disabled) {
  --btn-glow: 40;
  color: #9ff5f8;
}
button.ghost {
  background: transparent;
  color: var(--muted);
}
button.ghost:hover:not(:disabled):not(.is-disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

/* Press ripple — Bifrost aurora (cyan / gold). */
.bifrost-ripple {
  position: fixed;
  z-index: 5000;
  width: 0;
  height: 0;
  pointer-events: none;
  overflow: visible;
}
.bifrost-ripple-core,
.bifrost-ripple-ring,
.bifrost-ripple-mark {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% -50%;
}
.bifrost-ripple-core,
.bifrost-ripple-ring {
  border-radius: 50%;
}
.bifrost-ripple-core {
  width: 0.22rem;
  height: 0.22rem;
  background: radial-gradient(
    circle,
    rgba(20, 28, 36, 0.55) 0%,
    rgba(8, 12, 18, 0.4) 48%,
    rgba(4, 4, 8, 0.25) 72%,
    transparent 80%
  );
  box-shadow:
    0 0 6px rgba(92, 225, 230, 0.35),
    0 0 12px rgba(10, 8, 16, 0.3);
  animation: bifrost-ripple-core 0.72s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.bifrost-ripple-ring {
  width: 0.34rem;
  height: 0.34rem;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, #121018);
  box-shadow:
    0 0 5px rgba(92, 225, 230, 0.28),
    inset 0 0 4px rgba(6, 8, 12, 0.4);
  animation: bifrost-ripple-ring 0.78s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.bifrost-ripple-mark {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #f0d46a 0%, transparent 42%),
    radial-gradient(circle at 65% 70%, #5ce1e6 0%, transparent 48%),
    radial-gradient(circle, rgba(24, 18, 42, 0.85) 0%, transparent 70%);
  opacity: 0;
  filter: brightness(0.9);
  animation: bifrost-ripple-mark 0.78s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.bifrost-ripple-sparks {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.bifrost-ripple-spark {
  position: absolute;
  left: 0;
  top: 0;
  width: 0.2rem;
  height: 0.2rem;
  border-radius: 50%;
  translate: -50% -50%;
  background: radial-gradient(circle, #e8ffff 0%, #5ce1e6 50%, #2a7a90 100%);
  box-shadow:
    0 0 5px rgba(92, 225, 230, 0.9),
    0 0 10px rgba(240, 212, 106, 0.35);
  animation: bifrost-ripple-spark 0.58s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.bifrost-ripple-spark:nth-child(odd) {
  background: radial-gradient(circle, #fff4c8 0%, #f0d46a 55%, #b07a20 100%);
  box-shadow:
    0 0 5px rgba(240, 212, 106, 0.9),
    0 0 10px rgba(92, 225, 230, 0.3);
}
@keyframes bifrost-ripple-core {
  0% { transform: scale(0.35); opacity: 0.55; }
  100% { transform: scale(4.8); opacity: 0; }
}
@keyframes bifrost-ripple-ring {
  0% { transform: scale(0.5); opacity: 0.45; }
  100% { transform: scale(6.6); opacity: 0; }
}
@keyframes bifrost-ripple-mark {
  0% { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  28% { opacity: 0.75; }
  100% { transform: scale(1.15) rotate(12deg); opacity: 0; }
}
@keyframes bifrost-ripple-spark {
  0% { transform: translate(0, 0) scale(1); opacity: 0.95; }
  70% { opacity: 0.55; }
  100% { transform: translate(var(--sx, 20px), var(--sy, -20px)) scale(0.15); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
    transform: none;
  }
  button:hover:not(:disabled):not(.is-disabled),
  button:active:not(:disabled):not(.is-disabled) {
    --btn-lift: 0px;
  }
  .bifrost-ripple { display: none; }
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: 0;
}
.stage.has-panel {
  grid-template-columns: 1fr minmax(16rem, 22rem);
}

.arena-wrap {
  position: relative;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  flex: 1 1 auto;
}

#bevy-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: min(78vh, 52rem);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #07060c;
  position: relative;
  z-index: 1;
  touch-action: none;
  -ms-touch-action: none;
}

.touch-pad {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  /* Absolute corner chrome — not grid mid-board. */
  pointer-events: none;
  --pad-accent: var(--accent, #33d9f2);
  --pad-accent-2: var(--accent-2, #7eb8ff);
}
.touch-pad:not([hidden]) {
  display: block;
}
.touch-pad[hidden] {
  display: none !important;
}
.touch-bisect {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
  z-index: 1;
}
.touch-bisect-left {
  left: 0;
}
.touch-bisect-right {
  right: 0;
}
.touch-pad-stick {
  pointer-events: none;
  z-index: 2;
}
.touch-pad-left-col {
  position: absolute;
  left: max(0.15rem, env(safe-area-inset-left, 0px));
  bottom: max(0.15rem, env(safe-area-inset-bottom, 0px));
  z-index: 3;
  pointer-events: none;
}
.touch-pad-right-col {
  position: absolute;
  right: max(0.1rem, env(safe-area-inset-right, 0px));
  bottom: max(0.1rem, env(safe-area-inset-bottom, 0px));
  z-index: 3;
  pointer-events: none;
}
/* Stick −30% (3.5rem); faces +10% at 8/10/1 o'clock around R-stick, tangential to board corner. */
.touch-pad-face-wrap {
  --face: 2.64rem;
  --stick: 3.5rem;
  --orbit: 3.42rem; /* stick_r + face_r + gap */
  position: relative;
  width: 8rem;
  height: 8rem;
  pointer-events: none;
  z-index: 4;
}
.touch-pad-left {
  position: relative;
}
.touch-pad-right {
  position: absolute;
  right: 0;
  bottom: 0;
  left: auto;
  top: auto;
}
.touch-pad-base {
  position: relative;
  width: var(--stick, 3.5rem);
  height: var(--stick, 3.5rem);
  border-radius: 999px;
  opacity: 0.72;
  border: 0;
  background: radial-gradient(
    circle at 50% 45%,
    color-mix(in srgb, var(--pad-accent) 14%, transparent),
    color-mix(in srgb, #0a070e 28%, transparent) 55%,
    transparent 78%
  );
  pointer-events: none;
  touch-action: none;
  transition: left 0.05s ease-out, top 0.05s ease-out, opacity 0.15s ease;
  overflow: visible;
}
.touch-pad-base.is-active {
  opacity: 0.95;
}
.touch-pad-aim {
  background: radial-gradient(
    circle at 50% 45%,
    color-mix(in srgb, var(--pad-accent) 16%, transparent),
    color-mix(in srgb, #0a1220 28%, transparent) 55%,
    transparent 78%
  );
}
.touch-pad-ripple {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  pointer-events: none;
  overflow: visible;
}
.touch-pad-ripple-soft,
.touch-pad-ripple-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 46%;
  margin: -23% 0 0 -23%;
  border-radius: 999px;
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}
.touch-pad-ripple-soft {
  border: 0;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--pad-accent) 36%, transparent) 0%,
    color-mix(in srgb, var(--pad-accent) 14%, transparent) 42%,
    transparent 70%
  );
  filter: blur(0.7px);
}
.touch-pad-ripple-ring {
  background: transparent;
  box-shadow:
    0 0 0 1.25px color-mix(in srgb, var(--pad-accent) 58%, white 12%),
    0 0 10px 1px color-mix(in srgb, var(--pad-accent) 42%, transparent);
}
.touch-pad-aim .touch-pad-ripple-soft {
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--pad-accent) 36%, transparent) 0%,
    color-mix(in srgb, var(--pad-accent) 14%, transparent) 42%,
    transparent 70%
  );
}
.touch-pad-aim .touch-pad-ripple-ring {
  box-shadow:
    0 0 0 1.25px color-mix(in srgb, var(--pad-accent) 58%, white 12%),
    0 0 10px 1px color-mix(in srgb, var(--pad-accent) 42%, transparent);
}
.touch-pad-base.is-active .touch-pad-ripple-soft {
  animation: stick-ripple-soft 1.35s ease-out infinite;
}
.touch-pad-base.is-active .touch-pad-ripple-soft-delay {
  animation-delay: 0.45s;
}
.touch-pad-base.is-active .touch-pad-ripple-ring {
  animation: stick-ripple-ring 1.55s ease-out infinite;
}
.touch-pad-base.is-active .touch-pad-ripple-ring-delay {
  animation-delay: 0.7s;
}
@keyframes stick-ripple-soft {
  0% {
    transform: scale(0.42);
    opacity: 0.55;
  }
  60% {
    opacity: 0.2;
  }
  100% {
    transform: scale(2.55);
    opacity: 0;
  }
}
@keyframes stick-ripple-ring {
  0% {
    transform: scale(0.55);
    opacity: 0.7;
  }
  45% {
    opacity: 0.35;
  }
  100% {
    transform: scale(2.85);
    opacity: 0;
  }
}
.touch-pad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.1rem;
  height: 1.1rem;
  margin: -0.55rem 0 0 -0.55rem;
  border-radius: 999px;
  background: radial-gradient(
    circle at 40% 35%,
    color-mix(in srgb, var(--pad-accent) 42%, transparent),
    color-mix(in srgb, var(--pad-accent) 12%, transparent) 70%,
    transparent 100%
  );
  border: 0;
  box-shadow: 0 0 14px color-mix(in srgb, var(--pad-accent) 18%, transparent);
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.touch-pad-base.is-active .touch-pad-knob {
  opacity: 0.72;
}
.touch-pad-aim .touch-pad-knob {
  background: radial-gradient(
    circle at 40% 35%,
    color-mix(in srgb, var(--pad-accent) 45%, transparent),
    color-mix(in srgb, var(--pad-accent) 12%, transparent) 70%,
    transparent 100%
  );
  box-shadow: 0 0 14px color-mix(in srgb, var(--pad-accent) 18%, transparent);
}
.touch-face {
  position: absolute;
  width: var(--face, 2.64rem);
  height: var(--face, 2.64rem);
  border-radius: 999px;
  opacity: 0.8;
  border: 1.5px solid color-mix(in srgb, var(--pad-accent) 50%, transparent);
  background: color-mix(in srgb, var(--pad-accent) 55%, #0a070e);
  color: color-mix(in srgb, var(--pad-accent) 85%, white);
  font-weight: 800;
  letter-spacing: 0.02em;
  touch-action: manipulation;
  padding: 0;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: auto;
}
.touch-glyph {
  width: 55%;
  height: 55%;
  display: block;
}
/*
 * Clock around stick center (right=1.75rem, bottom=1.75rem):
 * α=h*30°; face_right = 1.75 - sin(α)*orbit - face/2; face_bottom = 1.75 + cos(α)*orbit - face/2
 * 8→Spin, 10→Grapple, 1→Jump — tangential to board corner chrome.
 */
.touch-face-spin {
  /* 8 o'clock */
  right: 3.39rem;
  bottom: -0.35rem;
  left: auto;
  top: auto;
}
.touch-face-grapple {
  /* 10 o'clock */
  right: 2.14rem;
  bottom: 2.14rem;
  left: auto;
  top: auto;
}
.touch-face-jump {
  /* 1 o'clock */
  right: -0.35rem;
  bottom: 3.39rem;
  left: auto;
  top: auto;
}
.touch-face:active,
.touch-face.is-held {
  background: color-mix(in srgb, var(--pad-accent) 78%, white);
  opacity: 1;
}
.touch-face-spin:active,
.touch-face-spin.is-held,
.touch-face-grapple:active,
.touch-face-grapple.is-held,
.touch-face-jump:active,
.touch-face-jump.is-held {
  background: color-mix(in srgb, var(--pad-accent) 78%, white);
}

/* Desktop / fine pointer: never show on-screen gamepad. */
@media (hover: hover) and (pointer: fine) {
  .touch-pad,
  .touch-pad:not([hidden]) {
    display: none !important;
  }
}

.arena-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 0.75rem;
  font-family: "Segoe UI", system-ui, sans-serif;
  z-index: 50;
}

.arena-hud[hidden] {
  display: none;
}

.ssbm-tag {
  display: none !important; /* paddle nameplates removed — controls live in .hud-howto */
}

.hud-howto {
  position: absolute;
  top: 0.45rem;
  right: 0.65rem;
  bottom: auto;
  transform: none;
  z-index: 8;
  pointer-events: none;
  max-width: 9.5rem;
  padding: 0.35rem 0.55rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(130, 140, 200, 0.35);
  background: rgba(10, 8, 18, 0.78);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  color: rgba(230, 234, 255, 0.92);
}
.hud-howto-win {
  right: auto;
  left: 0.65rem;
}
.hud-howto-toggle {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  width: 100%;
  margin: 0;
  padding: 0.2rem 0.1rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.hud-howto-chevron {
  flex: 0 0 auto;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid rgba(200, 210, 255, 0.75);
  border-bottom: 2px solid rgba(200, 210, 255, 0.75);
  rotate: 45deg;
  translate: 0 -0.1rem;
  transition: rotate 0.2s ease;
}
.hud-howto.is-collapsed .hud-howto-chevron {
  rotate: -45deg;
  translate: 0 0.05rem;
}
.hud-howto.is-collapsed {
  padding-bottom: 0.35rem;
}
.hud-howto.is-collapsed .hud-howto-body {
  display: none;
}
/* Hide how-to cards while pre-match / lobby / results cover the board. */
.arena-wrap.is-overlay-open .hud-howto {
  display: none;
}
/* Touch bisects steal mid-board taps — mute pad while lobby / ready / results are up. */
.arena-wrap.is-overlay-open .touch-pad {
  visibility: hidden;
  pointer-events: none !important;
}
.arena-wrap.is-overlay-open .touch-bisect,
.arena-wrap.is-overlay-open .touch-face {
  pointer-events: none !important;
}
@media (max-width: 1100px) {
  .hud-howto {
    top: max(0.35rem, env(safe-area-inset-top));
    bottom: auto;
    transform: none;
    max-width: min(46%, 11rem);
    font-size: 0.9em;
  }
  .hud-howto-win {
    left: 0.45rem;
    right: auto;
  }
  .hud-howto:not(.hud-howto-win) {
    right: 0.45rem;
    left: auto;
  }
  /* Default collapsed on tablet/phone so the board stays clear. */
  .hud-howto:not(.is-collapsed) {
    max-width: min(52%, 14rem);
  }
}
@media (max-width: 720px) {
  .hud-howto {
    position: absolute;
    transform: none;
    max-width: min(42%, 10.5rem);
    margin: 0;
    width: auto;
    top: max(0.3rem, env(safe-area-inset-top));
    bottom: auto;
  }
  .arena-wrap .hud-howto-win {
    left: 0.35rem;
    right: auto;
    order: unset;
  }
  .arena-wrap .hud-howto:not(.hud-howto-win) {
    right: 0.35rem;
    left: auto;
    order: unset;
  }
}
@media (min-width: 1101px) {
  /* Desktop: start expanded; still collapsible via header. */
  .hud-howto.is-collapsed {
    /* keep class for toggle, but JS clears is-collapsed on wide screens at bind */
  }
}
.hud-howto h3 {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(200, 210, 255, 0.85);
}
.hud-howto ul {
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}
.hud-howto li {
  font-size: 0.68rem;
  line-height: 1.25;
  font-weight: 600;
}
.hud-howto kbd {
  display: inline-block;
  padding: 0.05rem 0.28rem;
  border-radius: 0.25rem;
  border: 1px solid rgba(140, 150, 210, 0.45);
  background: rgba(24, 20, 40, 0.9);
  font-size: 0.62rem;
  font-weight: 700;
}

.controls-panel {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 50;
  width: min(18rem, 92%);
  padding: 0.85rem 0.95rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(130, 140, 200, 0.45);
  background: rgba(12, 10, 22, 0.94);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  color: #e8ecff;
}
.controls-panel.hidden { display: none; }
.controls-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
.controls-panel h2 {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.controls-map {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.controls-map > div {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.35rem;
  font-size: 0.72rem;
}
.controls-map dt {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(200, 210, 255, 0.8);
}
.controls-map dd {
  margin: 0;
  color: rgba(230, 234, 255, 0.9);
}
.controls-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.controls-note {
  margin: 0.55rem 0 0;
  font-size: 0.65rem;
  color: rgba(180, 190, 230, 0.7);
  line-height: 1.35;
}

.countdown {
  position: absolute;
  inset: 0;
  z-index: 46;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(20, 14, 40, 0.35), rgba(6, 4, 12, 0.55));
}
.countdown.hidden { display: none; }
.countdown #countdown-num {
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #f0d46a;
  text-shadow:
    0 0 24px rgba(240, 212, 106, 0.45),
    -3px -3px 0 #000,
    3px 3px 0 #000;
  animation: countdown-pop 0.55s ease-out;
}
.countdown.go #countdown-num {
  color: #5ce1e6;
  letter-spacing: 0.12em;
}
@keyframes countdown-pop {
  from { transform: scale(1.35); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}

.tag-head {
  display: inline-flex;
  align-items: baseline;
  gap: 0.28rem;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  paint-order: stroke fill;
  -webkit-text-stroke: 3px #000;
  text-shadow:
    0 0 1px #000,
    0 2px 0 #000,
    2px 0 0 #000,
    -2px 0 0 #000,
    0 -2px 0 #000;
}

.tag-num {
  font-size: 0.82rem;
  opacity: 0.92;
}

.tag-slot {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(245, 247, 255, 0.88);
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
}

.ssbm-tag.p1 .tag-head { color: #33d9f5; }
.ssbm-tag.p2 .tag-head { color: #f59242; }

.ssbm-score {
  position: absolute;
  top: 0.45rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(240, 243, 255, 0.95);
  text-shadow:
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    2px 2px 0 #000;
}

.ssbm-caller {
  position: absolute;
  top: 1.85rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
}

.ssbm-caller.owner-p1 { color: #33d9f5; }
.ssbm-caller.owner-p2 { color: #f59242; }

.results {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 40%, rgba(40, 24, 70, 0.92), rgba(6, 4, 12, 0.94));
  pointer-events: auto;
  text-align: center;
}
.results.hidden { display: none; }
.results.round-only .results-vote,
.results.round-only .results-actions {
  display: none !important;
}
.results h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #f0d46a;
  text-shadow: 0 0 24px rgba(240, 212, 106, 0.35);
}

.ready-up {
  position: absolute;
  inset: 0;
  z-index: 48;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 42%, rgba(28, 18, 52, 0.88), rgba(6, 4, 12, 0.92));
  pointer-events: auto;
  text-align: center;
}
.ready-up.hidden { display: none; }
.ready-up .ready-actions {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  margin-top: 0.35rem;
}
.ready-up h2 {
  margin: 0;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e8ecff;
}
.ready-hint {
  margin: 0;
  color: rgba(220, 225, 255, 0.72);
  font-size: 0.85rem;
}
.ready-hold-btn {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 8.5rem;
  min-height: 3rem;
  margin: 0.15rem auto 0.35rem;
  padding: 0.65rem 1.6rem;
  border-radius: 999px;
  border: 1.5px solid color-mix(in srgb, var(--accent, #33d9f2) 55%, transparent);
  background: color-mix(in srgb, var(--accent, #33d9f2) 18%, #0a070e);
  color: #e8f8ff;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease,
    background 0.12s ease;
}
.ready-hold-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent, #33d9f2) 78%, white);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent, #33d9f2) 28%, transparent);
}
.ready-hold-btn.holding {
  border-color: color-mix(in srgb, var(--accent, #33d9f2) 85%, white);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent, #33d9f2) 36%, transparent);
  transform: scale(1.02);
}
.ready-hold-btn.is-ready,
.ready-hold-btn:disabled {
  border-color: rgba(80, 220, 160, 0.75);
  background: rgba(24, 70, 48, 0.55);
  color: #b8ffd8;
  cursor: default;
  box-shadow: none;
  transform: none;
}
.ready-hold-ring {
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  pointer-events: none;
  background: conic-gradient(
    from -90deg,
    color-mix(in srgb, var(--accent, #33d9f2) 88%, white) calc(var(--hold, 0) * 360deg),
    transparent 0
  );
  opacity: calc(0.35 + var(--hold, 0) * 0.65);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
}
.ready-hold-label {
  position: relative;
  z-index: 1;
}
.ready-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  margin-top: 0.35rem;
}
.ready-slot {
  min-width: 10rem;
  padding: 0.55rem 0.9rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(140, 150, 200, 0.35);
  background: rgba(12, 10, 22, 0.75);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: #dce0ff;
}
.ready-slot.is-ready {
  border-color: rgba(80, 220, 160, 0.75);
  background: rgba(24, 70, 48, 0.55);
  color: #b8ffd8;
}

.embed-options {
  display: none;
  pointer-events: auto;
}
.pre-match {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 42%, rgba(28, 18, 52, 0.92), rgba(6, 4, 12, 0.94));
  pointer-events: auto;
  text-align: center;
}
.pre-match.hidden { display: none; }
.lobby-wait {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1.25rem;
  background: radial-gradient(circle at 50% 42%, rgba(18, 28, 52, 0.94), rgba(6, 4, 12, 0.95));
  pointer-events: auto;
  text-align: center;
}
.lobby-wait.hidden { display: none; }
.lobby-wait h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3.5vw, 1.9rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8ec8ff;
}
.lobby-wait-code {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #f0d46a;
  font-family: ui-monospace, monospace;
}
.lobby-wait-msg,
.lobby-wait-names {
  margin: 0;
  color: rgba(220, 225, 255, 0.78);
  font-size: 0.95rem;
  font-weight: 600;
}
.ui-focus {
  outline: 2px solid #f0d46a;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(240, 212, 106, 0.28);
}
button:disabled,
button.is-disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.35);
}
.pre-match h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f0d46a;
}
.pre-match-hint {
  margin: 0;
  color: rgba(220, 225, 255, 0.72);
  font-size: 0.85rem;
}
.pre-match-slots,
.results-vote {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}
.pre-match-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  margin-top: 0.35rem;
}
.pre-match-actions button {
  min-width: 8.5rem;
  padding: 0.65rem 1.1rem;
  font-weight: 700;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 0.45rem;
  background: rgba(24, 18, 42, 0.9);
  color: #e8ecff;
  cursor: pointer;
}
.pre-match-actions button:hover:not(:disabled):not(.is-disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 35%, transparent);
}
.pre-match-actions .ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.results-vote {
  margin: 0.35rem 0 0.5rem;
}
.results-detail {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}
.results-actions button {
  min-width: 8.5rem;
  padding: 0.65rem 1.1rem;
  font-weight: 700;
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.results-actions button:hover:not(:disabled):not(.is-disabled) {
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 35%, transparent);
}
.results-actions .ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
}
.panel.hidden { display: none; }

.field { display: grid; gap: 0.35rem; margin: 0.75rem 0; font-size: 0.9rem; }
.field input, .field select {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 0.45rem;
  border: 1px solid var(--border);
  background: #0d0b14;
  color: var(--text);
}

.inspector dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0.5rem 0 1rem;
}
.inspector dt { color: var(--muted); font-size: 0.8rem; }
.inspector dd { margin: 0; font-variant-numeric: tabular-nums; }

.fine { color: var(--muted); font-size: 0.78rem; line-height: 1.4; }

/* Lab iframe — chrome off; canvas fills the pane (camera handles aspect). */
html.embedded,
html.embedded body,
body.embedded {
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  background: #07060c;
  margin: 0;
}
html.embedded #shell,
body.embedded #shell {
  min-height: 100%;
  height: 100%;
  width: 100%;
}
html.embedded .topbar,
html.embedded .panel,
html.embedded .actions,
body.embedded .topbar,
body.embedded .panel {
  display: none !important;
}
html.embedded .inspector,
body.embedded .inspector {
  display: none;
}
html.embedded .inspector:not(.hidden),
body.embedded .inspector:not(.hidden) {
  display: block !important;
  position: fixed;
  right: 0.65rem;
  bottom: 0.65rem;
  z-index: 50;
  max-width: min(18rem, 92vw);
  max-height: min(16rem, 50vh);
  overflow: auto;
  padding: 0.65rem 0.75rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(130, 140, 200, 0.45);
  background: rgba(12, 10, 22, 0.94);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
html.embedded .embed-options,
body.embedded .embed-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem 0.65rem 0.35rem;
  background: linear-gradient(180deg, rgba(18, 12, 32, 0.96), rgba(10, 8, 18, 0.9));
  border-bottom: 1px solid rgba(120, 130, 190, 0.28);
  z-index: 20;
  flex: 0 0 auto;
  transition: padding 0.18s ease;
}
html.embedded .embed-options-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
html.embedded .embed-options-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
html.embedded .embed-chrome-bar {
  gap: 0.55rem;
  min-height: 1.4rem;
}
html.embedded .embed-collapse-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.15rem 0.35rem 0.15rem 0.2rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
html.embedded .embed-collapse-chevron {
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid rgba(200, 210, 255, 0.75);
  border-bottom: 2px solid rgba(200, 210, 255, 0.75);
  rotate: -135deg;
  translate: 0 0.08rem;
  transition: rotate 0.18s ease;
}
html.embedded .embed-options.is-collapsed .embed-collapse-chevron {
  rotate: 45deg;
  translate: 0 -0.05rem;
}
html.embedded .embed-options.is-collapsed {
  padding: 0.22rem 0.55rem;
  gap: 0;
}
html.embedded .embed-options.is-collapsed .embed-options-body {
  display: none;
}
html.embedded .embed-collapse-hint {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(170, 180, 230, 0.65);
}
html.embedded .embed-options.is-collapsed .embed-collapse-hint {
  display: inline;
}
html.embedded .embed-options:not(.is-collapsed) .embed-collapse-hint {
  display: none;
}
html.embedded .embed-brand {
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: rgba(200, 210, 255, 0.85);
  margin-right: 0.35rem;
}
html.embedded .embed-options button,
html.embedded .embed-options .embed-name {
  appearance: none;
  border: 1px solid rgba(130, 140, 200, 0.4);
  background: rgba(24, 18, 42, 0.9);
  color: #e8ecff;
  border-radius: 0.4rem;
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
html.embedded .embed-options .embed-name {
  /* 40% longer than prior 4.25rem — room for 7-letter names */
  width: 5.95rem;
  max-width: 5.95rem;
  text-transform: none;
  letter-spacing: 0.02em;
  font-weight: 600;
  cursor: text;
}
html.embedded .embed-icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(130, 140, 200, 0.4);
  background: rgba(24, 18, 42, 0.9);
  color: #e8ecff;
  border-radius: 0.4rem;
  cursor: pointer;
  flex: 0 0 auto;
}
html.embedded .embed-icon-btn:hover:not(:disabled):not(.is-disabled) {
  border-color: rgba(160, 180, 255, 0.7);
  color: #fff;
}
html.embedded .embed-icon-btn:active:not(:disabled):not(.is-disabled) {
  filter: brightness(1.1);
}
html.embedded .embed-icon-btn.copied {
  border-color: rgba(92, 225, 230, 0.85);
  color: #5ce1e6;
}
html.embedded .embed-status {
  margin: 0;
  font-size: 0.68rem;
  color: rgba(180, 190, 230, 0.75);
  min-height: 0.9rem;
}
html.embedded .embed-options button:hover:not(:disabled):not(.is-disabled) {
  border-color: rgba(160, 180, 255, 0.7);
}
html.embedded .embed-options button:active:not(:disabled):not(.is-disabled) {
  filter: brightness(1.1);
}
html.embedded .embed-options button[aria-pressed="true"] {
  background: rgba(90, 60, 150, 0.95);
  border-color: rgba(240, 212, 106, 0.95);
  color: #f0d46a;
  box-shadow: 0 0 0 1px rgba(240, 212, 106, 0.35), 0 0 12px rgba(180, 140, 255, 0.35);
  font-weight: 700;
}
html.embedded .embed-room-field {
  position: relative;
  flex: 0 0 auto;
  width: 7.6rem;
  max-width: 7.6rem;
}
html.embedded .embed-room-row input {
  flex: 0 0 auto;
  width: 100%;
  max-width: none;
  min-width: 0;
  padding: 0.28rem 2rem 0.28rem 0.45rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(130, 140, 200, 0.35);
  background: #0d0b14;
  color: #e8ecff;
  font-size: 0.78rem;
}
html.embedded .embed-room-row input:read-only {
  color: #f0d46a;
  border-color: rgba(240, 212, 106, 0.45);
  cursor: default;
}
html.embedded .embed-room-copy {
  position: absolute;
  right: 0.2rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.55rem;
  height: 1.55rem;
  border: none;
  background: transparent;
  color: rgba(200, 210, 255, 0.75);
}
html.embedded .embed-room-copy:hover {
  color: #fff;
  border: none;
}
html.embedded .embed-room-copy.is-paste {
  color: rgba(240, 212, 106, 0.85);
}
html.embedded .embed-room-copy.copied {
  color: #5ce1e6;
}
.name-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(120%);
  z-index: 80;
  padding: 0.45rem 0.85rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(240, 212, 106, 0.45);
  background: rgba(12, 10, 22, 0.92);
  color: #f0d46a;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.2s ease,
    transform 0.25s ease;
}
.name-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
html.embedded #shell {
  display: flex;
  flex-direction: column;
}
html.embedded .stage,
body.embedded .stage {
  display: flex !important;
  grid-template-columns: unset !important;
  align-items: stretch;
  justify-content: center;
  /* Leave room for parent-page chrome; embed options sit above. */
  padding: 0.35rem 0.75rem 1.25rem;
  gap: 0;
  height: auto;
  flex: 1 1 auto;
  width: 100%;
  min-height: 12rem;
  box-sizing: border-box;
  container-type: size;
}
html.embedded .arena-wrap,
body.embedded .arena-wrap {
  aspect-ratio: unset;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-height: 12rem;
  flex: 1 1 auto;
  position: relative;
}
html.embedded #bevy-canvas,
body.embedded #bevy-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-height: 12rem !important;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 0.5rem;
  touch-action: none;
}

html.embedded .touch-pad,
body.embedded .touch-pad {
  /* Always available in Lab embed on coarse pointers; CSS @media hides fine pointers. */
  z-index: 45;
}

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  #bevy-canvas { min-height: 58vh; }
  body.embedded #bevy-canvas { min-height: 12rem !important; }
}
