/* Chibi Smash Tennis — cartoon arcade UI */

:root {
  --font: "Baloo 2", "Comic Sans MS", "Segoe UI", sans-serif;
  --ink: #23304d;
  --ink-border: #2a3a5c;
  --yellow: #ffd23f;
  --orange: #ff9f43;
  --red: #ff6b6b;
  --green-1: #7bd85a;
  --green-2: #3aa93f;
  --card-shadow: 0 5px 0 rgba(20, 40, 80, 0.25), 0 12px 24px rgba(20, 40, 80, 0.3);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none; /* game-area touches never scroll/zoom */
}

body {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font-family: inherit;
}

/* ================= Menu ================= */

/* phase 4: the attract diorama plays behind every menu screen — light scrim only */
#menu {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(8, 14, 38, 0.45), rgba(8, 14, 38, 0.12) 40%, rgba(8, 14, 38, 0.6));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#menu.show {
  opacity: 1;
  pointer-events: auto;
}

/* customize screen: near-transparent so the live 3D preview shows through */
#menu.clear {
  background: linear-gradient(90deg, rgba(20, 35, 70, 0.42), transparent 55%);
}

#menu.clear .menu-ticker,
#menu.clear .corner-tag {
  display: none; /* keep the editor close-up clean */
}

.menu-screen {
  display: none;
  position: relative;
  max-width: min(92vw, 640px);
  margin: auto;
  padding: clamp(16px, 4vh, 40px) 12px;
  text-align: center;
}

.menu-screen.active {
  display: block;
}

/* ===== title v2: layered logo (PHASE4 §G) ===== */

.logo {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 0.45em;
  line-height: 1;
}

/* periodic sparkle sweep across the wordmark */
.logo.big::after {
  content: "";
  position: absolute;
  inset: -6%;
  background: linear-gradient(115deg, transparent 44%, rgba(255, 255, 255, 0.45) 50%, transparent 56%);
  background-size: 300% 100%;
  background-position: 150% 0;
  mix-blend-mode: screen;
  animation: sparkleSweep 4.6s linear 2.2s infinite;
  pointer-events: none;
}

@keyframes sparkleSweep {
  0% { background-position: 150% 0; }
  38% { background-position: -150% 0; }
  100% { background-position: -150% 0; }
}

.logo-word {
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.ll {
  display: inline-block;
  position: relative;
  font-size: clamp(2.6rem, 11vw, 5.6rem);
  font-weight: 800;
  color: var(--c, #ffd23f);
  text-shadow:
    0.06em 0.06em 0 var(--ink-border),
    0.11em 0.11em 0 rgba(0, 0, 0, 0.22),
    -2px -2px 0 rgba(255, 255, 255, 0.3);
  transform-origin: 50% 100%;
  animation:
    logoDrop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1) calc(var(--i, 0) * 0.06s) both,
    llFloat 3.4s ease-in-out calc(1.5s + var(--i, 0) * 0.1s) infinite;
}

/* drop-in squash-bounce entrance */
@keyframes logoDrop {
  0% { opacity: 0; transform: translateY(-2.2em); }
  55% { opacity: 1; transform: translateY(0) scale(1.06, 0.7); }
  75% { transform: translateY(-0.16em) scale(0.95, 1.08); }
  100% { transform: translateY(0) rotate(var(--r, 0deg)) scale(1); }
}

/* idle float */
@keyframes llFloat {
  0%, 100% { transform: rotate(var(--r, 0deg)) translateY(0); }
  50% { transform: rotate(var(--r, 0deg)) translateY(-0.09em); }
}

/* decorative tennis ball with white seam — sits BESIDE the wordmark, never in
   a letter slot (§G: a ball standing in for the A reads as SMOSH) */
.logo-ball {
  position: relative;
  display: inline-block;
  font-size: clamp(2.6rem, 11vw, 5.6rem);
  width: 0.5em;
  height: 0.5em;
  margin: 0 0 0.62em 0.14em; /* floats up by the cap height, clear of the letters */
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f4ff7a, #d9ee3f 55%, #a9c31f);
  box-shadow: 0.05em 0.06em 0 var(--ink-border), inset -0.06em -0.08em 0 rgba(0, 0, 0, 0.15);
  overflow: hidden;
  animation:
    logoDrop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1) calc(var(--i, 0) * 0.06s) both,
    llFloat 3.4s ease-in-out calc(1.5s + var(--i, 0) * 0.1s) infinite;
}

