@font-face {
  font-family: Manrope;
  src: url("./fonts/manrope.ttf") format("truetype");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: Manrope, system-ui, sans-serif;
  background: #fff;
  color: #263144;
  --line: #e9edf2;
  --muted: #5c6879;
  --blue: #365b94;
  --orange: #9a523c;
  --focus: #365b94;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
main {
  max-width: 47rem;
  margin: auto;
  padding: max(1.5rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(2rem, 8vw, 3.25rem); line-height: 1; letter-spacing: -.055em; }
h2 { font-size: 1rem; }
.top, .match-bar, .summary-head, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-icon {
  width: clamp(2rem, 9vw, 3rem);
  flex: none;
  color: var(--blue);
}
.eyebrow, .match-bar {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .07em;
  color: var(--muted);
  text-transform: uppercase;
}
.eyebrow { margin-bottom: .3rem; }
.match-bar { margin: 1.6rem 0 .65rem; }
.top[hidden] ~ #live-match .match-bar { margin-top: 0; }
#game-label { color: #263144; }
button, input { font: inherit; }
button {
  min-height: 44px;
  padding: .6rem .85rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #e7effb;
  color: #294d80;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.secondary {
  background: #f4f6f9;
  color: inherit;
}
.secondary:hover:not(:disabled) { background: #eaf0f6; }
#new-match, #undo {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
}
#new-match { flex: none; }
.actions button { padding-inline: .6rem; }
button svg {
  width: 1rem;
  height: 1rem;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
button:disabled { cursor: default; }
.secondary:disabled { color: #68758a; background: #f7f8fb; }
.court {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(.5rem, 2vw, .9rem);
}
.player {
  --ink: var(--blue);
  --paper: #f0f5fc;
  --edge: #e2ebf8;
  --pressed: #e2ebfa;
  --serving-paper: #d1dff4;
  --serving-pressed: #bed1ee;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: .35rem;
  align-items: center;
  justify-items: center;
  min-height: clamp(14rem, 44svh, 23rem);
  min-width: 0;
  padding: 1rem .5rem;
  border: 1px solid var(--edge);
  border-radius: 1.5rem;
  background: var(--paper);
  color: var(--ink);
}
.player[data-player="1"] {
  --ink: var(--orange);
  --paper: #fcf1ec;
  --edge: #f5e5dd;
  --pressed: #fae5db;
  --serving-paper: #f1d5c6;
  --serving-pressed: #e9c2af;
}
.player:active:not(:disabled) { background: var(--pressed); }
.name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  align-content: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  max-width: 100%;
  min-height: 2lh;
  font-size: clamp(.875rem, 4vw, 1.125rem);
  line-height: 1.15;
}
.serve {
  visibility: hidden;
  padding: .2rem .45rem;
  border-radius: 999px;
  background: var(--pressed);
  font-size: .7rem;
  font-weight: 750;
}
.serve.visible { visibility: visible; }
.points {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(3rem, 18vw, 8rem);
  font-weight: 750;
  line-height: .95;
  letter-spacing: -.065em;
  font-variant-numeric: tabular-nums;
}
#match-status {
  text-align: center;
  margin: .7rem 0;
  min-height: 1.4rem;
  color: var(--muted);
  font-size: .875rem;
  overflow-wrap: anywhere;
}
#keep-screen-on { display: block; margin: 0 auto .45rem; font-size: .82rem; }
.actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .25rem .6rem; }
#undo { background: transparent; color: var(--muted); }
#undo:hover:not(:disabled) { background: #f4f6f9; }
#undo:disabled { color: #8993a3; }
.between-games .player {
  grid-template-rows: auto 1fr;
  min-height: 0;
  padding: .65rem .5rem;
  border-radius: 1rem;
}
.between-games .name { min-height: 0; }
.between-games .serve { display: none; }
.between-games .points { font-size: clamp(1.7rem, 8vw, 2.7rem); }
#next-game {
  display: block;
  width: 100%;
  min-height: 3.7rem;
  margin-bottom: .45rem;
  border-radius: 1rem;
  background: #dce9fb;
  font-size: 1rem;
}
#next-game:active { background: #cfdef5; }
.pick-server { font-size: clamp(.9rem, 4vw, 1.35rem); letter-spacing: -.02em; }
.summary {
  margin-top: 1.15rem;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
}
#match-score { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.score-left { color: var(--blue); }
.score-right { color: var(--orange); }
#game-results {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: .65rem;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
#game-results th, #game-results td {
  padding: .5rem .25rem;
  text-align: center;
  overflow-wrap: anywhere;
}
#game-results th:first-child { width: 24%; text-align: left; }
#game-results tbody tr { border-top: 1px solid var(--line); }
#game-results tbody th { color: var(--muted); font-weight: 500; }
#game-results td:nth-child(2) { color: var(--blue); }
#game-results td:nth-child(3) { color: var(--orange); }
#empty { margin-top: .45rem; font-size: .85rem; color: var(--muted); }
.result {
  margin: 1.6rem 0 .75rem;
  padding: 1.5rem 1rem;
  border: 1px solid #e2ebf8;
  border-radius: 1.2rem;
  background: #f0f5fc;
  color: var(--blue);
  overflow-wrap: anywhere;
}
.result[data-winner="1"] {
  border-color: #f5e5dd;
  background: #fcf1ec;
  color: var(--orange);
}
.result .eyebrow { color: inherit; }
#winner-name { font-size: clamp(1.7rem, 7vw, 3rem); line-height: 1.1; }
#storage-error, #replace-note { color: #87341e; margin: .75rem 0; }
dialog {
  width: min(27rem, calc(100% - 1.5rem));
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
  color: inherit;
  box-shadow: 0 1rem 3rem #26314426;
}
dialog::backdrop { background: #26314466; }
form { display: grid; gap: .75rem; }
label { display: grid; gap: .25rem; }
input:not([type="radio"]) {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  background: #fff;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: .55rem .65rem;
}

#setup-title { font-size: 1.2rem; outline: none; }
#replace-note { margin: 0; font-size: .875rem; }
.setup-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .65rem;
}
.setup-players label, #settings legend {
  color: var(--muted);
  font-size: .875rem;
  font-weight: 700;
}
.setup-players input { color: #263144; font-size: 1rem; font-weight: 500; }
#settings fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
#settings legend { margin-bottom: .35rem; padding: 0; }
.choices {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: .25rem;
  padding: .25rem;
  border-radius: .9rem;
  background: #f4f6f9;
}
.choices label { position: relative; cursor: pointer; touch-action: manipulation; }
.choices input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.choices span {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: .25rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  text-align: center;
  font-size: .8rem;
  line-height: 1.2;
  font-weight: 650;
}
.choices input:checked + span {
  border-color: #cbdaf1;
  background: #e7effb;
  color: #294d80;
  font-weight: 800;
}
.choices input:focus-visible + span { outline: 2px solid var(--focus); }
#serve-help { margin-top: .35rem; color: var(--muted); font-size: .75rem; }

.history {
  margin-top: .8rem;
  padding: .15rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  font-size: .875rem;
}
.history summary {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  font-weight: 650;
}
.history summary::-webkit-details-marker { display: none; }
.history summary::before {
  content: "";
  width: .42rem;
  height: .42rem;
  margin-right: .12rem;
  flex: none;
  border: solid var(--muted);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
}
.history details[open] > summary::before,
.history[open] > summary::before { transform: rotate(45deg); }
.history summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#history-count {
  padding: .15rem .4rem;
  border-radius: 999px;
  background: #f4f6f9;
  color: var(--muted);
  font-size: .75rem;
}
#history-list { list-style: none; padding: 0; margin: 0; }
#history-list > li { border-top: 1px solid var(--line); }
.history-players { flex: 1; overflow-wrap: anywhere; }
#history-list strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
#history-empty, #history-list p { color: var(--muted); margin: .15rem 0 .75rem; overflow-wrap: anywhere; }
#history-list ol {
  list-style: none;
  padding: 0;
  margin: 0 0 .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
