:root {
  --ink: #1d1c1c;
  --paper: #fff48d;
  --coral: #ff8a7a;
  --peach: #ffc4a8;
  --cream: #fff4b0;
  --white: #ffffff;
  --shadow: 4px 4px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "DM Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, var(--coral) 0%, var(--peach) 35%, var(--cream) 70%, var(--paper) 100%);
  background-attachment: fixed;
  overflow: hidden;
  touch-action: none;
}

#wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 0.5rem;
}

canvas {
  display: block;
  max-width: 100%;
  width: min(800px, 100%);
  border: 4px solid var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #5c94fc;
  image-rendering: pixelated;
  cursor: pointer;
}

#hint kbd {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.75rem;
  margin: 0 1px;
}

.music-hint {
  color: #2d6a4f;
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

#game-stage {
  position: relative;
}

#hud {
  width: min(800px, 100%);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 0.35rem 0.25rem;
  font-weight: 700;
  font-size: 0.88rem;
}

#hud span {
  color: #c0392b;
}

#levelTitle {
  font-size: 1.15rem;
  margin: 0 0 0.25rem;
  letter-spacing: 1px;
}

#hint {
  opacity: 0.75;
  font-size: 0.78rem;
  text-align: center;
  margin-top: 0.35rem;
}

#hint a {
  color: var(--ink);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.panel {
  background: #fff;
  color: #1d1c1c;
  border: 4px solid #1d1c1c;
  border-radius: 1rem;
  box-shadow: 8px 8px 0 #1d1c1c;
  padding: 2rem;
  max-width: 22rem;
  text-align: center;
}

.panel h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.panel p {
  margin: 0 0 1.25rem;
  line-height: 1.6;
  font-size: 0.92rem;
}

.start-mobile-hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: #5a4a00;
}

.panel button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  border: 3px solid #1d1c1c;
  border-radius: 999px;
  background: #fff48d;
  box-shadow: 4px 4px 0 #1d1c1c;
  cursor: pointer;
}

.panel button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #1d1c1c;
}

/* ---- 手机触控 & 全屏 ---- */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: none;
}

#touch-controls.is-active {
  display: block;
}

.tc-stick-zone {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  pointer-events: auto;
  touch-action: none;
}

.tc-stick-base {
  position: absolute;
  inset: 0;
  border: 3px solid rgba(29, 28, 28, 0.55);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.tc-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: rgba(255, 244, 141, 0.92);
  box-shadow: 3px 3px 0 rgba(29, 28, 28, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tc-actions {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: auto;
}

.tc-btn {
  width: 56px;
  height: 56px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  box-shadow: 3px 3px 0 rgba(29, 28, 28, 0.55);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.tc-btn:active,
.tc-btn.is-pressed {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(29, 28, 28, 0.55);
  background: rgba(255, 244, 141, 0.95);
}

.tc-actions .tc-btn {
  width: 64px;
  height: 64px;
  font-size: 1.25rem;
}

.tc-a {
  background: rgba(255, 200, 168, 0.9);
}

.tc-b {
  background: rgba(200, 230, 255, 0.9);
}

.btn-fullscreen {
  margin-top: 0.35rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 700;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  box-shadow: 2px 2px 0 var(--ink);
}

body.mobile-play {
  overflow: hidden;
  height: 100dvh;
  height: 100svh;
}

body.mobile-play #wrap {
  min-height: 0;
  height: 100%;
  max-height: 100dvh;
  max-height: 100svh;
  width: 100vw;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  justify-content: flex-start;
  overflow: hidden;
}

body.mobile-play #levelTitle {
  display: none;
}

body.mobile-play #hud {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  z-index: 5;
  width: auto;
  flex: none;
  padding: 0;
  gap: 0.55rem 0.85rem;
  font-size: 0.72rem;
  line-height: 1.2;
  justify-content: flex-start;
  flex-wrap: wrap;
  background: transparent;
  border: none;
  color: #fff;
  pointer-events: none;
  text-shadow:
    1px 0 0 #1d1c1c,
    -1px 0 0 #1d1c1c,
    0 1px 0 #1d1c1c,
    0 -1px 0 #1d1c1c,
    1px 1px 0 #1d1c1c;
}

body.mobile-play #hud span {
  color: #ffe066;
}

body.mobile-play #hint,
body.mobile-play #musicHint {
  display: none;
}

body.mobile-play #game-stage {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  background: #5c94fc;
}

body.mobile-play canvas {
  display: block;
  flex: 0 0 auto;
  max-width: 100%;
  max-height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

body.mobile-play.game-running #touch-controls.is-active {
  display: block;
}

.btn-mobile-restart {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  padding: 0.7rem 1.6rem;
  font-size: 1rem;
  font-weight: 800;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff48d;
  box-shadow: 4px 4px 0 var(--ink);
  touch-action: manipulation;
  pointer-events: auto;
}

.btn-mobile-restart[hidden] {
  display: none !important;
}

body.mobile-play .btn-fullscreen {
  display: none;
}

/* 桌面：HUD 在 canvas 上方；手机：HUD 叠在 canvas 顶栏 */
@media (min-width: 901px), (pointer: fine) {
  #game-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(800px, 100%);
  }

  #hud {
    order: -1;
  }
}