.logo-ball::before,
.logo-ball::after {
  content: "";
  position: absolute;
  width: 110%;
  height: 110%;
  border: 0.055em solid #fff;
  border-radius: 50%;
}

.logo-ball::before { left: -68%; top: -22%; }
.logo-ball::after { right: -68%; bottom: -22%; }

.logo.small .ll {
  font-size: clamp(1.5rem, 6vw, 2.6rem);
  animation: llFloat 3.4s ease-in-out calc(var(--i, 0) * 0.1s) infinite;
}

.logo.small .logo-ball {
  font-size: clamp(1.5rem, 6vw, 2.6rem);
  animation: llFloat 3.4s ease-in-out calc(var(--i, 0) * 0.1s) infinite;
}

.logo-tag {
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  font-size: clamp(0.9rem, 3vw, 1.3rem);
  text-shadow: 2px 2px 0 rgba(20, 30, 70, 0.6);
  margin-top: 8px;
  animation: logoDrop 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) 0.75s both;
}

.title-screen {
  cursor: pointer;
}

.press-any {
  margin-top: clamp(26px, 8vh, 70px);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  font-size: clamp(1rem, 3.2vw, 1.5rem);
  text-shadow: 2px 2px 0 rgba(20, 30, 70, 0.7);
  animation: pressPulse 1.15s ease-in-out infinite;
}

@keyframes pressPulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* ===== mode cards ===== */

.mode-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2.2vw, 20px);
  width: min(92vw, 560px);
  margin: clamp(12px, 3.5vh, 28px) auto 0;
  perspective: 900px;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: clamp(12px, 2.6vh, 24px) 10px;
  border-radius: 20px;
  border: 4px solid #fff;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s;
  animation: cardIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.mode-card:nth-child(1) { animation-delay: 0.02s; }
.mode-card:nth-child(2) { animation-delay: 0.08s; }
.mode-card:nth-child(3) { animation-delay: 0.14s; }
.mode-card:nth-child(4) { animation-delay: 0.2s; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(26px) scale(0.85); }
}

.mode-card:hover,
.mode-card.gp-focus {
  transform: rotate3d(1, -1, 0, 7deg) scale(1.05);
}

.mode-card:active { transform: scale(0.94); }

