:root {
  --bg-base: #090d16;
  --team-a-bg: #0c357a;
  --team-a-bg-dark: #072252;
  --team-a-accent: #60a5fa;
  --team-b-bg: #9a3412;
  --team-b-bg-dark: #6c220a;
  --team-b-accent: #fb923c;
  --ball-lime: #bef264;
  --ball-lime-text: #1a2e05;
  --surface-glass: rgb(10 15 28 / 0.84);
  --surface-border: rgb(255 255 255 / 0.16);
  --text-primary: #ffffff;
  --text-muted: rgb(255 255 255 / 0.78);
  --target-size: 24px;
  --radius-pill: 999px;
  --radius-card: 1.25rem;
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-block-size: 100dvh;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow-wrap: break-word;
}

button,
input {
  font: inherit;
  color: inherit;
}

:where(button, input:not([type="checkbox"], [type="radio"])) {
  min-block-size: var(--target-size);
  min-inline-size: var(--target-size);
}

h1,
h2 {
  text-wrap: balance;
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* App Shell & Split Court */
.app-shell {
  position: relative;
  min-block-size: 100dvh;
  display: grid;
}

.court {
  display: grid;
  min-block-size: 100dvh;
  inline-size: 100%;
  gap: 3px;
  background-color: #020617;
}

/* Landscape: Side-by-Side (Left / Right) */
@media (orientation: landscape) {
  .court {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
  }
}

/* Portrait: Stacked (Top / Bottom) */
@media (orientation: portrait) {
  .court {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

/* Touch Score Zones */
.team-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  border: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter 120ms ease, transform 90ms ease;
  padding-inline: max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
}

.team-zone.team-a {
  background: radial-gradient(circle at 50% 45%, var(--team-a-bg) 0%, var(--team-a-bg-dark) 100%);
}

.team-zone.team-b {
  background: radial-gradient(circle at 50% 45%, var(--team-b-bg) 0%, var(--team-b-bg-dark) 100%);
}

@media (orientation: landscape) {
  .team-zone {
    padding-block-start: calc(3.75rem + env(safe-area-inset-top, 0px));
    padding-block-end: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (orientation: portrait) {
  .team-zone.team-a {
    padding-block-start: calc(3.6rem + env(safe-area-inset-top, 0px));
    padding-block-end: 2.85rem;
  }

  .team-zone.team-b {
    padding-block-start: 2.85rem;
    padding-block-end: calc(4.6rem + env(safe-area-inset-bottom, 0px));
  }
}

.team-zone:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: -5px;
}

.team-zone:active,
.team-zone.is-tapped {
  filter: brightness(1.22);
}

.team-zone.is-serving {
  box-shadow: inset 0 0 0 3px rgb(190 242 100 / 0.45);
}

.zone-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  max-inline-size: 100%;
}

.team-name {
  font-size: clamp(1rem, 0.75rem + 1.1dvw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-primary);
  text-shadow: 0 2px 8px rgb(0 0 0 / 0.45);
  max-inline-size: 100%;
  overflow-wrap: break-word;
}

.serve-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  background-color: var(--ball-lime);
  color: var(--ball-lime-text);
  font-size: clamp(0.7rem, 0.65rem + 0.35dvw, 0.9rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.35);
}

.serve-badge[hidden] {
  display: none;
}

.ball-dot {
  inline-size: 0.55rem;
  block-size: 0.55rem;
  border-radius: 50%;
  background-color: #365314;
}

.points-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-block-size: 0;
}

.points-value {
  font-size: clamp(4.5rem, 11dvh + 5dvw, 11.25rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 24px rgb(0 0 0 / 0.45);
}

.zone-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 2dvw, 1.5rem);
}

.counter-box {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  border-radius: 0.75rem;
  background-color: rgb(0 0 0 / 0.32);
  border: 1px solid rgb(255 255 255 / 0.14);
}

