@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-VariableFont_wght.ttf") format("truetype");
  font-weight: 200 1000;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-Italic-VariableFont_wght.ttf") format("truetype");
  font-weight: 200 1000;
  font-style: italic;
  font-display: block;
}

:root {
  --p1: #3cf27a;
  --p2: #ff3d8a;
  --ball: #f4f5fa;
  --ink: #eef0f8;
  --glass: rgba(16, 14, 30, 0.6);
  --line: rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05030c;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-weight: 800;
  user-select: none;
  -webkit-user-select: none;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#fg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

/* ---------- in-game HUD ----------
   Scales with the scene: game.js sets --u (1 at a 1600x900 window).
   --glass-l / --glass-r: screen distance of the glass walls' inner edges, also set by game.js. */

#hud {
  --u: 1;
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.score {
  position: absolute;
  top: calc(var(--u) * 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 8px);
  min-width: calc(var(--u) * 140px);
  transition: opacity .4s;
}
.score.p1 { left: calc(var(--glass-l, 0px) + var(--u) * 32px); color: var(--p1); }
.score.p2 { right: calc(var(--glass-r, 0px) + var(--u) * 32px); color: var(--p2); }
body[data-state="menu"] .score { opacity: 0; }

.score .label {
  display: flex;
  align-items: center;
  font-size: calc(var(--u) * 22px);
  font-weight: 900;
}
/* serve dot: always there, grows in / shrinks away; the centred name slides over with it */
.score .label::after {
  content: "";
  flex: none;
  width: 0;
  height: calc(var(--u) * 12px);
  margin-left: 0;
  border-radius: 50%;
  background: var(--ball);
  opacity: 0;
  transform: scale(0);
  transition: width .4s cubic-bezier(.3, 1.3, .5, 1), margin-left .4s cubic-bezier(.3, 1.3, .5, 1),
              transform .4s cubic-bezier(.3, 1.6, .5, 1), opacity .25s;
}
.score.serving .label::after {
  width: calc(var(--u) * 12px);
  margin-left: calc(var(--u) * 10px);
  opacity: 1;
  transform: scale(1);
}

.score .val {
  font-size: calc(var(--u) * 88px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score .val.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop {
  from { transform: scale(1.5); }
  to { transform: scale(1); }
}

.pips { display: flex; gap: calc(var(--u) * 8px); }
.pips i {
  position: relative;
  width: calc(var(--u) * 12px);
  height: calc(var(--u) * 12px);
  border-radius: 50%;
  border: calc(var(--u) * 2px) solid currentColor;
  opacity: .35;
  transition: opacity .25s;
}
/* the fill pops in with an overshoot when a touch is counted, and shrinks away when cleared
   (game.js staggers the clearing from the last dot back to the first) */
.pips i::before {
  content: "";
  position: absolute;
  inset: calc(var(--u) * -2px);
  border-radius: 50%;
  background: currentColor;
  transform: scale(0);
  transition: transform .22s cubic-bezier(.5, 0, .75, 0);
  transition-delay: inherit;
}
.pips i.on { opacity: 1; animation: pipPop .35s cubic-bezier(.3, 1.6, .5, 1); }
.pips i.on::before {
  transform: scale(1);
  transition: transform .35s cubic-bezier(.3, 1.8, .5, 1);
}
@keyframes pipPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); }
  100% { transform: scale(1); }
}

#banner {
  position: absolute;
  top: 30%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 6px);
  transform: translate(-50%, -50%) scale(.92);
  opacity: 0;
  transition: opacity .25s, transform .35s;
  text-align: center;
  white-space: nowrap;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner b {
  font-size: calc(var(--u) * 80px);
  font-weight: 900;
  line-height: 1;
}
#banner small {
  font-size: calc(var(--u) * 26px);
  font-weight: 800;
  color: var(--ink);
}

/* highlight callouts during a rally ("Great save", "Epic rally", "Match point"):
   same typography as the point banner, a little smaller and higher, short-lived */
#callout {
  position: absolute;
  top: 24%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 4px);
  transform: translate(-50%, -50%) scale(.8);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  text-align: center;
  white-space: nowrap;
}
#callout.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  transition: opacity .15s, transform .4s cubic-bezier(.3, 1.7, .5, 1);
}
#callout.out { transform: translate(-50%, -80%) scale(.95); }
#callout b {
  font-size: calc(var(--u) * 58px);
  font-weight: 900;
  line-height: 1;
}
#callout small {
  font-size: calc(var(--u) * 22px);
  font-weight: 800;
  color: var(--ink);
}

#ballMarker {
  position: absolute;
  top: calc(var(--u) * 8px);
  display: none;
  width: 0;
  height: 0;
  border-left: calc(var(--u) * 11px) solid transparent;
  border-right: calc(var(--u) * 11px) solid transparent;
  border-bottom: calc(var(--u) * 17px) solid var(--ball);
  transform: translateX(-50%);
}

/* ---------- overlays (menu, pause, game over): fixed size ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 3, 12, .15), rgba(5, 3, 12, .6));
  transition: opacity .4s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
#error.hidden { display: none; }

.panel {
  width: min(600px, 100%);
  padding: 40px 44px;
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 28px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.panel.small { width: min(460px, 100%); }
.panel h2 {
  margin: 0 0 16px;
  font-size: 44px;
  font-weight: 900;
  line-height: 1.1;
}
.panel p {
  margin: 18px 0 0;
  font-size: 20px;
  font-weight: 800;
  opacity: .85;
}
.panel pre {
  margin: 0;
  max-height: 50vh;
  overflow: auto;
  text-align: left;
  white-space: pre-wrap;
  font: 700 16px/1.4 "Nunito", sans-serif;
  color: #ffb3c8;
  user-select: text;
}

.title {
  margin: 0;
  font-size: clamp(72px, 14vw, 136px);
  font-weight: 1000;
  line-height: 1;
  background: linear-gradient(100deg, var(--p1), var(--p2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag {
  margin: 8px 0 30px;
  font-size: 22px;
  font-weight: 800;
  opacity: .75;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 30px;
}
.ctrl {
  padding: 18px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .07);
}
.ctrl.p1 { color: var(--p1); }
.ctrl.p2 { color: var(--p2); }
.ctrl h3 {
  margin: 0 0 14px;
  font-size: 24px;
  font-weight: 900;
}
.keys {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .06);
  box-shadow: 0 3px 0 rgba(255, 255, 255, .1);
  color: var(--ink);
  font: 900 18px/1 "Nunito", sans-serif;
}
.start kbd, .hint kbd, .panel p kbd { min-width: 34px; height: 34px; font-size: 16px; }

.start {
  font-size: 26px;
  font-weight: 900;
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
  50% { opacity: .55; }
}

.hint {
  margin-top: 22px;
  font-size: 18px;
  font-weight: 800;
  line-height: 2.2;
  opacity: .7;
}
.stats {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 800;
  opacity: .6;
}
.stats:empty { display: none; }

.final {
  font-size: 72px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
  .panel { padding: 28px 18px; }
  .controls { grid-template-columns: 1fr; }
}
