:root {
  --navy: #0b1d33;
  --ball: #d9f542;
  --blue: #2f7df6;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --warn: #ffb547;
  --text: #f2f6fa;
  --muted: #9fb2c6;
  --line: rgba(255, 255, 255, 0.1);
  --panel: rgba(8, 19, 34, 0.86);
  --box: rgba(255, 255, 255, 0.035);
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #07121f;
  color: var(--text);
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.ic {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
.icon-btn.off {
  opacity: 0.45;
}
.icon-btn.on {
  color: var(--ball);
}
.icon-btn.small {
  width: 30px;
  height: 30px;
}
.icon-btn.small .ic {
  width: 17px;
  height: 17px;
}

.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--ball);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- In-game HUD ---------- */
/* Scoreboard: dressed like each tournament's TV graphics. Hard court (the
   default) navy with a yellow games box, clay green with a light box, grass
   white names with green games and purple points. */
#scoreboard {
  --sb-bg: #0b1c3f;
  --sb-edge: #25407a;
  --sb-name: #ffffff;
  --sb-games-bg: #f3df4d;
  --sb-games: #0b1c3f;
  --sb-points-bg: transparent;
  --sb-points: #ffffff;
  --sb-serve: #ffffff;
  position: fixed;
  top: 16px;
  left: 16px;
  min-width: 240px;
  padding: 5px;
  background: var(--sb-bg);
  border: 1px solid var(--sb-edge);
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s;
}
body.playing #scoreboard {
  opacity: 1;
}
#scoreboard[data-surface='clay'] {
  --sb-bg: rgba(12, 78, 52, 0.94);
  --sb-edge: #2c7a55;
  --sb-games-bg: #eef3ea;
  --sb-games: #0c4e34;
}
#scoreboard[data-surface='grass'] {
  --sb-bg: transparent;
  --sb-edge: transparent;
  --sb-name: #3d1a6e;
  --sb-games-bg: #0b6b3a;
  --sb-games: #ffffff;
  --sb-points-bg: #4a2584;
  --sb-serve: #4a2584;
  padding: 0;
  box-shadow: none;
}
#scoreboard .row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) 34px 46px;
  align-items: center;
  column-gap: 8px;
  height: 34px;
  padding-left: 6px;
  color: var(--sb-name);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
#scoreboard .row + .row {
  margin-top: 3px;
}
#scoreboard .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#scoreboard .games,
#scoreboard .points {
  display: grid;
  place-items: center;
  height: 100%;
}
#scoreboard .games {
  background: var(--sb-games-bg);
  color: var(--sb-games);
  border-radius: 2px;
}
#scoreboard .points {
  background: var(--sb-points-bg);
  color: var(--sb-points);
}
#scoreboard .serve {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
#scoreboard .serve.on {
  background: var(--sb-serve);
}
#scoreboard .foot {
  padding: 4px 6px 1px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
/* Grass: white name strips, the server marked with a purple arrow after the name. */
#scoreboard[data-surface='grass'] .row {
  grid-template-columns: minmax(0, 1fr) 14px 34px 46px;
  column-gap: 0;
  padding-left: 12px;
  background: #ffffff;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
}
#scoreboard[data-surface='grass'] .serve {
  order: 1;
  width: 0;
  height: 0;
  border-radius: 0;
  border: 6px solid transparent;
  border-left: 0;
}
#scoreboard[data-surface='grass'] .serve.on {
  background: none;
  border-right: 8px solid var(--sb-serve);
}
#scoreboard[data-surface='grass'] .name {
  order: 0;
}
#scoreboard[data-surface='grass'] .games {
  order: 2;
  border-radius: 0;
}
#scoreboard[data-surface='grass'] .points {
  order: 3;
}
#scoreboard[data-surface='grass'] .foot {
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

#topright {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}
body:not(.playing) #topright {
  display: none;
}
#topright .icon-btn {
  background: rgba(8, 19, 34, 0.85);
  border-color: var(--line);
}
.pill {
  background: rgba(8, 19, 34, 0.85);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
}
body.has-ctrl #conn {
  border-color: var(--good);
}
#sound {
  display: none;
}
#sound.show {
  display: inline-block;
}
#speed {
  font-weight: 800;
  font-size: 22px;
  color: var(--ball);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(-6px);
  transition: 0.25s;
}
#speed.show {
  opacity: 1;
  transform: none;
}