.counter-label {
  font-size: clamp(0.7rem, 0.6rem + 0.3dvw, 0.85rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.counter-value {
  font-size: clamp(1.25rem, 1rem + 1.2dvw, 2.25rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Top Floating Bar */
.top-bar {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-block-start: max(0.5rem, env(safe-area-inset-top, 0px));
  padding-inline-start: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-inline-end: max(0.75rem, env(safe-area-inset-right, 0px));
  pointer-events: none;
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  pointer-events: auto;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  background-color: var(--surface-glass);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(10px);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.wake-dot {
  inline-size: 0.5rem;
  block-size: 0.5rem;
  border-radius: 50%;
  background-color: #94a3b8;
}

.wake-pill[data-status="active"] .wake-dot {
  background-color: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.wake-pill[data-status="unsupported"] {
  display: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  border-radius: var(--radius-pill);
  background-color: var(--surface-glass);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(10px);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 120ms ease;
}

.icon-btn:hover {
  background-color: rgb(30 41 59 / 0.92);
}

/* Center Seam Scoreboard */
.center-scoreboard {
  position: fixed;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  pointer-events: none;
}

.situation-badge {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  background-color: #facc15;
  color: #1c1917;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.45);
}

.situation-badge[hidden] {
  display: none;
}

.scoreboard-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 1rem;
  border-radius: 1rem;
  background-color: rgb(9 13 22 / 0.92);
  border: 1.5px solid rgb(255 255 255 / 0.22);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.55);
  backdrop-filter: blur(12px);
}

.sets-history {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.sets-history[hidden] {
  display: none;
}

.set-chip {
  padding: 0.1rem 0.4rem;
  border-radius: 0.4rem;
  background-color: rgb(255 255 255 / 0.1);
}

.current-games-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: clamp(1.25rem, 1rem + 0.8dvw, 1.75rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.team-a-text {
  color: #93c5fd;
}

.team-b-text {
  color: #fdba74;
}

.hud-game-sep {
  color: rgb(255 255 255 / 0.45);
}

/* Bottom Floating Action Dock */
.action-dock {
  position: fixed;
  inset-block-end: 0;
  inset-inline: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding-block-end: max(0.6rem, env(safe-area-inset-bottom, 0px));
  padding-inline: max(0.75rem, env(safe-area-inset-left, 0px));
  gap: 0.45rem;
  pointer-events: none;
}

.dock-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-pill);
  background-color: var(--surface-glass);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(12px);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.4);
  transition: transform 90ms ease, background-color 120ms ease, opacity 120ms ease;
}

.dock-btn:hover:not(:disabled) {
  background-color: rgb(30 41 59 / 0.94);
}

.dock-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.dock-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

@media (max-width: 390px) {
  .dock-btn {
    padding: 0.5rem 0.7rem;
    font-size: 0.78rem;
  }
}

/* Match Winner Overlay */
.winner-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background-color: rgb(2 6 23 / 0.72);
  backdrop-filter: blur(6px);
}

.winner-overlay[hidden] {
  display: none;
}

.winner-card {
  width: min(100%, 24rem);
  padding: 1.5rem;
  border-radius: var(--radius-card);
  background-color: #0f172a;
  border: 1px solid rgb(255 255 255 / 0.2);
  text-align: center;
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.65);
}

.winner-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--ball-lime);
}

.winner-title {
  font-size: clamp(1.5rem, 1.2rem + 1.2dvw, 2.25rem);
  font-weight: 900;
  margin-bottom: 0.5rem;
}

.winner-summary {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.winner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

/* Native Modal Dialog */
dialog {
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: var(--radius-card);
  background-color: #0f172a;
  color: var(--text-primary);
  padding: 0;
  width: min(calc(100vw - 2rem), 28rem);
  max-block-size: calc(100dvh - 2rem);
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.75);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background-color: rgb(2 6 23 / 0.72);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dialog-header h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

.dialog-close {
  background-color: rgb(255 255 255 / 0.08);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label,
.fieldset legend {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.field input[type="text"] {
  padding: 0.55rem 0.75rem;
  border-radius: 0.65rem;
  border: 1px solid rgb(255 255 255 / 0.2);
  background-color: #1e293b;
  color: var(--text-primary);
}

.fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
}

.segmented-3 {
  grid-template-columns: repeat(3, 1fr);
}

.seg-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--target-size);
  padding: 0.45rem 0.5rem;
  border-radius: 0.65rem;
  background-color: #1e293b;
  border: 1px solid rgb(255 255 255 / 0.14);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.seg-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-option:has(input:checked) {
  background-color: #2563eb;
  border-color: #60a5fa;
  color: #ffffff;
}

.seg-option:has(input:focus-visible) {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.btn {
  padding: 0.65rem 1.1rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary {
  background-color: #2563eb;
  color: #ffffff;
}

.btn-primary:hover {
  background-color: #1d4ed8;
}

.btn-secondary {
  background-color: #334155;
  color: #ffffff;
}

.btn-danger {
  background-color: rgb(220 38 38 / 0.2);
  border-color: rgb(248 113 113 / 0.45);
  color: #fecaca;
}

.btn-danger:hover {
  background-color: rgb(220 38 38 / 0.35);
}
