* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #1a1a2e;
  color: #fff;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-wrap {
  position: relative;
  width: min(1280px, 100vw);
  max-height: 100vh;
  max-height: 100dvh;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 4px #2a2a4a;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #87ceeb;
  cursor: pointer;
  image-rendering: pixelated;
  touch-action: none;
}

#desktop-hint {
  position: absolute;
  right: 0;
  bottom: 8px;
  left: 0;
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, .8);
  pointer-events: none;
}

kbd {
  display: inline-block;
  margin: 0 2px;
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 3px;
  background: rgba(255, 255, 255, .15);
  font: 11px monospace;
}

#mobile-controls, #rotate-tip { display: none; }

/* 手机版项目始终显示触控界面，方便在电脑浏览器中直接预览和调试。 */
@media all {
  #game-wrap {
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
    box-shadow: none;
  }

  canvas#game { object-fit: contain; }
  #desktop-hint { display: none; }

  #mobile-controls {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    pointer-events: none;
  }

  .control-group {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    pointer-events: none;
  }

  .joystick {
    position: relative;
    width: clamp(112px, 17vw, 148px);
    height: clamp(112px, 17vw, 148px);
    border: 2px solid rgba(255, 255, 255, .36);
    border-radius: 50%;
    background: rgba(12, 18, 38, .32);
    box-shadow: inset 0 0 24px rgba(0, 0, 0, .25);
    touch-action: none;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .joystick-ring {
    position: absolute;
    inset: 18%;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 50%;
    pointer-events: none;
  }

  .joystick::before,
  .joystick::after {
    position: absolute;
    top: 50%;
    color: rgba(255, 255, 255, .35);
    font-size: clamp(17px, 2.4vw, 23px);
    transform: translateY(-50%);
    pointer-events: none;
  }

  .joystick::before { left: 9px; content: "◀"; }
  .joystick::after { right: 9px; content: "▶"; }

  .joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48%;
    height: 48%;
    border: 2px solid rgba(255, 255, 255, .7);
    border-radius: 50%;
    background: rgba(73, 162, 255, .72);
    box-shadow: inset 0 0 15px rgba(255, 255, 255, .16), 0 5px 15px rgba(0, 0, 0, .3);
    transform: translate(-50%, -50%);
    pointer-events: none;
  }

  .control-button {
    width: clamp(58px, 9vw, 76px);
    height: clamp(58px, 9vw, 76px);
    border: 2px solid rgba(255, 255, 255, .6);
    border-radius: 50%;
    outline: none;
    background: rgba(12, 18, 38, .55);
    box-shadow: inset 0 0 14px rgba(255, 255, 255, .12), 0 4px 12px rgba(0, 0, 0, .25);
    color: #fff;
    font: 700 clamp(20px, 3.2vw, 28px)/1 "Microsoft YaHei", sans-serif;
    text-shadow: 0 2px 3px rgba(0, 0, 0, .5);
    touch-action: none;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .control-button.pressed {
    transform: scale(.92);
    background: rgba(73, 162, 255, .75);
  }

  .control-button.locked {
    border-color: #fff3a1;
    background: rgba(238, 73, 94, .9);
    box-shadow: inset 0 0 16px rgba(255, 255, 255, .25), 0 0 18px rgba(255, 83, 108, .7);
  }

  .control-button.locked::after {
    position: absolute;
    right: -2px;
    bottom: -2px;
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    border-radius: 50%;
    background: #39d98a;
    color: #10281e;
    content: "✓";
    font-size: 14px;
  }

  .jump {
    width: clamp(72px, 12vw, 94px);
    height: clamp(72px, 12vw, 94px);
    border-color: rgba(255, 224, 90, .85);
    background: rgba(231, 149, 28, .58);
  }

  .sprint { position: relative; background: rgba(221, 62, 91, .58); }

  .pause {
    width: clamp(44px, 7vw, 58px);
    height: clamp(44px, 7vw, 58px);
    font-size: clamp(16px, 2.4vw, 22px);
    opacity: .85;
  }
}

@media (pointer: coarse) and (orientation: portrait), (max-width: 820px) and (orientation: portrait) {
  #game-wrap { visibility: hidden; }

  #rotate-tip {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    padding: 24px;
    color: #fff;
    font-size: 24px;
    line-height: 1.7;
    text-align: center;
    background: radial-gradient(circle at 50% 35%, #324a7a, #16172c 65%);
  }

  #rotate-tip small { color: rgba(255, 255, 255, .65); font-size: 14px; }
}
