:root {
  color-scheme: dark;
  --bg: #101018;
  --panel: #202032;
  --ink: #f4f1d8;
  --muted: #9aa0b8;
  --green: #89d672;
  --blue: #69b8ff;
  --gold: #ffd15c;
  --danger: #ff6f7d;
}

* {
  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;
  background: linear-gradient(180deg, #111421 0%, #171627 58%, #211a2d 100%);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
}

.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);
  padding: 10px;
  border-width: 0;
  box-shadow: none;
}

.machine:fullscreen .stage-wrap {
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
}

.machine:fullscreen .legend {
  margin-bottom: 8px;
}

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

body.is-niveau2 .hud-box,
body.is-niveau2 .hud-box strong,
body.is-niveau2 .game-score-label,
body.is-niveau2 .game-score-value,
body.is-niveau2 .legend-text {
  color: var(--blue);
}

body.is-niveau2 .hud-box,
body.is-niveau2 .hud-box strong,
body.is-niveau2 .game-score-label,
body.is-niveau2 .game-score-value,
body.is-niveau2 .legend-text {
  text-shadow: 2px 2px 0 #245bba;
}

body.is-niveau3 .hud-box,
body.is-niveau3 .hud-box strong,
body.is-niveau3 .game-score-label,
body.is-niveau3 .game-score-value,
body.is-niveau3 .legend-text {
  color: #c77dff;
}

body.is-niveau3 .hud-box,
body.is-niveau3 .hud-box strong,
body.is-niveau3 .game-score-label,
body.is-niveau3 .game-score-value,
body.is-niveau3 .legend-text {
  text-shadow: 2px 2px 0 #5b2cc9;
}

body.is-niveau4 .hud-box,
body.is-niveau4 .hud-box strong,
body.is-niveau4 .game-score-label,
body.is-niveau4 .game-score-value,
body.is-niveau5 .hud-box,
body.is-niveau5 .hud-box strong,
body.is-niveau5 .game-score-label,
body.is-niveau5 .game-score-value,
body.is-niveau5 .legend-text,
body.is-niveau6 .hud-box,
body.is-niveau6 .hud-box strong,
body.is-niveau6 .game-score-label,
body.is-niveau6 .game-score-value,
body.is-niveau6 .legend-text,
body.is-niveau4 .legend-text {
  color: var(--danger);
}

body.is-niveau4 .hud-box,
body.is-niveau4 .hud-box strong,
body.is-niveau4 .game-score-label,
body.is-niveau4 .game-score-value,
body.is-niveau5 .hud-box,
body.is-niveau5 .hud-box strong,
body.is-niveau5 .game-score-label,
body.is-niveau5 .game-score-value,
body.is-niveau5 .legend-text,
body.is-niveau6 .hud-box,
body.is-niveau6 .hud-box strong,
body.is-niveau6 .game-score-label,
body.is-niveau6 .game-score-value,
body.is-niveau6 .legend-text,
body.is-niveau4 .legend-text {
  text-shadow: 2px 2px 0 #5d1320;
}

.legend-control {
  flex: 0 0 auto;
  width: 34px;
  min-height: 30px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.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;
  max-width: calc(100vw - 24px);
  color: var(--blue);
  text-decoration: none;
  text-transform: uppercase;
  border: 2px solid #08080e;
  background:
    linear-gradient(180deg, rgb(105 184 255 / 18%), transparent 58%),
    #202032;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    2px 2px 0 #08080e;
  -webkit-tap-highlight-color: transparent;
}

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

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

.arcade-back-button:hover .arcade-back-text,
.arcade-back-button:focus-visible .arcade-back-text {
  animation: arcade-back-blink 1.6s steps(2, end) infinite;
}

.arcade-back-button:hover,
.arcade-back-button:focus-visible {
  color: #d9f7ff;
  background:
    linear-gradient(180deg, rgb(112 215 255 / 28%), transparent 58%),
    #1f3658;
}

.arcade-back-button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.machine:fullscreen .settings-button,
.machine:-webkit-full-screen .settings-button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 31;
  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;
}

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

@keyframes arcade-back-blink {
  0%,
  100% {
    opacity: 1;
    color: var(--gold);
  }

  50% {
    opacity: 0.62;
    color: #d9f7ff;
  }
}

@media (prefers-reduced-motion: reduce) {
  .arcade-back-text {
    animation: none;
  }
}