#toast {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -10px) scale(0.9);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
#toast-title {
  font-size: clamp(40px, 7vw, 84px);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 0 4px 0 var(--navy), 0 10px 30px rgba(0, 0, 0, 0.5);
}
#toast.good #toast-title {
  color: var(--ball);
}
#toast-sub {
  margin-top: 4px;
  font-size: clamp(16px, 2.2vw, 26px);
  font-weight: 700;
  background: rgba(8, 19, 34, 0.8);
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
}
#toast-sub:empty {
  display: none;
}
#feedback {
  position: fixed;
  left: 50%;
  top: 58%;
  transform: translate(-50%, 8px);
  font-weight: 800;
  font-size: 24px;
  opacity: 0;
  transition: 0.2s;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}
#feedback.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#feedback.good {
  color: var(--ball);
}
#feedback.bad {
  color: #ffb3b3;
}
#hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 19, 34, 0.85);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 17px;
  max-width: calc(100% - 32px);
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
/* TV camera: your player stands at the bottom center and the far wall's
   sponsors sit at the top, so hints move to the bottom-left corner. */
body.tv-view #hint {
  left: 24px;
  transform: none;
  max-width: min(420px, 40vw);
  border-radius: 16px;
}
#hint.show {
  opacity: 1;
}

/* ---------- Overlays and cards ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(7, 18, 31, 0.6), rgba(7, 18, 31, 0.92));
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
.overlay.show {
  display: flex;
}
.card {
  width: min(960px, 100%);
  background: linear-gradient(180deg, #0f2641, #09182b);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  margin: auto;
}
.small {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}
.seg button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 700;
  transition: border-color 0.15s, background 0.15s;
}
.seg button:hover {
  background: rgba(255, 255, 255, 0.07);
}
.seg button.on {
  border-color: var(--blue);
  background: rgba(47, 125, 246, 0.2);
  box-shadow: inset 0 0 0 1px var(--blue);
}
button.primary {
  background: var(--ball);
  color: var(--navy);
  border: 0;
  border-radius: 14px;
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 800;
}
.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.actions button:not(.primary) {
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  border-radius: 14px;
  padding: 14px 22px;
  font-weight: 700;
}

/* ---------- Menu ---------- */
#menu {
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  background: #07121f;
  backdrop-filter: none;
}
#menu.show {
  display: flex;
}
/* While the game loads (body.booting: boot.js → main.js) the lobby and its
   wallpaper wait behind a bouncing ball, so they appear once, complete and
   translated, instead of filling in piece by piece. Shown anyway after 12 s if
   something failed. */
#menu > * {
  transition: opacity 0.35s ease;
}
.booting #menu > * {
  opacity: 0;
  animation: boot-reveal 0s 12s forwards;
}
.booting #menu::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f4ff9a, var(--ball) 45%, #a6bf12);
  box-shadow: 0 0 24px rgba(217, 245, 66, 0.35);
  animation:
    boot-bounce 0.45s ease-in infinite alternate,
    boot-hide 0s 12s forwards;
}
@keyframes boot-bounce {
  from {
    transform: translateY(-26px);
  }
  to {
    transform: translateY(14px) scale(1.06, 0.94);
  }
}
@keyframes boot-reveal {
  to {
    opacity: 1;
  }
}
@keyframes boot-hide {
  to {
    visibility: hidden;
  }
}
@media (prefers-reduced-motion: reduce) {
  .booting #menu::after {
    animation: boot-hide 0s 12s forwards;
  }
}

