@import url("https://fonts.googleapis.com/css2?family=Archivo+Black&family=IBM+Plex+Mono:wght@500;600&family=League+Spartan:wght@500;700&display=swap");

:root {
  color-scheme: dark;
  --navy: #061827;
  --cream: #f5dfad;
  --gold: #f3bd4d;
  --coral: #df6038;
  --cyan: #78d1d1;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 78% 12%, rgb(21 80 96 / 0.4), transparent 28rem),
    var(--navy);
  font-family: "IBM Plex Mono", monospace;
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
}

.shell {
  width: min(1280px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(0.75rem, 2vw, 1.75rem);
}

.masthead {
  display: flex;
  justify-content: space-between;
  border-top: 4px solid var(--cream);
  padding-top: 0.55rem;
  font-size: 0.65rem;
  letter-spacing: 0.14em;
}

.masthead p {
  margin: 0;
}

.brand {
  color: inherit;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  text-decoration: none;
}

.game {
  padding-top: clamp(1rem, 2.5vw, 2rem);
}

.game-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 0.8rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--cyan);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.15em;
}

h1 {
  margin: 0;
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(2.5rem, 6vw, 5.2rem);
  line-height: 0.86;
  letter-spacing: -0.065em;
  white-space: nowrap;
}

h1 span {
  color: var(--gold);
  text-shadow: 0.05em 0.05em 0 var(--coral);
}

.lede {
  max-width: 31rem;
  margin: 0;
  border-left: 2px solid var(--coral);
  padding-left: 0.8rem;
  font-family: "League Spartan", sans-serif;
  font-size: clamp(0.9rem, 1.4vw, 1.12rem);
  line-height: 1.35;
}

.cabinet {
  border: 1px solid rgb(245 223 173 / 0.35);
  padding: clamp(0.55rem, 1.2vw, 1rem);
  background: rgb(2 14 25 / 0.75);
  box-shadow: 0.8rem 0.8rem 0 rgb(223 96 56 / 0.16);
}

.difficulty {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.difficulty > span {
  margin-right: 0.25rem;
  color: var(--cyan);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
}

.difficulty button {
  min-width: 2.4rem;
  min-height: 2rem;
  border: 1px solid rgb(245 223 173 / 0.45);
  background: transparent;
  color: rgb(245 223 173 / 0.5);
  cursor: pointer;
}

.difficulty button[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
  background: rgb(243 189 77 / 0.14);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.hud div {
  border-top: 2px solid var(--cream);
  padding-top: 0.35rem;
}

.hud span,
.hud strong {
  display: block;
}

.hud span {
  color: var(--cyan);
  font-size: 0.56rem;
  letter-spacing: 0.12em;
}

.hud strong {
  margin-top: 0.1rem;
  color: var(--gold);
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(0.85rem, 1.6vw, 1.2rem);
}

.screen {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #000;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 12%;
  text-align: center;
  background: rgb(3 16 27 / 0.72);
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.overlay.is-win {
  top: auto;
  place-content: initial;
  padding: 0.65rem 1rem;
  text-align: left;
  background: rgb(3 16 27 / 0.8);
  backdrop-filter: none;
}

.overlay.is-win.is-collapsed {
  inset: auto 0 0 auto;
  padding: 0;
  background: transparent;
}

.overlay.is-win.is-collapsed > :not(.overlay__toggle) {
  display: none;
}

.overlay__toggle {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  min-height: 2rem;
  border: 1px solid rgb(245 223 173 / 0.65);
  background: rgb(3 16 27 / 0.86);
  color: var(--gold);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.overlay.is-win:not(.is-collapsed) .overlay__toggle {
  top: 50%;
  right: 0.6rem;
  bottom: auto;
  transform: translateY(-50%);
}

.overlay.is-win .overlay__label,
.overlay.is-win .overlay__action {
  display: inline;
  margin-right: 0.7rem;
}

.overlay.is-win h2 {
  display: inline;
  margin-right: 0.7rem;
  font-size: clamp(1rem, 2vw, 1.45rem);
}

.overlay.is-win p:not([class]) {
  display: inline;
  font-size: 0.85rem;
}

.overlay__label,
.overlay__action {
  color: var(--cyan);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.overlay h2 {
  margin: 0.6rem 0;
  color: var(--gold);
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(1.8rem, 4vw, 3.8rem);
  line-height: 0.95;
  text-transform: uppercase;
}

.overlay p:not([class]) {
  max-width: 34rem;
  font-family: "League Spartan", sans-serif;
  font-size: clamp(1rem, 1.7vw, 1.25rem);
  line-height: 1.4;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
}

.controls p,
.status {
  margin: 0;
}

kbd {
  color: var(--gold);
  font: inherit;
}

.status {
  margin-top: 0.4rem;
  color: var(--cyan);
  font-size: 0.62rem;
  text-transform: uppercase;
}

.touch-controls {
  display: none;
}

@media (max-width: 760px), (pointer: coarse) {
  .shell {
    padding: 0.65rem;
  }

  .masthead p,
  .lede,
  .keyboard-controls {
    display: none;
  }

  .game {
    padding-top: 0.65rem;
  }

  .game-heading {
    margin-bottom: 0.55rem;
  }

  h1 {
    font-size: clamp(2.3rem, 12vw, 4rem);
  }

  .cabinet {
    padding: 0.45rem;
    box-shadow: none;
  }

  .difficulty {
    margin-bottom: 0.4rem;
  }

  .difficulty button {
    min-width: 2.75rem;
    min-height: 2.4rem;
  }

  .hud {
    gap: 0.3rem;
  }

  .hud strong {
    font-size: clamp(0.72rem, 3.3vw, 1rem);
  }

  .touch-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.6rem;
    user-select: none;
  }

  .touch-controls button {
    border: 1px solid rgb(245 223 173 / 0.5);
    border-radius: 0.25rem;
    background: rgb(12 52 72 / 0.9);
    color: var(--cream);
    touch-action: none;
  }

  .touch-start {
    min-width: 5rem;
    min-height: 3.2rem;
    color: var(--gold) !important;
    font-size: 0.7rem;
  }

  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 3.4rem);
    grid-template-rows: repeat(3, 2.8rem);
  }

  .dpad button {
    font-size: 1.15rem;
  }

  .dpad [data-direction="up"] {
    grid-column: 2;
  }

  .dpad [data-direction="left"] {
    grid-row: 2;
  }

  .dpad [data-action="pause"] {
    grid-column: 2;
    grid-row: 2;
    color: var(--cyan);
  }

  .dpad [data-direction="right"] {
    grid-column: 3;
    grid-row: 2;
  }

  .dpad [data-direction="down"] {
    grid-column: 2;
    grid-row: 3;
  }
}

@media (max-width: 430px) {
  .difficulty > span {
    display: none;
  }

  .touch-controls {
    justify-content: space-between;
  }

  .dpad {
    grid-template-columns: repeat(3, 3rem);
    grid-template-rows: repeat(3, 2.55rem);
  }
}
