/* 画面の外 = 物理コントローラの見立て。ゲーム画面の中はすべて canvas にドットで描く */
:root { --body: #c9c9d3; --body2: #b4b4c0; --ink: #3a3a48; --dpad: #2e2e36; --a: #d8303c; --b: #e6bf1e; --x: #3a5ccc; --y: #2f9a52; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0c0c10; overflow: hidden; }
body { font-family: "DotGothic16", monospace; color: var(--ink); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#app { height: 100dvh; display: flex; 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); }
#screenWrap { position: relative; line-height: 0; background: #000; }
#screen { display: block; image-rendering: pixelated; image-rendering: crisp-edges; width: 256px; height: 224px; }

/* 横向き: [左手][画面][右手] */
#controls { display: contents; }
.cluster { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 150px; flex: none; }
.cluster.left { order: 0; }
#screenWrap { order: 1; }
.cluster.right { order: 2; }

/* 縦向き: 画面の下にパッド */
body.portrait #app { flex-direction: column; justify-content: flex-start; padding-top: max(8px, env(safe-area-inset-top)); gap: 10px; }
body.portrait #controls { order: 2; display: flex; width: 100%; max-width: 420px; justify-content: space-between; padding: 6px 14px 10px; background: var(--body); border-radius: 18px 18px 46px 46px; box-shadow: inset 0 -4px 0 var(--body2); }
body.portrait .cluster { width: auto; }
body.portrait #controls { margin-top: auto; margin-bottom: max(10px, env(safe-area-inset-bottom)); }
body.portrait #screenWrap { margin-top: auto; }
@media (orientation: portrait) and (min-height: 760px) {
  .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
  .abxy { width: 172px; height: 172px; }
  .abxy button { width: 60px; height: 60px; font-size: 18px; padding-top: 6px; }
  .abxy .x { left: 56px; } .abxy .y { top: 56px; } .abxy .a { left: 112px; top: 56px; } .abxy .b { left: 56px; top: 112px; }
  body.portrait #controls { padding: 12px 16px 16px; }
}

button { font-family: inherit; color: inherit; border: 0; padding: 0; cursor: pointer; touch-action: none; }
button small { display: block; font-size: 9px; line-height: 1.1; letter-spacing: 0; color: var(--ink); opacity: .85; margin-top: 1px; }
.on { transform: translateY(2px); filter: brightness(.82); }

.sh { width: 124px; height: 30px; border-radius: 14px 14px 6px 6px; background: var(--body2); font-size: 13px; line-height: 1; padding-top: 3px; box-shadow: 0 3px 0 #8e8e9c; }
.sh.on { box-shadow: 0 1px 0 #8e8e9c; }
.pill { width: 74px; height: 30px; border-radius: 15px; background: #6a6a78; color: #e8e8f0; font-size: 10px; line-height: 1; padding-top: 3px; box-shadow: 0 3px 0 #4a4a56; }
.pill small { color: #e8e8f0; }

.dpad { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
.dpad button, .dpad .c { background: var(--dpad); }
.dpad .u { grid-area: 1 / 2; border-radius: 6px 6px 0 0; }
.dpad .l { grid-area: 2 / 1; border-radius: 6px 0 0 6px; }
.dpad .c { grid-area: 2 / 2; }
.dpad .r { grid-area: 2 / 3; border-radius: 0 6px 6px 0; }
.dpad .d { grid-area: 3 / 2; border-radius: 0 0 6px 6px; }
.dpad button::after { content: ""; display: block; width: 0; height: 0; margin: auto; border: 6px solid transparent; }
.dpad .u::after { border-bottom-color: #55556a; border-top-width: 0; }
.dpad .d::after { border-top-color: #55556a; border-bottom-width: 0; }
.dpad .l::after { border-right-color: #55556a; border-left-width: 0; }
.dpad .r::after { border-left-color: #55556a; border-right-width: 0; }

.abxy { position: relative; width: 150px; height: 150px; }
.abxy button { position: absolute; width: 52px; height: 52px; border-radius: 50%; color: #fff; font-size: 16px; line-height: 1; padding-top: 4px; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.abxy button small { color: #fff; font-size: 8px; opacity: .95; }
.abxy .x { left: 49px; top: 0; background: var(--x); }
.abxy .y { left: 0; top: 49px; background: var(--y); }
.abxy .a { left: 98px; top: 49px; background: var(--a); }
.abxy .b { left: 49px; top: 98px; background: var(--b); color: #3a3010; }
.abxy .b small { color: #3a3010; }

body:not(.portrait) .cluster { background: var(--body); padding: 14px 10px 18px; border-radius: 30px; box-shadow: inset 0 -4px 0 var(--body2); }
@media (max-height: 420px) { .cluster { transform: scale(.82); } }
