:root {
  --bg: #080818;
  --surface: #101840;
  --line: #2a3468;
  --fg: #f4f2ff;
  --muted: #a8b0e0;
  --accent: #f8c028;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, sans-serif;
}
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

#stage {
  position: relative;
  /* the largest whole multiple of 160x144 is set by the media queries */
  width: 320px;
  margin: 0 auto;
  aspect-ratio: 160 / 144;
}
@media (min-width: 520px) and (min-height: 460px) { #stage { width: 480px; } }
@media (min-width: 680px) and (min-height: 620px) { #stage { width: 640px; } }
#screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  image-rendering: pixelated;
}
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgb(8 8 24 / 80%);
  color: var(--accent);
  font: inherit;
  font-size: 24px;
  cursor: pointer;
}
#overlay:disabled { color: var(--fg); cursor: default; }
#overlay[hidden] { display: none; }

h1 { margin: 24px 0 8px; font-size: 24px; }
h1 span { color: var(--muted); font-size: 16px; font-weight: normal; }
p { margin: 8px 0; }
a { color: var(--accent); }
#download { font-weight: bold; }
#banner { margin: 0 0 8px; color: var(--muted); font-size: 14px; text-align: center; }
.small, #latency { color: var(--muted); font-size: 14px; }
table { margin: 16px 0; border-collapse: collapse; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: center; }
th { color: var(--muted); font-size: 14px; font-weight: normal; }
kbd {
  display: inline-block;
  min-width: 24px;
  margin: 0 1px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font: 14px/22px ui-monospace, monospace;
}
label { display: inline-flex; align-items: center; gap: 8px; }

/* Touch controls: only where fingers are the main way to point */
#touch { display: none; }
@media (pointer: coarse) {
  main { padding: 0 max(8px, env(safe-area-inset-left)) 16px; }
  table { display: none; }
  #stage { width: min(100%, 480px, calc((100vh - 220px) * 160 / 144)); }
  #touch {
    display: flex;
    justify-content: space-between;
    max-width: 800px;
    margin: 16px auto 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
}
#dpad, #buttons {
  width: min(46vw, 190px);
  aspect-ratio: 1;
  touch-action: none;
}
#dpad {
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}
#dpad i { border-radius: 8px; background: var(--line); pointer-events: none; }
#dpad [data-key="up"] { grid-area: 1 / 2; }
#dpad [data-key="left"] { grid-area: 2 / 1; }
#dpad [data-key="right"] { grid-area: 2 / 3; }
#dpad [data-key="down"] { grid-area: 3 / 2; }
#buttons {
  display: grid;
  grid-template: 1fr 1fr / 1fr 1fr;
  gap: 4px;
}
#buttons b {
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #585878;
}
#buttons [data-key="B"] { background: #6c54ee; }
#buttons [data-key="A"] { background: #ee4474; }
#touch .down { filter: brightness(1.6); }
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #stage { width: calc(100vh * 160 / 144); max-width: calc(100vw - 400px); margin-top: 0; }
  #touch { position: fixed; inset: auto 8px 8px; max-width: none; margin: 0; pointer-events: none; }
  #dpad, #buttons { pointer-events: auto; }
}
