:root {
  color-scheme: dark;
  --bg: #090914;
  --cabinet: #18122a;
  --panel: #261a46;
  --ink: #fff7d7;
  --muted: #a7b2d8;
  --glass: #15314b;
  --cyan: #6be7ff;
  --green: #8cff7e;
  --pink: #ff72ba;
  --gold: #ffd15f;
  --shadow: #05050a;
}

* {
  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(90deg, rgb(107 231 255 / 0.05) 0 2px, transparent 2px 38px),
    linear-gradient(180deg, #080814 0%, #121628 48%, #21162d 100%);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
}

.cabinet {
  width: min(97vw, 1200px);
  display: grid;
  justify-items: center;
  padding: 14px;
  border: 4px solid #4c3a82;
  background:
    linear-gradient(180deg, rgb(39 24 74 / 0.96), rgb(15 13 31 / 0.98)),
    var(--cabinet);
  box-shadow:
    0 0 0 4px var(--shadow),
    0 24px 70px rgb(0 0 0 / 0.55);
}

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

.cabinet:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: stretch;
  justify-items: stretch;
  padding: 10px;
  border-width: 0;
  box-shadow: none;
}

.cabinet:fullscreen .legend,
.cabinet:-webkit-full-screen .legend {
  margin-bottom: 8px;
}

.cabinet:fullscreen .stage-shell,
.cabinet:-webkit-full-screen .stage-shell {
  align-self: center;
  justify-self: center;
  width: min(100%, (100vh - 78px) * 4 / 3);
  height: auto;
  min-height: 0;
  aspect-ratio: 4 / 3;
}

.cabinet:fullscreen canvas,
.cabinet:-webkit-full-screen canvas {
  width: 100%;
  height: 100%;
}

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

.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(--cyan);
  text-decoration: none;
  text-transform: uppercase;
  border: 2px solid var(--shadow);
  background:
    linear-gradient(180deg, rgb(107 231 255 / 18%), transparent 58%),
    #202032;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 0.24),
    2px 2px 0 var(--shadow);
  -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 var(--shadow);
}

.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 var(--shadow);
}

.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(107 231 255 / 30%), transparent 58%),
    #263a5c;
}

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

.cabinet:fullscreen .settings-button,
.cabinet:-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 var(--shadow);
  background:
    linear-gradient(180deg, rgb(255 209 95 / 18%), transparent 58%),
    #202032;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 0.24),
    2px 2px 0 var(--shadow);
}

.cabinet:fullscreen .arcade-back-button,
.cabinet:-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;
  }
}

.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 var(--shadow);
  background: #202032;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.24);
  font-weight: 700;
  white-space: nowrap;
  cursor: help;
  -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 var(--shadow);
  background: rgb(32 32 50 / 0.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 / 0.24),
    3px 3px 0 var(--shadow);
  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: var(--shadow);
  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 var(--shadow);
}

.settings-button {
  position: relative;
  color: var(--cyan);
}

.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 var(--shadow);
  background: currentColor;
  transform: translate(-50%, -50%);
}

.pause-button {
  color: var(--gold);
}

.game-meta {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 3;
  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);
}

.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 var(--shadow);
}

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

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

.plush-counter {
  position: absolute;
  left: 8px;
  bottom: 18px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  padding: 3px 8px;
  border: 2px solid var(--shadow);
  background: rgb(8 10 24 / 0.78);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 var(--shadow);
  pointer-events: none;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.24);
}

.plush-counter strong {
  color: var(--gold);
}

.stage-shell {
  position: relative;
  width: min(100%, 1200px);
  aspect-ratio: 4 / 3;
  margin-inline: auto;
  border: 4px solid #2d244f;
  background: #050913;
  overflow: hidden;
  box-shadow:
    inset 0 0 28px rgb(107 231 255 / 0.12),
    0 0 0 3px var(--shadow);
}

.game-score {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 2px;
  color: var(--gold);
  line-height: 1;
  pointer-events: none;
  text-align: center;
  text-shadow:
    2px 0 0 #5d3155,
    0 2px 0 #5d3155,
    3px 3px 0 var(--shadow);
  transform: translateX(-50%);
}

