@font-face {
  font-family: "Pixel Operator";
  src: url("PixelOperator8.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

[hidden] { display: none !important; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #070908;
  color: #e9dfc3;
  font-family: "Pixel Operator", monospace;
  font-size: 16px;
  line-height: 16px;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.playing {
  display: block;
}

button {
  font: inherit;
  color: #e9dfc3;
  background: #172329;
  border: 1px solid #e9dfc3;
  border-radius: 0;
  box-sizing: border-box;
  padding: 8px 12px;
  line-height: 16px;
  overflow: hidden;
  touch-action: manipulation;
}

button:active, button.chosen { background: #233434; }

h1 {
  font: inherit;
  font-size: 32px;
  margin: 0 0 8px;
}

.lede { margin: 0 0 20px; }

#picker, #options {
  box-sizing: border-box;
  width: min(420px, 100%);
  max-height: 100%;
  overflow: hidden;
  padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#builtin {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

#builtin button, #open, #notice { text-align: left; }

.notice { color: #f3d99b; margin: 8px 0 0; }

#stage {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070908;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "view";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#view {
  position: relative;
  grid-area: view;
  min-width: 0;
  min-height: 0;
  background: #070908;
}

#shoot.touch, #hud.touch { display: none; }

#screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #070908;
  touch-action: none;
}

#scroll {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  bottom: 8px;
  background: #172329;
  color: #e9dfc3;
  border: 1px solid #e9dfc3;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
}

#scroll-body {
  flex: 1 1 auto;
  overflow: hidden;
  white-space: pre-wrap;
}

#shoot, #desk-options {
  position: absolute;
  z-index: 2;
}

#shoot {
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 92px;
  min-height: 96px;
  padding: 4px;
  white-space: nowrap;
}

#desk-options { display: none; }

body.playing #desk-options { display: block; }

#hud {
  position: absolute;
  z-index: 2;
  box-sizing: border-box;
  display: none;
  flex-direction: row;
  align-items: stretch;
  gap: 6px;
  padding: 4px;
  min-width: 0;
  overflow: hidden;
  background: #070908;
}

#hud button {
  min-width: 0;
  min-height: 44px;
  padding: 2px;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
}

.keys {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(112px, 1.4fr) minmax(76px, 1fr);
  grid-template-areas:
    "go no"
    "opt yes"
    "worlds save"
    "torch pause";
  gap: 4px;
}

#go { grid-area: go; }
#hud-options { grid-area: opt; }
#worlds { grid-area: worlds; }
#torch { grid-area: torch; }
#no { grid-area: no; }
#yes { grid-area: yes; }
#save { grid-area: save; }
#pause { grid-area: pause; }

.dpad {
  display: grid;
  grid-template-columns: 58px 66px 72px;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 4px;
  width: 204px;
  height: 168px;
  flex: 0 0 auto;
  align-self: center;
}

.dpad button {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0 1px;
}

.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; }

#hud.below {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  gap: 6px;
  height: auto;
  overflow: visible;
  background: transparent;
}

#hud.below .dpad {
  width: 100%;
  height: 140px;
  grid-template-columns: 1fr 1.1fr 1.25fr;
  align-self: stretch;
}

#hud.below .keys {
  width: 100%;
  flex: 0 0 auto;
  grid-template-rows: 40px 40px 40px 40px;
}

#hud.below .keys button {
  min-height: 0;
  height: 40px;
}

@media (max-width: 900px), (max-height: 500px), (pointer: coarse) {
  #shoot.touch { display: flex; }
  #hud.touch { display: flex; }
  body.playing #desk-options { display: none; }
}

body.keyboard #shoot,
body.keyboard #hud { display: none !important; }
