* {
  box-sizing: border-box;
}

/* Author display rules must not un-hide an element carrying the hidden attribute. */
[hidden] {
  display: none !important;
}

:root {
  --accent: #b8ff3c; /* the Tiny Pickle green */
  --accent-ink: #0f1a00; /* text on the accent */
  --glass: rgba(9, 12, 18, 0.62); /* the 60/40 dark glass */
  --glass-strong: rgba(9, 12, 18, 0.84);
  --line: rgba(255, 255, 255, 0.14);
  --dim: rgba(255, 255, 255, 0.7);
  --fault: #ff4f45;
  --them: #ff9d42; /* the opponents' side of a banner */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
.toggle input:focus-visible + .switch {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#game-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- HUD ------------------------------------------------------------------------------------ */

/* Above the touch controls (20) so the pause button takes taps, below the menus (30). Nothing but
   the pause button takes a pointer. */
#hud {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#hud:not(.live) {
  display: none;
}

/* Under a menu (the pause menu, the game-over card) the menu's own panel is the read-out. */
body.menu-open #hud {
  visibility: hidden;
}

/* The scorebug's corner: bottom-left on desktop, top-left on phones. The ball-speed pop stacks on
   the scorebug's inner side (above it here, under it on phones), clear of every venue's jumbotron
   and big screen at the top of the picture. */
