:root {
  --bv-primary: #e76f51;
  --bv-primary-dark: #c45a3f;
  --bv-secondary: #2a9d8f;
  --bv-accent: #e9c46a;
  --bv-bg-dark: #264653;
  --bv-bg-light: #f8f9fa;
  --bv-score-left: #2a9d8f;
  --bv-score-right: #e76f51;
  --bv-sand: #f4a261;
  --bv-deuce: #e9c46a;
}

* {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

html, body {
  overscroll-behavior: none;
  min-height: 100dvh;
}

body {
  padding-top: env(safe-area-inset-top);
}

.view-section {
  display: none;
}
.view-section.active {
  display: block;
}

/* ── Navbar ── */
.navbar {
  padding-top: calc(0.5rem + env(safe-area-inset-top));
}
.navbar .btn {
  touch-action: manipulation;
}

/* ── Home Screen ── */
.home-hero {
  min-height: calc(100dvh - 56px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 1rem;
}
.home-hero .btn {
  min-height: 56px;
  font-size: 1.1rem;
  touch-action: manipulation;
}
.home-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 0.5rem;
}

/* ── Match Setup ── */
.match-setup {
  max-width: 540px;
  margin: 0 auto;
  padding: 1rem;
}
.match-setup input {
  font-size: 16px;
}

/* ── Fullscreen Scoring View ── */
.scoring-view {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  touch-action: manipulation;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.scoring-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem max(0.75rem, env(safe-area-inset-right)) 0.35rem max(0.75rem, env(safe-area-inset-left));
  font-size: 0.9rem;
  flex-shrink: 0;
}
.scoring-header-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.scoring-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.scoring-set-history-pill {
  --scoring-controls-radius: 9999px;
  position: absolute;
  top: max(12px, calc(env(safe-area-inset-top) * 0.25 + 8px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: calc(100% - 2rem);
  padding: 0.4rem 1rem;
  border-radius: var(--scoring-controls-radius);
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  pointer-events: none;
}
.scoring-set-history-pill:has(.scoring-set-history:empty) {
  display: none;
}
.scoring-set-history {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.scoring-header-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.scoring-main {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.score-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s;
  touch-action: manipulation;
  gap: 0.25rem;
}
.score-side:active {
  filter: brightness(0.85);
  transform: scale(0.98);
}
.score-side.side-left {
  background: var(--bv-score-left);
  color: #fff;
}
.score-side.side-right {
  background: var(--bv-score-right);
  color: #fff;
}
.score-side.serving {
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}
.score-side.score-flash {
  animation: scoreFlash 0.22s ease-out;
}

@keyframes scoreFlash {
  0% { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

.score-player-name {
  font-size: clamp(0.9rem, 3vw, 1.4rem);
  font-weight: 600;
  opacity: 0.9;
  text-align: center;
  padding: 0 0.5rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-player-name .server-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bv-deuce);
  margin-right: 6px;
  vertical-align: middle;
  animation: serverPulse 1s ease-in-out infinite;
}
.score-player-name .server-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.95;
  margin-right: 4px;
  vertical-align: middle;
}

@keyframes serverPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.score-number {
  font-size: clamp(4rem, 22vw, 14rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-sets {
  display: flex;
  gap: 6px;
  padding: 0.25rem 0;
}
.set-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
}
.set-dot.won {
  background: #fff;
  border-color: #fff;
}

.score-divider {
  width: 3px;
  background: rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.scoring-controls-overlay {
  --scoring-controls-radius: 9999px;
  position: absolute;
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  gap: 0.375rem;
  align-items: center;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.375rem max(0.375rem, env(safe-area-inset-right)) 0.375rem max(0.375rem, env(safe-area-inset-left));
  border-radius: var(--scoring-controls-radius);
  max-width: calc(100% - 1.5rem);
}
.scoring-controls-overlay .btn {
  min-height: 48px;
  min-width: 48px;
  border-radius: var(--scoring-controls-radius);
  touch-action: manipulation;
}
.scoring-controls-overlay .btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.match-point-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bv-deuce);
  color: #000;
}

.switch-sides-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bv-sand);
  color: #000;
}

/* ── Match Complete Overlay ── */
.match-complete-overlay {
  position: fixed;
  inset: 0;
  z-index: 1060;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
  padding: 1rem;
}
.match-complete-card {
  max-width: 400px;
  width: 100%;
  text-align: center;
}

/* ── Tournament Bracket ── */
.bracket-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
}
.bracket-grid {
  display: grid;
  gap: 0;
  min-width: max-content;
}
.bracket-match {
  padding: 4px;
}
.bracket-match .card {
  font-size: 0.85rem;
}
.bracket-match .card-body {
  padding: 0.4rem 0.6rem;
}
.bracket-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
}
.bracket-player.winner {
  font-weight: 700;
}
.bracket-player.loser {
  opacity: 0.5;
}

/* ── Round Robin Table ── */
.rr-table th, .rr-table td {
  text-align: center;
  vertical-align: middle;
  min-width: 40px;
}
.rr-table .rr-self {
  background: var(--bs-secondary-bg);
}

/* ── History ── */
.history-list .list-group-item {
  touch-action: manipulation;
}

/* ── Responsive ── */
@media (max-width: 576px) {
  .scoring-header { font-size: 0.8rem; }
  .score-player-name { font-size: clamp(0.85rem, 2.8vw, 1.1rem); }
}

@media (orientation: landscape) {
  .score-number {
    font-size: clamp(5rem, 32vh, 18rem);
  }
  .score-player-name {
    font-size: clamp(1rem, 4vh, 1.75rem);
  }
  .set-dot {
    width: 18px;
    height: 18px;
  }
  .scoring-header {
    font-size: 1rem;
  }
  .scoring-set-history-pill .scoring-set-history {
    font-size: 0.95rem;
  }
}

@media (orientation: portrait) and (max-height: 700px) {
  .score-number {
    font-size: clamp(3.5rem, 18vw, 10rem);
  }
  .scoring-header-main {
    gap: 0.1rem;
  }
}

@media (min-width: 768px) {
  .home-hero { gap: 1.5rem; }
  .home-hero .btn { min-height: 64px; font-size: 1.25rem; }
}

/* ── Resume Banner ── */
.resume-banner {
  touch-action: manipulation;
  cursor: pointer;
}

/* ── Utilities ── */
.gap-safe-bottom {
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
}