.mc-exhibition { background: linear-gradient(180deg, var(--green-1), var(--green-2)); }
.mc-mini { background: linear-gradient(180deg, var(--orange), #f2622a); }
.mc-custom { background: linear-gradient(180deg, #a78bfa, #7c5ce0); }
.mc-options { background: linear-gradient(180deg, #6ea8ff, #3b6fd4); }

.mc-name {
  font-weight: 800;
  font-size: clamp(1rem, 3.4vw, 1.45rem);
  letter-spacing: 0.08em;
}

.mc-sub {
  font-weight: 700;
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  opacity: 0.85;
}

/* CSS-art card icons */
.mc-art {
  position: relative;
  display: block;
  margin-bottom: 2px;
}

.art-court {
  width: 64px;
  height: 44px;
  background: #3b7fd4;
  border: 3px solid #fff;
  border-radius: 6px;
}

.art-court::after {
  content: "";
  position: absolute;
  inset: 6px 10px;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.art-court > i {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: #fff;
}

.art-target {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #b8291f;
}

.art-target > i:first-child {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: #e8452f;
}

.art-target > i:last-child {
  position: absolute;
  inset: 17px;
  border-radius: 50%;
  background: #fff;
}

.art-shirt {
  width: 54px;
  height: 46px;
  background: #ffd23f;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.2));
  clip-path: polygon(25% 0, 75% 0, 100% 30%, 82% 45%, 82% 100%, 18% 100%, 18% 45%, 0 30%);
}

.art-shirt > i {
  position: absolute;
  left: 50%;
  top: 0;
  width: 16px;
  height: 8px;
  margin-left: -8px;
  border-radius: 0 0 10px 10px;
  background: rgba(0, 0, 0, 0.25);
}

.art-gear {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 -20px 0 -14px #fff, 0 20px 0 -14px #fff, -20px 0 0 -14px #fff, 20px 0 0 -14px #fff,
    -14px -14px 0 -14px #fff, 14px 14px 0 -14px #fff, 14px -14px 0 -14px #fff, -14px 14px 0 -14px #fff;
}

.art-gear > i {
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: #3b6fd4;
}

.screen-title {
  color: #fff;
  font-weight: 800;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  letter-spacing: 0.14em;
  text-shadow: 3px 3px 0 rgba(30, 45, 90, 0.55);
  margin-bottom: clamp(12px, 3vh, 22px);
}

.back-btn {
  display: inline-block;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.22);
  border: 3px solid #fff;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
  font-size: clamp(0.85rem, 2.6vw, 1rem);
  letter-spacing: 0.06em;
  padding: 0.35em 1.3em;
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}

.back-btn:hover { transform: translateY(-2px); }

/* --- pickers / pills --- */

.pickers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(10px, 3vw, 28px);
  margin-bottom: clamp(14px, 3vh, 26px);
}

.picker-label {
  color: #fff;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  text-shadow: 1px 1px 0 rgba(30, 45, 90, 0.5);
  margin-bottom: 6px;
}

.pill-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.pill-row.wrap {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.pill {
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 0.4em 1em;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-weight: 700;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s, color 0.15s;
}

.pill:hover {
  transform: translateY(-2px) scale(1.06);
}

.pill.sel {
  background: linear-gradient(180deg, var(--yellow), var(--orange));
  color: #4a2c00;
  text-shadow: none;
  transform: scale(1.08);
  box-shadow: 0 4px 0 rgba(20, 40, 80, 0.25);
}

/* dark variant for pills on light cards (character editor) */
.pill.dark {
  background: #eef2ff;
  border-color: #b9c6e8;
  color: var(--ink);
  text-shadow: none;
  font-size: 0.85rem;
  padding: 0.3em 0.85em;
}

.pill.dark.sel {
  background: linear-gradient(180deg, var(--yellow), var(--orange));
  border-color: #fff;
  color: #4a2c00;
}

.surf-dot {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  margin-right: 0.45em;
  vertical-align: -0.06em;
  border: 2px solid rgba(255, 255, 255, 0.85);
}

.play-btn {
  font-size: clamp(1.5rem, 5vw, 2.3rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0.45em 2em;
  border-radius: 26px;
  border: 4px solid #fff;
  background: linear-gradient(180deg, var(--green-1), var(--green-2));
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.play-btn:hover {
  transform: scale(1.1, 0.94);
}

.play-btn:active {
  transform: scale(0.92);
}

.help-card {
  display: inline-block;
  background: rgba(255, 255, 255, 0.93);
  border: 3px solid var(--ink-border);
  border-radius: 18px;
  padding: 12px 20px 16px;
  color: var(--ink);
  box-shadow: var(--card-shadow);
  font-size: clamp(0.78rem, 2.2vw, 0.95rem);
}

.help-title {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  margin-bottom: 8px;
  color: #5b6b93;
}

.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 16px;
  text-align: left;
  align-items: center;
  font-weight: 600;
}

kbd {
  display: inline-block;
  background: #eef2ff;
  border: 2px solid #b9c6e8;
  border-bottom-width: 3px;
  border-radius: 7px;
  padding: 0 0.4em;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.92em;
}

/* --- mini games picker --- */

.mg-list {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.mg-card {
  width: min(80vw, 250px);
  text-align: left;
  background: rgba(255, 255, 255, 0.93);
  border: 3px solid var(--ink-border);
  border-radius: 18px;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mg-card:hover {
  transform: translateY(-3px) scale(1.03);
}

.mg-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--ink);
}

.mg-desc {
  font-weight: 600;
  font-size: 0.85rem;
  color: #5b6b93;
  margin: 4px 0 8px;
}

.mg-best {
  font-weight: 800;
  font-size: 0.8rem;
  color: #ff6b35;
}

/* --- character editor --- */

.menu-screen[data-screen="customize"] {
  margin: auto auto auto clamp(8px, 4vw, 56px);
  max-width: min(88vw, 360px);
  text-align: left;
}

.cust-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid var(--ink-border);
  border-radius: 18px;
  padding: 14px 18px 18px;
  box-shadow: var(--card-shadow);
  max-height: 74vh;
  overflow-y: auto;
}

.cust-title {
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #5b6b93;
  font-size: clamp(0.85rem, 2.4vw, 1rem);
}

.cust-label {
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: #5b6b93;
  text-transform: uppercase;
  margin: 12px 0 5px;
}

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

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(35, 48, 77, 0.3);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s;
}

.swatch:hover { transform: scale(1.15); }

.swatch.sel {
  box-shadow: 0 0 0 3px var(--ink-border);
  transform: scale(1.12);
}

.swatch.none {
  background: #fff;
  color: #c33;
  font-weight: 800;
  font-size: 0.9rem;
  line-height: 1;
}

/* --- racket brand cards (PHASE4 §F) --- */

.racket-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.racket-card {
  flex: 0 0 auto;
  width: 106px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: #f6f8ff;
  border: 3px solid #b9c6e8;
  border-radius: 14px;
  padding: 8px 6px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}

.racket-card:hover { transform: translateY(-2px); }

.racket-card.sel {
  border-color: var(--ink-border);
  box-shadow: 0 0 0 3px var(--yellow);
}

.rk {
  position: relative;
  display: block;
  width: 30px;
  height: 52px;
}

.rk-head {
  position: absolute;
  left: 50%;
  top: 0;
  width: 28px;
  height: 34px;
  margin-left: -14px;
  border: 5px solid var(--frame, #63666e);
  border-radius: 50%;
  box-sizing: border-box;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.7) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.7) 0 1px, transparent 1px 5px),
    var(--strings, #ddd);
}

.rk-handle {
  position: absolute;
  left: 50%;
  top: 32px;
  width: 6px;
  height: 20px;
  margin-left: -3px;
  border-radius: 3px;
  background: var(--grip, #444);
}

.rk-name {
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.rk-tag {
  font-weight: 700;
  font-size: 0.58rem;
  color: #5b6b93;
}

.rk-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}

.rk-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rk-stat b {
  font-size: 0.52rem;
  color: #5b6b93;
  width: 2.2em;
  letter-spacing: 0.04em;
}

.rk-bar {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: #dde4f5;
  overflow: hidden;
  display: block;
}

.rk-bar > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--yellow), var(--orange));
}

/* --- options screen (PHASE4 §G) --- */

.opt-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid var(--ink-border);
  border-radius: 18px;
  padding: 14px 18px 18px;
  box-shadow: var(--card-shadow);
  width: min(86vw, 400px);
  margin: 0 auto;
  text-align: left;
}

.opt-slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.opt-slider {
  flex: 1;
  accent-color: var(--orange);
  cursor: pointer;
  min-width: 0;
}

.opt-val {
  font-weight: 800;
  color: var(--ink);
  min-width: 3em;
  text-align: right;
  font-size: 0.85rem;
}

.reset-wrap {
  margin-top: 18px;
  text-align: center;
}

.reset-btn {
  border: 3px solid #fff;
  border-radius: 14px;
  background: linear-gradient(180deg, #fa5252, #c92a2a);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 0.45em 1.2em;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.14s;
}

.reset-btn:hover { transform: scale(1.05); }

.reset-confirm {
  display: none;
  margin-top: 10px;
  font-weight: 700;
  color: var(--ink);
}

.reset-confirm.show {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.reset-confirm button {
  border-radius: 12px;
  border: 3px solid #fff;
  font-weight: 800;
  padding: 0.35em 1em;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  color: #fff;
}

.reset-yes { background: linear-gradient(180deg, #fa5252, #c92a2a); }
.reset-no { background: linear-gradient(180deg, #6ea8ff, #3b6fd4); }

/* --- ticker + corner tag (PHASE4 §G) --- */

.menu-ticker {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: rgba(8, 14, 38, 0.8);
  border-top: 2px solid rgba(255, 255, 255, 0.25);
  overflow: hidden;
  white-space: nowrap;
}

.tk-tag {
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--yellow), var(--orange));
  color: #4a2c00;
  font-weight: 800;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  border-radius: 6px;
  padding: 2px 8px;
}

.tk-text {
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tk-text.show {
  opacity: 0.95;
  transform: none;
}

.corner-tag {
  position: absolute;
  right: 12px;
  bottom: 42px;
  color: #fff;
  opacity: 0.55;
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* --- menu toast --- */

.menu-toast {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  transform: translate(-50%, 10px);
  background: rgba(25, 35, 70, 0.9);
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  border: 2px solid #fff;
  padding: 0.5em 1.3em;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

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

/* ================= HUD ================= */

#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.hud-game {
  transition: opacity 0.3s ease, visibility 0.3s;
}

.hud-game.hud-hidden {
  opacity: 0;
  visibility: hidden; /* keeps invisible touch buttons untappable */
}

/* --- scoreboard --- */

.score-card {
  position: absolute;
  top: 12px;
  left: 12px;
  min-width: clamp(120px, 16vw, 170px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(232, 241, 255, 0.95));
  border: 3px solid var(--ink-border);
  border-radius: 16px;
  padding: 8px 14px 10px;
  color: var(--ink);
  box-shadow: var(--card-shadow);
}

.score-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
}

.serve-dot {
  font-size: 0.85em;
  visibility: hidden;
}

.score-row.serving .serve-dot {
  visibility: visible;
  animation: wiggle 0.9s ease-in-out infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-14deg); }
  50% { transform: rotate(14deg); }
}

.score-name {
  flex: 1;
  letter-spacing: 0.06em;
}

.score-games {
  background: var(--ink-border);
  color: #fff;
  border-radius: 8px;
  min-width: 1.5em;
  text-align: center;
  padding: 0 0.25em;
}

.score-points {
  margin-top: 6px;
  padding-top: 4px;
  border-top: 2px dashed #b9c6e8;
  text-align: center;
  font-weight: 800;
  font-size: clamp(1.2rem, 3.6vw, 1.7rem);
  color: #ff6b35;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
}

/* --- power meter --- */

.power-wrap {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: clamp(220px, 38vw, 420px);
  text-align: center;
}

.power-label {
  opacity: 0;
  transform: translateY(6px);
  font-weight: 800;
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(30, 45, 90, 0.55);
  margin-bottom: 4px;
  transition: opacity 0.25s, transform 0.25s;
}

.power-bar {
  height: 20px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: rgba(10, 25, 60, 0.45);
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(20, 40, 80, 0.3);
}

.power-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--yellow), var(--orange), #ff5b5b);
  transition: width 0.18s ease-out;
}

.power-wrap.full .power-label {
  opacity: 1;
  transform: none;
  animation: labelPulse 0.9s ease-in-out infinite;
}

.power-wrap.full .power-bar {
  animation: glowPulse 0.9s ease-in-out infinite;
}

@keyframes labelPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 3px 0 rgba(20, 40, 80, 0.3), 0 0 8px 2px rgba(255, 210, 63, 0.55); }
  50% { box-shadow: 0 3px 0 rgba(20, 40, 80, 0.3), 0 0 22px 7px rgba(255, 159, 67, 0.9); }
}

