﻿* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body { font-family: "Times New Roman", serif; color: #111; }
#stage {
  width: 100%; height: 100vh; height: 100dvh;
  position: relative; isolation: isolate; overflow: hidden;
  background: #a7ddfa; user-select: none;
}
#yard { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
button {
  font: 16px Arial, sans-serif;
  color: #101010; background: #e8e8e8;
  border: 2px outset #eee; border-radius: 0;
  padding: 5px 10px; cursor: pointer; touch-action: manipulation;
}
button:active, button.is-held { border-style: inset; background: #ccc; }
button:focus-visible { outline: 3px dashed #171173; outline-offset: 3px; }
button:disabled { color: #585858; cursor: default; }
.hud {
  position: absolute; top: max(2.8%, env(safe-area-inset-top)); left: 2.5%; right: 2.5%;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 5vw;
}
.player strong { font-size: clamp(22px, 3.1vw, 42px); }
.player small { font: 14px Arial, sans-serif; }
.player small + small { white-space: nowrap; }
.other { text-align: right; }
.health {
  margin-top: 3px; display: flex; gap: 2px; height: clamp(12px, 2vh, 20px);
  width: min(29vw, 440px); border: 2px solid #171717; background: #171717;
}
.health i { flex: 1; background: #64f239; }
.health i.empty { background: #a59592; }
.health[aria-valuemax="20"] { gap: 1px; }
.other .health { margin-left: auto; flex-direction: row-reverse; }
.hud > * { grid-row: 1; }
.clock { grid-column: 2; }
#stage[data-player="jake"] .player:first-child { grid-column: 3; text-align: right; }
#stage[data-player="jake"] .player:first-child .health { margin-left: auto; flex-direction: row-reverse; }
#stage[data-player="jake"] .other { grid-column: 1; text-align: left; }
#stage[data-player="jake"] .other .health { margin-left: 0; flex-direction: row; }
.clock { text-align: center; font-weight: bold; }
#time { display: block; font-size: clamp(24px, 4.4vh, 46px); line-height: 1; }
#round { font: 12px Arial, sans-serif; text-transform: lowercase; }
.main-action, .announcer, .versus { position: absolute; left: 50%; }
.versus {
  bottom: 37%; transform: translateX(-50%) rotate(8deg);
  font: italic bold clamp(27px, 3.5vw, 56px)/1 Georgia, serif;
}
#stage:not([data-phase="ready"]) .versus { display: none; }
.main-action { top: 32%; transform: translate(-50%, -50%); z-index: 3; }
#action { font: bold clamp(18px, 2.5vw, 32px) Arial, sans-serif; padding: 3px .85em 5px; }
#stage[data-phase="fight"] .main-action { top: 11%; }
#stage[data-phase="fight"] #action { font: 15px Arial, sans-serif; }
#stage:is([data-phase="done"], [data-phase="paused"]) .main-action { top: 33%; }
.fighter {
  position: absolute; bottom: 23%; width: max-content;
  height: min(35vh, 31vw); height: min(35dvh, 31vw);
  transform: translate(-50%, calc(var(--air) * -1 * min(21vh, 28vw))); pointer-events: none;
  --direction: 1; --flip: 1; --air: 0;
}
#jamie { left: 26%; }
#jake { left: 74%; --direction: -1; }
.fighter img {
  width: auto; height: 100%; display: block;
  transform-origin: 50% 98%; transform: scaleX(var(--flip));
}
.fighter::before, .fighter::after {
  content: ""; position: absolute; top: 100%; height: clamp(9px, 2.2vh, 24px); width: 9px;
  border-left: 3px solid black; border-bottom: 3px solid black;
  transform: skewX(-16deg); left: 26%;
}
.fighter::after { left: 68%; transform: skewX(14deg); }
.speech:not(:empty) {
  position: absolute; z-index: 1; bottom: calc(100% + 12px); left: 50%;
  transform: translateX(-50%) rotate(-2deg); border: 2px solid #161616;
  padding: 3px 7px; background: white; white-space: nowrap;
  font: bold clamp(14px, 2vw, 25px) "Comic Sans MS", cursive;
}
.speech:not(:empty)::after {
  content: ""; position: absolute; top: 100%; left: 30%;
  width: 8px; height: 8px; background: white;
  border: solid #161616; border-width: 0 2px 2px 0; transform: translateY(-3px) skewY(35deg);
}
.fighter.is-moving img { animation: shuffle .21s steps(2,end) infinite; }
@keyframes shuffle { 50% { transform: translateY(-4px) rotate(2deg) scaleX(var(--flip)); } }
.fighter.is-winding img { transform: rotate(calc(var(--direction) * -10deg)) scaleX(var(--flip)); }
.fighter.is-attacking img { animation: smack .34s steps(2,end) both; }
@keyframes smack {
  0% { transform: rotate(calc(var(--direction) * -8deg)) scaleX(var(--flip)); }
  32%, 64% { transform: translateX(calc(var(--direction) * 18%)) rotate(calc(var(--direction) * 14deg)) scaleX(var(--flip)); }
  100% { transform: scaleX(var(--flip)); }
}
.fighter.is-hurt img { animation: ouch .26s steps(2,end); }
@keyframes ouch { 50% { transform: translateY(-8px) rotate(calc(var(--direction) * -13deg)) scaleX(var(--flip)); } }
.fighter.is-down img { transform: rotate(calc(var(--direction) * -79deg)) scaleX(var(--flip)); }
#stage[data-phase="paused"] .fighter img { animation-play-state: paused; }
.announcer { top: 21%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
#message { white-space: nowrap; font: bold italic clamp(32px,5vw,76px)/1 Georgia,serif; }
#message[data-kind="hit"] { display: block; transform: rotate(-10deg); color: #a50000; }
#verdict { display: block; margin-top: 4px; font-size: clamp(14px,1.6vw,22px); white-space: nowrap; }
footer {
  position: absolute; left: max(2.5%,env(safe-area-inset-left)); right: max(2.5%,env(safe-area-inset-right));
  bottom: max(3%,env(safe-area-inset-bottom)); display: flex; align-items: end;
  justify-content: space-between; gap: 6px; pointer-events: none;
}
.play-keys, .options { display: flex; gap: 4px; pointer-events: auto; }
.p2-controls, .versus-key { display: none; }
#stage[data-mode="versus"] .solo-key, #stage[data-mode="versus"] #swap { display: none; }
#stage[data-mode="versus"] .versus-key { display: inline; }
.pad-label { align-self: center; margin-right: 3px; font: bold 14px Arial, sans-serif; }
#stage[data-mode="versus"] footer {
  display: grid; grid-template-columns: 1fr 1fr; align-items: end; row-gap: 7px;
}
#stage[data-mode="versus"] .p1-controls { justify-self: start; }
#stage[data-mode="versus"] .p2-controls { display: flex; justify-self: end; }
#stage[data-mode="versus"] .options { grid-column: 1 / -1; justify-self: center; }
.play-keys button { min-width: 46px; min-height: 44px; touch-action: none; }
#left, #right { font-size: 22px; }
#attack { text-transform: lowercase; }
.hint { white-space: nowrap; }
.options button { font-size: 14px; }
.sound-off, #sound[data-muted=true] .sound-on { display: none; }
#sound[data-muted=true] .sound-off { display: inline; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@media (max-width: 640px) {
  .hud { top: max(13px,env(safe-area-inset-top)); }
  footer { flex-direction: column; align-items: center; gap: 8px; }
  .options button { min-height: 36px; }
  .play-keys { justify-content: center; flex-wrap: wrap; }
  .play-keys button { min-width: 42px; padding-inline: 7px; }
  .play-keys .hint { display: none; }
  .player small { font-size: 12px; }
  #stage[data-mode="versus"] footer { grid-template-columns: 1fr; gap: 4px; }
  #stage[data-mode="versus"] :is(.p1-controls,.p2-controls) { justify-self: center; }
  #stage[data-mode="versus"] .hint.versus-key { display: none; }
  .main-action { top: 33%; }
  .fighter { bottom: 27%; }
  .versus { bottom: 33%; }
}
@media (max-height: 500px) {
  .hud { top: max(5px,env(safe-area-inset-top)); }
  .player strong { font-size: 21px; }
  .health { height: 11px; }
  #time { font-size: 23px; }
  .main-action, #stage:is([data-phase="done"],[data-phase="paused"]) .main-action { top: 39%; }
  #stage[data-phase="fight"] .main-action { top: 21%; }
  footer { flex-direction: row; align-items: flex-end; }
  .fighter { bottom: 22%; height: min(31vh, 31vw); }
}
@media (max-height: 500px) and (max-width: 850px) {
  .play-keys .hint { display: none; }
  #stage[data-mode="versus"] .hint.versus-key { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .fighter.is-moving img, .fighter.is-hurt img { animation: none; }
}
