* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: #0b0b10;
  color: #6f6a86;
  font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background-image: radial-gradient(ellipse at center, #16161f 0%, #06060a 75%);
}

#stage {
  position: relative;
  line-height: 0;
  box-shadow: 0 0 0 4px #23202e, 0 0 0 8px #12111a, 0 18px 50px rgba(0,0,0,.8);
  border-radius: 3px;
  touch-action: none;
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* 掃描線 + 輕微色偏，加強 CRT 味道 */
#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,.18) 0px,
    rgba(0,0,0,.18) 1px,
    rgba(255,255,255,0) 1px,
    rgba(255,255,255,0) 3px
  );
  mix-blend-mode: multiply;
  opacity: .55;
}

#hint {
  font-size: 12px;
  letter-spacing: 1px;
  user-select: none;
}

/* 全螢幕按鈕：固定在畫面右上角，不佔版面、不隨畫布縮放位移 */
#fsBtn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 36px;
  height: 36px;
  border: 2px solid rgba(242, 193, 78, .55);
  background: rgba(13, 11, 19, .55);
  color: #f2c14e;
  font-size: 17px;
  line-height: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(1px);
  -webkit-tap-highlight-color: transparent;
}
#fsBtn:hover,
#fsBtn:active { background: rgba(242, 193, 78, .30); border-color: #f2c14e; }
#fsBtn[hidden] { display: none; }

/* 全螢幕狀態下把提示文字收起，讓遊戲畫面盡量佔滿 */
body.fs-active { gap: 0; }
body.fs-active #hint { display: none; }

/* ------------------------------------------------------------
   觸控操作（十字鍵 + 確定／選單）
   平常隱藏；只在「粗指標」裝置（手機／平板）上顯示。
   ------------------------------------------------------------ */
#touchpad {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  user-select: none;
  -webkit-user-select: none;
}

.tp-dpad, .tp-actions {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  pointer-events: auto;
}
.tp-dpad {
  left: max(14px, env(safe-area-inset-left));
  width: 132px;
  height: 132px;
}
.tp-actions {
  right: max(14px, env(safe-area-inset-right));
  width: 132px;
  height: 132px;
}

.tp-btn {
  position: absolute;
  border: 2px solid rgba(242, 193, 78, .55);
  background: rgba(22, 18, 40, .55);
  color: #f2c14e;
  font-size: 20px;
  line-height: 1;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  backdrop-filter: blur(1px);
}
.tp-btn:active,
.tp-btn.tp-active {
  background: rgba(242, 193, 78, .38);
  border-color: #f2c14e;
}

.tp-up    { top: 0;    left: 44px;  width: 44px; height: 44px; }
.tp-down  { top: 88px; left: 44px;  width: 44px; height: 44px; }
.tp-left  { top: 44px; left: 0;     width: 44px; height: 44px; }
.tp-right { top: 44px; left: 88px;  width: 44px; height: 44px; }

.tp-ok   { right: 0;  bottom: 0;  width: 62px; height: 62px; border-radius: 50%; font-size: 18px; }
.tp-menu { right: 74px; bottom: 20px; width: 44px; height: 44px; border-radius: 50%; font-size: 16px; }
.tp-music { right: 12px; bottom: 80px; width: 36px; height: 36px; border-radius: 50%; font-size: 14px; opacity: .8; }

/* 粗指標裝置（手機／平板）：滿版顯示、隱藏鍵盤提示、收起邊框 */
@media (pointer: coarse) {
  html, body { gap: 0; }
  #hint { display: none; }
  #touchpad { display: block; }
  #stage {
    box-shadow: none;
    border-radius: 0;
  }
}
@media (pointer: fine) {
  #touchpad { display: none !important; }
}

@media (max-width: 640px) and (pointer: fine) {
  #hint { font-size: 10px; text-align: center; padding: 0 12px; }
}
