/*
 * The stage is a fixed-aspect box that letterboxes inside the viewport, so all
 * overlay chrome is sized in container units (cqh/cqw) against the stage rather
 * than in vw/vh against the viewport. Sized in viewport units, the HUD lands on
 * its clamp() floor on a portrait phone and swallows the court.
 */

:root {
  --sand: #f6ddaa;
  --deep: #08283f;
  --deep-2: #0d3d5f;
  --orange: #f97b45;
  --azure: #48a6f5;
  --ink: #0b1c28;
  --panel: rgba(9, 32, 50, 0.93);
  --edge: rgba(255, 255, 255, 0.16);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* An author rule that sets `display` beats the UA stylesheet's [hidden] rule,
   so make the attribute authoritative before anything else can override it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(120% 80% at 50% 0%, #12557f 0%, var(--deep-2) 45%, var(--deep) 100%);
  color: #eaf4fb;
  font: 500 16px/1.5 "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  width: min(100%, 1280px);
  height: 100%;
  padding: clamp(8px, 1.6vh, 18px) clamp(8px, 2vw, 22px);
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vh, 14px);
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.brand {
  margin: 0;
  font-size: clamp(15px, 2.4vh, 25px);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.brand .ball {
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset -3px -4px 0 -1px #ffc93c, inset 4px 4px 0 -1px #2f7fd6;
  flex: 0 0 auto;
}

.toolbar { display: flex; gap: 8px; }

.tool, .cta, .seg button, .pad {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.tool {
  padding: 7px 12px;
  font-size: clamp(12px, 1.7vh, 14px);
  white-space: nowrap;
}
.tool:hover, .seg button:hover { background: rgba(255, 255, 255, 0.15); }
.tool:active { transform: translateY(1px); }
.tool[aria-pressed="false"] { opacity: 0.45; }

@media (max-width: 620px) { .tool span { display: none; } }

/* ------------------------------------------------------------------ stage */

/* The court is the box the stage is fitted into. Its size comes from the flex
   line alone (basis 0), never from its contents, so writing a size onto the
   stage inside a ResizeObserver on this element cannot feed back. */
.court {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

/* Sized in JS from the measured court, because no CSS form of "fit this fixed
   ratio inside a box constrained on both axes" survives a flex stretch: on a
   portrait phone `aspect-ratio` loses to the stretched height and the canvas
   renders squashed. The declaration below is the pre-script fallback only. */
.stage {
  position: relative;
  width: min(100%, 1200px);
  aspect-ratio: 1200 / 760;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.09);

  /* Makes cqw/cqh below resolve against the court, not the viewport. */
  container-type: size;
  container-name: stage;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

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

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2cqw;
  padding: 2.2cqh 2.4cqw;
  pointer-events: none;
  font-family: "Trebuchet MS", system-ui, sans-serif;
}

.team {
  display: flex;
  align-items: center;
  gap: 1.4cqw;
  background: rgba(6, 26, 42, 0.42);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 0.9cqh 1.8cqw;
  min-width: 0;
}

.team__name {
  font-size: clamp(9px, 3.4cqh, 19px);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team--left .team__name { color: var(--orange); }
.team--right .team__name { color: var(--azure); }

.team__score {
  font-size: clamp(16px, 7cqh, 44px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.team__serve {
  font-size: clamp(7px, 2.3cqh, 12px);
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 0.35cqh 0.9cqw;
  border-radius: 999px;
  background: #ffd75e;
  color: #4a3200;
  opacity: 0;
  transition: opacity 0.2s;
}
.team__serve.is-on { opacity: 1; }

.rally {
  align-self: center;
  margin-top: 1cqh;
  font-size: clamp(8px, 2.6cqh, 14px);
  letter-spacing: 0.12em;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}

/* ----------------------------------------------------------------- banner */

.banner {
  position: absolute;
  left: 50%;
  top: 34cqh;
  transform: translate(-50%, -50%);
  font-size: clamp(18px, 9cqh, 62px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
  white-space: nowrap;
}

@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 3cqh 3cqw;
  background: rgba(4, 20, 34, 0.55);
  backdrop-filter: blur(3px);
}

.panel {
  width: min(92cqw, 560px);
  max-height: 94cqh;
  overflow: auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: clamp(12px, 4cqh, 30px) clamp(14px, 4cqw, 34px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.panel__title {
  margin: 0 0 0.25em;
  font-size: clamp(17px, 6.4cqh, 34px);
  letter-spacing: 0.01em;
}

.panel__sub {
  margin: 0 0 clamp(10px, 2.6cqh, 20px);
  font-size: clamp(11px, 3cqh, 16px);
  color: rgba(226, 240, 250, 0.72);
}

.panel__body { display: grid; gap: clamp(7px, 1.8cqh, 14px); }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.field__label {
  font-size: clamp(10px, 2.7cqh, 14px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 240, 250, 0.6);
}

.seg { display: flex; gap: 4px; background: rgba(0, 0, 0, 0.28); padding: 4px; border-radius: 12px; }

.seg button {
  border: 0;
  background: transparent;
  padding: 0.7cqh 1.6cqw;
  min-width: 4.6em;
  border-radius: 9px;
  font-size: clamp(10px, 2.7cqh, 14px);
  font-weight: 600;
}
.seg button.is-on { background: #ffd75e; color: #40300a; }

.cta {
  margin-top: clamp(12px, 3cqh, 22px);
  width: 100%;
  padding: clamp(9px, 2.6cqh, 15px);
  font-size: clamp(13px, 3.6cqh, 19px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #40300a;
  background: linear-gradient(180deg, #ffe07a, #ffc93c);
  border-color: rgba(0, 0, 0, 0.2);
}
.cta:hover { filter: brightness(1.06); }
.cta:active { transform: translateY(1px); }

.keys {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 3cqw, 30px);
  margin-top: clamp(10px, 2.6cqh, 18px);
  font-size: clamp(9px, 2.5cqh, 13px);
  color: rgba(226, 240, 250, 0.75);
}
.keys__col { display: grid; gap: 3px; }
.keys__alt { color: rgba(226, 240, 250, 0.45); }

.rules {
  margin: clamp(8px, 2cqh, 14px) 0 0;
  font-size: clamp(9px, 2.4cqh, 12.5px);
  color: rgba(226, 240, 250, 0.5);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.1em 0.4em;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.1);
  font: inherit;
  font-size: 0.92em;
}

/* A decision about the device, not about the box — so it reads the viewport. */
.rotate-hint {
  display: none;
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: rgba(226, 240, 250, 0.5);
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint { display: block; }
}

/* --------------------------------------------------------- touch controls */

/* These belong to the device, not to the court, so they sit outside the stage
   and are sized in viewport units. Inside it they would be measured against a
   letterboxed strip and would cover the game they exist to play. */
.pads {
  flex: 0 0 auto;
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 0;
  user-select: none;
  -webkit-user-select: none;
}
.pads__side { display: flex; gap: 12px; }

.pad {
  width: clamp(58px, 17vw, 88px);
  height: clamp(58px, 17vw, 88px);
  border-radius: 50%;
  font-size: clamp(18px, 5vw, 26px);
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.3);
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.pad.is-down { background: #ffd75e; color: #40300a; }
.pad--jump { background: rgba(255, 215, 94, 0.26); }

/* Media queries still read the viewport — that is the right question for
   "is this a touch device", as opposed to "how big is the court". */
@media (pointer: coarse) {
  .pads.is-live { display: flex; }
}

/* --------------------------------------------------------------- footnote */

.footnote {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: clamp(10px, 1.6vh, 13px);
  color: rgba(226, 240, 250, 0.45);
}
.footnote a { color: rgba(226, 240, 250, 0.6); }

@media (max-height: 560px) {
  .footnote { display: none; }
  .brand { font-size: 15px; }
}
