:root {
  --navy: #0b1d33;
  --ball: #dff23a;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --text: #f5f8fb;
  --muted: #a9bdd0;
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, #16365a, var(--navy) 70%);
  color: var(--text);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  cursor: pointer;
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.screen.show {
  display: flex;
}

#connect {
  justify-content: center;
  text-align: center;
}

.logo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f4ff8a, var(--ball) 45%, #a9bd12);
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(223, 242, 58, 0.35);
}
.logo::before,
.logo::after {
  content: '';
  position: absolute;
  width: 84px;
  height: 84px;
  border: 4px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}
.logo::before {
  left: -58px;
}
.logo::after {
  right: -58px;
}

h1 {
  margin: 4px 0 0;
  font-size: 32px;
}
.muted {
  color: var(--muted);
  margin: 0;
}
.small {
  font-size: 13px;
  line-height: 1.5;
}
.mono {
  font-family: ui-monospace, Menlo, monospace;
}

#room {
  width: 220px;
  text-align: center;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.3em;
  padding: 12px 0 12px 0.3em;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ball);
  text-transform: uppercase;
  user-select: text;
}
#room:focus {
  outline: none;
  border-color: var(--ball);
}

.seg {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 4px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
}
.seg button.on {
  background: var(--ball);
  color: var(--navy);
}

button.primary {
  background: var(--ball);
  color: var(--navy);
  border: 0;
  border-radius: 18px;
  padding: 18px 28px;
  font-size: 22px;
  font-weight: 800;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 28px rgba(223, 242, 58, 0.3);
}
button.primary:active {
  transform: scale(0.98);
}

.err {
  color: #ffb3b3;
  min-height: 1.2em;
  margin: 0;
  font-weight: 600;
}

/* ---------- Play screen ---------- */
.top {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.pill {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
}
.pill.ok {
  border-color: var(--good);
  color: var(--good);
}
.pill.bad {
  border-color: var(--bad);
  color: #ffb3b3;
}

.message {
  min-height: 56px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transition: 0.2s;
}
.message.show {
  opacity: 1;
}
.message.good {
  color: var(--ball);
}

.meter-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}
.ring {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  position: relative;
}
.ring.pulse {
  animation: pulse 0.45s ease-out;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(223, 242, 58, 0.8);
    border-color: var(--ball);
  }
  100% {
    box-shadow: 0 0 0 40px rgba(223, 242, 58, 0);
  }
}
.racket-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.05s linear;
}
.racket-icon .head {
  width: 64px;
  height: 84px;
  border-radius: 50%;
  border: 6px solid var(--paint, #d62839);
  box-shadow: 0 0 0 2px var(--side, #1b1b1f), inset 0 0 0 1px var(--stripe, #fff);
  background: repeating-linear-gradient(0deg, transparent 0 7px, rgba(255, 255, 255, 0.5) 7px 8px),
    repeating-linear-gradient(90deg, transparent 0 7px, rgba(255, 255, 255, 0.5) 7px 8px);
}
.racket-icon .handle {
  width: 12px;
  height: 58px;
  background: repeating-linear-gradient(-30deg, var(--side, #222) 0 6px, rgba(255, 255, 255, 0.15) 6px 8px);
  border-top: 4px solid var(--stripe, #fff);
  border-radius: 4px;
  margin-top: -2px;
}
.meter {
  position: relative;
  width: min(320px, 100%);
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
#meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7fd1ff, var(--ball));
  border-radius: 999px;
}
#meter-th {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  opacity: 0.6;
}
.swing-label {
  font-weight: 800;
  font-size: 20px;
  color: var(--ball);
  opacity: 0;
  transition: opacity 0.15s;
  min-height: 1.2em;
}
.swing-label.show {
  opacity: 1;
}

.hint {
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
  max-width: 360px;
  margin: 0;
  min-height: 3em;
}

.actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}
#tap {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 700;
  width: 100%;
  max-width: 360px;
}

.settings {
  width: 100%;
  max-width: 360px;
  color: var(--muted);
}
.settings summary {
  cursor: pointer;
  font-weight: 700;
  text-align: center;
  padding: 6px;
}
.settings .row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  align-items: center;
}

/* ---------- 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);
}
