/* Shared theme for the menu and every game page. Colors come from the GWA logo. */

@font-face {
  font-family: "Press Start 2P";
  src: url("../assets/fonts/press-start-2p-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}

:root {
  --ink: #05070f;
  --panel: #0c1226;
  --panel-raised: #151d3a;
  --blue: #1e7bff;
  --blue-deep: #0b47a8;
  --red: #f2232b;
  --red-deep: #96101a;
  --violet: #8a63b8;
  --violet-deep: #4c3370;
  --white: #ffffff;
  --muted: #a3afcc;
  --pixel: 4px;
  --font: "Press Start 2P", ui-monospace, "Courier New", monospace;
}

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

html {
  background: var(--ink);
  color: var(--white);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { margin: 0; min-height: 100dvh; }

a { color: inherit; text-decoration: none; }

/* Chunky stepped corners, the 8-bit stand-in for a rounded rectangle. */
.pixel-corners {
  clip-path: polygon(
    0 var(--pixel), var(--pixel) var(--pixel), var(--pixel) 0,
    calc(100% - var(--pixel)) 0, calc(100% - var(--pixel)) var(--pixel), 100% var(--pixel),
    100% calc(100% - var(--pixel)), calc(100% - var(--pixel)) calc(100% - var(--pixel)), calc(100% - var(--pixel)) 100%,
    var(--pixel) 100%, var(--pixel) calc(100% - var(--pixel)), 0 calc(100% - var(--pixel))
  );
}

/* ---------- Menu ---------- */

.menu-page {
  background:
    url("../assets/circuit-bg.svg") center / cover fixed no-repeat,
    linear-gradient(90deg,
      #06122f 0 25%, #070c20 25% 50%, #120813 50% 75%, #260609 75% 100%);
  background-blend-mode: soft-light, normal;
}

.menu {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 32px 16px 24px;
}

.marquee {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.marquee-logo {
  width: clamp(128px, 28vw, 208px);
  height: auto;
  aspect-ratio: 1;
  display: block;
  border: var(--pixel) solid var(--white);
  box-shadow: calc(var(--pixel) * -2) calc(var(--pixel) * 2) 0 var(--blue),
              calc(var(--pixel) * 2) calc(var(--pixel) * 2) 0 var(--red);
}

.marquee h1 {
  margin: 8px 0 0;
  font-size: clamp(22px, 7.2vw, 56px);
  font-weight: 400;
  line-height: 1.35;
}

.marquee h1 span { display: block; }

.marquee .owner { font-size: 0.62em; color: var(--muted); }

.marquee .title {
  text-shadow: calc(var(--pixel) * -1) 0 0 var(--blue), var(--pixel) var(--pixel) 0 var(--red);
}

.prompt {
  margin: 0;
  min-height: 1em;
  font-size: 16px;
  color: var(--white);
  animation: blink 1.2s steps(2, jump-none) infinite;
}

@keyframes blink { to { opacity: 0; } }

.game-grid {
  list-style: none;
  margin: 32px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 20px;
}

.game-tile {
  --accent: var(--blue);
  --accent-deep: var(--blue-deep);
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 112px;
  padding: 20px;
  background: var(--panel-raised);
  border: var(--pixel) solid var(--accent);
  box-shadow: 0 calc(var(--pixel) * 2) 0 var(--accent-deep);
  outline: none;
}

.game-tile[data-accent="red"] { --accent: var(--red); --accent-deep: var(--red-deep); }
.game-tile[data-accent="violet"] { --accent: var(--violet); --accent-deep: var(--violet-deep); }

a.game-tile:hover, a.game-tile:focus-visible {
  background: var(--accent-deep);
  border-color: var(--white);
}

a.game-tile:active {
  transform: translateY(calc(var(--pixel) * 2));
  box-shadow: none;
}

.game-tile[aria-disabled="true"] {
  background: var(--panel);
  border-style: dashed;
  box-shadow: none;
  color: var(--muted);
}

.game-tile[aria-disabled="true"] svg { opacity: 0.55; }

.game-tile svg { display: block; width: 64px; height: 64px; }

.game-name { display: block; font-size: 16px; line-height: 1.5; }

.game-meta {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

a.game-tile .game-meta { color: #cfd7ea; }

.game-tag {
  font-size: 12px;
  padding: 8px 10px;
  background: var(--accent);
  color: var(--white);
}

.game-tile[aria-disabled="true"] .game-tag {
  background: none;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}

.game-badge {
  display: block;
  margin-top: 10px;
  font-size: 8px;
  line-height: 1.5;
  color: #ffd23f;
}

.menu-footer {
  margin-top: 40px;
  font-size: 8px;
  line-height: 1.9;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 420px) {
  .game-tile { grid-template-columns: 48px 1fr auto; gap: 12px; padding: 16px 12px; min-height: 96px; }
  .game-tile svg { width: 48px; height: 48px; }
  .game-meta { font-size: 8px; }
}

/* ---------- Game pages ---------- */

.game-page {
  height: 100dvh;
  display: grid;
  grid-template:
    "head" auto
    "stage" minmax(0, 1fr)
    "pad" auto / minmax(0, 1fr);
  background: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

.game-bar {
  grid-area: head;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: var(--pixel) solid var(--blue-deep);
}

.game-bar h1 { margin: 0; font-size: 16px; font-weight: 400; }

.bar-button {
  font: inherit;
  font-size: 12px;
  min-height: 40px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  color: var(--white);
  background: var(--panel-raised);
  border: var(--pixel) solid var(--blue);
  cursor: pointer;
}

.bar-button:hover, .bar-button:focus-visible { background: var(--blue-deep); outline: none; }

.bar-button[aria-pressed="false"] { border-color: var(--muted); color: var(--muted); }

.stage-wrap {
  grid-area: stage;
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage {
  --stage-ratio: 1.3333;
  position: relative;
  width: min(100cqw, calc(100cqh * var(--stage-ratio)));
  aspect-ratio: var(--stage-ratio);
  background: #000;
}

.stage canvas { display: block; width: 100%; height: 100%; }

.stage.is-loading canvas { visibility: hidden; }

.stage.is-loading::before {
  content: "LOADING";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text, #fff);
}

/* Faint scanlines, so the picture reads as a CRT rather than a flat bitmap. */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgb(0 0 0 / 0.16) 0 1px, transparent 1px 3px);
}

@media (max-width: 480px) {
  .game-bar h1 { display: none; }
  .bar-button { font-size: 8px; }
}

/* A gamepad's dialed number, sitting clear of the score and the players' names. */
.number-dial {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translateX(-50%);
  z-index: 1;
  min-width: 96px;
  padding: 12px 16px;
  font-size: 24px;
  text-align: center;
  color: var(--white);
  background: var(--blue-deep);
  border: var(--pixel) solid var(--white);
}

.game-toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 12px 16px;
  font-size: 12px;
  color: var(--white);
  background: var(--panel-raised);
  border: var(--pixel) solid var(--blue);
  opacity: 0;
  pointer-events: none;
}

.game-toast.is-showing { opacity: 1; }

/* A game that ships as its own page, with its own touch controls inside the frame. */
.framed-game { grid-template: "head" auto "stage" minmax(0, 1fr) / minmax(0, 1fr); }

.game-frame {
  grid-area: stage;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ---------- Notices and error screens ---------- */

.game-screen {
  --accent: var(--blue);
  width: min(100% - 32px, 480px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px;
  color: var(--white);
  font-family: var(--font);
  text-align: center;
  background: var(--panel-raised);
  border: var(--pixel) solid var(--accent);
}

.game-screen[data-tone="error"] { --accent: var(--red); }

.game-screen::backdrop { background: rgb(5 7 15 / 0.85); }

.game-screen h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
}

.game-screen p {
  margin: 20px 0 24px;
  font-size: 12px;
  line-height: 2;
  color: #cfd7ea;
}

.game-screen-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.screen-button {
  font: inherit;
  font-size: 12px;
  flex: 1 1 180px;
  min-height: 48px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  background: var(--panel);
  border: var(--pixel) solid var(--muted);
  cursor: pointer;
  outline: none;
}

.screen-button:first-child { background: var(--accent); border-color: var(--accent); }

.screen-button:hover,
.screen-button:focus-visible { border-color: var(--white); }

/* ---------- Touch controls ---------- */

.touch-pad {
  grid-area: pad;
  display: none;
  gap: 12px;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

html.show-controls .touch-pad { display: flex; }

.touch-button {
  font: inherit;
  flex: 1 1 0;
  min-width: 72px;
  min-height: 88px;
  padding: 8px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--white);
  background: var(--blue-deep);
  border: var(--pixel) solid var(--blue);
  box-shadow: 0 calc(var(--pixel) * 2) 0 #06275f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-button[data-tone="red"] {
  background: var(--red-deep);
  border-color: var(--red);
  box-shadow: 0 calc(var(--pixel) * 2) 0 #4d070c;
}

.touch-button[data-size="small"] { flex: 0 0 72px; font-size: 12px; }

/* Number entry: a four-column grid, sized to leave the game screen its full width. */
html.show-controls .touch-pad[data-layout="keypad"] {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 60px;
  gap: 8px;
}

.touch-pad[data-layout="keypad"] .touch-button {
  min-width: 0;
  min-height: 0;
  padding: 0;
}

/* Kept on screen, invisibly, because a phone won't open its keyboard for a hidden field. */
.touch-keyboard-field {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;
}

.touch-button.is-down {
  transform: translateY(calc(var(--pixel) * 2));
  box-shadow: none;
  border-color: var(--white);
}

/* Phone on its side: the picture takes the height and the buttons move beside it. */
@media (orientation: landscape) and (max-height: 520px) {
  .game-page {
    grid-template:
      "stage head" auto
      "stage pad" minmax(0, 1fr) / minmax(0, 1fr) auto;
  }

  .game-bar {
    flex-direction: column;
    align-items: stretch;
    border-bottom: 0;
  }

  .game-bar h1 { display: none; }
  .stage-wrap { padding: 4px; }
  .touch-pad { flex-direction: column; width: 184px; padding-top: 0; }
  html.show-controls .touch-pad[data-layout="keypad"] { width: 296px; grid-auto-rows: 1fr; gap: 4px; padding: 4px 8px; }
  html:not(.show-controls) .game-page { grid-template-columns: minmax(0, 1fr) 160px; }
  .touch-button[data-size="small"] { flex: 0 0 56px; min-height: 56px; }

  /* A framed game keeps the full screen, so MENU floats in a free corner of it. */
  html .framed-game,
  html:not(.show-controls) .framed-game { grid-template: "stage" minmax(0, 1fr) / minmax(0, 1fr); }

  .framed-game .game-bar {
    position: fixed;
    top: 4px;
    left: 4px;
    z-index: 10;
    padding: 0;
    background: none;
  }

  .framed-game .bar-button { min-height: 32px; font-size: 8px; opacity: 0.75; }
}

@media (prefers-reduced-motion: reduce) {
  .prompt { animation: none; }
}