.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 {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border: 2px solid #08080e;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.debug-panel {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  align-items: center;
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  border: 2px solid #70d7ff;
  background: rgb(8 8 14 / 86%);
  color: #d9f7ff;
  font-size: 11px;
  text-transform: uppercase;
  box-shadow: 2px 2px 0 #08080e;
}

.debug-panel[hidden] {
  display: none;
}

.debug-panel button {
  min-height: 32px;
  font-size: 12px;
  background: #1f3658;
}

.debug-panel strong {
  color: #ffd15c;
}

.gamepad-popup {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  width: min(300px, 30vw);
  min-width: 220px;
  padding: 12px;
  border: 3px solid #70d7ff;
  background: rgb(8 8 14 / 92%);
  color: #d9f7ff;
  font-size: 12px;
  box-shadow: 4px 4px 0 #08080e;
}

.gamepad-popup[hidden] {
  display: none;
}

.gamepad-popup h2 {
  margin: 0;
  color: #ffd15c;
  font-size: 18px;
  line-height: 1;
  text-transform: uppercase;
}

.gamepad-readout {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.35;
}

@media (max-width: 760px) {
  .gamepad-popup {
    top: 8px;
    right: 8px;
    bottom: 8px;
    width: min(220px, 46vw);
    min-width: 0;
    font-size: 10px;
  }

  .gamepad-popup h2 {
    font-size: 14px;
  }
}

.hud-box {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0;
  text-align: center;
  white-space: nowrap;
  text-shadow: 2px 2px 0 #08080e;
}

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

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

.hud-label {
  display: inline-block;
}

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

.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;
  text-align: center;
  pointer-events: none;
}

.game-score.is-on-fire {
  animation: scoreFireShake 0.26s steps(2, end) infinite alternate;
}

.game-score.is-on-fire::before,
.game-score.is-on-fire::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  z-index: 0;
  width: calc(100% + 18px);
  height: 26px;
  image-rendering: pixelated;
  pointer-events: none;
  transform: translateX(-50%);
  animation: scorePixelFire 0.32s steps(2, end) infinite;
}

.game-score.is-on-fire::before {
  background: linear-gradient(
    90deg,
    transparent 0 5%,
    #5d1320 5% 10%,
    #e9434f 10% 16%,
    transparent 16% 22%,
    #ff6f00 22% 30%,
    transparent 30% 36%,
    #e9434f 36% 44%,
    #ffd15c 44% 49%,
    transparent 49% 56%,
    #ff6f00 56% 65%,
    transparent 65% 72%,
    #e9434f 72% 80%,
    #ffd15c 80% 84%,
    transparent 84% 91%,
    #ff6f00 91% 96%,
    transparent 96% 100%
  );
  clip-path: polygon(
    0 100%,
    0 72%,
    8% 72%,
    8% 44%,
    14% 44%,
    14% 100%,
    22% 100%,
    22% 18%,
    30% 18%,
    30% 100%,
    38% 100%,
    38% 50%,
    47% 50%,
    47% 100%,
    56% 100%,
    56% 24%,
    65% 24%,
    65% 100%,
    73% 100%,
    73% 36%,
    82% 36%,
    82% 100%,
    91% 100%,
    91% 52%,
    100% 52%,
    100% 100%
  );
}

.game-score.is-on-fire::after {
  bottom: 16px;
  width: calc(100% - 4px);
  height: 14px;
  background: linear-gradient(
    90deg,
    transparent 0 13%,
    #ffffff 13% 16%,
    #ffd15c 16% 22%,
    transparent 22% 34%,
    #ffd15c 34% 41%,
    transparent 41% 52%,
    #ffffff 52% 55%,
    #ffd15c 55% 62%,
    transparent 62% 75%,
    #ffd15c 75% 82%,
    transparent 82% 100%
  );
  clip-path: polygon(
    0 100%,
    12% 100%,
    12% 42%,
    20% 42%,
    20% 100%,
    34% 100%,
    34% 18%,
    43% 18%,
    43% 100%,
    53% 100%,
    53% 34%,
    63% 34%,
    63% 100%,
    75% 100%,
    75% 28%,
    84% 28%,
    84% 100%,
    100% 100%
  );
  opacity: 0.95;
  animation-direction: reverse;
}

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

.game-score-value {
  position: relative;
  display: inline-block;
  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%);
}

.game-score.is-on-fire .game-score-label,
.game-score.is-on-fire .game-score-value {
  position: relative;
  z-index: 1;
  color: #ffd15c;
  animation: scoreFireText 0.34s steps(2, end) infinite alternate;
  text-shadow:
    2px 0 0 #5d1320,
    0 2px 0 #5d1320,
    2px 2px 0 #08080e,
    0 -1px 0 #ffffff,
    1px -2px 0 #ff6f00;
}

