/* ===== 马卡龙配色 ===== */
:root {
  --bg-cream: #FFF5F0;
  --bg-cream-2: #FFE8E0;
  --pink-1: #FFB6C1;
  --pink-2: #FF9EAA;
  --pink-3: #FF6B8A;
  --mint: #B5EAD7;
  --mint-2: #8BE2C6;
  --peach: #FFDAC1;
  --lavender: #C7CEEA;
  --lavender-2: #B0B8E0;
  --yellow: #FFF1A8;
  --coral: #FFB5A7;
  --text-dark: #5C4A5C;
  --text-mid: #8A7A8A;
  --white: #FFFFFF;
  --shadow-soft: 0 8px 24px rgba(255, 158, 170, 0.25);
  --shadow-lift: 0 12px 32px rgba(255, 158, 170, 0.35);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: var(--text-dark);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  background: linear-gradient(135deg, var(--bg-cream) 0%, var(--bg-cream-2) 50%, #FFE0EB 100%);
  background-attachment: fixed;
  position: relative;
}

/* 装饰性背景圆点 */
body::before,
body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
body::before {
  width: 200px;
  height: 200px;
  background: var(--mint);
  opacity: 0.3;
  top: -60px;
  right: -60px;
}
body::after {
  width: 300px;
  height: 300px;
  background: var(--lavender);
  opacity: 0.25;
  bottom: -100px;
  left: -100px;
}

.game-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  gap: 10px;
}

/* ===== 顶部信息栏 ===== */
.top-bar {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.score-box {
  background: var(--white);
  border-radius: 20px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: var(--shadow-soft);
  min-width: 70px;
  border: 2px solid var(--pink-1);
}

.score-box.best {
  border-color: var(--mint-2);
}

.score-label {
  font-size: 11px;
  color: var(--text-mid);
  font-weight: bold;
  letter-spacing: 1px;
}

.score-value {
  font-size: 22px;
  font-weight: bold;
  color: var(--pink-3);
  line-height: 1.2;
}

.score-box.best .score-value {
  color: var(--mint-2);
}

.center-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.level-box {
  background: var(--white);
  border-radius: 16px;
  padding: 4px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-soft);
  border: 2px solid var(--yellow);
}

.level-label {
  font-size: 11px;
  color: var(--text-mid);
  font-weight: bold;
}

.level-value {
  font-size: 20px;
  font-weight: bold;
  color: #E8B94D;
  line-height: 1.1;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}

.speed-box {
  background: var(--white);
  border-radius: 16px;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-soft);
  border: 2px solid var(--lavender);
}

.speed-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--lavender);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}

.speed-btn:active {
  transform: scale(0.88);
  background: var(--lavender-2);
}

.speed-level-row {
  display: flex;
  align-items: baseline;
  gap: 1px;
  min-width: 40px;
  justify-content: center;
}

.speed-level {
  font-size: 16px;
  font-weight: bold;
  color: var(--lavender-2);
  line-height: 1.1;
}

.speed-level-of {
  font-size: 10px;
  color: var(--text-mid);
  font-weight: bold;
}

/* ===== 画布容器 ===== */
.canvas-container {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#game-canvas {
  background: var(--white);
  border-radius: 28px;
  box-shadow: var(--shadow-lift);
  border: 3px solid var(--pink-1);
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* ===== 遮罩界面 ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 245, 240, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 28px;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--white);
  border-radius: 28px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow-lift);
  border: 3px solid var(--pink-1);
  max-width: 320px;
  width: 85%;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay-card.small {
  padding: 24px 20px;
}

@keyframes pop-in {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* 可爱蛇预览 */
.cute-snake-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.snake-head-preview {
  width: 70px;
  height: 70px;
  background: var(--pink-2);
  border-radius: 50%;
  position: relative;
  box-shadow: 0 4px 12px rgba(255, 107, 138, 0.3);
  animation: bounce 1.2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.snake-head-preview .eye {
  position: absolute;
  width: 12px;
  height: 14px;
  background: var(--white);
  border-radius: 50%;
  top: 22px;
}
.snake-head-preview .eye.left { left: 15px; }
.snake-head-preview .eye.right { right: 15px; }

.snake-head-preview .eye::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 7px;
  background: var(--text-dark);
  border-radius: 50%;
  top: 4px;
  left: 3px;
}

.snake-head-preview .blush {
  position: absolute;
  width: 12px;
  height: 7px;
  background: var(--coral);
  border-radius: 50%;
  opacity: 0.7;
  top: 38px;
}
.snake-head-preview .blush.left { left: 6px; }
.snake-head-preview .blush.right { right: 6px; }

.snake-head-preview .mouth {
  position: absolute;
  width: 12px;
  height: 6px;
  border: 2px solid var(--text-dark);
  border-top: none;
  border-radius: 0 0 12px 12px;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
}

.overlay-title {
  font-size: 26px;
  font-weight: bold;
  color: var(--pink-3);
  margin-bottom: 8px;
  text-shadow: 2px 2px 0 var(--yellow);
}

.overlay-title.small {
  font-size: 22px;
}

.overlay-subtitle {
  font-size: 14px;
  color: var(--text-mid);
  margin-bottom: 20px;
  line-height: 1.5;
}

.game-over-icon {
  font-size: 56px;
  margin-bottom: 8px;
}

/* ===== 按钮 ===== */
.cute-btn {
  display: inline-block;
  padding: 12px 32px;
  border: none;
  border-radius: 24px;
  font-size: 16px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  margin: 4px;
  min-width: 140px;
}

.cute-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}

