:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #040907;
  color: #f5fff9;
}

* { box-sizing: border-box; }

body {
  min-height: 100dvh;
  margin: 0;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #123226, #040907 70%);
}

main { width: min(100%, 1000px, calc(131.58dvh - 237px)); }

.game-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid #2a6850;
  background: #07100d;
  box-shadow: 0 16px 50px #000b;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 25 / 19;
}

#status {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 1rem;
  display: grid;
  place-items: center;
  text-align: center;
  background: #07100dee;
  color: #70f2be;
}

#status[hidden] { display: none; }

.controls {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
}

.directions {
  display: grid;
  grid-template-columns: repeat(2, minmax(64px, 110px));
  gap: 8px;
}

.actions {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  min-width: 44px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid #55efbc;
  border-radius: 6px;
  background: #101a17;
  color: #f5fff9;
  font: inherit;
  font-weight: 700;
  touch-action: manipulation;
  cursor: pointer;
}

button span { display: block; font-size: .7rem; color: #a5c8b7; }
button:hover { background: #173e2e; }
button:active { transform: translateY(1px); background: #22563f; }
button:focus-visible { outline: 3px solid #ffbd2e; outline-offset: 2px; }
.keyboard-help { margin: 10px 0 0; color: #a5b9af; text-align: center; font-size: .78rem; }

@media (max-width: 620px), (orientation: portrait) {
  body { align-items: start; }
  .controls { align-items: stretch; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; flex: 1; }
  .actions button:first-child { grid-column: 1 / -1; }
  .keyboard-help { display: none; }
}

@media (orientation: landscape) and (max-height: 800px) {
  main {
    width: min(100%, calc(131.58dvh + 211px));
    display: grid;
    grid-template-columns: minmax(0, 1fr) 228px;
    gap: 12px;
    align-items: center;
  }

  .controls {
    display: grid;
    margin-top: 0;
    gap: 8px;
  }

  .directions { grid-template-columns: repeat(2, minmax(64px, 1fr)); }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions button:first-child { grid-column: 1 / -1; }
  .keyboard-help { display: none; }
}

@media (pointer: fine) and (min-width: 900px) {
  .controls { opacity: .88; }
}