.game-score.is-on-fire .game-score-value {
  color: #fff0a8;
  text-shadow:
    3px 0 0 #5d1320,
    0 3px 0 #5d1320,
    3px 3px 0 #08080e,
    0 -2px 0 #ffd15c,
    2px -4px 0 #ff6f00,
    -2px -5px 0 #e9434f;
}

@keyframes scoreFireText {
  from {
    filter: none;
  }
  to {
    filter: brightness(1.25);
  }
}

@keyframes scoreFireShake {
  from {
    transform: translateX(-50%) translateY(0);
  }
  to {
    transform: translateX(-50%) translateY(-1px);
  }
}

@keyframes scorePixelFire {
  from {
    transform: translateX(-50%) translateY(0);
  }
  to {
    transform: translateX(-50%) translateY(-3px);
  }
}

.time-warning {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 2px;
  transform: translate(-50%, -50%);
  color: #ff334d;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  pointer-events: none;
  animation: warning-pulse 0.5s steps(2, end) infinite;
}

.record-flash {
  position: absolute;
  top: 34%;
  left: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  color: #ffd15c;
  font-weight: 700;
  font-size: clamp(16px, 4vw, 30px);
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  text-shadow:
    3px 0 0 #5d3155,
    0 3px 0 #5d3155,
    3px 3px 0 #08080e,
    0 0 16px rgb(255 209 92 / 70%);
  animation: record-pop 0.75s steps(2, end) infinite;
}

.record-flash[hidden] {
  display: none;
}

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

