:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #101d2c;
  color: #eef4f4;
  --lime: #efd79a;
  --teal: #67e0d3;
  --coral: #ff927e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* The court, controls, overlays and their actual hit targets share one policy.
   manipulation still permits pinch and some iOS versions also double-tap zoom. */
#app, #app * { touch-action: none; }
/* The modal is a sibling of #app. Menus must scroll even when a drag starts on
   a large button/label; touch-policy preserves their activation on double taps. */
#dialog { touch-action: pan-y; }
#dialog :is(button, label) { touch-action: pan-y; }
#dialog :is(a, input, select, textarea, [contenteditable], [role="button"]) { touch-action: none; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}
.control-symbols { position: absolute; pointer-events: none; }
#replay-overlay { position: fixed; inset: 0; z-index: 8; background: transparent; touch-action: none; }
.replay-badge { position: absolute; left: 50%; top: calc(var(--safe-top) + 65px); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 8px 15px; border: 1px solid #fff3; border-radius: 20px; color: #fff2cf; background: #122c3de8; font-size: 12px; font-weight: 700; letter-spacing: .12em; white-space: nowrap; }
.replay-badge i { width: 7px; height: 7px; border-radius: 50%; background: #f4ce80; box-shadow: 0 0 12px #f4ce8077; }
.replay-caption { position: absolute; bottom: calc(var(--safe-bottom) + 24px); left: 50%; transform: translateX(-50%); min-width: 156px; min-height: 48px; padding: 10px 22px; border: 1px solid #99b9beaa; border-radius: 26px; background: #153847f2; box-shadow: 0 4px 14px #06151d55; color: #eaf1ed; font-size: 14px; font-weight: 700; white-space: nowrap; }
.replay-caption:active { background: #2d5d6d; box-shadow: 0 0 0 3px #8bdfd438; }
.replay-caption b { margin-left: 14px; font-size: 20px; vertical-align: -1px; }
[data-replay] #controls, [data-replay] #play-hud, [data-replay] #pause { visibility: hidden; pointer-events: none; }
.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1400px;
  margin: auto;
  padding: calc(var(--safe-top) + 5px) calc(var(--safe-right) + 9px)
    calc(var(--safe-bottom) + 5px) calc(var(--safe-left) + 9px);
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) 27px;
  gap: 5px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.brand img { border-radius: 9px; }
.brand b { color: var(--lime); font-size: 10px; }
.brand small { display: block; font-size: 8px; letter-spacing: .18em; color: #91a8b6; }
.top-actions { display: flex; gap: 4px; }
.top-actions button {
  width: 44px;
  height: 44px;
  background: #1e3244;
  border: 1px solid #48606d;
  border-radius: 12px;
  font-size: 20px;
}
.top-actions svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  vertical-align: middle;
}
.scoreboard {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 14px;
  border: 1px solid #b4cdd4a8;
  border-radius: 999px;
  background: #142b39e8;
  box-shadow: 0 2px 8px #0b192c42;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.score-value { display: inline-flex; align-items: center; gap: 5px; font-size: 20px; line-height: 1; }
.score-value b { min-width: 1ch; text-align: center; font-variant-numeric: tabular-nums; }
.score-value > span { opacity: .62; }
.teal { color: var(--teal); }
.coral { color: var(--coral); }

.view {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid #476073;
  background: #132a3b;
  isolation: isolate;
}
#court { width: 100%; height: 100%; display: block; touch-action: none; }
.home {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 23px 20px;
  background: linear-gradient(180deg, #0c1e30f5 0%, #0c1e30e8 18%, #0c1e3035 37%, #0c1e3018 62%, #0c1e30e6 100%);
}
.eyebrow { font-size: 10px; letter-spacing: .19em; font-weight: 850; color: var(--lime); margin: 0 0 14px; }
.hero h1 { font-size: clamp(31px, 9vw, 60px); line-height: 1.15; letter-spacing: -.04em; margin: 0 0 16px; text-shadow: 0 2px 12px #071727; }
.hero > p:last-child { font-size: 13px; line-height: 1.6; color: #d7e5e7; }
.home-actions { display: grid; gap: 9px; }
.home-actions button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 14px 17px;
  border-radius: 13px;
  font-size: 18px;
  font-weight: 850;
  border: 1px solid #7d9eaa;
}
.home-actions button span { font-size: 11px; }
.start { background: linear-gradient(140deg, #f6e6b6, var(--lime)); color: #153138; border-color: #fff0c9 !important; }
.secondary { background: #173647e8; }
.home-caption { font-size: 10px; color: #bdd0d8; text-align: center; margin-top: 5px; }
footer { display: flex; align-items: center; justify-content: space-between; font-size: 9px; color: #9cb1bf; gap: 4px; }
footer > div { display: flex; align-items: center; gap: 8px; }
footer button { border: 0; background: none; color: var(--lime); padding: 6px 2px; text-decoration: underline; font-size: 10px; font-weight: 750; }

.app[data-screen="play"] {
  position: relative;
  display: block;
  max-width: none;
  padding: 0;
  overflow: hidden;
  isolation: isolate;
}
.app[data-screen="play"] .view { position: absolute; inset: 0; border: 0; border-radius: 0; }
.app[data-screen="play"] .view::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, #071d2bd9 0%, #102e3e64 10%, transparent 22%, transparent 87%, #081e2c42 100%);
  pointer-events: none;
}
.app[data-screen="play"] .topbar {
  position: absolute;
  z-index: 2;
  top: calc(var(--safe-top) + 8px);
  left: calc(var(--safe-left) + 9px);
  right: calc(var(--safe-right) + 9px);
  height: 44px;
  justify-content: end;
  pointer-events: none;
}
.app[data-screen="play"] .scoreboard {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.app[data-screen="play"] #pause {
  display: grid;
  place-items: center;
  padding: 0;
  pointer-events: auto;
  border-radius: 50%;
  border-color: #c2d7d285;
  background: #102b39ed;
  box-shadow: 0 4px 14px #071a2d52, inset 0 1px 0 #f7f1de12;
}
.app[data-screen="play"] :is(.brand, #sound, #help, footer, #gesture-hint) { display: none !important; }
#callout {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 5px 10px;
  border-radius: 8px;
  background: #142b39de;
  color: #f2ffdb;
  font-size: 11px;
  font-weight: 820;
  white-space: nowrap;
  pointer-events: none;
}
#callout:empty { display: none; }

.controls {
  --action-cell: 82px;
  --action-size: 58px;
  --action-tactic: 48px;
  --action-gap: 7px;
  --action-right: clamp(54px, calc(32vw - 48px), 90px);
  --action-cluster-width: calc(3 * var(--action-tactic) + 2 * var(--action-gap));
  --action-bottom: 23px;
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.movement {
  position: absolute;
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  width: min(46%, 320px, calc(100% - var(--safe-left) - var(--safe-right) - var(--action-right) - var(--action-cluster-width) - 8px));
  height: clamp(172px, 26svh, 230px);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#joystick {
  position: absolute;
  left: 20px;
  bottom: 24px;
  width: 108px;
  height: 108px;
  border: 2px solid #eff9f56e;
  border-radius: 50%;
  background: #e1f9ee17;
  box-shadow: inset 0 0 24px #2a545862;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#stick {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 48px;
  border: 2px solid #e6f6f6ba;
  border-radius: 50%;
  background: #d9f0eba3;
  box-shadow: 0 3px 10px #122a3a66;
  pointer-events: none;
}
.circle-actions {
  position: absolute;
  right: calc(var(--safe-right) + var(--action-right));
  bottom: calc(var(--safe-bottom) + var(--action-bottom));
  display: grid;
  grid-template-columns: repeat(3, var(--action-tactic));
  grid-template-rows: var(--action-tactic) var(--action-size) var(--action-cell);
  gap: var(--action-gap);
  place-items: center;
}
#serve-controls { display: contents; }
.circle-actions button {
  --button-light: #2f6470;
  --button-dark: #13303e;
  --button-rim: #e7f8f2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: var(--action-size);
  height: var(--action-size);
  padding: 0;
  border: 2px solid var(--button-rim);
  border-radius: 50%;
  background: linear-gradient(150deg, var(--button-light), var(--button-dark) 88%);
  box-shadow: 0 3px 7px #0e273663, inset 0 0 0 1px #ffffff26;
  color: #f5ffff;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.05;
  white-space: nowrap;
  text-shadow: 0 1px 2px #123440a0;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.circle-actions button:disabled { opacity: .68; cursor: default; }
.circle-actions button[data-down] {
  box-shadow: 0 2px 5px #0e273663, inset 0 0 0 2px #ffffff6b;
  filter: brightness(1.14);
}
.circle-actions svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-solid { fill: currentColor; stroke: none; }
.circle-actions [data-slot="mode"] { grid-area: 3 / 1 / 4 / 3; justify-self: start; }
.circle-actions [data-slot="quick"] { grid-area: 1 / 2; }
.circle-actions [data-slot="call"] { grid-area: 1 / 3; }
.circle-actions [data-slot="lift"] { grid-area: 2 / 1 / 3 / 3; justify-self: start; }
.circle-actions [data-slot="high"] {
  grid-area: 2 / 2 / 3 / 4;
  justify-self: end;
  margin-right: calc((var(--action-cell) - var(--action-size)) / 2);
}
.circle-actions :is([data-slot="mode"], [data-slot="call"], [data-slot="quick"]) {
  width: var(--action-tactic);
  height: var(--action-tactic);
  border-width: 1px;
}
.circle-actions [data-slot="primary"] {
  grid-area: 3 / 2 / 4 / 4;
  justify-self: end;
  width: var(--action-cell);
  height: var(--action-cell);
  font-size: 16px;
  gap: 3px;
}
.circle-actions [data-slot="primary"] svg { width: 30px; height: 30px; }
.circle-actions [data-gesture="receive"] {
  --button-light: #38b3ab;
  --button-dark: #165c65;
  --button-rim: #d0fff7;
}
.circle-actions [data-gesture="attack"] {
  --button-light: #fa8368;
  --button-dark: #ae423a;
  --button-rim: #ffecdf;
}
.circle-actions [data-gesture="set"] {
  --button-light: #5b91b6;
  --button-dark: #274e72;
  --button-rim: #dcefff;
}

.error {
  position: absolute;
  inset: 70px max(20px, var(--safe-right)) 160px max(20px, var(--safe-left));
  display: grid;
  place-content: center;
  z-index: 9;
  padding: 20px;
  border: 1px solid #e8b36a;
  border-radius: 15px;
  background: #152d40;
  font-size: 14px;
  line-height: 1.6;
}
dialog {
  position: fixed;
  inset: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 10px)
    calc(var(--safe-bottom) + 10px) calc(var(--safe-left) + 10px);
  margin: auto;
  width: 420px;
  max-width: calc(100% - var(--safe-left) - var(--safe-right) - 20px);
  max-height: calc(100% - var(--safe-top) - var(--safe-bottom) - 20px);
  padding: 0;
  background: #172e40;
  color: #edf5f5;
  border: 1px solid #65818e;
  border-radius: 17px;
  overscroll-behavior: contain;
}
dialog::backdrop { background: #07131dbb; }
#dialog-content { padding: 21px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.dialog-head h2 { margin: 0 0 12px; font-size: 25px; }
.close { width: 44px; height: 44px; border: 1px solid #627e8b; border-radius: 9px; background: #233e51; font-size: 20px; }
.dialog-copy { font-size: 12px; color: #c3d6de; line-height: 1.7; margin: 0 0 14px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 15px; }
.dialog-actions button { flex: 1; min-height: 44px; border: 1px solid #668c98; border-radius: 9px; background: #26465b; font-size: 13px; font-weight: 750; white-space: nowrap; }
.dialog-actions .accent { background: var(--lime); color: #17313d; border-color: var(--lime); }
.pause-tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 12px 0; }
.pause-tools button {
  min-height: 44px;
  border: 1px solid #668c98;
  border-radius: 9px;
  background: #203b50;
  font-size: 13px;
  font-weight: 750;
}
fieldset { border: 0; padding: 0; margin: 12px 0; }
legend { font-size: 12px; margin-bottom: 6px; color: #bfccd4; }
.options { display: flex; gap: 6px; }
.options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.options label { flex: 1; padding: 10px 3px; text-align: center; background: #254459; border: 1px solid #597c8a; border-radius: 8px; font-size: 12px; }
.options input:checked + label { background: var(--teal); color: #163342; }
.options input:focus-visible + label { outline: 2px solid var(--lime); }
.guide { padding-left: 19px; font-size: 12px; line-height: 1.7; color: #ccdee4; }
.guide li { margin: 7px 0; }
.guide strong { color: var(--teal); }
.version { font-size: 9px; color: #9fbbc8; }
.athlete-loading { color: #c3d6de; font-size: 12px; line-height: 1.5; text-align: center; }
.athlete-loading button { margin-top: 6px; min-height: 40px; padding: 6px 16px; border: 1px solid #8ae8dc; border-radius: 12px; background: #203b50; color: #fff; }
.home-actions button:disabled { opacity: .55; cursor: wait; }
.dialog-copy a { color: var(--teal); }
.zone-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.zone-grid button { padding: 8px; border: 1px solid #6b8995; background: #27465a; border-radius: 8px; font-size: 12px; }
.zone-grid button[data-selected] { background: var(--teal); color: #112f3a; }

@media (max-width: 360px) {
  #joystick { left: 13px; width: 94px; height: 94px; }
  #stick { width: 42px; height: 42px; }
}
@media (max-width: 360px), (orientation: landscape) {
  .controls { --action-cell: 68px; --action-size: 52px; --action-tactic: 46px; --action-gap: 5px; --action-bottom: 18px; }
}
@media (orientation: landscape) {
  .controls { --action-right: 80px; }
  .home { flex-direction: row; align-items: center; padding: 20px 28px; gap: 35px; background: linear-gradient(90deg, #0c1e30dd, #0c1e3022 55%, #0c1e30bb); }
  .hero h1 { font-size: clamp(28px, 6vw, 55px); }
  .hero > p:last-child { font-size: 11px; }
  .home-actions { width: min(280px, 45%); }
  .movement { width: min(36%, 320px); height: min(66svh, 210px); }
  #joystick { bottom: 16px; width: 88px; height: 88px; }
  #stick { width: 39px; height: 39px; }
  #callout { left: calc(var(--safe-left) + 14px); transform: none; }
}
@media (max-height: 650px) and (orientation: portrait) {
  .home { padding: 17px; }
  .hero h1 { font-size: 31px; }
  .hero > p:last-child { display: none; }
}
