/* Match Point: a TV-scoreboard look. Dark court green, white lines, volt accent. */
:root {
  --ink: #08130f;
  --sheet: #0e1c17;
  --sheet-raised: #142721;
  --rule: #26403a;
  --text: #f1f5ee;
  --muted: #9db3aa;
  --volt: #d8ff3e;
  --volt-ink: #0b130d;
  --coral: #ff7a59;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  overscroll-behavior: none;
}

body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#court {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

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

/* ---------- Screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(4, 10, 8, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0s 0.25s;
}

body[data-screen="welcome"] [data-for="welcome"],
body[data-screen="home"] [data-for="home"],
body[data-screen="settings"] [data-for="settings"],
body[data-screen="paused"] [data-for="paused"],
body[data-screen="result"] [data-for="result"] {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s;
}

.sheet {
  width: min(100%, 400px);
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 24px 24px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--sheet);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(8px);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

body[data-screen="welcome"] [data-for="welcome"] .sheet,
body[data-screen="home"] [data-for="home"] .sheet,
body[data-screen="settings"] [data-for="settings"] .sheet,
body[data-screen="paused"] [data-for="paused"] .sheet,
body[data-screen="result"] [data-for="result"] .sheet { transform: none; }

.sheet.tall { max-height: min(100%, 720px); }

.wordmark {
  font-family: var(--display);
  font-style: italic;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--volt);
}

h1, h2 {
  margin-top: 6px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2.3rem;
  line-height: 1.05;
}

h2 { font-size: 2rem; margin-top: 0; }

.stack {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.how, .note {
  margin-top: 18px;
  font-size: 0.9rem;
  color: var(--muted);
}

.note { margin-top: 10px; font-size: 0.85rem; }

/* Home facts */
.facts {
  display: grid;
  margin-top: 20px;
  border-top: 1px solid var(--rule);
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--rule);
}

.facts dt { color: var(--muted); }
.facts dd { font-weight: 600; text-align: right; }

/* ---------- Controls ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 20px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--sheet-raised);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}

.button:active { transform: scale(0.98); }

.button.primary {
  border-color: var(--volt);
  background: var(--volt);
  color: var(--volt-ink);
}

.button.small {
  min-height: 44px;
  padding: 0 16px;
  font-size: 1rem;
}

.button:focus-visible,
.icon-button:focus-visible,
.stepper button:focus-visible,
.presets button:focus-visible,
.segmented input:focus-visible + span,
.switch input:focus-visible,
.field input:focus-visible {
  outline: 2px solid var(--volt);
  outline-offset: 2px;
}

.field { display: grid; gap: 8px; }
.field span, .label, legend { font-size: 0.9rem; color: var(--muted); }

.field input {
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--ink);
  font-size: 1.1rem;
}

/* ---------- Settings ---------- */

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.settings { display: grid; gap: 22px; }

.group {
  display: grid;
  gap: 10px;
  padding: 0;
  border: 0;
}

legend { margin-bottom: 10px; padding: 0; }

body[data-mode="points"] [data-mode="timer"],
body[data-mode="timer"] [data-mode="points"] { display: none; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--ink);
}

.segmented label { position: relative; }

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.segmented input:checked + span {
  background: var(--sheet-raised);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--volt);
}

.stepper {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--ink);
}

.stepper button {
  min-height: 52px;
  border: 0;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.stepper output {
  text-align: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.presets button {
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: none;
  font-weight: 600;
  cursor: pointer;
}

.presets button[aria-pressed="true"] {
  border-color: var(--volt);
  color: var(--volt);
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  cursor: pointer;
}

.switch input {
  appearance: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: var(--rule);
  cursor: pointer;
  transition: background 0.2s;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}

.switch input:checked { background: var(--volt); }
.switch input:checked::after { transform: translateX(20px); background: var(--volt-ink); }

/* ---------- In-match HUD ---------- */

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: start;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

body[data-screen="match"] .hud,
body[data-screen="paused"] .hud,
body[data-screen="result"] .hud { opacity: 1; }

.board {
  grid-column: 2;
  justify-self: center;
  display: grid;
  grid-template-columns: auto auto auto auto;
  align-items: stretch;
  overflow: hidden;
  border-radius: 8px;
  font-family: var(--display);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.board-name {
  display: grid;
  place-items: center;
  padding: 6px 12px;
  background: var(--sheet);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.board-name.you { color: var(--volt); }

.board-score {
  display: grid;
  place-items: center;
  min-width: 46px;
  padding: 4px 10px;
  background: var(--text);
  color: var(--ink);
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.board-score + .board-score { border-left: 1px solid #c9d3cc; }
.board-score.bump { animation: bump 0.4s ease-out; }

.clock {
  grid-column: 2;
  justify-self: center;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--sheet);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.clock.low { color: var(--coral); }

.icon-button {
  grid-column: 3;
  grid-row: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--sheet);
  pointer-events: auto;
  cursor: pointer;
}

.icon-button svg { width: 20px; height: 20px; fill: var(--text); }
body:not([data-screen="match"]) .icon-button { visibility: hidden; }

.callout {
  position: fixed;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(1.8rem, 9vw, 2.6rem);
  opacity: 0;
  pointer-events: none;
}

.callout.show { animation: callout 0.8s ease-out; }
.callout.accent { color: var(--volt); }

.serve-hint {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

body[data-screen="match"][data-phase="serve"] .serve-hint { opacity: 1; }

/* Result */
.final {
  margin-top: 6px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 4rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--volt);
}

@keyframes bump {
  40% { transform: scale(1.25); }
}

@keyframes callout {
  0% { opacity: 0; transform: translateY(8px); }
  20% { opacity: 1; transform: none; }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
}