/* --- announcements (redesigned: compact, never mid-screen) --- */

.announce-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* normal: small banner, top-center, ≤40vw, ≤1.2s */
.announce {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -16px);
  max-width: 40vw;
  padding: 0.28em 1.1em;
  border-radius: 999px;
  background: rgba(25, 35, 70, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.7);
  color: #fff;
  font-weight: 800;
  font-size: clamp(16px, 2.2vw, 26px);
  letter-spacing: 0.05em;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: bannerSlide 1.15s ease forwards;
}

@keyframes bannerSlide {
  0% { opacity: 0; transform: translate(-50%, -16px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  82% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -12px); }
}

/* big: one short semi-transparent scale-pop in the UPPER third (≤0.8s) —
   the ball's flight zone (center/lower screen) stays clear */
.announce.big {
  top: 16vh;
  max-width: 60vw;
  padding: 0;
  background: none;
  border: none;
  color: var(--yellow);
  font-size: clamp(1.5rem, 4.5vw, 2.7rem);
  letter-spacing: 0.06em;
  text-shadow: 3px 3px 0 rgba(30, 45, 90, 0.8), -1px -1px 0 rgba(255, 255, 255, 0.3);
  animation: bigPop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes bigPop {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.4); }
  18% { opacity: 0.92; transform: translate(-50%, 0) scale(1.14); }
  38% { transform: translate(-50%, 0) scale(1); }
  75% { opacity: 0.92; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 0) scale(1.06); }
}