/* Lobby wallpaper (one per court), with a shade so the panels stay readable. */
.wallpaper {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.wp {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: 22% center;
  opacity: 0;
  transform: scale(1.03);
  transition: opacity 0.7s ease, transform 1.4s ease;
}
.wp.hard {
  background-image: url('../img/lobby-hard.webp');
}
.wp.clay {
  background-image: url('../img/lobby-clay.webp');
}
.wp.grass {
  background-image: url('../img/lobby-grass.webp');
}
#menu[data-surface='hard'] .wp.hard,
#menu[data-surface='clay'] .wp.clay,
#menu[data-surface='grass'] .wp.grass {
  opacity: 1;
  transform: none;
}
.wallpaper::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(4, 10, 20, 0.05) 0%, rgba(4, 10, 20, 0.3) 45%, rgba(4, 10, 20, 0.45) 100%),
    linear-gradient(180deg, rgba(4, 10, 20, 0.15) 0%, rgba(4, 10, 20, 0.2) 50%, rgba(4, 10, 20, 0.65) 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(16px, 4vw, 64px);
  background: rgba(5, 13, 25, 0.72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.brand em {
  font-style: normal;
  color: var(--ball);
}
.brand-tag {
  margin-left: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0;
}
.ball-logo {
  position: relative;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle at 35% 30%, #f4ff9a, var(--ball) 45%, #a6bf12);
  box-shadow: 0 0 16px rgba(217, 245, 66, 0.35);
}
.ball-logo::before,
.ball-logo::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}
.ball-logo::before {
  left: -21px;
}
.ball-logo::after {
  right: -21px;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.top-link {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 600;
}
.top-link:hover {
  background: rgba(255, 255, 255, 0.08);
}
.top-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 6px;
}
.lang {
  display: flex;
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.lang button {
  border: 0;
  background: none;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}
.lang button.on {
  background: rgba(47, 125, 246, 0.25);
  color: var(--text);
}

/* Panels sit to the right so the player in the wallpaper shows on the left,
   and the whole lobby is centered vertically (no scrolling on laptops). */
.menu {
  position: relative;
  z-index: 2;
  width: min(1120px, 100%);
  margin: auto clamp(0px, 3vw, 56px) auto auto;
  padding: 20px clamp(16px, 3vw, 32px) 76px;
}

.menu-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}
.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.panel-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-head h2 {
  margin: 1px 0 3px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.step {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 900;
}
.step.lime {
  background: var(--ball);
  color: var(--navy);
}
.step.blue {
  background: var(--blue);
  color: #fff;
}

/* 1. Connect */
.qr-wrap {
  background: #fff;
  border-radius: 16px;
  padding: 12px;
  width: min(224px, 100%);
  aspect-ratio: 1;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
}
#qr {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}
#qr:not([src]) {
  visibility: hidden;
}
/* Until the room is open (online it takes a moment) the box is a soft pulse,
   not a blank white square, and the code fades in when it's ready. */
.qr-wrap {
  transition: background-color 0.3s ease;
}
.qr-wrap:has(#qr:not([src])) {
  background: rgba(255, 255, 255, 0.07);
  animation: qr-wait 1.2s ease-in-out infinite alternate;
}
#qr[src] {
  animation: qr-in 0.35s ease;
}
@keyframes qr-wait {
  to {
    background: rgba(255, 255, 255, 0.14);
  }
}
@keyframes qr-in {
  from {
    opacity: 0;
  }
}
.status-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(255, 181, 71, 0.08);
  border: 1px solid rgba(255, 181, 71, 0.35);
  font-weight: 700;
}
.status-pill .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse 1.6s ease-in-out infinite;
}
body.has-ctrl .status-pill {
  background: rgba(61, 220, 132, 0.1);
  border-color: rgba(61, 220, 132, 0.5);
}
body.has-ctrl .status-pill .dot {
  background: var(--good);
  animation: none;
  box-shadow: 0 0 10px var(--good);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
.url-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.mini-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.url-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
}
.url-field code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
}
.code-chip {
  flex: none;
  font-size: 12px;
  color: var(--muted);
}
.code-chip b {
  color: var(--ball);
  letter-spacing: 0.12em;
  font-size: 14px;
}
.tip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.tip-ic {
  width: 34px;
  height: 34px;
  stroke-width: 1.6;
  color: var(--ball);
}
.tip p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: #c7d5e3;
}

