:root {
  --bg: #111214;
  --fg: #d8dadf;
  --muted: #7d828c;
  --btn: #2a2c31;
  --btn-pressed: #3d4048;
  --btn-ab: #6b2a3c;
  --btn-ab-pressed: #8a3a50;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* Disables double-tap-to-zoom on iOS (user-scalable=no is ignored there). */
  touch-action: manipulation;
}

#player {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

#screen {
  position: relative;
  display: grid;
  place-items: center;
}

#canvas {
  display: block;
  /* Size is set in main.js to the largest whole-number scale that fits. */
  width: 320px;
  height: 288px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

#status {
  position: absolute;
  margin: 0;
  color: var(--muted);
}

#status:empty { display: none; }

/* ---------- On-screen controls (touch devices only) ---------- */
#controls {
  display: none;
  width: min(100%, 420px);
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "dpad ab"
    "menu menu";
  align-items: center;
  row-gap: 20px;
  touch-action: none;
}

.touch #controls { display: grid; }
.touch .keys { display: none; }

#dpad {
  grid-area: dpad;
  position: relative;
  width: 144px;
  height: 144px;
  justify-self: start;
}

#dpad .arm, #dpad .hub {
  position: absolute;
  background: var(--btn);
}

#dpad .up, #dpad .down { left: 48px; width: 48px; height: 50px; }
#dpad .left, #dpad .right { top: 48px; width: 50px; height: 48px; }
#dpad .up { top: 0; border-radius: 8px 8px 0 0; }
#dpad .down { bottom: 0; border-radius: 0 0 8px 8px; }
#dpad .left { left: 0; border-radius: 8px 0 0 8px; }
#dpad .right { right: 0; border-radius: 0 8px 8px 0; }
#dpad .hub { left: 48px; top: 48px; width: 48px; height: 48px; }
#dpad .arm.pressed { background: var(--btn-pressed); }

#ab {
  grid-area: ab;
  justify-self: end;
  display: flex;
  gap: 16px;
  transform: rotate(-20deg);
}

#ab .round:last-child { margin-top: -28px; }

/* Undo the group's slant on each (circular) button so the letters sit upright. */
#ab .round { transform: rotate(20deg); }

#menu {
  grid-area: menu;
  display: flex;
  justify-content: center;
  gap: 24px;
}

button {
  font: inherit;
  color: var(--fg);
  border: 0;
  cursor: pointer;
  touch-action: none;
}

.round {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--btn-ab);
  font-weight: 700;
  font-size: 18px;
}

.round.pressed { background: var(--btn-ab-pressed); }

.pill {
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--btn);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pill.pressed { background: var(--btn-pressed); }

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
}

#toolbar p { margin: 0; }

#mute {
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--btn);
  border-radius: 999px;
  font-size: 12px;
}

button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