/* OPTIONS: announcement size 'minimal' shrinks both banner kinds further */
.announce-minimal .announce {
  font-size: clamp(12px, 1.6vw, 18px);
  padding: 0.2em 0.9em;
}

.announce-minimal .announce.big {
  top: 12vh;
  font-size: clamp(1.1rem, 3vw, 1.8rem);
}

/* --- cinematic replay (DESIGN-PHASE2 §1) --- */

.cine-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  background: #05070d;
  transition: height 0.35s ease;
}

.cine-bar.top { top: 0; }
.cine-bar.bottom { bottom: 0; }

.cinematic .cine-bar { height: 9vh; }

/* the top letterbox bar would half-cover the scoreboard — HUD fades out for the take */
.cinematic .hud-game,
.cinematic .serve-speed {
  opacity: 0;
  visibility: hidden;
}

.cine-tag,
.cine-hint {
  position: absolute;
  right: 18px;
  color: #fff;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.3s ease 0.2s;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
}

.cine-tag {
  top: calc(9vh + 10px);
  letter-spacing: 0.14em;
  font-size: clamp(0.8rem, 2.2vw, 1.05rem);
}

.cine-dot {
  color: #ff4040;
  animation: recBlink 1s steps(2, jump-none) infinite;
}

@keyframes recBlink {
  0% { opacity: 1; }
  100% { opacity: 0.15; }
}