.hud-corner {
  position: absolute;
  left: calc(18px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

/* As wide as its names need, within limits: hud.js shortens a name that still does not fit
   (nameLadder), so none is ever cut off mid-word. */
.scorebug {
  min-width: 272px;
  max-width: 340px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#hud.intro .scorebug {
  opacity: 0;
  transform: translateY(10px);
}

.sb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(184, 255, 60, 0.13);
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.sb-tour {
  color: var(--accent);
  font-weight: 900;
}

.sb-venue {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-team {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 36px;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sb-team + .sb-team {
  border-top: 1px solid var(--line);
}

.sb-serve {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.sb-team.serving .sb-serve {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(184, 255, 60, 0.9);
}

.sb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The server number, on the serving team's row only. */
.sb-server {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.sb-server:empty {
  visibility: hidden;
}

.sb-points {
  font-size: 24px;
  font-weight: 900;
  text-align: right;
}

.sb-team.serving .sb-points {
  color: var(--accent);
}

.sb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.32);
  border-top: 1px solid var(--line);
}

.sb-call {
  font-size: 20px;
  font-weight: 900;
}

.sb-dash {
  margin: 0 3px;
  color: var(--dim);
}

.sb-rally {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.sb-rally b {
  margin-left: 4px;
  font-size: 15px;
  color: #fff;
}

.sb-rally.live b {
  color: var(--accent);
}

/* The ball-speed pop, on the scorebug's inner side, bigger for a faster ball (--pop 0..1). It rises
   toward its place from the scorebug (--pop-from). */
.hud-pop {
  --pop: 0;
  --pop-from: 6px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 14px 5px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: calc(18px + 18px * var(--pop));
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
  opacity: 0;
  transform-origin: left bottom;
}

.hud-pop.show {
  animation: pop 0.8s ease-out forwards;
}

.hud-pop-unit {
  font-size: 0.48em;
  color: var(--dim);
  text-transform: uppercase;
}

.hud-pop-kind {
  font-size: 0.4em;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.hud-pop-kind:empty {
  display: none;
}

@keyframes pop {
  0% { opacity: 0; transform: translateY(var(--pop-from)) scale(0.86); }
  12% { opacity: 1; transform: translateY(0) scale(1.06); }
  24% { transform: translateY(0) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateY(0) scale(1); }
}

.hud-pop-perfect {
  display: none;
  align-self: center;
  margin-right: 4px;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hud-pop.perfect .hud-pop-perfect {
  display: inline-block;
  animation: slide-tag 0.25s ease-out;
}

@keyframes slide-tag {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: none; }
}

/* Banners: a chip (why the rally ended), the headline, a detail line. Upper third, above the far
   court and clear of both thumbs. */
.hud-banner {
  position: absolute;
  top: 15%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  max-width: 90vw;
  opacity: 0;
  transform: translateX(-50%);
}

.hud-banner.show {
  animation: banner 1.8s ease-out forwards;
}

@keyframes banner {
  0% { opacity: 0; transform: translate(calc(-50% - 48px), 0) skewX(-10deg); }
  10% { opacity: 1; transform: translate(-50%, 0) skewX(0); }
  86% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(calc(-50% + 36px), 0); }
}

.hud-banner-chip {
  padding: 3px 10px;
  border-radius: 4px;
  background: var(--fault);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.hud-banner-chip.winner {
  background: var(--accent);
  color: var(--accent-ink);
}

.hud-banner-title {
  padding: 4px 22px 6px;
  background: var(--glass-strong);
  border-left: 6px solid var(--accent);
  border-radius: 2px 8px 8px 2px;
  font-size: 46px;
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.05;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.hud-banner[data-tone='them'] .hud-banner-title {
  border-left-color: var(--them);
}

.hud-banner-detail {
  padding: 3px 12px;
  border-radius: 4px;
  background: var(--glass);
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-replay {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 12px;
  border-radius: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 0.15s ease;
}

.hud-replay.show {
  opacity: 1;
}

.hud-replay-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 8px #ff3b30;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to { visibility: hidden; }
}

/* The venue card during the fly-in, where the scorebug will be. */
.hud-intro {
  position: absolute;
  left: calc(22px + var(--safe-left));
  bottom: calc(22px + var(--safe-bottom));
  max-width: min(560px, 62vw);
  padding: 14px 20px 12px;
  border-left: 6px solid var(--accent);
  border-radius: 2px 12px 12px 2px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateX(-24px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#hud.intro .hud-intro {
  opacity: 1;
  transform: none;
}

.hud-intro-kicker {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--accent);
}

.hud-intro-venue {
  margin-top: 4px;
  font-size: 32px;
  font-style: italic;
  font-weight: 900;
  line-height: 1.05;
  text-transform: uppercase;
}

.hud-intro-tagline {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--dim);
}

.hud-intro-skip {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.hud-pause {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.hud-pause span {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: #fff;
}

#hud.intro .hud-pause,
#hud.over .hud-pause {
  display: none;
}

/* Phones: the scorebug, with the speed pop under it, and the fly-in card go top-left; everything is
   out of the bottom 35 %, where the thumbs are. */
body.touch-mode .hud-corner {
  top: calc(8px + var(--safe-top));
  bottom: auto;
  left: calc(10px + var(--safe-left));
  flex-direction: column-reverse;
  gap: 6px;
}

body.touch-mode .scorebug {
  min-width: 196px;
  max-width: 240px;
  border-radius: 10px;
}

body.touch-mode .sb-head {
  padding: 3px 10px;
  font-size: 8.5px;
}

body.touch-mode .sb-team {
  grid-template-columns: 9px minmax(0, 1fr) auto 26px;
  gap: 6px;
  padding: 3px 10px;
  font-size: 12.5px;
}

body.touch-mode .sb-serve {
  width: 8px;
  height: 8px;
}

body.touch-mode .sb-server {
  min-width: 15px;
  padding: 0 4px;
  font-size: 10px;
}

body.touch-mode .sb-points {
  font-size: 17px;
}

body.touch-mode .sb-foot {
  padding: 3px 10px;
}

body.touch-mode .sb-call {
  font-size: 15px;
}

body.touch-mode .sb-rally {
  font-size: 9px;
}

body.touch-mode .sb-rally b {
  font-size: 12px;
}

body.touch-mode .hud-pop {
  --pop-from: -6px;
  padding: 3px 12px 4px;
  font-size: calc(14px + 13px * var(--pop));
  transform-origin: left top;
}

body.touch-mode .hud-pop-perfect {
  font-size: 10px;
  padding: 1px 6px;
}

body.touch-mode .hud-banner {
  top: 17%;
  gap: 3px;
}

body.touch-mode .hud-banner-chip {
  font-size: 9.5px;
  padding: 2px 8px;
}

body.touch-mode .hud-banner-title {
  font-size: 27px;
  padding: 2px 14px 4px;
  border-left-width: 5px;
}

body.touch-mode .hud-banner-detail {
  font-size: 9.5px;
  padding: 2px 8px;
}

body.touch-mode .hud-replay {
  top: calc(10px + var(--safe-top));
  font-size: 11px;
  padding: 4px 12px 4px 10px;
}

body.touch-mode .hud-intro {
  top: calc(8px + var(--safe-top));
  bottom: auto;
  left: calc(10px + var(--safe-left));
  max-width: min(380px, 52vw);
  padding: 9px 14px 8px;
}

body.touch-mode .hud-intro-venue {
  font-size: 21px;
}

body.touch-mode .hud-intro-tagline {
  font-size: 11.5px;
}

body.touch-mode .hud-intro-skip {
  margin-top: 6px;
  font-size: 9.5px;
}

body.touch-mode .hud-pause {
  top: calc(8px + var(--safe-top));
  right: calc(10px + var(--safe-right));
}

/* --- touch controls: the floating joystick (touchControls.js; the swipe hint styles itself) --- */

#touch-controls {
  position: fixed;
  inset: 0;
  display: none;
  touch-action: none;
  z-index: 20;
}

body.touch-mode #touch-controls {
  display: block;
}

/* The menus take every touch while they are up; the fly-in is the broadcast's, uncluttered. */
body.menu-open #touch-controls,
body.in-intro #touch-controls {
  visibility: hidden;
}

.touch-joystick-base {
  position: fixed;
  width: 110px;
  height: 110px;
  margin-left: -55px;
  margin-top: -55px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: none;
  pointer-events: none;
}

.touch-joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin-left: -25px;
  margin-top: -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #10131a;
  color: #fff;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.rotate-overlay-icon {
  font-size: 48px;
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate-overlay {
    display: flex;
  }
}

.context-lost-message {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  background: rgba(16, 19, 26, 0.92);
  font-size: 18px;
  font-weight: 600;
}

.context-lost-message.show {
  display: flex;
}

/* --- menus ------------------------------------------------------------------------------------ */

/* Above the touch controls (20) and the HUD (25); below the rotate (9999) and context-lost (10000)
   overlays. */
#menu {
  position: fixed;
  inset: 0;
  z-index: 30;
  touch-action: manipulation;
}

/* The title sits over the live venue: darker at the top and bottom edges, where the text is. */
#menu[data-screen='title'] {
  background: linear-gradient(180deg, rgba(5, 7, 11, 0.62) 0%, rgba(5, 7, 11, 0.18) 34%, rgba(5, 7, 11, 0.22) 55%, rgba(5, 7, 11, 0.78) 100%);
}

/* Game over: the scene, the celebration and the confetti stay in view behind the card. */
#menu[data-screen='gameover'] {
  background: radial-gradient(ellipse at 50% 50%, rgba(5, 7, 11, 0.25), rgba(5, 7, 11, 0.55));
}

