:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #201621;
  --ink: #fff3e8;
  --muted: #bca9b4;
  --blue: #5bb8ff;
  --cyan: #4ee7ff;
  --gold: #ff4f64;
  --yellow: #ffb84d;
  --danger: #ff6f7d;
  --green: #8effd2;
  --red: #e9434f;
  --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.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(180deg, #070c18 0%, #18253e 46%, #2a1328 100%);
  background-size: 24px 24px, 24px 24px, auto;
}

button,
a {
  font: inherit;
}

.machine {
  width: min(97vw, 1200px);
  padding: 14px;
  border: 4px solid #383852;
  background:
    linear-gradient(180deg, rgb(255 79 100 / 10%), transparent 42%),
    #15101b;
  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;
  touch-action: pan-x;
}

.legend-items {
  min-width: 0;
  display: flex;
  flex: 1 1 auto;
  justify-content: flex-start;
  gap: 8px;
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  padding: 3px;
  scrollbar-width: none;
  touch-action: pan-x;
}

.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:
    linear-gradient(180deg, rgb(91 184 255 / 10%), transparent 58%),
    #221827;
  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: #ff6a7a;
  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;
}

@keyframes boostLegendPulse {
  from {
    box-shadow:
      inset 0 -3px 0 rgb(0 0 0 / 24%),
      2px 2px 0 #08080e,
      0 0 0 rgb(255 79 100 / 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 79 100 / 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 79 100 / 22%), transparent 58%),
    #221827;
  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;
  max-width: calc(100vw - 24px);
  color: var(--gold);
  text-decoration: none;
  border: 2px solid #08080e;
  background:
    linear-gradient(180deg, rgb(255 79 100 / 24%), transparent 58%),
    #221827;
  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(--yellow);
  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(255 111 125 / 32%), transparent 58%),
    #3a1728;
}

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

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

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

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

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

.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 {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-shadow: 2px 2px 0 #08080e;
}

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

.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 #2f9cff,
    0 3px 0 #711827,
    3px 3px 0 #08080e,
    0 0 12px rgb(255 79 100 / 44%);
}

.newspaper-counter {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 4px 7px 4px 5px;
  color: var(--ink);
  font-size: clamp(16px, 4vw, 24px);
  font-weight: 900;
  line-height: 1;
  background: rgb(8 8 14 / 72%);
  border-top: 3px solid var(--blue);
  box-shadow: 3px 3px 0 #08080e;
  pointer-events: none;
}

.newspaper-counter-icon {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
}

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

.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: #ff6a7a;
  box-shadow: 3px 3px 0 #08080e;
}

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

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

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

.stored-bonus-empty {
  color: var(--muted);
  margin-top: 6px;
  font-size: 46px;
  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;
}

.settings-modal {
  position: fixed;
  z-index: 100;
  background: rgb(8 8 18 / 68%);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.settings-panel {
  max-height: calc(100dvh - 36px);
  overflow: auto;
}

.message,
.settings-panel {
  width: min(520px, 100%);
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
  border: 4px solid #ff4f64;
  background:
    linear-gradient(180deg, rgb(91 184 255 / 14%), transparent 48%),
    linear-gradient(140deg, rgb(255 79 100 / 16%), transparent 66%),
    #201621;
  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 #ff4f64,
    0 5px 0 #08080e;
}

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

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

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

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

.debug-choice {
  display: grid;
  gap: 6px;
}

.debug-panel strong,
.debug-choice span {
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.debug-choice-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.debug-option {
  min-height: 32px;
  padding: 6px 9px;
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
  background: #1f3658;
  border: 2px solid #08080e;
  box-shadow:
    inset 0 -2px 0 rgb(0 0 0 / 26%),
    2px 2px 0 #08080e;
  cursor: pointer;
}

.debug-option.is-selected {
  color: #08080e;
  background: #70d7ff;
}

.debug-option:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

@media (max-width: 560px), (orientation: portrait) {
  .debug-panel {
    grid-template-columns: 1fr;
  }
}

.start-button,
.settings-action,
.settings-close {
  min-height: 38px;
  padding: 9px 12px;
  color: #08080e;
  font-weight: 900;
  text-transform: uppercase;
  text-decoration: none;
  background: #ff4f64;
  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,
.settings-header h3 {
  margin: 0;
  color: #fff;
  font-size: 20px;
  text-transform: uppercase;
}

.settings-close {
  min-width: 42px;
  min-height: 36px;
  padding: 0 10px;
}

.settings-pause-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  color: #08080e;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: #5bb8ff;
  box-shadow: 3px 3px 0 #08080e;
}

.settings-label,
.settings-meta span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

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

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

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

.settings-home {
  background: #5bb8ff;
}

.jump-button-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
  transform: translate(-50%, -50%);
}

@media (max-width: 560px), (orientation: portrait) {
  :root {
    --mobile-controls-reserve: 0px;
  }

  .arcade-back-button {
    display: none;
  }

  body {
    display: block;
    min-height: 100dvh;
    overflow: hidden;
    background: #07101f;
  }

  .machine {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    min-width: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 8px 0 0;
    border: 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% - 54px);
    gap: 6px;
  }

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

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

  .game-meta {
    top: var(--mobile-hud-top);
    font-size: var(--mobile-hud-font-size);
  }

  .game-score {
    top: var(--mobile-score-top);
  }

  .game-score-label {
    font-size: var(--mobile-score-label-size);
  }

  .game-score-value {
    font-size: var(--mobile-score-value-size);
  }

  .stored-bonus {
    display: none;
  }

  .newspaper-counter {
    left: 10px;
    bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .controls.mobile-control-reserve {
    left: 50%;
    right: auto;
    bottom: calc(70px + env(safe-area-inset-bottom));
    width: auto;
    height: auto;
    transform: translateX(-50%);
    --mobile-controls-justify: flex-end;
    --mobile-control-size: 84px;
    --mobile-controls-padding: 0;
    overflow: visible;
  }
}