/* 2. Match setup */
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.box {
  position: relative;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--box);
  border: 1px solid var(--line);
}
.box.wide {
  grid-column: 1 / -1;
}
.box-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 700;
}
.box-label .ic {
  width: 18px;
  height: 18px;
}
.label-value {
  margin-left: auto;
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.name-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
}
.name-field:focus-within {
  border-color: var(--blue);
}
.field-ic {
  width: 18px;
  height: 18px;
  color: var(--muted);
}
#player-name {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 11px 0;
}
#player-name.invalid {
  color: #ffb3b3;
}
/* Shown next to the "Your player" label, so it takes no extra space. */
.name-status {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 12px;
  font-weight: 700;
}
.name-status.ok {
  color: var(--good);
}
.name-status.bad {
  color: #ffb3b3;
}
.avatars {
  display: flex;
  gap: 8px;
}
.avatar-btn {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid transparent;
  background: radial-gradient(circle at 50% 35%, #294a70, #13263f);
  transition: transform 0.15s, border-color 0.15s;
}
.avatar-btn img {
  width: 100%;
  height: 100%;
  display: block;
}
.avatar-btn img:not([src]) {
  visibility: hidden;
}
.avatar-btn:hover {
  transform: scale(1.06);
}
.avatar-btn.on {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, 0.3);
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mode-card {
  position: relative;
  display: flex;
  flex-direction: column; /* icon on top, so the text gets the whole width */
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s, background 0.15s;
}
.mode-card:hover {
  background: rgba(255, 255, 255, 0.07);
}
.mode-card b {
  display: block;
  font-size: 15px;
  white-space: nowrap;
}
.mode-card small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}
.mode-ic {
  width: 22px;
  height: 22px;
  color: var(--blue);
}
.check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  padding: 3px;
  border-radius: 50%;
  background: var(--ball);
  color: var(--navy);
  stroke-width: 3;
  opacity: 0;
  transform: scale(0.6);
  transition: 0.15s;
}
.on > .check {
  opacity: 1;
  transform: none;
}
.mode-card.on {
  border-color: var(--blue);
  background: rgba(47, 125, 246, 0.14);
}

.courts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.court-card {
  position: relative;
  aspect-ratio: 16 / 8.4;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}
.court-card.hard {
  background: linear-gradient(160deg, #3f7f5f, #2d5d9f);
}
.court-card.clay {
  background: linear-gradient(160deg, #1c4a32, #c4643c);
}
.court-card.grass {
  background: linear-gradient(160deg, #3a2466, #4b8b39);
}
.court-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.court-card img:not([src]) {
  visibility: hidden;
}
.court-info {
  position: absolute;
  inset: auto 0 0;
  padding: 26px 10px 8px;
  background: linear-gradient(transparent, rgba(3, 9, 18, 0.88));
}
.court-info b {
  display: block;
  font-size: 16px;
}
.court-info small {
  font-size: 12px;
  color: #c7d5e3;
}
.court-card:hover {
  transform: translateY(-2px);
}
.court-card.on {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, 0.28);
}
.court-card .check {
  top: auto;
  bottom: 9px;
  right: 9px;
}

/* Outfit swatches (in Your player): shirt / shorts, headband stripe on top */
.kits {
  display: flex;
  gap: 8px;
}
.kit-btn {
  position: relative;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: linear-gradient(135deg, var(--a) 0 52%, var(--b) 52% 100%);
  transition: transform 0.15s;
}
.kit-btn::after {
  content: '';
  position: absolute;
  top: 5px;
  left: 50%;
  width: 11px;
  height: 4px;
  margin-left: -5.5px;
  border-radius: 2px;
  background: var(--c);
}
.kit-btn:hover {
  transform: scale(1.08);
}
.kit-btn.on {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, 0.35);
}
/* The racket cards grow to fill their box, level with the rules next to it. */
#box-racket {
  display: flex;
  flex-direction: column;
}
.rackets {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(72px, 1fr);
  gap: 8px;
}
.racket-card {
  position: relative;
  padding: 4px 2px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02) 70%);
  transition: transform 0.15s, border-color 0.15s;
}
.racket-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.racket-card img:not([src]) {
  visibility: hidden;
}
.racket-card:hover {
  transform: translateY(-2px);
}
.racket-card.on {
  border-color: var(--blue);
  background: radial-gradient(circle at 50% 40%, rgba(47, 125, 246, 0.35), rgba(47, 125, 246, 0.08) 70%);
}

