:root {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: #17251f;
  background: #f3f5f1;
  --green: #087346;
  --line: #c8d5ce;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button {
  min-height: 44px;
  padding: .6rem 1rem;
  border: 1px solid transparent;
  border-radius: .55rem;
  cursor: pointer;
  font-weight: 650;
}
button:hover { filter: brightness(.93); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #158858;
  outline-offset: 3px;
}
button[aria-disabled="true"] { opacity: .55; cursor: default; }
.outline { color: var(--green); background: #fff; border-color: var(--line); }
.accent { color: #fff; background: var(--green); }
.shell { width: min(75rem, 100%); margin: auto; padding: clamp(1rem, 4vw, 3rem); }
.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .65rem; }
h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.match-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  margin: 1.25rem 0 .85rem;
}
#format { margin: 0; color: #38574a; font-weight: 700; text-align: center; }
.voice-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  padding: 0;
  color: var(--green);
  background: #e3f4e9;
  border-color: #aacabb;
}
.voice-toggle[aria-pressed="false"] { color: #53655d; background: #fff; border-color: var(--line); }
.voice-toggle[aria-pressed="true"] .sound-off,
.voice-toggle[aria-pressed="false"] .sound-wave { display: none; }
.voice-toggle:disabled { opacity: .55; cursor: default; }
.board { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: clamp(.5rem, 2vw, 1.5rem); }
.player {
  min-width: 0;
  padding: clamp(.65rem, 2.3vw, 1.6rem);
  border: 2px solid transparent;
  border-radius: 1rem;
  color: #f5fbf7;
  background: #182520;
  box-shadow: 0 8px 18px #16291e20;
}
.player.winning { border-color: #eac55b; }
.player-heading { display: flex; align-items: center; justify-content: center; gap: .2rem .5rem; }
.first-serve {
  border-color: #739286;
  padding: .25rem .55rem;
  color: #f5fbf7;
  background: transparent;
  font-size: .8rem;
  white-space: nowrap;
}
.first-serve[aria-pressed="true"] { border-color: #8aebba; color: #8aebba; }
.first-serve:focus-visible { outline-color: #8aebba; }
.player h2 { display: flex; align-items: center; justify-content: center; gap: .35rem; min-width: 0; margin: 0; color: #8aebba; font-size: clamp(1rem, 2.3vw, 1.4rem); line-height: 1.25; }
.player-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.serve-badge { white-space: nowrap; border-radius: .35rem; padding: .12rem .35rem; color: #10251b; background: #8aebba; font-size: .75rem; vertical-align: middle; }
.handicap-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: .25rem .4rem;
  padding: .4rem;
  background: #23362e;
  border: 1px solid #3f594d;
  border-radius: .65rem;
}
.handicap-label { color: #d3e0d8; font-size: .75rem; }
.handicap-editor input {
  min-width: 0;
  padding: .35rem .25rem;
  text-align: center;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.handicap-editor button {
  padding-inline: .45rem;
  color: #e6f8ee;
  background: #395649;
  font-size: .8rem;
}
.handicap-editor .handicap-clear { background: transparent; border-color: #739286; }
.handicap-editor :focus-visible { outline-color: #8aebba; }
.handicap-status {
  grid-column: 1 / -1;
  margin: 0;
  color: #b8d4c5;
  font-size: .7rem;
  text-align: center;
}
.numbers { display: grid; grid-template-columns: 3fr 2fr; align-items: start; gap: .3rem; margin-block: 1.2rem; text-align: center; }
.player:last-child .numbers { grid-template-columns: 2fr 3fr; }
.numbers > div { min-width: 0; }
.numbers span { display: block; color: #d3e0d8; font-weight: 650; }
output { display: block; font-family: system-ui, sans-serif; font-variant-numeric: tabular-nums; font-weight: 800; line-height: 1.12; }
.points { font-size: clamp(2rem, 8vw, 7.5rem); }
.sets { color: #ffdc6b; font-size: clamp(1.5rem, 5vw, 4.8rem); }
.actions { display: flex; justify-content: center; }
.controls, .control-stack, .secondary-controls { display: grid; gap: .45rem; }
.controls {
  grid-template-columns: minmax(44px, 1fr) minmax(0, 1.85fr);
}
.player:last-child .controls {
  grid-template-columns: minmax(0, 1.85fr) minmax(44px, 1fr);
}
.player:last-child .controls > button { grid-column: 2; }
.secondary-controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.secondary-controls button { padding-inline: .15rem; color: #f5fbf7; background: #33463d; }
.controls > button {
  grid-column: 1;
  grid-row: 1;
  min-height: 72px;
  padding-inline: .15rem;
  font-size: clamp(1.1rem, 2.25vw, 1.45rem);
  color: #10251b;
  background: #8aebba;
}
.controls button:focus-visible { outline-color: #8aebba; }
.versus { color: #477260; font: 800 clamp(1.15rem, 3.5vw, 3.5rem) system-ui, sans-serif; }
#result { margin: .85rem 0; min-height: 1.5rem; text-align: center; font-weight: 800; color: var(--green); overflow-wrap: anywhere; }
.actions { flex-wrap: wrap; gap: .65rem; }
dialog { padding: 0; width: min(32rem, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem); border: 0; border-radius: .9rem; color: inherit; }
dialog::backdrop { background: #0b1813aa; }
#settings { display: flex; flex-direction: column; max-height: calc(100dvh - 1.5rem); }
form header, form footer { display: flex; align-items: center; gap: .55rem; padding: .75rem 1rem; }
form header { justify-content: space-between; border-bottom: 1px solid var(--line); }
form header h2 { margin: 0; color: var(--green); font-size: 1.25rem; }
form footer { justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); }
form footer button { padding-inline: .65rem; }
.icon { background: transparent; color: #264b39; font-size: 1.5rem; min-width: 44px; padding: 0; }
.fields { overflow-y: auto; padding: 1rem; }
fieldset { margin: 0 0 1rem; padding: 0 0 1rem; border: 0; border-bottom: 1px solid var(--line); min-width: 0; }
label { display: grid; gap: .4rem; color: var(--green); font-weight: 700; }
label + label { margin-top: .8rem; }
input, select { width: 100%; min-height: 44px; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .4rem; color: #17251f; background: #fff; font-weight: 400; }
@media (max-width: 720px) {
  .shell { padding: clamp(.6rem, 3vw, 1rem); }
  .top button { padding-inline: .65rem; font-size: .875rem; }
  .match-heading { margin-block: .65rem; }
  .board { align-items: stretch; }
  .player { padding: clamp(.4rem, 2vw, .85rem); border-radius: .85rem; }
  .player-heading { display: grid; justify-items: center; grid-template-columns: minmax(0, 1fr); gap: .3rem; }
  .player h2 { width: 100%; min-height: 1.3rem; font-size: clamp(.875rem, 3.3vw, 1.1rem); }
  .serve-badge { padding-inline: .25rem; font-size: .65rem; }
  .numbers { margin-block: .7rem; }
  .numbers span { font-size: .8rem; }
.numbers > div { container-type: inline-size; }
  .points { --mobile-digit-size: clamp(3.4rem, 65cqi, 7rem); }
  .sets { --mobile-digit-size: clamp(2rem, 64cqi, 5rem); }
  .numbers output {
    display: grid;
    place-items: center;
    min-height: calc(1.05 * var(--mobile-digit-size));
    font-size: var(--mobile-digit-size);
    line-height: 1.05;
  }
  .numbers output[data-wide] { font-size: min(44cqi, var(--mobile-digit-size)); }
  .controls, .control-stack, .secondary-controls { gap: .3rem; }
  .controls, .player:last-child .controls { grid-template-columns: minmax(0, 1fr); }
  .controls > button, .player:last-child .controls > button { grid-column: 1; grid-row: 2; }
  .controls > button { min-height: 56px; white-space: nowrap; }
  .actions { gap: .35rem; }
  .actions button { padding-inline: .55rem; font-size: .8rem; }
  #result:empty { min-height: 0; margin-block: .65rem; }
  .secondary-controls button { padding: .2rem .1rem; font-size: clamp(.65rem, 2.2vw, .875rem); line-height: 1.12; }
  .handicap-editor { padding: .25rem; gap: .2rem; }
  .handicap-label { gap: .2rem; white-space: nowrap; font-size: .7rem; }
  .handicap-editor button { font-size: .7rem; white-space: nowrap; }
  .handicap-editor input, .handicap-editor button { padding-inline: .12rem; }
  .handicap-editor input { appearance: textfield; }
  .handicap-editor input::-webkit-inner-spin-button { appearance: none; }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .versus { display: none; }
}