.time-warning-label {
  font-size: clamp(12px, 2.5vw, 18px);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.time-warning-value {
  font-size: clamp(46px, 12vw, 82px);
  text-shadow:
    3px 0 0 #5d1320,
    0 3px 0 #5d1320,
    3px 3px 0 #08080e,
    0 0 14px rgb(255 51 77 / 55%);
}

@keyframes warning-pulse {
  50% {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes timer-bump {
  40% {
    transform: scale(1.35);
    color: #f3d8ff;
    text-shadow: 0 0 10px rgb(199 125 255 / 85%);
  }
}

@keyframes record-pop {
  50% {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #101018;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(8 8 14 / 68%);
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

.settings-modal {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(8 8 14 / 74%);
}

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

.settings-panel {
  width: min(100%, 360px);
  padding: 16px;
  border: 4px solid #08080e;
  background: #1a1a2a;
  box-shadow:
    0 0 0 4px #30304a,
    8px 8px 0 rgb(8 8 14 / 86%);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-header h2 {
  margin: 0;
  color: var(--gold);
  font-size: 22px;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.settings-close {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 20px;
}

.settings-row,
.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.settings-row {
  margin-top: 10px;
}

.settings-value,
.settings-meta strong {
  color: var(--gold);
}

.settings-slider {
  width: 100%;
  margin: 6px 0 8px;
  appearance: none;
  -webkit-appearance: none;
  height: 18px;
  border: 3px solid #08080e;
  background: linear-gradient(180deg, #222638, #171927);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 24%);
}

.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 28px;
  border: 3px solid #08080e;
  background: var(--gold);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 24%);
  cursor: ew-resize;
}

.settings-slider::-moz-range-thumb {
  width: 18px;
  height: 28px;
  border: 3px solid #08080e;
  border-radius: 0;
  background: var(--gold);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 24%);
  cursor: ew-resize;
}

.settings-slider::-moz-range-track {
  height: 18px;
  border: 3px solid #08080e;
  border-radius: 0;
  background: linear-gradient(180deg, #222638, #171927);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 24%);
}

.settings-action {
  width: 100%;
  margin-top: 6px;
  background: #30304a;
  color: var(--ink);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.settings-home {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 3px solid #08080e;
  background: #5d3155;
  color: var(--gold);
  font:
    700 20px/1 "Courier New",
    Courier,
    monospace;
  text-align: center;
  text-decoration: none;
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 28%);
}

.settings-home:active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 28%);
}

.message {
  max-width: 460px;
}

.overlay-level {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: clamp(13px, 3vw, 18px);
  font-weight: 700;
  line-height: 1;
  text-shadow: 2px 2px 0 #08080e;
}

.overlay-level.is-level-2 {
  color: var(--blue);
  text-shadow: 2px 2px 0 #245bba;
}

.overlay-level.is-level-3 {
  color: #c77dff;
  text-shadow: 2px 2px 0 #5b2cc9;
}

.overlay-level.is-level-4 {
  color: var(--danger);
  text-shadow: 2px 2px 0 #5d1320;
}

.overlay-level.is-level-5 {
  color: var(--danger);
  text-shadow: 2px 2px 0 #5d1320;
}

.overlay-level.is-level-6 {
  color: var(--danger);
  text-shadow: 2px 2px 0 #5d1320;
}

.message h1 {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: clamp(24px, 6vw, 44px);
  line-height: 1;
  text-shadow: 4px 4px 0 #5d3155;
}

.message p {
  margin: 8px 0;
  color: var(--ink);
  font-size: clamp(13px, 2.7vw, 17px);
  line-height: 1.45;
}

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

.start-button {
  min-width: min(260px, 100%);
  margin-top: 14px;
  padding: 0 18px;
  background: #5d3155;
  color: var(--gold);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.start-button[hidden] {
  display: none;
}

.controls {
  display: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  min-height: 48px;
  border: 3px solid #08080e;
  background: #30304a;
  color: var(--ink);
  font:
    700 20px/1 "Courier New",
    Courier,
    monospace;
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 28%);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button:active,
button.is-key-active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 28%);
}

.controls .jump-button {
  position: relative;
  overflow: hidden;
  color: var(--ink);
  font-size: 0;
  line-height: 0;
  touch-action: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

.controls .jump-button::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.controls .jump-button::before {
  border-right: 9px solid transparent;
  border-bottom: 13px solid currentColor;
  border-left: 9px solid transparent;
}

.mobile-joystick,
.mobile-joystick * {
  box-sizing: border-box;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 13px;
  text-align: center;
}

.legend-items {
  display: flex;
  flex: 1 1 460px;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: center;
  min-width: 0;
}

.legend-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 2px 8px 2px 4px;
  border: 2px solid #08080e;
  background: #202032;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 24%);
  font-weight: 700;
  white-space: nowrap;
  cursor: help;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.legend-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 12;
  width: max-content;
  max-width: min(260px, 84vw);
  padding: 7px 9px;
  border: 2px solid #08080e;
  background: rgb(32 32 50 / 97%);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  text-transform: none;
  white-space: normal;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    3px 3px 0 #08080e;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

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

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

.legend-item:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

.legend-text {
  color: var(--gold);
  text-shadow: 2px 2px 0 #08080e;
}

.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%),
      0 0 0 rgb(255 209 92 / 0%);
    transform: translateY(0);
  }

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

@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-height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 8px 0 var(--mobile-controls-reserve);
    border-width: 0;
    box-shadow: none;
  }

  .legend {
    padding: 0 8px;
    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;
  }

  .legend-item::after {
    top: calc(100% + 8px);
    bottom: auto;
    font-size: 11px;
    transform: translate(-50%, -4px);
  }

  .legend-item::before {
    top: calc(100% + 2px);
    bottom: auto;
    border-top-color: transparent;
    border-bottom-color: #08080e;
    transform: translate(-50%, -4px);
  }

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

  .stage-wrap {
    width: 100vw;
    height: 100%;
    min-height: 0;
    margin-top: 0;
    aspect-ratio: auto;
    border-left-width: 0;
    border-right-width: 0;
  }

  .game-meta {
    font-size: 16px;
  }

  .hud-box {
    min-height: 48px;
    font-size: 16px;
  }

  .game-score-label {
    font-size: 15px;
  }

  .game-score {
    top: 64px;
  }

  .game-score-value {
    font-size: 56px;
  }

  .time-warning-label {
    font-size: 16px;
  }

  .time-warning-value {
    font-size: 72px;
  }

  .record-flash {
    font-size: 24px;
  }

  .stage-wrap:has(.overlay:not([hidden])) .game-score {
    opacity: 0;
  }

  .overlay {
    z-index: 6;
  }

  .overlay-level {
    font-size: 16px;
  }

  .message h1 {
    font-size: 32px;
  }

  .message p {
    font-size: 16px;
  }

  .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,
      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%);
  }

  .mobile-jump {
    z-index: 1;
    flex: 0 0 auto;
    width: min(34vw, 156px);
    min-width: 120px;
    min-height: 120px;
    border-radius: 999px;
    border-width: 4px;
    background: rgb(48 48 74 / 94%);
    box-shadow: inset 0 -5px 0 rgb(8 8 14 / 24%);
  }

  .mobile-jump::before {
    border-right-width: 14px;
    border-bottom-width: 20px;
    border-left-width: 14px;
  }
}
