:root {
  color-scheme: dark;
  --bg: #101018;
  --panel: #202032;
  --ink: #f4f1d8;
  --muted: #aab0c4;
  --blue: #69b8ff;
  --cyan: #70d7ff;
  --gold: #ffd15c;
  --yellow: #ffe45c;
  --danger: #ff6f7d;
  --green: #89d672;
  --shadow: #08080e;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  height: 100%;
  margin: 0;
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  min-height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(180deg, #111421 0%, #142234 58%, #18172b 100%);
  background-size: 24px 24px, 24px 24px, auto;
}

button,
a {
  font: inherit;
}

.machine {
  width: min(97vw, 1200px);
  padding: 14px;
  border: 4px solid #383852;
  background: #161622;
  box-shadow:
    0 0 0 4px #090910,
    0 24px 80px rgb(0 0 0 / 55%);
}

.machine:fullscreen {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  padding: 10px;
  border-width: 0;
  box-shadow: none;
}

.legend {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.legend-items {
  min-width: 0;
  display: flex;
  flex: 1 1 auto;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 3px;
  scrollbar-width: none;
}

.legend-items::-webkit-scrollbar {
  display: none;
}

.legend-item {
  position: relative;
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: #202032;
  border: 2px solid #08080e;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    2px 2px 0 #08080e;
}

.legend-item::after {
  position: fixed;
  left: 50vw;
  top: 54px;
  z-index: 40;
  width: max-content;
  max-width: min(260px, 72vw);
  padding: 7px 8px;
  color: #08080e;
  content: attr(data-tooltip);
  background: var(--gold);
  box-shadow: 3px 3px 0 #08080e;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  text-transform: none;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

.legend-item::before {
  position: fixed;
  left: 50vw;
  top: 44px;
  z-index: 41;
  border: 6px solid transparent;
  border-bottom-color: #08080e;
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

.legend-item:focus-visible::before,
.legend-item:focus-visible::after,
.legend-item:hover::before,
.legend-item:hover::after,
.legend-item.is-tooltip-visible::before,
.legend-item.is-tooltip-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.legend-icon {
  width: 24px;
  height: 24px;
  display: block;
  image-rendering: pixelated;
}

.legend-item.is-boosted {
  border-color: var(--gold);
  animation: boostLegendPulse 0.62s ease-in-out infinite alternate;
}

.legend-item.is-boosted .legend-text {
  color: var(--gold);
  text-shadow:
    2px 2px 0 #08080e,
    0 0 8px rgb(255 209 92 / 82%);
}

@keyframes boostLegendPulse {
  from {
    box-shadow:
      inset 0 -3px 0 rgb(0 0 0 / 24%),
      2px 2px 0 #08080e,
      0 0 0 rgb(255 209 92 / 0%);
    transform: translateY(0);
  }

  to {
    box-shadow:
      inset 0 -3px 0 rgb(0 0 0 / 24%),
      2px 2px 0 #08080e,
      0 0 12px rgb(255 209 92 / 76%);
    transform: translateY(-1px);
  }
}

.legend-control {
  flex: 0 0 auto;
  width: 34px;
  min-height: 30px;
  padding: 0;
  color: var(--gold);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  border: 2px solid #08080e;
  background:
    linear-gradient(180deg, rgb(255 209 92 / 18%), transparent 58%),
    #202032;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    2px 2px 0 #08080e;
  cursor: pointer;
}

.arcade-back-button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  width: auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  color: var(--blue);
  text-decoration: none;
}

.arcade-back-icon {
  display: block;
  font-size: 34px;
  line-height: 0.72;
  transform: translateY(-1px);
  text-shadow: 2px 2px 0 #08080e;
}

.arcade-back-text {
  display: block;
  color: var(--gold);
  font-size: 12px;
  line-height: 1;
  text-shadow: 2px 2px 0 #08080e;
}

.settings-button {
  position: relative;
}

.settings-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  background: currentColor;
  transform: translate(-50%, -50%) scale(0.55);
  box-shadow:
    0 -10px 0 currentColor,
    0 10px 0 currentColor,
    -10px 0 0 currentColor,
    10px 0 0 currentColor,
    -7px -7px 0 currentColor,
    7px -7px 0 currentColor,
    -7px 7px 0 currentColor,
    7px 7px 0 currentColor,
    -4px -4px 0 2px currentColor,
    4px -4px 0 2px currentColor,
    -4px 4px 0 2px currentColor,
    4px 4px 0 2px currentColor;
}

.settings-icon::before {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  content: "";
  border: 2px solid #08080e;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.machine:fullscreen .arcade-back-button,
.machine:-webkit-full-screen .arcade-back-button {
  display: none;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-inline: auto;
  overflow: hidden;
  border: 4px solid #08080e;
  background: #080812;
}

.machine:fullscreen .stage-wrap {
  align-self: center;
  justify-self: center;
  width: auto;
  height: auto;
  min-height: 0;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.game-meta {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(12px, 2vw, 16px);
}

.hud-box,
.banana-counter {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-shadow: 2px 2px 0 #08080e;
}

.hud-box strong,
.banana-counter strong {
  color: var(--gold);
}

.hud-box.is-bumped strong {
  animation: timer-bump 0.34s ease-out;
}

.banana-counter {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  color: var(--ink);
  font-size: clamp(12px, 2vw, 15px);
  font-weight: 900;
  text-transform: uppercase;
  pointer-events: none;
}

.game-score {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 1px;
  transform: translateX(-50%);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.game-score-label {
  color: #f4f1d8;
  font-size: clamp(10px, 2vw, 14px);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.game-score-value {
  color: var(--gold);
  font-size: clamp(28px, 7vw, 52px);
  text-shadow:
    3px 0 0 #5d3155,
    0 3px 0 #5d3155,
    3px 3px 0 #08080e,
    0 0 12px rgb(255 209 92 / 45%);
}

.time-warning {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  justify-items: center;
  color: #fff;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-shadow:
    4px 0 0 #5d1320,
    0 4px 0 #5d1320,
    4px 4px 0 #08080e;
}

.time-warning[hidden] {
  display: none;
}

.time-warning-label {
  color: var(--danger);
  font-size: 22px;
  font-weight: 900;
}

.time-warning-value {
  color: #fff0a8;
  font-size: clamp(56px, 18vw, 118px);
  line-height: 0.88;
}

.effect-strip {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
}

.effect-pill {
  padding: 5px 7px;
  color: #08080e;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--gold);
  box-shadow: 3px 3px 0 #08080e;
}

.stored-bonus {
  position: absolute;
  top: 17.5%;
  right: 8px;
  z-index: 3;
  width: 166px;
  height: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--ink);
  background: rgb(8 8 14 / 82%);
  border-top: 6px solid var(--cyan);
  box-shadow:
    inset 0 -5px 0 #08080e,
    5px 5px 0 #08080e;
  pointer-events: none;
}

.stored-bonus::after {
  position: absolute;
  left: 16px;
  top: 38px;
  width: 134px;
  height: 2px;
  background: rgb(112 215 255 / 32%);
  content: "";
}

.stored-bonus-label {
  height: 34px;
  display: grid;
  place-items: end center;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 3px 3px 0 #08080e;
}

.stored-bonus-icon {
  width: 70px;
  height: 70px;
  margin-top: 6px;
  image-rendering: pixelated;
}

.stored-bonus-empty {
  color: var(--muted);
  margin-top: 10px;
  font-size: 54px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 3px 3px 0 #08080e;
}

.stored-bonus.has-bonus .stored-bonus-empty {
  display: none;
}

.stored-bonus:not(.has-bonus) .stored-bonus-icon {
  display: none;
}

.overlay,
.settings-modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(8 8 18 / 78%);
}

.overlay[hidden],
.settings-modal[hidden] {
  display: none;
}

.message,
.settings-panel {
  width: min(520px, 100%);
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
  border: 4px solid var(--gold);
  background:
    linear-gradient(180deg, rgb(112 215 255 / 14%), transparent 58%),
    #202032;
  box-shadow:
    0 0 0 4px #08080e,
    8px 8px 0 #08080e;
}

.overlay-level {
  margin-bottom: 8px;
  color: var(--green);
  font-weight: 900;
  text-transform: uppercase;
}

.message h1 {
  margin: 0 0 10px;
  color: #fff;
  font-size: clamp(2rem, 8vw, 4.2rem);
  line-height: 0.92;
  text-transform: uppercase;
  text-shadow:
    4px 0 0 #2f9cff,
    -4px 0 0 #f5a623,
    0 5px 0 #08080e;
}

.message p {
  margin: 8px 0;
  font-weight: 700;
  line-height: 1.35;
}

.muted {
  color: var(--muted);
}

.start-button,
.settings-action,
.settings-close {
  min-height: 38px;
  padding: 9px 12px;
  color: #08080e;
  font-weight: 900;
  text-transform: uppercase;
  text-decoration: none;
  background: var(--gold);
  border: 0;
  box-shadow: 4px 4px 0 #08080e;
  cursor: pointer;
}

.start-button {
  min-width: 150px;
  margin-top: 12px;
}

.settings-panel {
  display: grid;
  gap: 12px;
  text-align: left;
}

.settings-header,
.settings-row,
.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-header h2 {
  margin: 0;
  color: var(--gold);
  text-transform: uppercase;
}

.settings-close {
  min-width: 38px;
  padding: 0;
}

.settings-slider {
  width: 100%;
  accent-color: var(--gold);
}

.settings-action {
  display: block;
  width: 100%;
  text-align: center;
}

.settings-home {
  background: var(--blue);
}

.settings-subpanel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 3px solid #08080e;
  background: rgb(8 8 14 / 34%);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 20%);
}

.settings-subpanel[hidden] {
  display: none;
}

.settings-subpanel-header h3 {
  margin: 0;
  color: var(--cyan);
  font-size: 16px;
  text-transform: uppercase;
}

.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.settings-toggle[aria-pressed="true"] {
  background: var(--blue);
}

.settings-toggle strong {
  flex: 0 0 auto;
}

.settings-meta {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.controls {
  display: none;
}

.mobile-joystick,
.jump-button {
  -webkit-tap-highlight-color: transparent;
}

@keyframes timer-bump {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.42);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 560px), (orientation: portrait) {
  :root {
    --mobile-controls-reserve: calc(184px + env(safe-area-inset-bottom));
  }

  body {
    align-items: start;
    min-height: 100dvh;
    overflow: hidden;
    padding: 0;
  }

  .machine {
    width: 100vw;
    height: 100dvh;
    min-width: 0;
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 8px 0 var(--mobile-controls-reserve);
    border-width: 0;
    box-shadow: none;
    overflow: hidden;
  }

  .legend {
    width: 100%;
    min-width: 0;
    padding: 0 8px;
    margin-bottom: 6px;
    font-size: 13px;
    gap: 6px;
  }

  .legend-control {
    width: 48px;
    min-height: 44px;
    font-size: 24px;
  }

  .legend-control .settings-icon {
    transform: translate(-50%, -50%) scale(0.75);
  }

  .legend-items {
    flex-basis: calc(100% - 108px);
    gap: 6px;
  }

  .legend-item {
    padding-right: 6px;
  }

  .stored-bonus {
    top: 10%;
    width: 125px;
    height: 90px;
    border-top-width: 5px;
    box-shadow:
      inset 0 -4px 0 #08080e,
      4px 4px 0 #08080e;
  }

  .stored-bonus::after {
    left: 12px;
    top: 29px;
    width: 101px;
  }

  .stored-bonus-label {
    height: 25px;
    font-size: 19px;
    text-shadow: 3px 3px 0 #08080e;
  }

  .stored-bonus-icon {
    width: 53px;
    height: 53px;
    margin-top: 5px;
  }

  .stored-bonus-empty {
    margin-top: 8px;
    font-size: 40px;
    text-shadow: 3px 3px 0 #08080e;
  }

  .stage-wrap {
    display: grid;
    place-items: center;
    justify-self: stretch;
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    margin-top: 0;
    aspect-ratio: auto;
    border-left-width: 0;
    border-right-width: 0;
  }

  #game {
    justify-self: center;
    align-self: center;
  }

  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    align-items: end;
    justify-content: space-between;
    margin: 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    background:
      linear-gradient(
        180deg,
        rgb(16 16 24 / 0%) 0%,
        rgb(29 32 40 / 54%) 24%,
        rgb(29 32 40 / 94%) 25%,
        rgb(29 32 40 / 94%) 100%
      ),
      repeating-linear-gradient(
        90deg,
        #343842 0 30px,
        #151821 30px 32px,
        #343842 32px 62px,
        #20242d 62px 64px
      );
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
  }

  .controls::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 24px;
    height: 2px;
    background: #7b8490;
    opacity: 0.85;
  }

  .controls::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    top: 31px;
    height: 8px;
    background: repeating-linear-gradient(
      90deg,
      transparent 0 14px,
      #4a505c 14px 24px,
      #4a505c 14px 24px,
      transparent 24px 32px,
      #555d6a 32px 40px,
      transparent 40px 58px
    );
    opacity: 0.95;
  }

  button {
    min-height: 62px;
    font-size: 30px;
  }

  .mobile-joystick {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    width: 128px;
    height: 128px;
    border-radius: 50%;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .mobile-joystick::before {
    content: "";
    position: absolute;
    inset: -64px;
    border-radius: 50%;
    background: transparent;
  }

  .mobile-joystick-ring {
    position: absolute;
    inset: 10px;
    border: 4px solid rgb(112 215 255 / 42%);
    border-radius: 50%;
    background: rgb(8 8 14 / 18%);
    box-shadow: inset 0 0 0 2px rgb(8 8 14 / 56%);
  }

  .mobile-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    border: 3px solid #08080e;
    border-radius: 50%;
    background: rgb(63 125 255 / 88%);
    box-shadow: inset 0 -3px 0 rgb(8 8 14 / 24%);
    transform: translate(-50%, -50%);
    transition: transform 80ms ease-out;
    pointer-events: none;
  }

  .mobile-joystick.is-active .mobile-joystick-ring {
    border-color: rgb(217 247 255 / 62%);
    background: rgb(8 8 14 / 24%);
  }

  .jump-button {
    z-index: 1;
    flex: 0 0 auto;
    width: min(34vw, 156px);
    min-width: 120px;
    min-height: 120px;
    position: relative;
    overflow: hidden;
    border: 4px solid #08080e;
    border-radius: 999px;
    background: rgb(48 48 74 / 94%);
    box-shadow: inset 0 -5px 0 rgb(8 8 14 / 24%);
    color: var(--ink);
    font-size: 0;
    line-height: 0;
    touch-action: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .jump-button::before {
    content: "?";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 4px solid #08080e;
    background: #69b8ff;
    color: #f4f1d8;
    font-size: 34px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 3px 3px 0 #08080e;
    box-shadow:
      inset 0 -5px 0 rgb(8 8 14 / 18%),
      3px 3px 0 #08080e;
    pointer-events: none;
    transform: translate(-50%, -50%);
  }

  .jump-button.is-key-active {
    transform: translateY(2px);
    box-shadow: inset 0 -2px 0 rgb(8 8 14 / 24%);
  }
}