.cine-hint {
  bottom: calc(9vh + 10px);
  font-weight: 700;
  font-size: clamp(0.7rem, 1.8vw, 0.85rem);
  letter-spacing: 0.08em;
  opacity: 0;
}

.cinematic .cine-tag,
.cinematic .cine-hint {
  opacity: 0.92;
}

/* IN/OUT verdict stamp: upper third, compact, thunk-in (PHASE3 §A sizing) */
.verdict-stamp {
  position: absolute;
  top: 15vh;
  left: 50%;
  padding: 0.06em 0.55em;
  border: 4px solid #fff;
  border-radius: 16px;
  color: #fff;
  font-weight: 800;
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  letter-spacing: 0.12em;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  box-shadow: var(--card-shadow);
  animation: stampThunk 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.verdict-stamp.in { background: linear-gradient(180deg, #40c057, #2b8a3e); }
.verdict-stamp.out { background: linear-gradient(180deg, #fa5252, #c92a2a); }

@keyframes stampThunk {
  0% { opacity: 0; transform: translate(-50%, 0) scale(2.4) rotate(-7deg); }
  55% { opacity: 1; transform: translate(-50%, 0) scale(0.94) rotate(2deg); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1) rotate(-2deg); }
}

/* --- overlays (pause / match end) --- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 25, 55, 0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.pause-card {
  text-align: center;
  color: #fff;
}

.pause-title {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-shadow: 4px 4px 0 rgba(20, 30, 70, 0.8);
}

.pause-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin: 18px 0 12px;
}

.pause-btn {
  width: min(70vw, 280px);
  font-size: clamp(1rem, 3.2vw, 1.3rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.45em;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.14s;
}

.pause-btn.hidden {
  display: none;
}

.pause-btn.sel {
  background: linear-gradient(180deg, var(--yellow), var(--orange));
  border-color: #fff;
  color: #4a2c00;
  text-shadow: none;
  transform: scale(1.05);
  box-shadow: var(--card-shadow);
}

.pause-hint {
  font-weight: 700;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  opacity: 0.85;
  text-shadow: 2px 2px 0 rgba(20, 30, 70, 0.7);
}

.end-card {
  background: linear-gradient(180deg, #ffffff, #e8f1ff);
  border: 4px solid var(--ink-border);
  border-radius: 24px;
  padding: clamp(20px, 5vh, 40px) clamp(28px, 7vw, 60px);
  text-align: center;
  color: var(--ink);
  box-shadow: var(--card-shadow);
  transform: scale(0.7);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.show .end-card {
  transform: scale(1);
}

.end-title {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0.04em;
}

.end-card.win .end-title { color: #2f9e44; }
.end-card.lose .end-title { color: #e8590c; }

.end-sub {
  margin-top: 2px;
  font-weight: 700;
  color: #5b6b93;
  font-size: clamp(0.9rem, 2.6vw, 1.1rem);
}

.end-score {
  margin: 10px 0 20px;
  font-weight: 700;
  font-size: clamp(1rem, 3vw, 1.3rem);
}

.end-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.again-btn,
.menu-btn {
  font-size: clamp(1rem, 3.2vw, 1.4rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.5em 1.6em;
  border-radius: 20px;
  border: 4px solid #fff;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.again-btn {
  background: linear-gradient(180deg, var(--orange), #f2622a);
  animation: bounceY 1.1s ease-in-out infinite;
}

.menu-btn {
  background: linear-gradient(180deg, #6ea8ff, #3b6fd4);
}

.again-btn:hover {
  animation-play-state: paused;
  transform: scale(1.08, 0.94);
}

.menu-btn:hover {
  transform: scale(1.08, 0.94);
}

.again-btn:active,
.menu-btn:active {
  transform: scale(0.92);
}

@keyframes bounceY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
  }
}

/* --- mini game HUD pill (DESIGN-PHASE3 G) --- */

.mg-hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.32em 1.3em;
  border-radius: 999px;
  background: rgba(25, 35, 70, 0.85);
  border: 3px solid rgba(255, 255, 255, 0.75);
  color: #fff;
  font-weight: 800;
  font-size: clamp(14px, 2.1vw, 22px);
  letter-spacing: 0.06em;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  display: none;
}

.mg-hud.show { display: block; }

/* --- serve meter (two-press serve, DESIGN-PHASE3 B) --- */

.serve-meter {
  position: absolute;
  right: clamp(12px, 4vw, 48px);
  bottom: 22vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.12s ease-out, transform 0.12s ease-out;
}

.serve-meter.show {
  opacity: 1;
  transform: none;
}

.sm-track {
  position: relative;
  width: 18px;
  height: clamp(120px, 24vh, 190px);
  border: 3px solid #fff;
  border-radius: 999px;
  background: rgba(10, 25, 60, 0.5);
  box-shadow: 0 3px 0 rgba(20, 40, 80, 0.3);
  overflow: hidden;
}

.sm-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 80%;
  top: 0;
  background: linear-gradient(180deg, rgba(123, 216, 90, 0.9), rgba(123, 216, 90, 0.4));
}

.sm-marker {
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: 0;
  height: 8px;
  margin-bottom: -4px;
  border-radius: 4px;
  background: var(--yellow, #ffd23f);
  box-shadow: 0 0 6px rgba(255, 210, 63, 0.9);
}

.serve-meter.sweet .sm-marker {
  background: #fff;
  box-shadow: 0 0 10px #7bd85a;
}

.sm-label {
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(30, 45, 90, 0.55);
}

/* --- serve speed popup (small, near the scoreboard) --- */

.serve-speed {
  position: absolute;
  top: 12px;
  left: calc(24px + clamp(120px, 16vw, 170px));
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--ink-border, #2a3a5e);
  color: #ff6b35;
  font-weight: 800;
  font-size: clamp(0.8rem, 2vw, 1rem);
  opacity: 0;
  pointer-events: none;
}

.serve-speed.flash {
  animation: speedPop 1.4s ease-out forwards;
}

@keyframes speedPop {
  0% { opacity: 0; transform: translateY(6px) scale(0.7); }
  12% { opacity: 1; transform: translateY(0) scale(1.12); }
  22% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-4px); }
}

/* --- scoreboard flash on score change --- */

.score-points.flash {
  animation: pointsFlash 0.6s ease-out;
}

@keyframes pointsFlash {
  0% { transform: scale(1.35); color: #fff; text-shadow: 0 0 10px #ffd23f; }
  100% { transform: scale(1); }
}

.score-card.flash {
  animation: cardFlash 0.7s ease-out;
}

@keyframes cardFlash {
  0%, 30% { box-shadow: 0 0 0 4px #ffd23f, var(--card-shadow, 0 4px 0 rgba(0,0,0,0.2)); }
  100% { box-shadow: var(--card-shadow, 0 4px 0 rgba(0,0,0,0.2)); }
}

/* --- gamepad focus ring (DESIGN-PHASE2 §2) --- */

.gp-focus {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
  box-shadow: 0 0 14px rgba(255, 210, 63, 0.9);
}

/* --- touch controls (DESIGN-PHASE2 §3) --- */

.touch-stick {
  position: absolute;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  background: rgba(20, 35, 70, 0.28);
  display: none;
  pointer-events: none;
}

.touch-mode .touch-stick.on {
  display: block;
}

.ts-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.touch-pause {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 3px solid #fff;
  background: rgba(25, 35, 70, 0.65);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 800;
  pointer-events: auto;
  cursor: pointer;
}

.touch-mode .touch-pause {
  display: block;
}

.touch-power {
  display: none;
  position: absolute;
  right: clamp(16px, 5vw, 40px);
  bottom: clamp(80px, 16vh, 130px);
  width: clamp(76px, 20vw, 100px);
  height: clamp(76px, 20vw, 100px);
  border-radius: 50%;
  border: 4px solid #fff;
  background: radial-gradient(circle at 35% 30%, var(--yellow), var(--orange) 70%, #ff5b5b);
  color: #4a2c00;
  font-weight: 800;
  font-size: clamp(1rem, 3.4vw, 1.3rem);
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4);
  pointer-events: auto;
  cursor: pointer;
  animation: glowPulse 0.9s ease-in-out infinite;
}

.touch-mode .touch-power.show {
  display: block;
}

.touch-power:active {
  transform: scale(0.9);
}
