* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #fff;
  color: #111;
  font-family: 'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.room-badge {
  position: fixed;
  left: 10px;
  bottom: 6px;
  font-size: 0.7rem;
  color: #bbb;
  z-index: 5;
  pointer-events: none;
  display: none;
}
.room-badge.visible { display: block; }

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px 24px;
  gap: 12px;
}
.screen.active { display: flex; }

h1 { font-size: 2rem; font-weight: 800; }
h2 { font-size: 1.4rem; font-weight: 700; }
.sub { color: #888; font-size: 0.9rem; }

.best-of-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}
.best-of-picker select {
  padding: 6px 10px;
  border: 1px solid #444;
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: #111;
}

.btn {
  width: 100%;
  max-width: 300px;
  padding: 16px;
  border: none;
  border-radius: 4px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.1s;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-ghost { background: #fff; color: #222; border: 2px solid #222; }

/* join */
#code-input {
  width: 100%;
  max-width: 300px;
  padding: 18px;
  border: 2px solid #222;
  border-radius: 4px;
  background: #fff;
  color: #111;
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
  outline: none;
  margin-bottom: 4px;
}
#code-input:focus { border-color: #2563eb; }

/* lobby */
.room-code {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: 10px;
  color: #2563eb;
  cursor: pointer;
}
.share-link {
  background: #fff;
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 0.8rem;
  color: #888;
  word-break: break-all;
  text-align: center;
  max-width: 320px;
  cursor: pointer;
  border: 1px solid #222;
}
.share-link:active { background: #f5f5f5; }
.copy-hint {
  font-size: 0.8rem;
  color: #2563eb;
  height: 18px;
  opacity: 0;
  transition: opacity 0.3s;
}
.copy-hint.visible { opacity: 1; }

/* game */
#game {
  display: none;
  flex-direction: column;
  height: 100%;
}
#game.active { display: flex; }

.scoreboard {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px 16px 16px;
  gap: 12px;
  flex-shrink: 0;
}
.score-col {
  flex: 1;
  text-align: center;
  border: 2px solid #222;
  border-radius: 4px;
  padding: 10px 0;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
#serve-me.serving { background: #2563eb; border-color: #2563eb; }
#serve-opp.serving { background: #dc2626; border-color: #dc2626; }
/* serving column is filled with the player color, so invert the text to read on it */
.score-col.serving .score-label,
.score-col.serving .score-num { color: #fff; }
/* white circles showing how many serves the server has left: a vertical
   column pinned to each player's outer edge (left player left, right player right) */
.serve-dots {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#dots-me { left: 14px; }
#dots-opp { right: 14px; }
.serve-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #d38b8b;
  margin-bottom: 4px;
}
.score-label.mine { color: #2563eb; }
.score-num {
  font-size: 6rem;
  font-weight: 900;
  line-height: 1;
  color: #dc2626;
}
.score-num.mine { color: #2563eb; }
/* game/match ball callout, centered in the tap zone above the tap label */
.ball-indicator {
  display: none;
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  line-height: 1.1;
}
.ball-indicator.show { display: block; animation: ball-pulse 1.1s ease-in-out infinite; }
.ball-indicator .ball-who {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.85;
}
.ball-indicator .ball-what {
  font-size: 2.4rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.ball-indicator.mine { color: #2563eb; }
.ball-indicator.opp { color: #dc2626; }
@keyframes ball-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Hype line: sits just below the game/match ball indicator. The two are
   mutually exclusive today (level score vs. someone holding a lead). */
.hype {
  --hype-a: #2563eb;
  --hype-b: #7dd3fc;
  display: none;
  position: absolute;
  top: 36%;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  line-height: 1;
}
/* Deuce runs hot — it's the bigger moment of the two. */
.hype.hot {
  --hype-a: #dc2626;
  --hype-b: #fbbf24;
}
.hype.show {
  display: block;
  animation: hype-breathe 1.7s ease-in-out infinite;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.12));
}
.hype-text {
  display: inline-block;
  font-size: 2.6rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 5px;
  /* A highlight band sweeps across the letters forever — the text itself is
     transparent and the gradient shows through it. */
  background-image: linear-gradient(100deg,
    var(--hype-a) 0%, var(--hype-a) 32%, var(--hype-b) 50%,
    var(--hype-a) 68%, var(--hype-a) 100%);
  background-size: 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: hype-in 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both,
             hype-shimmer 2.4s linear infinite;
}
@keyframes hype-in {
  0% { transform: scale(0.6) rotate(-4deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes hype-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes hype-shimmer {
  0% { background-position: 160% 0; }
  100% { background-position: -60% 0; }
}
}
.score-num.bump { animation: bump 0.28s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.score-sep {
  align-self: center;
  font-size: 3rem;
  font-weight: 900;
  color: #222;
}

.set-tally {
  text-align: center;
  font-size: 0.75rem;
  color: #888;
  padding-bottom: 8px;
  flex-shrink: 0;
}


.tap-zone {
  flex: 1;
  margin: 0 16px;
  border: 2px solid #222;
  border-radius: 4px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.tap-zone:active { background: #fafafa; }
.tap-label {
  font-size: 0.85rem;
  color: #ccc;
  text-transform: uppercase;
  letter-spacing: 3px;
  pointer-events: none;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.12);
  transform: scale(0);
  animation: ripple 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple {
  to { transform: scale(6); opacity: 0; }
}

.controls {
  display: flex;
  gap: 16px;
  padding: 14px 16px;
  flex-shrink: 0;
}
.ctrl-btn {
  flex: 1;
  padding: 14px;
  background: #fff;
  border: 2px solid #222;
  border-radius: 4px;
  color: #222;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.ctrl-btn:active { background: #fafafa; color: #333; }

.status-bar {
  text-align: center;
  font-size: 0.72rem;
  color: #ccc;
  padding: 0 16px 14px;
  flex-shrink: 0;
}

/* winner */
.winner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 10;
  border-top: 2px solid #222;
}
.winner-title { font-size: 1.8rem; font-weight: 800; color: #111; }
.winner-score { font-size: 5rem; font-weight: 900; color: #2563eb; line-height: 1; }

/* debug */
.debug-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.8);
  color: #0f0;
  font-family: monospace;
  font-size: 0.65rem;
  padding: 3px 8px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* name input */
.name-input {
  width: 100%;
  max-width: 300px;
  padding: 14px 16px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #fff;
  color: #111;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  margin-bottom: 4px;
}
.name-input:focus { border-color: #2563eb; }
.name-input.input-error { border-color: #dc2626; }

/* history */
.history-panel {
  position: fixed;
  inset: 0;
  background: #fff;
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 20px 16px;
  z-index: 10;
  border-top: 2px solid #222;
}
.history-panel.open { display: flex; }
.history-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.history-title { font-weight: 700; font-size: 1.5rem; }
.history-back {
  position: absolute;
  left: 0;
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: #222;
  cursor: pointer;
  padding: 6px 10px;
}
.history-back svg {
  width: 26px;
  height: 26px;
}
.history-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.history-table th, .history-table td {
  padding: 10px 6px;
  border-bottom: 1px solid #e5e5e5;
}
.history-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  font-weight: 600;
  text-align: center;
}
.history-table th:first-child { text-align: left; }
.history-table td.date {
  color: #aaa;
  font-size: 0.75rem;
  white-space: nowrap;
}
.history-table td.score {
  text-align: center;
  color: #888;
}
.history-table td.score.win {
  font-weight: 700;
  color: #111;
}
.match-detail {
  font-size: 0.68rem;
  color: #ccc;
  white-space: nowrap;
}

/* leaderboard screen: table sits at the top at its natural height, the
   head-to-head section fills the rest (its own list scrolls) */
#leaderboard { justify-content: flex-start; }
#leaderboard-content { flex: 0 0 auto; overflow: visible; }

/* head-to-head picker on the leaderboard screen */
.h2h {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 18px;
  border-top: 1px solid #e5e5e5;
  padding-top: 14px;
}
.h2h h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  font-weight: 600;
  margin-bottom: 10px;
}
.h2h-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.h2h-picker select {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  font-size: 0.9rem;
  border: 2px solid #222;
  border-radius: 4px;
  background: #fff;
}
.h2h-vs {
  color: #888;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.h2h-summary {
  text-align: center;
  font-size: 0.9rem;
  color: #111;
  margin-bottom: 10px;
}
.h2h-summary b { font-weight: 700; }