#menu.sheet-open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.55);
}

.btn,
.pill {
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 24px rgba(184, 255, 60, 0.28);
}

.btn.secondary {
  background: var(--glass);
  border-color: var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.btn:active,
.pill:active {
  transform: scale(0.97);
}

.pill {
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 14px;
  font-weight: 800;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.segmented [role='radio'] {
  min-width: 70px;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--dim);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.segmented [aria-checked='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* The title screen. */
.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  height: 100%;
  padding: calc(20px + var(--safe-top)) calc(24px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

.title-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 1180px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.logo-wrap {
  position: relative;
  flex: 0 0 auto;
  height: 180px;
  aspect-ratio: 512 / 502;
}

/* A soft glow in the accent colour behind the logo, over a dark halo that lifts it off the crowd;
   the logo itself is transparent, never boxed. */
.logo-wrap::before {
  content: '';
  position: absolute;
  inset: -24%;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(184, 255, 60, 0.55) 0%, rgba(184, 255, 60, 0.26) 30%, rgba(184, 255, 60, 0) 58%),
    radial-gradient(circle, rgba(5, 7, 11, 0.7) 0%, rgba(5, 7, 11, 0.45) 40%, rgba(5, 7, 11, 0) 70%);
}

.logo-wrap picture {
  display: contents;
}

.logo {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45));
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-8px) rotate(1.5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .logo {
    animation: none;
  }
}

.wordmark {
  margin: 0;
  font-size: 88px;
  font-style: italic;
  font-weight: 900;
  line-height: 0.86;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 4px 0 #1c2d00, 0 12px 30px rgba(0, 0, 0, 0.6);
}

.wordmark span {
  display: block;
}

.title-tag {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(5, 7, 11, 0.55);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.86);
}

