:root {
  --black: #140f23;
  --ink: #261a39;
  --white: #fff7df;
  --cyan: #30e6ff;
  --lime: #96ff3f;
  --pink: #ff3eb5;
  --purple: #7b48ff;
  --orange: #ff9f1c;
  --red: #ff315a;
  --yellow: #ffe04d;
  --blue: #2f7dff;
  --shadow: 8px 8px 0 #00000042;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--black);
  color: var(--white);
  font-family: "Courier New", "Monaco", monospace;
  image-rendering: pixelated;
}

button {
  font: inherit;
}

.pilot-arcade {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 560px;
  overflow: hidden;
  background: #2f7dff;
}

.pilot-game-canvas,
.pilot-game-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

body.is-playing,
body.is-playing .pilot-arcade,
body.is-playing .pilot-game-canvas,
body.is-playing .pilot-game-canvas canvas {
  cursor: none;
}

.arcade-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(4, 104px);
  gap: 6px;
  align-items: stretch;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  visibility: hidden;
  transition: opacity 120ms linear, transform 120ms linear, visibility 0s linear 120ms;
}

body.is-playing .arcade-hud {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  transition-delay: 0s;
}

.gate-meter,
.hud-counter {
  border: 3px solid var(--black);
  background: var(--white);
  color: var(--black);
  box-shadow: 3px 3px 0 #0000003d;
  text-transform: uppercase;
}

.gate-meter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: center;
  min-height: 22px;
  padding: 0;
  background: var(--white);
}

.gate-track {
  position: relative;
  height: 100%;
  min-height: 22px;
  overflow: hidden;
  background: var(--white);
}

.gate-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--lime);
  box-shadow: inset 0 4px 0 #ffffff75;
  transition: width 120ms linear, background 120ms linear;
}

.gate-meter.is-hit .gate-fill {
  background: var(--red);
}

.gate-meter.is-cleared .gate-fill {
  background: var(--yellow);
}

