:root {
  color-scheme: dark;
  --ink: #f8fbff;
  --page: #162434;
  --panel: #24384b;
  --edge: #6f8196;
  --accent: #94d13d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.14)),
    var(--page);
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

.shell {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #0e1722;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #9fb4c8;
}

.audio-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 3px solid var(--edge);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel), transparent 6%);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 5px 0 rgba(20, 31, 45, 0.3);
  cursor: pointer;
  touch-action: manipulation;
}

.audio-toggle:disabled {
  display: none;
}

.sound-icon {
  position: relative;
  width: 22px;
  height: 20px;
}

.sound-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  width: 8px;
  height: 8px;
  background: var(--ink);
  box-shadow: 7px -5px 0 1px var(--ink), 7px 5px 0 1px var(--ink);
  clip-path: polygon(0 18%, 45% 18%, 100% 0, 100% 100%, 45% 82%, 0 82%);
}

.sound-icon::after {
  content: "";
  position: absolute;
  right: 0;
  top: 2px;
  width: 9px;
  height: 16px;
  border: 3px solid var(--accent);
  border-left: 0;
  border-radius: 0 12px 12px 0;
}

.audio-toggle.muted {
  border-color: #d95f5f;
}

.audio-toggle.muted .sound-icon::after {
  right: -1px;
  top: 8px;
  width: 18px;
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: #ff6b6b;
  transform: rotate(-35deg);
}

.touch-controls {
  position: absolute;
  bottom: 14px;
  display: none;
  gap: 12px;
  pointer-events: none;
  z-index: 2;
}

/* 左手区：左 / 右 移动键，固定在屏幕左下角 */
.touch-controls-left {
  left: 14px;
  grid-template-columns: repeat(2, 58px);
}

/* 右手区：上（跳跃 / 爬梯）键，固定在屏幕右下角 */
.touch-controls-right {
  right: 14px;
  grid-template-columns: 58px;
}

/* JS 显式判断设备后加的类：手机/平板才加上，电脑（鼠标）不显示 */
.touch-controls.is-visible {
  display: grid;
}

/* CSS 原生兜底：触屏/无悬停设备直接显示（电脑鼠标设备不显示） */
@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

.touch-button {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 3px solid var(--edge);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel), transparent 8%);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  /* 三个方向键默认 50% 半透明，不遮挡游戏画面 */
  opacity: 0.5;
  transition: opacity 120ms ease;
}

/* 按下时提高到 85%，给手指明确的按压反馈；抬起后回到 50% */
.touch-button:active {
  opacity: 0.85;
}

@media (max-aspect-ratio: 16 / 9) {
  .shell {
    width: 100vw;
  }
}