.title-corner {
  display: flex;
  gap: 10px;
  align-self: flex-start;
}

/* The venue carousel: scroll-snap cards, the picked one centred. */
.carousel {
  --card: 236px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 1180px;
}

.carousel-track {
  flex: 1;
  display: flex;
  gap: 14px;
  padding: 10px calc(50% - var(--card) / 2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}

.carousel-track::-webkit-scrollbar {
  display: none;
}

.carousel-arrow {
  flex: 0 0 44px;
  height: 44px;
  padding: 0 0 4px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.carousel-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.venue-card {
  display: flex;
  flex: 0 0 var(--card);
  flex-direction: column;
  gap: 5px;
  padding: 8px 8px 10px;
  border-radius: 16px;
  border: 2px solid transparent;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  text-align: left;
  cursor: pointer;
  opacity: 0.6;
  transform: scale(0.92);
  scroll-snap-align: center;
  touch-action: pan-x;
  transition: transform 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

.venue-card[aria-checked='true'] {
  opacity: 1;
  transform: scale(1);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(184, 255, 60, 0.18), 0 14px 36px rgba(0, 0, 0, 0.45);
}

/* The swatch: the venue's sky over its apron, and its court in perspective, all CSS gradients. */
.venue-swatch {
  position: relative;
  display: block;
  aspect-ratio: 2 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 30%, var(--sky-low) 52%, var(--ground) 52%, var(--ground) 100%);
}

.venue-court {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 57%;
  bottom: 7%;
  clip-path: polygon(31% 0, 69% 0, 100% 100%, 0 100%);
  background: linear-gradient(180deg, #fff 0 4%, var(--court) 4% 30%, var(--kitchen) 30% 47%, #fff 47% 51%, var(--kitchen) 51% 68%, var(--court) 68% 96%, #fff 96%);
}

.venue-name {
  font-size: 15px;
  font-weight: 900;
  line-height: 1.15;
}

.venue-tagline {
  display: -webkit-box;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.3;
  color: var(--dim);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.title-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px 18px;
}

.modes {
  display: flex;
  gap: 10px;
}

.modes .btn.primary {
  min-width: 190px;
  font-size: 17px;
}

.title-hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-align: center;
  color: var(--dim);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

/* Sheets: Settings (also the pause menu) and Player, over a dimmed backdrop. */
.sheet {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(440px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: min(660px, calc(100% - 32px - var(--safe-top) - var(--safe-bottom)));
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  animation: sheet-in 0.22s ease-out;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 16px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

#menu-player-sheet {
  width: min(760px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
}

.sheet-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px 20px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  margin: 0;
  font-size: 20px;
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  outline: none;
}

.sheet-pause {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.sheet-pause .btn {
  flex: 1;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  padding: 4px 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-label {
  font-weight: 800;
}

.toggle-note {
  font-size: 12px;
  color: var(--dim);
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.15s ease;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.toggle input:checked + .switch {
  background: var(--accent);
}

.toggle input:checked + .switch::after {
  transform: translateX(20px);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.field-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.field .segmented {
  display: flex;
}

.field .segmented [role='radio'] {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
}

input[type='text'] {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font: inherit;
  font-size: 16px; /* 16 px or iOS zooms in on focus */
  -webkit-user-select: text;
  user-select: text;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.swatch {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: var(--swatch);
  cursor: pointer;
  touch-action: manipulation;
}

.swatch[aria-checked='true'] {
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent);
}

.player-body {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 4px 20px;
  align-items: start;
}

.player-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 20px;
}

/* The career stats under the look, in small tiles like the game-over card's. */
.career {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 0 0;
}

.career-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 6px;
  margin: 0;
}

.career-stats div {
  padding: 6px 8px 7px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
}

.career-stats dt {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--dim);
}

.career-stats dd {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
}

/* The player in their colours: cap, head, shirt, an arm and the paddle, mirrored for a lefty. */
.player-preview {
  position: relative;
  height: 200px;
  margin-top: 14px;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 90%, rgba(184, 255, 60, 0.22), rgba(184, 255, 60, 0) 70%);
}

.player-preview[data-hand='left'] {
  transform: scaleX(-1);
}

.player-preview > span {
  position: absolute;
  display: block;
}

.pp-head {
  left: 58px;
  top: 34px;
  width: 36px;
  height: 38px;
  border-radius: 45%;
  background: var(--pp-skin);
}

.pp-cap {
  left: 54px;
  top: 27px;
  width: 44px;
  height: 17px;
  border-radius: 20px 20px 4px 4px;
  background: var(--pp-kit);
  box-shadow: 10px 6px 0 -4px var(--pp-kit);
}

.pp-body {
  left: 50px;
  top: 76px;
  width: 52px;
  height: 70px;
  border-radius: 16px 16px 10px 10px;
  background: var(--pp-kit);
}

.pp-body::before,
.pp-body::after {
  content: '';
  position: absolute;
  top: 66px;
  width: 16px;
  height: 46px;
  border-radius: 6px;
  background: var(--pp-skin);
}

.pp-body::before {
  left: 7px;
}

.pp-body::after {
  right: 7px;
}

.pp-arm {
  left: 98px;
  top: 82px;
  width: 14px;
  height: 52px;
  border-radius: 7px;
  background: var(--pp-skin);
  transform: rotate(-38deg);
  transform-origin: 50% 8px;
}

.pp-paddle {
  left: 116px;
  top: 104px;
  width: 26px;
  height: 36px;
  border-radius: 13px 13px 9px 9px;
  background: var(--pp-paddle);
  border: 2px solid rgba(0, 0, 0, 0.35);
  transform: rotate(-38deg);
}

/* The game-over card, over the still-running scene. */
.gameover {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.gameover-card {
  width: min(470px, 100%);
  padding: 20px 24px 22px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: sheet-rise 0.35s ease-out;
}

@keyframes sheet-rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.gameover-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--accent);
}

.gameover h2 {
  margin: 4px 0 10px;
  font-size: 34px;
  font-style: italic;
  font-weight: 900;
  text-transform: uppercase;
}

.gameover[data-winner='0'] h2 {
  color: var(--accent);
}

.gameover-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.go-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.go-points {
  font-size: 58px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.gameover[data-winner='0'] .us .go-points,
.gameover[data-winner='1'] .them .go-points {
  color: var(--accent);
}

.go-name {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.go-sep {
  width: 16px;
  height: 5px;
  border-radius: 3px;
  background: var(--dim);
}

.gameover-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  margin: 16px 0;
}

.gameover-stats div {
  padding: 8px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
}

.gameover-stats dt {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.gameover-stats dd {
  margin: 3px 0 0;
  font-size: 19px;
  font-weight: 900;
}

.gameover-actions {
  display: flex;
  gap: 10px;
}

.gameover-actions .btn {
  flex: 1;
}

.toast {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  z-index: 3;
  max-width: 90vw;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--glass-strong);
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Mid-height screens (small laptops, tablets on their side). */
@media (max-height: 640px) {
  .logo-wrap {
    height: 140px;
  }

  .wordmark {
    font-size: 66px;
  }

  .carousel {
    --card: 210px;
  }

  .title-screen {
    gap: 10px;
  }
}

/* Short landscape phones (up to 420 px tall): everything on the title fits without scrolling. */
@media (max-height: 420px) {
  .title-screen {
    gap: 6px;
    padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(12px + var(--safe-left));
  }

  .brand {
    gap: 10px;
  }

  .logo-wrap {
    height: 120px;
  }

  .wordmark {
    font-size: 44px;
    line-height: 0.88;
  }

  .title-tag {
    margin-top: 7px;
    font-size: 10px;
  }

  .title-corner .pill {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
  }

  .carousel {
    --card: 166px;
    gap: 4px;
  }

  .carousel-track {
    gap: 8px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .carousel-arrow {
    flex-basis: 36px;
    height: 36px;
    font-size: 24px;
  }

  .venue-card {
    gap: 3px;
    padding: 5px 5px 6px;
    border-radius: 12px;
  }

  .venue-swatch {
    aspect-ratio: 5 / 2;
    border-radius: 8px;
  }

  .venue-name {
    font-size: 12px;
  }

  .venue-tagline {
    font-size: 9.5px;
    line-height: 1.25;
  }

  .title-controls {
    gap: 8px 10px;
  }

  .segmented [role='radio'] {
    min-width: 54px;
    min-height: 38px;
    padding: 6px 10px;
    font-size: 13px;
  }

  .modes {
    gap: 8px;
  }

  .btn {
    min-height: 42px;
    padding: 9px 14px;
    font-size: 13px;
  }

  .modes .btn.primary {
    min-width: 150px;
    font-size: 14px;
  }

  .title-hint {
    font-size: 10px;
  }

  .sheet {
    max-height: calc(100% - 16px - var(--safe-top) - var(--safe-bottom));
    border-radius: 14px;
  }

  .sheet-head {
    padding: 6px 10px 6px 16px;
  }

  .sheet-head h2 {
    font-size: 17px;
  }

  .sheet-head .pill {
    min-height: 34px;
    padding: 5px 14px;
  }

  .sheet-pause {
    padding: 8px 12px;
  }

  .sheet-body {
    padding: 0 16px 10px;
  }

  .toggle,
  .field {
    padding: 7px 0;
  }

  .field {
    gap: 5px;
  }

  .player-body {
    grid-template-columns: 104px minmax(0, 1fr);
    column-gap: 12px;
  }

  .player-preview {
    height: 150px;
    margin-top: 8px;
    transform: scale(0.72);
    transform-origin: 30% 0;
  }

  .player-preview[data-hand='left'] {
    transform: scale(-0.72, 0.72);
  }

  .player-fields {
    column-gap: 14px;
  }

  /* The label beside the tiles, not over them: the Player sheet must not scroll on a phone. */
  .career {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding-top: 5px;
  }

  .career-stats {
    flex: 1;
    gap: 4px;
  }

  .career-stats div {
    padding: 3px 6px 4px;
    border-radius: 7px;
  }

  .career-stats dt {
    font-size: 8.5px;
  }

  .career-stats dd {
    margin-top: 1px;
    font-size: 12px;
    line-height: 1.15;
  }

  .field .segmented [role='radio'] {
    padding: 5px 6px;
  }

  input[type='text'] {
    padding: 7px 12px;
  }

  .swatch {
    width: 30px;
    height: 30px;
  }

  .swatches {
    gap: 7px;
  }

  .gameover-card {
    padding: 12px 18px 14px;
  }

  .gameover h2 {
    margin: 2px 0 4px;
    font-size: 24px;
  }

  .go-points {
    font-size: 42px;
  }

  .gameover-stats {
    margin: 10px 0;
  }

  .gameover-stats dd {
    font-size: 16px;
  }
}

.webgl-warning {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
  background: #10131a;
}

.webgl-warning h1 {
  margin: 0;
  font-size: 28px;
}

.webgl-warning p {
  max-width: 520px;
  margin: 0;
  opacity: 0.85;
  line-height: 1.5;
}

.webgl-warning code {
  background: rgba(255, 255, 255, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
}

.webgl-warning-detail {
  opacity: 0.55;
  font-size: 13px;
}
