:root {
  color-scheme: dark;
  --bezel: #101014;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0a0a0c;
  color: #c8c8d0;
  font-family: system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px;
}

#toolbar {
  display: flex;
  justify-content: flex-end;
  width: calc(120px * var(--scale, 3) + 20px);
}

#toolbar button {
  font: inherit;
  font-size: 12px;
  color: #c8c8d0;
  background: #1b1b22;
  border: 1px solid #32323c;
  border-radius: 5px;
  padding: 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
}

#toolbar button:active { background: #2c2c38; }

/* モダンモード中はボタンの見た目も切り替わる */
#toolbar button.modern {
  color: #eaf6ff;
  background: linear-gradient(180deg, #2a4a6e, #1a2c44);
  border-color: #3e6a96;
}

#stage {
  display: grid;
  place-items: center;
  padding: 10px;
  background: var(--bezel);
  border-radius: 6px;
  box-shadow: 0 0 0 1px #26262e, 0 8px 24px rgba(0, 0, 0, 0.6);
}

/* 120x120 を整数倍だけで拡大する。中間補間は一切かけない。 */
#screen {
  image-rendering: pixelated;
  display: block;
  width: calc(120px * var(--scale, 3));
  height: calc(120px * var(--scale, 3));
  /* キャンバスを直接タッチ操作するので、スクロールやダブルタップ拡大に取られない */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

/* 意味のある出来事のメッセージを送るボタン。画面の欄外・十字キーの上に置く。
   場所を常に確保しておき、押せないときは薄くするだけにして、
   出たり消えたりでレイアウトがずれないようにしている。 */
#msgBar {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 52px;
  margin-top: -4px;
}

#okBtn {
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #10100a;
  background: #e8c840;
  border: 1px solid #f0dc80;
  border-radius: 8px;
  width: 176px;
  height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.12s ease;
}

#okBtn:active { background: #f0d860; }

#okBtn:disabled {
  color: #4a4a52;
  background: #1b1b22;
  border-color: #2a2a34;
  opacity: 0.5;
  cursor: default;
}

/* まだ押せない（読ませている）あいだ */
#okBtn.waiting {
  color: #6a6250;
  background: #3a3424;
  border-color: #4a4230;
  opacity: 1;
  cursor: default;
}

#pad {
  display: flex;
  align-items: center;
  gap: 28px;
}

#pad button {
  font: inherit;
  font-size: 13px;
  color: #d4d4dc;
  background: #1b1b22;
  border: 1px solid #32323c;
  border-radius: 5px;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

#pad button:active { background: #2c2c38; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(3, 40px);
  gap: 3px;
}

.dpad button[data-key="up"]    { grid-area: 1 / 2; }
.dpad button[data-key="left"]  { grid-area: 2 / 1; }
.dpad button[data-key="down"]  { grid-area: 3 / 2; }
.dpad button[data-key="right"] { grid-area: 2 / 3; }

.keys {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keys button {
  width: 92px;
  height: 40px;
}

/* キーボードがある環境ではパッドを畳む */
@media (hover: hover) and (pointer: fine) {
  #pad { opacity: 0.45; }
  #pad:hover { opacity: 1; }
}