.game-score-label {
  color: var(--ink);
  font-size: clamp(10px, 2vw, 13px);
  font-weight: 900;
  text-transform: uppercase;
}

.game-score-value {
  font-size: clamp(38px, 7vw, 68px);
  font-weight: 900;
}

.time-warning {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 2px;
  transform: translate(-50%, -50%);
  color: #ff6f7d;
  line-height: 1;
  text-align: center;
  text-shadow:
    4px 0 0 #5d1320,
    0 4px 0 #5d1320,
    4px 4px 0 var(--shadow),
    0 0 18px rgb(255 111 125 / 0.7);
  pointer-events: none;
  animation: timer-bump 0.34s steps(2, end) infinite alternate;
}

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

.time-warning-label {
  color: var(--ink);
  font-size: clamp(14px, 3vw, 22px);
  font-weight: 900;
  text-transform: uppercase;
}

.time-warning-value {
  font-size: clamp(72px, 19vw, 148px);
  font-weight: 900;
}

@keyframes timer-bump {
  from {
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    transform: translate(-50%, -50%) scale(1.06);
  }
}

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 / 0.68);
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

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

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

.settings-panel {
  width: min(100%, 380px);
  padding: 16px;
  border: 4px solid var(--shadow);
  background: #1a1a2a;
  box-shadow:
    0 0 0 4px #30304a,
    8px 8px 0 rgb(5 5 10 / 0.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;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 var(--shadow);
}

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

.settings-row,
.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 var(--shadow);
}

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

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

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

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

.settings-slider::-moz-range-track {
  height: 18px;
  border: 3px solid var(--shadow);
  border-radius: 0;
  background: linear-gradient(180deg, #222638, #171927);
}

.settings-action {
  width: 100%;
  margin-top: 8px;
  text-transform: uppercase;
}

.settings-home {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 3px solid var(--shadow);
  color: var(--gold);
  background: #5d3155;
  font: inherit;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  text-shadow: 2px 2px 0 var(--shadow);
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.28);
}

.settings-home:active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgb(0 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: 900;
  line-height: 1;
  text-shadow: 2px 2px 0 var(--shadow);
}

.message h1,
.overlay-panel 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,
.overlay-panel p {
  margin: 8px 0;
  color: var(--ink);
  font-size: clamp(13px, 2.7vw, 17px);
  font-weight: 700;
  line-height: 1.45;
}

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

button {
  min-height: 48px;
  border: 3px solid var(--shadow);
  border-radius: 0;
  color: var(--ink);
  background: #30304a;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.28);
}

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

.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 var(--shadow);
}

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

.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;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-right: 9px solid transparent;
  border-bottom: 13px solid currentColor;
  border-left: 9px solid transparent;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

@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;
  }

  .cabinet {
    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% - 162px);
    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: var(--shadow);
    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-shell {
    align-self: start;
    justify-self: center;
    width: min(100vw, calc((100dvh - var(--mobile-controls-reserve) - 86px) * 16 / 21));
    height: auto;
    max-width: 100vw;
    min-height: 0;
    margin-top: 0;
    aspect-ratio: 16 / 21;
    border-left-width: 0;
    border-right-width: 0;
  }

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

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

  .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;
  }

  .overlay {
    z-index: 6;
  }

  .overlay-panel h1 {
    font-size: 32px;
  }

  .overlay-panel 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 / 0.54) 24%,
        rgb(29 32 40 / 0.94) 25%,
        rgb(29 32 40 / 0.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(107 231 255 / 0.42);
    border-radius: 50%;
    background: rgb(8 8 14 / 0.18);
    box-shadow: inset 0 0 0 2px rgb(8 8 14 / 0.56);
  }

  .mobile-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    border: 3px solid var(--shadow);
    border-radius: 50%;
    background: rgb(63 125 255 / 0.88);
    box-shadow: inset 0 -3px 0 rgb(8 8 14 / 0.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 / 0.62);
    background: rgb(8 8 14 / 0.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 / 0.94);
    box-shadow: inset 0 -5px 0 rgb(8 8 14 / 0.24);
  }

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