*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --paper: #eee7d8;
  --paper-deep: #d6c9ae;
  --ink: #141619;
  --ink-soft: #37383a;
  --blue: #145fc8;
  --blue-hot: #69d7ff;
  --green: #77d253;
  --red: #f04a43;
  --rust: #b95b39;
  --mono: 'Courier New', ui-monospace, monospace;
  --sans: Arial, Helvetica, sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

.page {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--paper);
}

.top-bar {
  z-index: 50;
}

.crossing-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
  isolation: isolate;
  outline: none;
  touch-action: none;
}

.crossing-stage[data-phase='play'] {
  cursor: grab;
}

.crossing-stage[data-phase='play']:active {
  cursor: grabbing;
}

.crossing-stage:focus-visible {
  outline: 3px solid var(--blue-hot);
  outline-offset: -3px;
}

#crossingCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-hud {
  position: absolute;
  z-index: 6;
  inset: 18px 20px auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.location-readout {
  display: grid;
  width: min(360px, 42vw);
  gap: 3px;
  color: var(--ink);
  text-transform: uppercase;
}

.location-readout__index,
.location-readout span:last-child,
.run-stat > span {
  font: 700 9px/1.2 var(--mono);
  letter-spacing: .12em;
}

.location-readout__index {
  color: var(--blue);
}

.location-readout strong {
  font: 900 clamp(18px, 2vw, 28px)/.95 var(--sans);
  letter-spacing: -.03em;
}

.location-readout span:last-child {
  color: rgba(20, 22, 25, .58);
}

.run-stats {
  display: flex;
  border: 2px solid var(--ink);
  background: rgba(238, 231, 216, .9);
  box-shadow: 4px 4px 0 rgba(20, 22, 25, .2);
}

.run-stat {
  min-width: 72px;
  min-height: 52px;
  padding: 7px 10px;
  display: grid;
  align-content: center;
  gap: 5px;
  border-left: 1px solid rgba(20, 22, 25, .2);
}

.run-stat:first-child {
  border-left: 0;
}

.run-stat > span {
  color: rgba(20, 22, 25, .55);
}

.run-stat > strong {
  font: 900 18px/1 var(--mono);
}

.run-stat--current {
  min-width: 128px;
}

.charge-cells {
  display: grid;
  grid-template-columns: repeat(6, 13px);
  gap: 3px;
}

.charge-cells i {
  width: 13px;
  height: 13px;
  display: block;
  background: rgba(20, 22, 25, .15);
  border: 1px solid rgba(20, 22, 25, .25);
}

.charge-cells i.is-full {
  background: var(--blue);
  border-color: var(--ink);
}

.charge-cells i.is-low {
  background: var(--red);
}

.start-card,
.result-card {
  position: absolute;
  z-index: 8;
  border: 3px solid var(--ink);
  box-shadow: 9px 9px 0 rgba(20, 22, 25, .86);
}

.start-card {
  left: 22px;
  bottom: 24px;
  width: min(440px, calc(100vw - 44px));
  padding: 23px 24px 24px;
  color: var(--paper);
  background: var(--ink);
}