.cute-btn.primary {
  background: linear-gradient(180deg, var(--pink-2) 0%, var(--pink-3) 100%);
  color: var(--white);
  box-shadow: 0 4px 0 #E85576;
}

.cute-btn.primary:active {
  box-shadow: 0 2px 0 #E85576;
}

.cute-btn.secondary {
  background: var(--mint);
  color: var(--text-dark);
  box-shadow: 0 4px 0 var(--mint-2);
}

.cute-btn.secondary:active {
  box-shadow: 0 2px 0 var(--mint-2);
}

.hint-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.hint-chip {
  background: var(--bg-cream);
  color: var(--text-mid);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--pink-1);
}

/* ===== 最终分数 ===== */
.final-scores {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 16px 0;
}

.final-score-item {
  background: var(--bg-cream);
  border-radius: 16px;
  padding: 12px 20px;
  min-width: 80px;
  border: 2px solid var(--pink-1);
}

.final-score-item.best {
  border-color: var(--mint-2);
}

.final-score-label {
  display: block;
  font-size: 11px;
  color: var(--text-mid);
  margin-bottom: 4px;
}

.final-score-value {
  display: block;
  font-size: 28px;
  font-weight: bold;
  color: var(--pink-3);
}

.final-score-item.best .final-score-value {
  color: var(--mint-2);
}

.new-record {
  background: var(--yellow);
  color: var(--text-dark);
  font-size: 14px;
  font-weight: bold;
  padding: 6px 16px;
  border-radius: 16px;
  margin-bottom: 12px;
  display: inline-block;
  animation: wiggle 0.6s ease-in-out infinite alternate;
}

.new-record.hidden {
  display: none;
}

@keyframes wiggle {
  from { transform: rotate(-3deg); }
  to { transform: rotate(3deg); }
}

/* ===== 底部控制栏 ===== */
.bottom-bar {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--white);
  color: var(--pink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  border: 2px solid var(--pink-1);
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.icon-btn svg {
  width: 26px;
  height: 26px;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ===== 虚拟方向键 ===== */
.dpad {
  position: relative;
  width: 240px;
  height: 240px;
  flex-shrink: 0;
}

.dpad-btn {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 26px;
  border: none;
  background: linear-gradient(180deg, #ffffff 0%, #fff0f3 100%);
  color: var(--pink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 0 #f7a8b8, 0 8px 16px rgba(255, 158, 170, 0.35);
  border: 3px solid var(--pink-1);
  transition: all 0.1s ease;
}

.dpad-btn svg {
  width: 36px;
  height: 36px;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: var(--pink-2);
  color: var(--white);
  transform: translateY(3px);
  box-shadow: 0 3px 0 #f7a8b8, 0 4px 8px rgba(255, 158, 170, 0.3);
}

.dpad-btn.up { top: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.up:active { transform: translateX(-50%) translateY(3px); }
.dpad-btn.down { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-btn.down:active { transform: translateX(-50%) translateY(3px); }
.dpad-btn.left { left: 0; top: 50%; transform: translateY(-50%); }
.dpad-btn.left:active { transform: translateY(-50%) translateY(3px); }
.dpad-btn.right { right: 0; top: 50%; transform: translateY(-50%); }
.dpad-btn.right:active { transform: translateY(-50%) translateY(3px); }

/* ===== 响应式 ===== */
@media (min-width: 600px) {
  .top-bar, .bottom-bar, .canvas-container {
    max-width: 520px;
  }

  .dpad {
    display: none;
  }

  .bottom-bar {
    justify-content: center;
    gap: 24px;
    align-items: center;
  }
}

@media (max-width: 380px) {
  .dpad {
    width: 200px;
    height: 200px;
  }
  .dpad-btn {
    width: 68px;
    height: 68px;
    border-radius: 22px;
  }
  .dpad-btn svg {
    width: 30px;
    height: 30px;
  }
  .score-value {
    font-size: 18px;
  }
  .score-box {
    padding: 6px 12px;
    min-width: 58px;
  }
  .level-value {
    font-size: 16px;
  }
  .level-box {
    padding: 3px 12px;
  }
  .speed-level {
    font-size: 14px;
  }
  .speed-btn {
    width: 20px;
    height: 20px;
  }
}

/* 横屏适配 */
@media (max-height: 500px) and (orientation: landscape) {
  .game-wrapper {
    padding: 8px;
    gap: 6px;
  }
  .top-bar {
    max-width: none;
    width: auto;
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 5;
  }
  .canvas-container {
    max-width: none;
    height: 100%;
  }
  .bottom-bar {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
    width: auto;
    z-index: 5;
  }
  .dpad {
    width: 180px;
    height: 180px;
  }
  .dpad-btn {
    width: 60px;
    height: 60px;
    border-radius: 18px;
  }
  .dpad-btn svg {
    width: 26px;
    height: 26px;
  }
}
