:root {
  color-scheme: light;
  --body: #e7ebdf;
  --panel: #dce3d4;
  --text: #172014;
  --line: #737e6e;
  --key: #f0f4e9;
  --accent: #bbff58;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --body: #111511;
    --panel: #1b231a;
    --text: #e4eddc;
    --line: #56664e;
    --key: #293426;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --body: #111511;
  --panel: #1b231a;
  --text: #e4eddc;
  --line: #56664e;
  --key: #293426;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--body);
  color: var(--text);
  font: 16px/1.4 ui-monospace, monospace;
}

.cabinet {
  max-width: 64rem;
  margin: auto;
  padding: max(8px, var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
    max(8px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 50px;
}

h1 {
  margin: 0;
  font-size: clamp(1rem, 4.5vw, 2rem);
  line-height: 1.1;
  text-transform: uppercase;
}

button {
  min-height: 44px;
  min-width: 44px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--key);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
button:active, button[data-held], #play {
  background: var(--accent);
  color: #192210;
}

#screen {
  position: relative;
  width: min(100%, 75svh);
  margin: auto;
  aspect-ratio: 4 / 3;
  border: 2px solid var(--line);
  background: #090d08;
}

#player, #launch { position: absolute; inset: 0; }
#launch {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .65rem;
  padding: 1rem;
  background: #090d08;
  color: #e4eddc;
  text-align: center;
}
#play { min-width: 8rem; font-weight: bold; }
#status { margin: 0; }

#controls {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  max-width: 40rem;
  margin: 8px auto 0;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  touch-action: none;
  user-select: none;
}

.directions {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-areas: ". up ." "left down right";
  gap: 4px;
}

.directions button { font-size: 1.35rem; }
.up { grid-area: up; }
.down { grid-area: down; }
.left { grid-area: left; }
.right { grid-area: right; }

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  gap: 4px;
  font-size: .82rem;
}

.special { grid-column: span 2; }

@media (orientation: landscape) and (min-width: 600px) {
  .cabinet:has(#controls:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
    align-items: center;
    gap: 8px;
  }
  header { grid-column: 1 / -1; }
  #screen { width: min(100%, calc((100svh - 82px) * 4 / 3)); }
  #controls { flex-direction: column; align-items: center; margin: 0; }
}
