:root {
  --bg: #0d0e14;
  --fg: #f4f1ea;
  --muted: #8b8fa3;
  --accent: #ffd23f;
  --accent-dark: #b8901a;
  --p1: #2fe0d6;   /* Kurai's teal */
  --p2: #ff8a1f;   /* the robot's orange */
  --display: "Arial Black", Impact, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* 16:9 box as large as the window allows, leaving room for the help footer. */
#stage {
  position: relative;
  width: min(100%, calc((100vh - 130px) * 16 / 9));
  aspect-ratio: 16 / 9;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(5, 6, 10, 0.65);
  backdrop-filter: blur(2px);
}

.overlay.hidden { display: none; }

.ko-card { text-align: center; }

#ko-title {
  margin: 0;
  font: italic 900 clamp(44px, 9vw, 110px)/1 var(--display);
  letter-spacing: 0.04em;
  color: var(--accent);
  -webkit-text-stroke: 3px #000;
  text-shadow: 0 6px 0 #000;
}

#ko-winner {
  margin: 0.4em 0 0.2em;
  font: 900 clamp(20px, 3vw, 34px) var(--display);
}

#ko-score {
  margin: 0 0 1.4em;
  color: var(--muted);
  font-weight: 700;
}

.btn {
  min-width: 220px;
  padding: 14px 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #111;
  font: 900 20px/1 var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark);
}

.btn:hover { filter: brightness(1.08); }

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--accent-dark);
}

.btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.btn.secondary {
  background: #2a2d3d;
  color: var(--fg);
  box-shadow: 0 4px 0 #14161f;
}

.menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.menu.row { flex-direction: row; justify-content: center; }

/* Title screen: the arena stays visible behind the logo. */
.overlay.title {
  background: linear-gradient(rgba(8, 6, 18, 0.15), rgba(8, 6, 18, 0.55));
  backdrop-filter: none;
}

.title-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  text-align: center;
}

#logo {
  width: 62%;
  height: auto;
  margin-bottom: 4%;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
}

.logo-text {
  margin: 0 0 4%;
  font: italic 900 clamp(40px, 8vw, 96px)/1 var(--display);
  color: var(--accent);
  -webkit-text-stroke: 3px #000;
}

/* In the menu, the highlighted choice is yellow and the other one dark, so
   it's obvious what Enter will pick. */
.title .btn {
  min-width: 280px;
  font-size: clamp(18px, 2.4vw, 26px);
  background: rgba(20, 22, 34, 0.85);
  color: var(--fg);
  box-shadow: 0 4px 0 #0a0b12;
}

.title .btn:focus {
  background: var(--accent);
  color: #111;
  box-shadow: 0 4px 0 var(--accent-dark);
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.title .hint {
  color: var(--fg);
  text-shadow: 0 1px 3px #000;
}

/* Who made it: two lines along the bottom of the title screen, on the floor
   under the fighters' feet, placed apart from the menu so nothing above moves. */
.credits {
  position: absolute;
  right: 0;
  bottom: 2%;
  left: 0;
  padding: 0 2%;
  color: var(--fg);
  font-size: clamp(11px, 1.15vw, 14px);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.9);
}

.credits p { margin: 0; }

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.help {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 32px;
  color: var(--muted);
  font-size: 14px;
}

.help strong { margin-right: 4px; }
.help .p1 { color: var(--p1); }
.help .p2 { color: var(--p2); }
.help .or { margin-left: 6px; }

/* Only the controls for the current mode. */
.mode-1 .only-2,
.mode-2 .only-1 { display: none; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  margin: 0 1px;
  padding: 1px 5px;
  border: 1px solid #3a3d4d;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #1a1c26;
  color: var(--fg);
  font: 600 12px/1.4 ui-monospace, monospace;
  text-align: center;
}

/* --- Choosing the fighters ---------------------------------------------------
   The cards sit in the top half; below them the stage shows the two being
   chosen, standing where they will fight. */
.overlay.select {
  align-items: flex-start;
  background: linear-gradient(rgba(8, 6, 18, 0.82), rgba(8, 6, 18, 0.7) 52%, rgba(8, 6, 18, 0) 70%);
  backdrop-filter: none;
}

.select-card {
  width: 100%;
  padding-top: 3.2%;
  text-align: center;
}

#select-title {
  margin: 0 0 2.2%;
  font: italic 900 clamp(16px, 3vw, 38px)/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  -webkit-text-stroke: 1.5px #000;
  text-shadow: 0 3px 0 #000;
}

