html,
body {
  margin: 0;
  height: 100%;
  background: #05070c;
  overflow: hidden;
  color: #eef1f6;
  user-select: none;
  -webkit-user-select: none;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}
canvas#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:focus-visible {
  outline: 2px solid #ffb37a;
  outline-offset: 2px;
}
.ov {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.ov.on {
  display: flex;
}
/* menu */
#menu {
  background: linear-gradient(180deg, rgba(5, 7, 12, 0.55), rgba(5, 7, 12, 0.82));
  flex-direction: column;
  gap: 22px;
  overflow: auto;
}
#menu h1 {
  margin: 0;
  font-size: clamp(34px, 6vw, 64px);
  letter-spacing: 0.2em;
  font-weight: 800;
  color: #fff;
  text-align: center;
}
#menu h1 span {
  color: #ff8a3d;
}
#menu p.tag {
  margin: -10px 0 0;
  color: rgba(232, 238, 248, 0.7);
  font-size: 15px;
  text-align: center;
}
.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 250px));
  gap: 14px;
}
.mode {
  text-align: left;
  padding: 18px 18px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(14, 19, 30, 0.78);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition:
    transform 0.12s,
    border-color 0.12s,
    background 0.12s;
}
.mode:hover {
  transform: translateY(-3px);
  border-color: #ff8a3d;
  background: rgba(24, 30, 46, 0.9);
}
.mode b {
  display: block;
  font-size: 19px;
  margin-bottom: 6px;
  color: #fff;
}
.mode i {
  display: block;
  font-style: normal;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: #ffb37a;
  margin-bottom: 8px;
}
.mode span {
  display: block;
  font-size: 13.5px;
  line-height: 1.45;
  color: rgba(226, 232, 243, 0.78);
}
.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  font-size: 13px;
  color: rgba(226, 232, 243, 0.75);
  max-width: 820px;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 7px;
  margin-right: 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  font:
    600 12px ui-monospace,
    Menlo,
    Consolas,
    monospace;
  color: #fff;
  text-align: center;
}
@media (max-width: 820px) {
  .modes {
    grid-template-columns: minmax(0, 340px);
  }
}
/* in-game */
#hud {
  display: none;
}
body.playing #hud {
  display: block;
}
#stats {
  position: fixed;
  left: 18px;
  top: 14px;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}
#sMain {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
#sAux {
  font-size: 15px;
  color: #ffc79c;
  font-weight: 600;
  margin-top: 2px;
  min-height: 19px;
}
#top {
  position: fixed;
  right: 14px;
  top: 12px;
  display: flex;
  gap: 6px;
}
#top button,
.row button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-weight: 600;
  background: rgba(10, 14, 22, 0.62);
}
#top button:hover,
.row button:hover {
  background: rgba(40, 48, 66, 0.8);
}
#sSub {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  font-size: 13.5px;
  color: rgba(232, 238, 248, 0.85);
  pointer-events: none;
  white-space: nowrap;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(8, 11, 18, 0.55);
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
#sSub:empty {
  display: none;
}
#meter {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  width: min(360px, 70vw);
  height: 16px;
  border-radius: 999px;
  background: rgba(8, 11, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.22);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.12s;
  pointer-events: none;
}
#meter.on {
  opacity: 1;
}
#mZone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: #35d07f;
  opacity: 0.9;
}
#mFill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.85));
  border-right: 3px solid #fff;
  box-sizing: border-box;
  mix-blend-mode: screen;
}
#mLabel {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}
#mLabel.on {
  opacity: 1;
}
#mLabel.ok {
  color: #5fe39c;
}
#toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: clamp(22px, 3.4vw, 38px);
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85);
  text-align: center;
  white-space: nowrap;
}
#toast.show {
  animation: pop 1.6s ease-out forwards;
}
@keyframes pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.9);
  }
  10% {
    opacity: 1;
    transform: translateX(-50%) scale(1.04);
  }
  18% {
    transform: translateX(-50%) scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  #toast.show {
    animation: popr 1.6s linear forwards;
  }
  @keyframes popr {
    0%,
    80% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
  .mode {
    transition: none;
  }
}
.card {
  min-width: 280px;
  max-width: 420px;
  padding: 26px 28px;
  border-radius: 18px;
  background: rgba(12, 16, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  text-align: center;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 34px;
  font-weight: 800;
}
.card .body {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(226, 232, 243, 0.85);
  margin-bottom: 18px;
}
.row {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.row button.pri {
  background: #e8621c;
  border-color: #e8621c;
  color: #fff;
}
.row button.pri:hover {
  background: #f47a36;
}
#load {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: rgba(255, 179, 122, 0.85);
  pointer-events: none;
  background: #05070c;
}
#fail {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  color: #c9d2e0;
  background: #05070c;
}

