:root {
  --bg: #0a0a0d;
  --frame: #1c1c22;
  --muted: #8a8a94;
  --pad: rgba(255, 255, 255, 0.07);
  --pad-line: rgba(255, 255, 255, 0.16);
  --btn-a: #d82800;
  --btn-b: #8c1800;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #d8d8d8;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#frame {
  line-height: 0;
  background: #000;
  box-shadow: 0 0 0 3px var(--frame), 0 18px 50px rgba(0, 0, 0, 0.7);
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

#hint {
  margin: 0;
  max-width: 920px;
  padding: 0 16px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

body.touch-on #hint { display: none; }
body.touch-on.portrait #app { justify-content: flex-start; padding-top: calc(56px + env(safe-area-inset-top)); }

/* ------------------------------------------------------------ site navigation */
.site-nav {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 10;
  display: flex;
  gap: 8px;
}
.site-nav a {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2px solid var(--pad-line);
  border-radius: 10px;
  background: var(--pad);
  color: #cfcfcf;
  font: 700 18px/1 system-ui, sans-serif;
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}
.site-nav a:hover, .site-nav a:focus-visible { border-color: #f8b800; color: #fff; outline: none; }

/* ------------------------------------------------------------ touch pad */
.touch[hidden] { display: none; }
.touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 230px;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}

.dpad {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(26px + env(safe-area-inset-bottom));
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: var(--pad);
  border: 2px solid var(--pad-line);
  pointer-events: auto;
  touch-action: none;
}
.arr {
  position: absolute;
  width: 0;
  height: 0;
  border: 13px solid transparent;
  opacity: 0.7;
}
.arr.up { left: 50%; top: 12px; transform: translateX(-50%); border-top: 0; border-bottom: 18px solid #ddd; }
.arr.down { left: 50%; bottom: 12px; transform: translateX(-50%); border-bottom: 0; border-top: 18px solid #ddd; }
.arr.left { top: 50%; left: 12px; transform: translateY(-50%); border-left: 0; border-right: 18px solid #ddd; }
.arr.right { top: 50%; right: 12px; transform: translateY(-50%); border-right: 0; border-left: 18px solid #ddd; }

.buttons {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: auto;
}
.tbtn {
  width: 74px;
  height: 74px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font: 700 22px/1 system-ui, sans-serif;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.5);
  touch-action: none;
}
.tbtn.a { background: var(--btn-a); margin-bottom: 34px; }
.tbtn.b { background: var(--btn-b); width: 62px; height: 62px; }
.tbtn.on, .tsmall.on { filter: brightness(1.4); transform: scale(0.94); }

.tsmall {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 2px solid var(--pad-line);
  border-radius: 999px;
  background: var(--pad);
  color: #cfcfcf;
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  pointer-events: auto;
  touch-action: none;
}
.tsmall.on { transform: translateX(-50%) scale(0.94); }

@media (orientation: landscape) {
  .touch { top: 0; height: auto; }
  .tsmall {
    left: auto;
    right: max(24px, env(safe-area-inset-right));
    bottom: auto;
    top: calc(18px + env(safe-area-inset-top));
    transform: none;
  }
  .tsmall.on { transform: scale(0.94); }
}