.gate-percent {
  display: grid;
  place-items: center;
  min-height: 22px;
  border-left: 3px solid var(--black);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.hud-counter {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  gap: 7px;
  padding: 4px 6px;
}

.hud-counter span {
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.hud-counter strong {
  font-size: 19px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.hud-counter.trust { background: #ffe04d; }
.hud-counter.proof { background: #30e6ff; }
.hud-counter.ready { background: #96ff3f; }
.hud-counter.champs { background: #ff9f1c; }

body:not(.is-simulator-mode) .arcade-hud {
  grid-template-columns: minmax(0, 1fr);
}

body:not(.is-simulator-mode) .hud-counter {
  display: none;
}

body:not(.is-simulator-mode) .gate-meter {
  grid-template-columns: minmax(0, 1fr);
  grid-column: 1 / -1;
  overflow: hidden;
}

body:not(.is-simulator-mode) .gate-track,
body:not(.is-simulator-mode) .gate-percent {
  grid-area: 1 / 1;
}

body:not(.is-simulator-mode) .gate-percent {
  position: relative;
  z-index: 1;
  justify-self: end;
  width: 48px;
  height: 100%;
  border-left: 0;
  background: transparent;
}

.hud-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sound-toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  border: 3px solid var(--black);
  background: var(--yellow);
  color: var(--black);
  box-shadow: 3px 3px 0 #0000003d;
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.sound-toggle svg {
  display: block;
  width: 21px;
  height: 21px;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.sound-toggle[aria-pressed="true"] {
  background: var(--white);
  color: #5f5668;
}

.sound-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #0000003d;
}

body.is-playing .sound-toggle {
  cursor: none;
}

.arcade-start,
.arcade-result,
.story-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 15, 35, 0.38);
}

.story-layer {
  z-index: 8;
}

.arcade-start.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.intro-decor {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.arcade-start:not(.is-intro) .intro-decor {
  display: none;
}

.intro-decor img {
  position: absolute;
  display: block;
  image-rendering: pixelated;
  user-select: none;
}

.intro-title-art {
  top: clamp(18px, 4.6vh, 52px);
  left: 50%;
  width: min(760px, 70vw);
  max-height: 26vh;
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(6px 6px 0 rgba(0, 0, 0, 0.24));
}

.intro-champion {
  filter: drop-shadow(6px 6px 0 rgba(0, 0, 0, 0.2));
}

.intro-champion-elephant {
  z-index: 3;
  top: calc(50% - 270px);
  left: 50%;
  width: clamp(128px, 14vw, 184px);
  transform: translateX(-50%);
}

.intro-champion-female {
  top: calc(50% - 220px);
  left: max(18px, calc(50% - 530px));
  width: clamp(132px, 15vw, 210px);
}

.intro-champion-male {
  top: calc(50% - 224px);
  right: max(18px, calc(50% - 540px));
  width: clamp(132px, 15vw, 210px);
}

.arcade-panel {
  position: relative;
  z-index: 2;
  width: min(620px, calc(100vw - 32px));
  border: 6px solid var(--black);
  background: var(--white);
  color: var(--black);
  padding: 24px;
  box-shadow: var(--shadow);
}

.result-panel {
  width: min(760px, calc(100vw - 32px));
}

.arcade-start .arcade-panel,
.arcade-result .arcade-panel {
  text-align: center;
}

.arcade-kicker {
  margin: 0 0 8px;
  color: var(--pink);
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
}

.arcade-panel h1,
.arcade-panel h2 {
  margin: 0;
  font-size: clamp(44px, 8vw, 88px);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
}

.arcade-panel h2 {
  font-size: clamp(34px, 6vw, 60px);
  white-space: nowrap;
}

.arcade-panel p:not(.arcade-kicker) {
  max-width: 54ch;
  margin: 14px 0 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.42;
}

.arcade-start .arcade-panel p:not(.arcade-kicker),
.arcade-result .arcade-panel p:not(.arcade-kicker) {
  margin-right: auto;
  margin-left: auto;
}

.arcade-config {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  margin-right: auto;
  margin-left: auto;
}

.arcade-config-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.arcade-config-row button,
.arcade-primary-action,
.arcade-secondary-action {
  min-height: 48px;
  border: 4px solid var(--black);
  background: #30e6ff;
  color: var(--black);
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 4px 4px 0 #00000033;
}

.arcade-config-row button {
  padding: 0 14px;
  font-size: 20px;
  line-height: 1;
  min-height: 56px;
}

.arcade-config-row button[data-scale-option="boutique"] {
  background: #30a7ff;
}

.arcade-config-row button[data-scale-option="midSize"] {
  background: var(--lime);
}

.arcade-config-row button[data-scale-option="large"] {
  background: #ff9a2e;
}

.arcade-config-row button[data-scale-option="enterprise"] {
  background: #ff4f64;
}

.arcade-config-row button:hover {
  filter: brightness(1.08) saturate(1.06);
}

.arcade-config-row button.is-active {
  background: var(--lime);
}

.arcade-config-row button span {
  margin-left: 6px;
  font-size: 1em;
  line-height: 1;
}

.difficulty-select h1,
.champion-select h1 {
  max-width: 100%;
  font-size: 40px;
  line-height: 0.95;
  white-space: nowrap;
}

.champion-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.champion-card {
  display: grid;
  place-items: center;
  min-height: 206px;
  border: 4px solid var(--black);
  background: #fff2a8;
  box-shadow: 4px 4px 0 #00000033;
  cursor: pointer;
}

.champion-card img {
  display: block;
  width: min(78%, 150px);
  height: 174px;
  object-fit: contain;
  image-rendering: pixelated;
}

.champion-card[data-character-option="elephant"] img {
  width: min(88%, 178px);
}

.champion-select.is-hover-ready .champion-card:hover,
.champion-card.is-active {
  background: var(--lime);
}

.arcade-primary-action {
  width: 100%;
  margin-top: 16px;
  background: var(--pink);
  color: var(--white);
  font-size: 20px;
}

.arcade-secondary-action {
  width: 100%;
  margin-top: 16px;
  background: var(--lime);
  color: var(--black);
  font-size: 20px;
}

.arcade-config-row button:active,
.champion-card:active,
.arcade-primary-action:active,
.arcade-secondary-action:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #00000033;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.result-stats div {
  display: grid;
  gap: 4px;
  border: 4px solid var(--black);
  background: #fff2a8;
  padding: 10px;
  text-align: center;
}

.result-stats span {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.result-stats strong {
  font-size: 18px;
  font-weight: 900;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-actions.is-single-action {
  grid-template-columns: 1fr;
}

.result-actions .arcade-primary-action,
.result-actions .arcade-secondary-action {
  margin-top: 16px;
}

.story-panel {
  --story-block: 230px;
  display: grid;
  grid-template-columns: var(--story-block) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  width: min(620px, calc(100vw - 32px));
  height: 290px;
  max-height: calc(100svh - 32px);
  overflow: auto;
  scrollbar-width: none;
  border: 6px solid var(--black);
  background: var(--white);
  color: var(--black);
  padding: 24px;
  box-shadow: var(--shadow);
}

.story-panel::-webkit-scrollbar {
  display: none;
}

.story-character {
  display: grid;
  place-items: center;
  align-self: start;
  position: relative;
  width: var(--story-block);
  aspect-ratio: 1;
  min-height: 0;
  overflow: hidden;
  border: 4px solid var(--black);
  background: #fff2a8;
  box-shadow: 4px 4px 0 #0000002e;
}

.story-character img {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  max-width: 78%;
  max-height: 80%;
  object-fit: contain;
  image-rendering: pixelated;
  transform: translate(-50%, -50%);
}

.story-character img[src$="-failure.png"] {
  transform: translate(-50%, -52%);
}

.story-copy {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  align-self: stretch;
  gap: 8px;
  height: var(--story-block);
  min-width: 0;
}

.story-text {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  max-width: 100%;
}

.story-copy h2 {
  margin: 0;
  font-size: clamp(25px, 2.7vw, 30px);
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
}

.story-copy p {
  margin: 0;
  font-size: clamp(16px, 1.28vw, 18px);
  font-weight: 800;
  line-height: 1.24;
}

.story-progress {
  display: flex;
  gap: 6px;
  min-height: 10px;
  margin-top: 0;
}

.story-progress span {
  width: 10px;
  height: 10px;
  border: 2px solid var(--black);
  background: var(--white);
}

.story-progress span.is-active {
  background: var(--lime);
}

.story-actions {
  display: grid;
  grid-template-columns: 46px 46px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  margin-top: 0;
}

.story-actions.is-final {
  grid-template-columns: 46px minmax(0, 1fr);
}

.story-arrow,
.story-primary {
  min-height: 46px;
  border: 4px solid var(--black);
  background: var(--cyan);
  color: var(--black);
  cursor: pointer;
  font-weight: 900;
  box-shadow: 4px 4px 0 #00000033;
}

.story-arrow {
  display: grid;
  place-items: center;
  font-size: 28px;
  line-height: 1;
}

.story-arrow:disabled {
  opacity: 0.45;
  cursor: default;
}

.story-primary {
  background: var(--pink);
  color: var(--white);
  font-size: 15px;
  line-height: 1.1;
  padding: 0 14px;
  white-space: normal;
  text-transform: uppercase;
}

.story-arrow:active:not(:disabled),
.story-primary:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #00000033;
}

@media (max-width: 1040px) {
  .arcade-hud {
    grid-template-columns: minmax(180px, 1fr) repeat(4, 96px);
  }

  .gate-meter {
    grid-column: auto;
  }
}

@media (max-width: 680px) {
  .pilot-arcade {
    min-height: 100svh;
  }

  .arcade-hud {
    top: 8px;
    left: 8px;
    right: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .gate-meter,
  .hud-counter {
    border-width: 3px;
    box-shadow: 3px 3px 0 #0000003d;
  }

  .gate-meter {
    grid-column: span 4;
  }

  .hud-counter {
    padding: 5px;
  }

  .hud-counter strong {
    font-size: 15px;
  }

  .arcade-start,
  .arcade-result {
    justify-items: center;
    align-items: center;
    padding-right: 12px;
    padding-left: 12px;
  }

  .arcade-start.is-intro {
    align-items: center;
  }

  .arcade-panel,
  .result-panel {
    width: min(400px, 100%);
    padding: 16px;
  }

  .intro-title-art {
    top: max(calc(env(safe-area-inset-top) + 76px), calc(50% - 330px));
    width: min(340px, 84vw);
    max-height: 112px;
  }

  .intro-champion-female,
  .intro-champion-male {
    display: none;
  }

  .intro-champion-elephant {
    z-index: 2;
    top: max(calc(env(safe-area-inset-top) + 168px), calc(50% - 222px));
    width: clamp(132px, 38vw, 164px);
  }

  .arcade-start.is-intro .arcade-panel {
    z-index: 3;
  }

  .arcade-config-row {
    grid-template-columns: 1fr;
  }

  .difficulty-select h1,
  .champion-select h1 {
    font-size: 30px;
    white-space: normal;
  }

  .champion-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 14px;
  }

  .champion-card {
    min-height: 132px;
  }

  .champion-card img {
    width: min(44vw, 124px);
    height: 112px;
  }

  .champion-card[data-character-option="elephant"] img {
    width: min(48vw, 142px);
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }

  .story-layer {
    padding: 12px;
  }

  .story-panel {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
    width: min(340px, calc(100vw - 28px));
    height: auto;
    padding: 12px;
    border-width: 5px;
  }

  .story-character {
    min-height: 0;
    width: 100%;
    aspect-ratio: 1;
    justify-self: center;
  }

  .story-character img {
    width: auto;
    max-width: 86%;
    max-height: 86%;
  }

  .story-copy {
    grid-template-rows: minmax(0, 1fr) auto auto;
    gap: 9px;
    width: 100%;
    height: 184px;
    min-height: 0;
    text-align: center;
  }

  .story-text {
    align-content: center;
    justify-items: center;
    gap: 8px;
    max-width: min(30ch, 100%);
    justify-self: center;
  }

  .story-copy h2 {
    font-size: clamp(19px, 5.6vw, 23px);
    line-height: 1;
    white-space: nowrap;
  }

  .story-copy p {
    font-size: 15px;
    line-height: 1.3;
  }

  .story-progress {
    justify-content: center;
  }

  .story-actions {
    grid-template-columns: 54px 54px;
    justify-content: center;
  }

  .story-actions.is-final {
    grid-template-columns: 54px minmax(0, 220px);
  }

  .story-arrow,
  .story-primary {
    min-height: 52px;
  }

  .story-primary {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