#box-rules .cpu-only {
  margin-bottom: 14px;
}

/* Short screens (laptops at 768 px): a tighter lobby so it fits without scrolling. */
@media (max-height: 820px) and (min-width: 861px) {
  .menu {
    padding-top: 10px;
    padding-bottom: 64px;
  }
  .panel {
    padding: 16px;
  }
  .panel-head {
    margin-bottom: 10px;
  }
  .setup-grid {
    gap: 10px;
  }
  .box {
    padding: 10px 12px;
  }
  .court-card {
    aspect-ratio: 16 / 7.4;
  }
  .rackets {
    grid-auto-rows: minmax(64px, 1fr);
  }
  .seg button {
    padding: 8px 12px;
  }
}

/* The big button sits on the bottom edge of the setup panel. */
.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 12px 0 -54px;
}
.cta-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 17px 72px;
  border: 0;
  border-radius: 999px;
  background: var(--ball);
  color: var(--navy);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 10px 40px rgba(217, 245, 66, 0.35);
  transition: transform 0.15s, filter 0.15s;
}
.cta-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}
.cta-btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
  box-shadow: none;
  font-size: 18px;
  letter-spacing: 0.02em;
}
.cta-ic {
  width: 22px;
  height: 22px;
  stroke: none;
}
.cta p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

/* CTA icon: magnifier to find an opponent, play to start with a friend */
.cta-btn .cta-search {
  stroke: currentColor;
  stroke-width: 3;
}
.cta-btn .cta-play,
body.vs-friend .cta-btn .cta-search {
  display: none;
}
body.vs-friend .cta-btn .cta-play {
  display: block;
}

/* ---------- Finding a rival ---------- */
.mm {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-height: 420px;
  justify-content: center;
  text-align: center;
}
body.searching .mm {
  display: flex;
}
body.searching .setup .panel-head,
body.searching .setup-grid,
body.searching .setup .cta {
  display: none;
}
@keyframes mm-spin {
  to {
    transform: rotate(360deg);
  }
}
.mm-title {
  margin: 0;
  font-size: clamp(32px, 4vw, 48px);
  font-weight: 900;
  letter-spacing: -0.02em;
}
.mm-title em {
  font-style: normal;
  color: var(--ball);
}
.mm-window {
  position: relative;
  width: 100%;
  display: flex;
  overflow: hidden;
  padding: 18px 0;
  /* fade the cards out at both ends */
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}
.mm-strip {
  display: flex;
  column-gap: 12px;
  flex: none;
  will-change: transform;
}
/* Motion blur while the roulette spins fast */
.mm-strip.spinning .mm-card {
  filter: blur(2.5px);
  opacity: 0.8;
}
/* Marker: where the roulette stops */
.mm-window::before,
.mm-window::after {
  content: '';
  position: absolute;
  left: 50%;
  z-index: 1;
  margin-left: -9px;
  border: 9px solid transparent;
}
.mm-window::before {
  top: 0;
  border-top-color: var(--ball);
}
.mm-window::after {
  bottom: 0;
  border-bottom-color: var(--ball);
}
.mm-card {
  position: relative;
  width: 118px;
  flex: none;
  padding: 16px 8px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.3s, border-color 0.3s, box-shadow 0.3s, filter 0.5s, opacity 0.5s;
}
.mm-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
}
.mm-avatar svg {
  width: 38px;
  height: 38px;
  fill: var(--c);
}
.mm-card b {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.mm-level {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
}
.mm-level i {
  width: 5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
}
.mm-level i.on {
  background: var(--blue);
}
.mm-bot {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9px;
  font-weight: 900;
  color: var(--muted);
}
.mm-card.found {
  transform: scale(1.12);
  border: 2px solid var(--ball);
  box-shadow: 0 0 30px rgba(217, 245, 66, 0.35);
}
.mm-card.found .mm-level i.on {
  background: var(--ball);
}
.mm-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 800;
  min-height: 32px;
}
.mm-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(217, 245, 66, 0.25);
  border-top-color: var(--ball);
  animation: mm-spin 0.8s linear infinite;
}
.mm-status.found .mm-spinner {
  display: none;
}
.mm-status.found {
  color: var(--ball);
}
.mm-cancel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 11px 30px;
  font-weight: 800;
}
.mm-cancel:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Phones: open the game on a big screen ---------- */
body.phone > :not(#phone-gate) {
  display: none !important;
}
.gate {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 22px;
  text-align: center;
  background:
    linear-gradient(rgba(6, 14, 30, 0.82), rgba(6, 14, 30, 0.94)),
    url('../img/lobby-hard.webp') center / cover;
}
.gate[hidden] {
  display: none;
}
.gate-art {
  width: 132px;
  margin-top: 10px;
  fill: none;
  stroke: var(--ball);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.gate h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.gate p {
  margin: 0;
  max-width: 340px;
  color: var(--muted);
  line-height: 1.45;
}
.gate-url {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}
.gate-url code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  color: var(--ball);
}
.gate-url button {
  flex: none;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 800;
}
.gate-cta {
  margin-top: 8px;
  padding: 15px 34px;
  font-size: 17px;
  text-decoration: none;
}
.gate .gate-note {
  font-size: 13px;
}

