:root {
  --ink: #e8e2d0;
  --stone: #2a2622;
  --stone-dark: #15120f;
  --gold: #d9b04a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0a0908;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  height: 100%;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#frame {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen {
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100vw;
  max-height: 100vh;
  width: min(100vw, 133.33vh);   /* keep 4:3 */
  height: auto;
  aspect-ratio: 4 / 3;
  box-shadow: 0 0 0 2px #000, 0 0 40px rgba(0,0,0,0.8);
}

#hint {
  position: fixed;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  margin: 0;
  font-size: 12px;
  color: #6b6355;
  pointer-events: none;
}

/* Touch controls — only shown on coarse pointers */
#touch-controls { display: none; }

@media (pointer: coarse) {
  #touch-controls {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    justify-content: space-between;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    pointer-events: none;
  }
  #hint { display: none; }
  #touch-controls .dpad,
  #touch-controls .actions { pointer-events: auto; }

  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 4px;
  }
  .dpad .up { grid-column: 2; grid-row: 1; }
  .dpad .left { grid-column: 1; grid-row: 2; }
  .dpad .right { grid-column: 3; grid-row: 2; }
  .dpad .down { grid-column: 2; grid-row: 3; }

  .actions { display: flex; align-items: flex-end; gap: 14px; }

  #touch-controls button {
    font-size: 20px;
    color: var(--ink);
    background: rgba(42,38,34,0.85);
    border: 2px solid #000;
    border-radius: 10px;
    width: 52px; height: 52px;
  }
  .actions .a, .actions .b { width: 64px; height: 64px; border-radius: 50%; }
  #touch-controls button:active { background: var(--gold); color: #000; }
}