.roster {
  display: flex;
  justify-content: center;
  gap: 2.4%;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 19%;
  padding: 0 0 1%;
  overflow: hidden;
  border: 3px solid #0a0b12;
  border-radius: 10px;
  background: rgba(20, 22, 34, 0.9);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.card .face {
  position: relative;
  width: 100%;
  aspect-ratio: 1.3;
  overflow: hidden;
  background-color: #2a2d3d;
}

/* The fighter's idle drawing behind the frame, placed by select-screen.js so
   the whole head shows whatever shape the frame is. */
.card .face .art {
  position: absolute;
  top: 50%;
  left: 50%;
  aspect-ratio: 1;
  background: center / 100% 100% no-repeat;
}

.card .name {
  margin-top: 4%;
  font: 900 clamp(12px, 1.9vw, 24px)/1.1 var(--display);
  letter-spacing: 0.06em;
}

.card .style {
  min-height: 2.5em;
  padding: 3% 6% 0;
  color: var(--muted);
  font-size: clamp(9px, 1.05vw, 13px);
  line-height: 1.25;
}

.card:focus {
  border-color: var(--accent);
  outline: 3px solid #fff;
  outline-offset: 2px;
  background: rgba(40, 42, 60, 0.95);
}

.card:focus .face { background-color: #474b66; }

/* Who has picked this card: the first choice top left, the second top right. */
.card .tags {
  position: absolute;
  inset: 5px 5px auto;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.card .tag {
  padding: 2px 7px;
  border-radius: 4px;
  color: #111;
  font: 900 clamp(9px, 1.1vw, 13px)/1.3 var(--display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card .tag:empty { visibility: hidden; }
.card .tag.one { background: var(--p1); }
.card .tag.two { background: var(--p2); }
.card.picked-one { border-color: var(--p1); }
.card.picked-two { border-color: var(--p2); }

.tool.back {
  position: absolute;
  top: 4%;
  left: 2.5%;
}

/* The sound button would sit on the heading here; M still works. */
body.selecting .stage-tools { display: none; }

/* Results line for matches won so far; empty until the second match. */
#ko-series {
  margin: -1em 0 1.2em;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

#pause-title {
  margin: 0 0 0.5em;
  font: italic 900 clamp(32px, 6vw, 72px)/1 var(--display);
  letter-spacing: 0.04em;
  color: var(--accent);
  -webkit-text-stroke: 2px #000;
  text-shadow: 0 5px 0 #000;
}

.menu.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.menu.grid .btn { min-width: 0; padding-inline: 24px; white-space: nowrap; }

/* Sound and pause, tucked under the timer. */
.stage-tools {
  position: absolute;
  top: 13.4%;
  left: 50%;
  display: flex;
  gap: 8px;
  transform: translateX(-50%);
}

.tool {
  width: 38px;
  height: 30px;
  padding: 0;
  border: 2px solid rgba(255, 210, 63, 0.7);
  border-radius: 6px;
  background: rgba(17, 17, 17, 0.75);
  color: var(--fg);
  font: 700 13px/1 system-ui, sans-serif;
  cursor: pointer;
}

.tool:hover { background: rgba(40, 40, 48, 0.9); }
.tool:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.tool.off { color: var(--muted); text-decoration: line-through; border-color: rgba(139, 143, 163, 0.6); }
#pause-btn { font-size: 10px; letter-spacing: 1px; }
body:not(.playing) #pause-btn { display: none; }
body.results .stage-tools { display: none; }  /* the results have the middle of the stage */
body.in-round:not(.playing) .stage-tools { display: none; }  /* paused: the menu has its own sound button */

.touch-only { display: none; }

/* --- Phones: on-screen buttons -----------------------------------------------
   body.touch is set by main.js once the screen is touched (or straight away
   on a phone). The keyboard help goes, the stage takes the space, and two
   pads sit in the bottom corners, one per thumb. */

#touch { display: none; }

body.touch {
  --tkey: clamp(54px, 17vh, 76px);       /* one button */
  --gutter: 92px;                        /* kept clear each side of the stage for the pads */
  gap: 0;
  padding: 0;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch .help,
body.touch .keys-only,
body.touch [data-mode="2"] { display: none; }   /* two players need a keyboard */
body.touch .touch-only { display: block; }

body.touch #stage {
  width: min(100vw - 2 * var(--gutter), 100vh * 16 / 9);
  width: min(100vw - 2 * var(--gutter), 100dvh * 16 / 9);
}

body.touch .tool { width: 44px; height: 34px; }
body.touch .card .style { min-height: 0; }

body.touch.playing #touch { display: block; }

.pad {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  padding: 14px;                          /* a near miss still counts */
  touch-action: none;
}

.pad.move {
  left: max(0px, env(safe-area-inset-left));
  grid-template-columns: repeat(2, var(--tkey));
}

.pad.act {
  right: max(0px, env(safe-area-inset-right));
  grid-template-columns: repeat(2, var(--tkey));
}

.tkey {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--tkey);
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  background: rgba(13, 14, 20, 0.45);
  color: rgba(255, 255, 255, 0.9);
  font: 900 12px/1 var(--display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;                   /* the pad takes the touches and works out the button */
}

.pad.move .tkey { font-size: 24px; }
.tkey.punch, .tkey.kick { border-color: rgba(255, 210, 63, 0.85); color: var(--accent); }
.tkey.special { border-color: rgba(47, 224, 214, 0.85); color: var(--p1); }
.tkey.on { background: rgba(255, 255, 255, 0.85); color: #111; transform: scale(0.94); }

/* Held upright: the stage goes to the top and the pads get the room below. */
@media (orientation: portrait) {
  body.touch {
    --tkey: clamp(64px, 20vw, 92px);
    justify-content: flex-start;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  body.touch #stage { width: 100vw; }
  /* The stage is small here: sound and pause go just under it. */
  body.touch .stage-tools { top: calc(100% + 12px); }
  body.touch #stage::after {
    content: "Turn your phone sideways for a bigger picture";
    position: absolute;
    top: calc(100% + 64px);
    left: 0;
    right: 0;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
  }
  body.touch .pad { bottom: max(28px, env(safe-area-inset-bottom)); }
  /* No room on the stage for the credits here: they go under that line. */
  body.touch .credits { top: calc(100% + 100px); bottom: auto; color: var(--muted); font-size: 12px; text-shadow: none; }

  /* The stage is short here, so the menus go side by side. */
  body.touch .btn { min-width: 0; padding: 12px 22px; font-size: 15px; }
  body.touch #ko-title { font-size: 40px; -webkit-text-stroke-width: 2px; }
  body.touch #ko-winner { margin: 0.2em 0 0.1em; font-size: 18px; }
  body.touch #ko-score { margin-bottom: 0.6em; }
  body.touch #pause-title { font-size: 28px; }
  body.touch .menu.grid { gap: 8px; }
  body.touch .menu.grid .btn { padding: 12px 8px; font-size: 13px; }
}

/* Short screens (a phone on its side): tighter menus so they fit the stage. */
@media (max-height: 480px) {
  .btn { padding: 11px 26px; font-size: 16px; }
  .title .btn { min-width: 220px; font-size: 18px; }
  #logo { width: 52%; margin-bottom: 3%; }
  #ko-title { font-size: 56px; }
  #ko-winner { margin: 0.2em 0 0.1em; }
  #ko-score { margin-bottom: 0.7em; }
  #pause-title { font-size: 36px; margin-bottom: 0.4em; }
  .menu.grid { gap: 10px; }
  .menu.row .btn { min-width: 0; }
  .select-card { padding-top: 2%; }
  #select-title { margin-bottom: 1.6%; }
  .card { width: 17%; }
  .card .face { aspect-ratio: 1.55; }
  .card .style { padding-inline: 3%; }
}

/* A phone on its side. The pads are wider than the room beside the stage, and
   used to sit on its bottom corners, over the feet of a fighter backed into
   one. So here the stage goes to the top and stops short enough for its ground
   line (8/9 of the way down, which is half its width) to clear the bottom row
   of buttons: those cover only the strip of floor in front of the fighters.
   Jump and the special go up the right-hand edge, beside the stage. */
@media (orientation: landscape) and (max-height: 480px) {
  body.touch {
    --vh: 100vh;
    --tkey: clamp(46px, 14.5vh, 62px);         /* a button's height */
    --tkey-w: clamp(60px, 9vw, 84px);          /* the ones over the floor are wide instead */
    --pad-bottom: max(8px, env(safe-area-inset-bottom));
    --gutter: 72px;
    --stage-w: min(100vw - 2 * var(--gutter), (var(--vh) - var(--pad-bottom) - var(--tkey) - 4px) * 2);
    --side: calc((100vw - var(--stage-w)) / 2);  /* the room either side of the stage */
    justify-content: flex-start;
  }

  @supports (height: 100dvh) {
    body.touch { --vh: 100dvh; }
  }

  body.touch #stage { width: var(--stage-w); }

  .pad {
    bottom: var(--pad-bottom);
    padding: 14px 6px 0;
  }

  .pad.move {
    padding-right: 14px;
    grid-template-columns: repeat(2, var(--tkey-w));
  }

  .pad.act {
    padding-left: 14px;
    grid-template-columns: var(--tkey-w) clamp(58px, var(--side) - 10px - env(safe-area-inset-right, 0px), 84px);
    grid-template-areas:
      ". jump"
      ". special"
      "punch kick";
  }

  .tkey { letter-spacing: 0.02em; }            /* "Rocket" has to fit the narrow column */
  .tkey.jump { grid-area: jump; }
  .tkey.special { grid-area: special; }
  .tkey.punch { grid-area: punch; }
  .tkey.kick { grid-area: kick; }
}

/* A narrow stage (a phone held upright): bigger faces, names only. */
@media (max-width: 560px) {
  .card { width: 25%; border-width: 2px; }
  .card .face { aspect-ratio: 1.45; }
  .card .style { display: none; }
  .card .name { margin: 5% 0 3%; }
}