/* ---------- Roles: CPU, host inviting a friend, guest ---------- */
.guest-only,
.friend-only {
  display: none;
}
body.guest .guest-only,
body.vs-friend .friend-only {
  display: block;
}
body.guest .host-only,
body.vs-friend .cpu-only,
body.guest #again {
  display: none !important;
}
.invite-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
#invite-link {
  flex: 1 1 240px;
  min-width: 0;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  word-break: break-all;
  user-select: all;
}
.invite-row button {
  border: 0;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 800;
  background: var(--ball);
  color: var(--navy);
}
.status-line {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 14px;
  line-height: 1.45;
}
.status-line:empty {
  display: none;
}
.status-line.ok {
  background: rgba(61, 220, 132, 0.12);
  border: 1px solid rgba(61, 220, 132, 0.45);
}
.status-line.bad {
  background: rgba(255, 93, 93, 0.12);
  border: 1px solid rgba(255, 93, 93, 0.45);
}
#join-box .link {
  margin-top: 10px;
}

/* ---------- Accounts: header buttons, sign-in dialog, profile form ---------- */
body:not(.accounts) .signed-out-only,
body.signed-in .signed-out-only,
body:not(.signed-in) .signed-in-only,
body.accounts:not(.signed-in) .profile-only {
  display: none !important;
}
.top-cta {
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  background: var(--ball);
  color: var(--navy);
  font-weight: 800;
  white-space: nowrap;
}
.top-cta:hover {
  filter: brightness(1.08);
}
#account {
  z-index: 31;
}
.account-card {
  position: relative;
  width: min(520px, 100%);
}
.acct-close {
  position: absolute;
  top: 14px;
  right: 14px;
}
.acct-tabs {
  margin: 0 44px 18px 0;
}
.acct-form {
  display: grid;
  gap: 12px;
}
.acct-form[hidden] {
  display: none;
}
.acct-lead,
.acct-email {
  margin: 0;
  color: var(--muted);
}
.acct-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.acct-form label small {
  font-weight: 500;
}
.acct-form input:not([type='checkbox']),
.acct-form select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color-scheme: dark;
}
.acct-form input:focus,
.acct-form select:focus {
  outline: none;
  border-color: var(--blue);
}
.acct-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.acct-form .acct-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.acct-form .acct-check[hidden] {
  display: none;
}
.acct-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--ball);
}
.acct-legal {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.acct-legal a {
  color: var(--ball);
}
.acct-error {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
  color: #ffb3b3;
}
.acct-error.ok {
  color: var(--good);
}
.acct-submit {
  width: 100%;
  padding: 13px;
  font-size: 16px;
}
.acct-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#profile-form {
  margin-top: 6px;
}
@media (max-width: 560px) {
  .acct-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Your player (profile) ---------- */
#profile {
  z-index: 30;
}
.profile-card {
  width: min(460px, 100%);
}
.profile-card h2 {
  margin: 0;
  font-size: 28px;
}
.profile-sub {
  margin: 6px 0 4px;
  color: var(--muted);
}
.profile-card h3 {
  margin: 20px 0 10px;
  font-size: 15px;
  color: var(--ball);
}
.profile-card .avatars {
  gap: 14px;
}
.profile-card .avatar-btn {
  width: 84px;
  height: 84px;
}
.profile-card .kits {
  gap: 12px;
  margin-bottom: 22px;
}
.profile-card .kit-btn {
  width: 42px;
  height: 42px;
}
.top-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #294a70, #13263f);
}
.top-avatar:not([src]) {
  visibility: hidden;
}
/* Your picture in the lobby, with a pencil: tap to customize */
.edit-look {
  position: relative;
  overflow: visible;
}
.edit-look img {
  border-radius: 50%;
}
.edit-badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ball);
  color: var(--navy);
}
.edit-badge svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