.start-card__kicker,
.result-card__kicker {
  margin: 0 0 8px;
  color: var(--blue-hot);
  font: 700 10px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.start-card h1,
.result-card h2 {
  margin: 0;
  font: 950 clamp(42px, 5vw, 68px)/.82 var(--sans);
  letter-spacing: -.07em;
  text-transform: uppercase;
}

.start-card > p:not(.start-card__kicker),
.result-card > p:not(.result-card__kicker) {
  margin: 16px 0 0;
  max-width: 36ch;
  font: 700 17px/1.3 var(--sans);
}

.start-card__rules {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font: 700 10px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.start-card__rules span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rule-mark {
  width: 11px;
  height: 11px;
  display: block;
  border: 2px solid var(--paper);
}

.rule-mark--blue { background: var(--blue-hot); }
.rule-mark--green { background: var(--green); }
.rule-mark--red { background: var(--red); }

.start-button,
.again-button,
.result-card__actions a {
  min-height: 48px;
  border: 2px solid currentColor;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  font: 800 11px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  text-decoration: none;
}

.start-button {
  width: 100%;
  margin-top: 20px;
  color: var(--ink);
  background: var(--blue-hot);
}

.start-button:disabled {
  cursor: wait;
  color: rgba(238, 231, 216, .5);
  background: transparent;
}

.start-button:not(:disabled):hover,
.start-button:not(:disabled):focus-visible {
  background: var(--green);
}

.crossing-stage[data-phase='intro'] .rule-mark {
  animation: ruleSignal 1.8s steps(2, end) infinite;
}

.crossing-stage[data-phase='intro'] .start-card__rules span:nth-child(2) .rule-mark {
  animation-delay: .24s;
}

.crossing-stage[data-phase='intro'] .start-card__rules span:nth-child(3) .rule-mark {
  animation-delay: .48s;
}

.crossing-stage[data-phase='intro'] .start-button:not(:disabled) {
  animation: startSignal 1.4s steps(2, end) infinite;
}

@keyframes ruleSignal {
  50% { transform: translateY(-2px); }
}

@keyframes startSignal {
  50% { box-shadow: inset 0 -5px 0 rgba(20, 22, 25, .18); }
}

.result-card {
  left: 22px;
  bottom: 24px;
  width: min(480px, calc(100vw - 44px));
  padding: 22px 24px 24px;
  background: rgba(238, 231, 216, .96);
}

.result-card[hidden] {
  display: none;
}

.result-card__kicker {
  color: var(--rust);
}

.result-card h2 {
  font-size: clamp(38px, 4vw, 58px);
}

.result-card__actions {
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.again-button {
  color: var(--paper);
  background: var(--blue);
}

.result-card__actions a {
  color: var(--ink);
  background: transparent;
}

.control-hint {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 15px;
  margin: 0;
  transform: translateX(-50%);
  padding: 9px 12px;
  color: var(--paper);
  background: rgba(20, 22, 25, .88);
  font: 700 9px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.crossing-stage[data-phase='play'] .control-hint {
  opacity: 1;
}

.crossing-stage[data-interacted='true'] .control-hint {
  opacity: 0;
}

.event-callout {
  position: absolute;
  z-index: 9;
  top: 90px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 2px solid var(--ink);
  color: var(--paper);
  background: var(--ink);
  box-shadow: 4px 4px 0 var(--red);
  font: 800 11px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.event-callout[hidden] {
  display: none;
}

.crossing-stage[data-phase='intro'] .game-hud {
  opacity: .48;
}

.crossing-stage[data-phase='result'] .game-hud {
  opacity: .74;
}

.info-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 22, 25, .82);
  backdrop-filter: blur(10px);
}

.info-overlay[hidden] {
  display: none;
}

.info-modal {
  position: relative;
  width: min(520px, 100%);
  padding: 30px;
  border: 3px solid var(--ink);
  background: var(--paper);
  box-shadow: 10px 10px 0 var(--blue);
}

.info-modal__eyebrow {
  margin: 0 0 9px;
  color: var(--blue);
  font: 700 10px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
}

.info-modal h2 {
  margin: 0 0 16px;
  font: 950 44px/.9 var(--sans);
  letter-spacing: -.06em;
  text-transform: uppercase;
}

.info-modal p:not(.info-modal__eyebrow) {
  margin: 10px 0 0;
  font: 700 15px/1.45 var(--sans);
}

.info-modal__credit {
  color: rgba(20, 22, 25, .58);
  font-size: 12px !important;
}

.info-modal a {
  color: inherit;
}

.info-close {
  margin-top: 20px;
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 10px 16px;
  color: var(--paper);
  background: var(--ink);
  font: 800 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--blue-hot);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .game-hud {
    inset: 11px 12px auto;
    gap: 8px;
  }

  .location-readout {
    width: 44vw;
  }

  .location-readout strong {
    font-size: 17px;
  }

  .location-readout span:last-child {
    display: none;
  }

  .run-stat {
    min-width: 50px;
    min-height: 44px;
    padding: 6px 7px;
  }

  .run-stat--current {
    min-width: 86px;
  }

  .run-stat > span {
    font-size: 7px;
  }

  .run-stat > strong {
    font-size: 14px;
  }

  .charge-cells {
    grid-template-columns: repeat(6, 8px);
    gap: 2px;
  }

  .charge-cells i {
    width: 8px;
    height: 10px;
  }

  .start-card {
    right: 12px;
    bottom: 14px;
    left: 12px;
    width: auto;
    padding: 18px;
    box-shadow: 6px 6px 0 rgba(20, 22, 25, .86);
  }

  .start-card h1 {
    font-size: 40px;
  }

  .start-card > p:not(.start-card__kicker) {
    margin-top: 12px;
    font-size: 14px;
  }

  .start-card__rules {
    margin-top: 13px;
    gap: 10px;
    font-size: 8px;
  }

  .start-button {
    min-height: 44px;
    margin-top: 15px;
  }

  .result-card {
    left: 12px;
    bottom: 13px;
    width: calc(100vw - 24px);
    padding: 18px;
    box-shadow: 6px 6px 0 rgba(20, 22, 25, .86);
  }

  .result-card > p:not(.result-card__kicker) {
    font-size: 14px;
  }

  .result-card__actions {
    margin-top: 14px;
  }

  .control-hint {
    bottom: 9px;
    max-width: calc(100vw - 24px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .event-callout {
    top: 76px;
    max-width: calc(100vw - 24px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 9px;
  }
}

@media (max-height: 650px) and (min-width: 721px) {
  .start-card {
    bottom: 14px;
    padding: 17px 20px 18px;
  }

  .start-card h1 {
    font-size: 44px;
  }

  .start-card > p:not(.start-card__kicker) {
    margin-top: 11px;
    font-size: 14px;
  }

  .start-card__rules,
  .start-button {
    margin-top: 12px;
  }
}

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