:root {
  color-scheme: dark;
  --page-bg: #161b24;
  --frame: #f0c34e;
  --frame-dark: #5a3e1b;
  --stage-width: min(calc(100vw - 32px), calc((100dvh - 166px) * 16 / 9), 1600px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--page-bg);
  font-family: "Courier New", Courier, monospace;
}

body {
  display: grid;
  min-height: 100dvh;
}

.game-shell {
  display: grid;
  grid-template-rows: auto auto;
  gap: clamp(12px, 1.6dvh, 20px);
  height: 100dvh;
  min-height: 100dvh;
  place-items: center;
  align-content: center;
  padding: clamp(10px, 1.8dvh, 18px);
  background:
    linear-gradient(180deg, #233143 0%, #22252e 52%, #163323 100%);
}

#game {
  display: block;
  width: var(--stage-width);
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 156px);
  aspect-ratio: 16 / 9;
  border: 4px solid var(--frame);
  background: #8bd4f7;
  box-shadow:
    0 0 0 4px var(--frame-dark),
    0 18px 40px rgb(0 0 0 / 35%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  user-select: none;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 1.2vw, 18px);
  width: var(--stage-width);
  max-width: calc(100vw - 32px);
}

.control-button {
  --power: 0%;
  -webkit-appearance: none;
  appearance: none;
  background-color: #2a3340;
  background-image: none;
  border: 4px solid var(--frame);
  border-radius: 6px;
  color: #fff3c4;
  box-shadow:
    0 0 0 3px var(--frame-dark),
    0 8px 0 #151922;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: clamp(86px, 10dvh, 122px);
  min-width: 0;
  padding: clamp(12px, 1.6dvh, 18px);
  row-gap: 8px;
  text-align: center;
  touch-action: none;
  user-select: none;
  font-family: inherit;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

.control-button span {
  font-size: clamp(22px, 2.2vw, 34px);
  font-weight: 700;
  line-height: 1;
}

.control-button small {
  color: #9fc4d6;
  font-size: clamp(12px, 1vw, 16px);
  line-height: 1;
  min-height: 1em;
}

.control-button:active,
.control-button.is-held {
  transform: translateY(5px);
  box-shadow:
    0 0 0 3px var(--frame-dark),
    0 3px 0 #151922;
}

.control-button.is-full {
  box-shadow:
    0 0 0 3px var(--frame-dark),
    0 0 24px rgb(240 195 78 / 45%),
    0 8px 0 #151922;
}

.control-button.is-held.is-full {
  box-shadow:
    0 0 0 3px var(--frame-dark),
    0 0 24px rgb(240 195 78 / 45%),
    0 3px 0 #151922;
}

.power-track {
  display: block;
  width: 100%;
  height: clamp(9px, 1.2dvh, 14px);
  border: 2px solid #131922;
  background: #15202c;
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 6%);
}

.power-fill {
  display: block;
  width: var(--power);
  height: 100%;
  background: linear-gradient(90deg, #f0c34e 0%, #ef3342 100%);
  transition: width 45ms linear;
}

.jump-button {
  background-color: #293a50;
}

.crouch-button {
  background-color: #2d3d31;
}

button.control-button {
  align-items: stretch;
  width: 100%;
}

noscript {
  position: fixed;
  inset: auto 16px 16px;
  color: #fff7cc;
  text-align: center;
}

.leaderboard-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(8 13 18 / 72%);
}

.leaderboard-modal[hidden] {
  display: none;
}

.leaderboard-card {
  width: min(92vw, 440px);
  border: 4px solid var(--frame);
  border-radius: 6px;
  background: #19242d;
  box-shadow:
    0 0 0 4px var(--frame-dark),
    0 24px 50px rgb(0 0 0 / 45%);
  color: #fff3c4;
  display: grid;
  gap: 12px;
  padding: 22px;
}

.leaderboard-card h2,
.leaderboard-card p {
  margin: 0;
}

.leaderboard-card h2 {
  font-size: 26px;
}

.leaderboard-card p,
.leaderboard-card label {
  color: #c4d9df;
  font-size: 14px;
}

.leaderboard-card input {
  -webkit-appearance: none;
  appearance: none;
  border: 3px solid #f0c34e;
  border-radius: 4px;
  background: #0f161d;
  color: #fff3c4;
  font: 18px "Courier New", Courier, monospace;
  padding: 12px;
}

.leaderboard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.leaderboard-actions button {
  -webkit-appearance: none;
  appearance: none;
  border: 3px solid #f0c34e;
  border-radius: 4px;
  background: #e53740;
  color: #fff3c4;
  cursor: pointer;
  font: 700 15px "Courier New", Courier, monospace;
  padding: 12px;
}

.leaderboard-actions button:last-child {
  background: #293a50;
}

@media (max-width: 700px) {
  :root {
    --stage-width: min(calc(100vw - 16px), calc((100dvh - 130px) * 16 / 9));
  }

  .game-shell {
    padding: 8px;
    gap: 8px;
  }

  #game {
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 122px);
    border-width: 3px;
  }

  .controls {
    gap: 8px;
    max-width: calc(100vw - 16px);
  }

  .control-button {
    min-height: 74px;
    border-width: 3px;
    padding: 10px;
    row-gap: 6px;
  }

  .control-button span {
    font-size: 20px;
  }

  .control-button small {
    font-size: 11px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  :root {
    --stage-width: min(calc(100vw - 24px), calc((100dvh - 108px) * 16 / 9), 1500px);
  }

  .game-shell {
    gap: 8px;
    padding: 8px 12px;
  }

  #game {
    max-height: calc(100dvh - 104px);
  }

  .control-button {
    min-height: 72px;
    padding: 8px 12px;
    row-gap: 5px;
  }
}