/* ---------- How it works ---------- */
#help {
  z-index: 30;
}
.help-card {
  width: min(600px, 100%);
  line-height: 1.55;
}
.help-card h2 {
  margin: 0 0 6px;
  font-size: 28px;
}
.help-card h3 {
  margin: 18px 0 6px;
  font-size: 16px;
  color: var(--ball);
}
.help-card ol {
  margin: 0;
  padding-left: 22px;
  color: #d6e2ee;
}
.help-how {
  color: #d6e2ee;
}
.help-how p {
  margin: 0 0 10px;
}
.help-card .actions {
  margin-top: 18px;
}

/* ---------- End of match and ranking ---------- */
.small-card {
  width: min(460px, 100%);
  text-align: center;
}
.small-card h2 {
  margin: 0;
  font-size: 40px;
}
.big-score {
  font-size: 56px;
  font-weight: 900;
  color: var(--ball);
  margin: 8px 0 16px;
}
.stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 18px;
}
.stats b {
  display: block;
  font-size: 28px;
}
.stats span {
  color: var(--muted);
  font-size: 13px;
}
.over-points {
  min-height: 1.4em;
  margin: -6px 0 18px;
  font-weight: 800;
  color: var(--ball);
}
#ranking {
  z-index: 30;
}
.rank-card {
  width: min(620px, 100%);
}
.rank-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.rank-head h2 {
  margin: 0;
  font-size: 28px;
}
.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.rank-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.rank-table td {
  padding: 9px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-weight: 600;
}
.rank-table td:nth-child(2) {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-table tr.me td {
  color: var(--ball);
}
.rank-table tr:nth-child(-n + 3) td:first-child {
  color: var(--ball);
  font-weight: 900;
}
.rank-table td.muted {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

/* ---------- Staging badge ---------- */
.env-badge {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  padding: 3px 10px;
  border-radius: 999px;
  background: #ff8a00;
  color: #1a0f00;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* ---------- Smaller screens ---------- */
@media (max-width: 1180px) {
  .brand-tag {
    display: none;
  }
}
@media (max-width: 1080px) {
  .menu-grid {
    grid-template-columns: minmax(280px, 330px) 1fr;
  }
  .setup-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 860px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }
  .connect {
    display: grid;
    grid-template-columns: 170px 1fr;
    column-gap: 18px;
    align-items: start;
  }
  .connect .panel-head,
  .connect .tip {
    grid-column: 1 / -1;
  }
  .connect .qr-wrap {
    grid-row: span 2;
    margin: 0;
  }
  .connect .url-block {
    margin-top: 12px;
    padding-top: 0;
    border-top: 0;
  }
  .top-link span {
    display: none;
  }
  .menu {
    margin: 0 auto;
  }
}
@media (max-width: 560px) {
  .connect {
    display: block;
  }
  .connect .qr-wrap {
    margin: 0 auto 16px;
  }
  .modes {
    grid-template-columns: 1fr;
  }
  .cta-btn {
    padding: 16px 44px;
  }
}