#history-list ol li { padding: .25rem .45rem; border-radius: .5rem; background: #f4f6f9; }

@media (max-width: 36rem) and (orientation: portrait) {
  .court:not(.between-games) {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: 1fr;
  }
  .court:not(.between-games) .player {
    min-height: clamp(9.5rem, 31svh, 19rem);
    gap: .25rem;
    padding: .6rem;
  }
  .court:not(.between-games) .name { min-height: 0; }
  .court:not(.between-games) .points:not(.pick-server) {
    font-size: clamp(5rem, min(30vw, 18svh), 10rem);
  }
}

/* Keep the score within the available screen while a game is active. */
.playing main {
  max-width: none;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(.5rem, env(safe-area-inset-top)) .5rem max(.25rem, env(safe-area-inset-bottom));
}
.playing #live-match { flex: 1; display: flex; flex-direction: column; }
.playing .match-bar { margin: 0 .25rem .4rem; flex-wrap: wrap; }
.playing .court {
  flex: 1;
  min-height: 0;
  grid-auto-rows: 1fr;
}
.playing .court .player {
  min-height: 0;
  grid-template-rows: auto auto 1fr;
  padding: .5rem;
  gap: .2rem;
}
.playing .court .name { min-height: 0; }
.playing .court .points:not(.pick-server) {
  font-size: clamp(4rem, min(35vw, 51svh), 28rem);
  line-height: .85;
}
.playing .summary { display: none; }
.playing #match-status { margin: .25rem 0; min-height: 1.2rem; font-size: .8rem; }
.serve {
  font-size: .85rem;
  padding: .3rem .8rem;
  letter-spacing: .06em;
}
.serving {
  background: var(--serving-paper);
  border: 7px solid var(--ink);
  box-shadow: inset 0 0 0 2px white;
}
.player.serving:active:not(:disabled) { background: var(--serving-pressed); }
.serving .serve { background: var(--ink); color: white; }
.danger-link { background: transparent; color: #a13f32; font-size: .8rem; }
.danger { background: #a13f32; color: white; }
#reset-dialog p { margin: .85rem 0; font-size: .9rem; }
#reset-error { color: #a13f32; }
@media (orientation: portrait) {
  .playing .court { grid-template-columns: minmax(0, 1fr); }
  .playing .court .points:not(.pick-server) {
    font-size: clamp(4rem, min(48vw, 29svh), 23rem);
  }
}

#resume-match { display: block; width: 100%; margin-top: 1.25rem; min-height: 3.5rem; }
#exit-match { background: transparent; color: var(--muted); font-size: .82rem; }

.online-bar { display: flex; align-items: center; gap: .5rem; margin: .6rem 0; }
#online-open { min-height: 36px; padding: .3rem .65rem; font-size: .75rem; flex: none; }
#online-status { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
#online-dialog > * + *, #online-share > * + *, #online-join-section > * + * { margin-top: .7rem; }
#online-dialog p { font-size: .85rem; color: var(--muted); }
#online-dialog #online-error { color: #a13f32; }
#online-qr img { display: block; width: 100%; max-width: 20rem; margin: auto; image-rendering: pixelated; }
.playing .online-bar { margin: 0 0 .3rem; }

#online-scan { width: 100%; min-height: 3rem; }
#online-video { display: block; width: 100%; max-height: 35svh; object-fit: cover; border-radius: 1rem; background: #172033; }
#online-camera > * + * { margin-top: .6rem; }
#online-scan-note:empty { display: none; }