/* ---------- touch controls (phones and tablets) ---------- */
#touch,
#bFull,
#bPause,
.tkeys {
  display: none;
}
body.touch .keys {
  display: none;
}
body.touch .tkeys {
  display: flex;
}
.tkeys b {
  color: #ffb37a;
  font-weight: 700;
}
.rotHint,
.iosHint {
  display: none;
}
body.ioshint .iosHint {
  display: inline;
  color: #fff;
}
@media (orientation: portrait) {
  .rotHint {
    display: inline;
    color: #fff;
  }
}
body.touch {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.touch.playing #touch {
  display: block;
}
body.touch #bPause {
  display: inline-block;
}
body.touch.canfull #bFull {
  display: inline-block;
}
body.touch #top {
  top: calc(8px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  gap: 5px;
}
body.touch #top button {
  padding: 7px 10px;
  font-size: 11.5px;
}
body.touch #stats {
  left: calc(14px + env(safe-area-inset-left));
  top: calc(8px + env(safe-area-inset-top));
}
body.touch #sMain {
  font-size: 20px;
}
body.touch #sAux {
  font-size: 13px;
}
body.touch #sSub {
  bottom: calc(10px + env(safe-area-inset-bottom));
  font-size: 12px;
  max-width: 38vw;
  padding: 5px 11px;
}
body.touch #meter {
  width: min(300px, 40vw);
  bottom: calc(52px + env(safe-area-inset-bottom));
}
body.touch #mLabel {
  bottom: calc(76px + env(safe-area-inset-bottom));
}
#joyZone {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 46vw;
  height: 76vh;
  touch-action: none;
}
#touch[data-ctx="contest"] #joyZone {
  display: none;
}
#joyBase {
  position: absolute;
  left: calc(96px + env(safe-area-inset-left));
  top: calc(100% - 96px - env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  margin: -62px 0 0 -62px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(10, 14, 22, 0.3);
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.15s;
}
#joyBase.on {
  opacity: 1;
}
#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.tb {
  position: fixed;
  width: 62px;
  height: 62px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.32);
  background: rgba(10, 14, 22, 0.52);
  color: #fff;
  font:
    800 11px/1 ui-sans-serif,
    system-ui,
    sans-serif;
  letter-spacing: 0.05em;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tb.big {
  width: 92px;
  height: 92px;
  font-size: 15px;
  background: rgba(232, 98, 28, 0.78);
  border-color: rgba(255, 205, 170, 0.75);
}
.tb.sm {
  width: 54px;
  height: 54px;
  font-size: 10px;
}
.tb.down {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.38);
}
.tb.off {
  opacity: 0.32;
}
.tb.hide {
  display: none;
}
#tA {
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
}
#tB {
  right: calc(124px + env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
}
#tC {
  right: calc(37px + env(safe-area-inset-right));
  bottom: calc(128px + env(safe-area-inset-bottom));
}
#tD {
  right: calc(101px + env(safe-area-inset-right));
  bottom: calc(110px + env(safe-area-inset-bottom));
}
#tE {
  right: calc(160px + env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
}
#tF {
  right: calc(200px + env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
}
#rotate {
  z-index: 20;
  background: rgba(5, 7, 12, 0.88);
}
/* short landscape screens (phones on their side): keep the menu on one screen */
@media (max-height: 520px) {
  #menu {
    gap: 10px;
    justify-content: flex-start;
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  #menu h1 {
    font-size: 28px;
  }
  #menu p.tag {
    margin: -4px 0 0;
    font-size: 12.5px;
  }
  .modes {
    grid-template-columns: repeat(3, minmax(0, 220px));
    gap: 10px;
  }
  .mode {
    padding: 11px 12px;
    border-radius: 13px;
  }
  .mode b {
    font-size: 15.5px;
    margin-bottom: 4px;
  }
  .mode i {
    font-size: 10.5px;
    margin-bottom: 4px;
  }
  .mode span {
    font-size: 11.5px;
    line-height: 1.35;
  }
  .keys {
    font-size: 11.5px;
    gap: 5px 14px;
  }
  .card {
    padding: 16px 20px;
  }
  .card h2 {
    font-size: 26px;
  }
}
