/* ===== 全局 & 字体 ===== */
@import url('https://fonts.googleapis.com/css2?family=ZCOOL+KuaiLe&family=Ma+Shan+Zheng&display=swap');

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

:root {
  --sv-bg: #1a1510;
  --sv-bg2: #2a2218;
  --sv-panel: #3a2e20;
  --sv-border: #6b5a3e;
  --sv-border-light: #8b7a5e;
  --sv-gold: #f0c040;
  --sv-gold-dark: #c89828;
  --sv-green: #6aab3d;
  --sv-green-dark: #3d7a20;
  --sv-blue: #5b8dd9;
  --sv-red: #d94040;
  --sv-brown: #8b6b3a;
  --sv-text: #f0e6d0;
  --sv-text-dim: #a09880;
  --sv-path: #3a4a28;
  --sv-thorn: #4a2020;
  --font-title: 'Ma Shan Zheng', 'ZCOOL KuaiLe', cursive;
  --font-body: 'ZCOOL KuaiLe', 'Ma Shan Zheng', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  background: var(--sv-bg);
  color: var(--sv-text);
  font-family: var(--font-body);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  image-rendering: pixelated;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.5s;
}

/* ===== 星露谷风格按钮 ===== */
.sv-btn {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 12px 28px;
  border: 3px solid var(--sv-border);
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  letter-spacing: 2px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 4px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.sv-btn-primary {
  background: linear-gradient(180deg, #6aab3d 0%, #4a8a25 100%);
  color: #fff;
  border-color: #3d7a20;
  box-shadow: 0 4px 0 #2a5a10, 0 6px 12px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.sv-btn-primary:hover { background: linear-gradient(180deg, #7abb4d 0%, #5a9a35 100%); transform: translateY(-1px); }
.sv-btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #2a5a10, 0 2px 6px rgba(0,0,0,0.3); }

.sv-btn-secondary {
  background: linear-gradient(180deg, #5a4a30 0%, #3a2e20 100%);
  color: var(--sv-gold);
  border-color: var(--sv-border);
  box-shadow: 0 4px 0 #2a1e10, 0 6px 12px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}
.sv-btn-secondary:hover { background: linear-gradient(180deg, #6a5a40 0%, #4a3e30 100%); }
.sv-btn-secondary:active { transform: translateY(2px); box-shadow: 0 2px 0 #2a1e10; }

.sv-btn-icon {
  background: var(--sv-panel);
  border: 2px solid var(--sv-border);
  color: var(--sv-gold);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.15s;
}
.sv-btn-icon:hover { background: #4a3e28; border-color: var(--sv-gold); }

.btn-icon { font-size: 18px; }

/* ===== 封面 ===== */
#cover-screen {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #0f0c08 0%, #1a1510 30%, #2a2018 70%, #1a1510 100%);
  z-index: 100;
  overflow: hidden;
}
#cover-canvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 0;
}
.cover-content {
  z-index: 1; display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 500px; padding: 20px;
}

/* 封面场景动画 */
.cover-scene {
  position: relative;
  width: 200px;
  height: 120px;
  margin-bottom: 10px;
}
.scene-ground {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 30px;
  background: linear-gradient(180deg, #4a6a28 0%, #3a5a18 100%);
  border-radius: 50% 50% 0 0 / 30px 30px 0 0;
}
.scene-ground::before {
  content: '🌱  🌿  🌱';
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 8px;
  animation: grassSway 2s ease-in-out infinite;
}
@keyframes grassSway { 0%,100%{transform:translateX(-50%) rotate(0)} 50%{transform:translateX(-50%) rotate(2deg)} }

.scene-character {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
}
.char-body {
  font-size: 52px;
  animation: digAnimation 2s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(240,192,64,0.4));
}
@keyframes digAnimation {
  0%,100% { transform: translateY(0) rotate(0); }
  15% { transform: translateY(-20px) rotate(-15deg); }
  30% { transform: translateY(5px) rotate(5deg); }
  45% { transform: translateY(-8px) rotate(-5deg); }
  60% { transform: translateY(3px) rotate(2deg); }
}
.char-shadow {
  width: 40px;
  height: 8px;
  background: rgba(0,0,0,0.3);
  border-radius: 50%;
  margin: 0 auto;
  animation: shadowPulse 2s ease-in-out infinite;
}
@keyframes shadowPulse { 0%,100%{transform:scaleX(1);opacity:0.3} 15%{transform:scaleX(0.6);opacity:0.15} 30%{transform:scaleX(1.1);opacity:0.35} }

.scene-particles {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}

/* 标题 */
.title-container { text-align: center; margin-bottom: 30px; }
.game-title {
  font-family: var(--font-title);
  font-size: 56px;
  color: var(--sv-gold);
  text-shadow: 2px 2px 0 var(--sv-gold-dark), 4px 4px 0 rgba(0,0,0,0.5), 0 0 30px rgba(240,192,64,0.3);
  letter-spacing: 12px;
  display: flex;
  justify-content: center;
  gap: 4px;
}
.title-char {
  display: inline-block;
  animation: charFloat 3s ease-in-out infinite;
}
@keyframes charFloat {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.game-subtitle {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--sv-text-dim);
  margin-top: 8px;
  letter-spacing: 6px;
  opacity: 0;
  animation: fadeSlideUp 1s 0.5s forwards;
}
@keyframes fadeSlideUp { 0%{opacity:0;transform:translateY(10px)} 100%{opacity:1;transform:translateY(0)} }

/* 输入框 */
.cover-input-group { margin-bottom: 24px; width: 100%; max-width: 300px; }
.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--sv-bg2);
  border: 3px solid var(--sv-border);
  border-radius: 4px;
  padding: 0 12px;
  transition: border-color 0.2s;
}
.input-wrapper:focus-within { border-color: var(--sv-gold); }
.input-icon { font-size: 20px; margin-right: 8px; }
#nickname-input {
  background: transparent;
  border: none;
  color: var(--sv-gold);
  padding: 12px 0;
  font-size: 18px;
  font-family: var(--font-body);
  text-align: center;
  width: 100%;
  outline: none;
}
#nickname-input::placeholder { color: #6b5a3e; }

/* 封面按钮 */
.cover-buttons { display: flex; gap: 15px; margin-bottom: 30px; flex-wrap: wrap; justify-content: center; }

/* 提示 */
.cover-tips {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  opacity: 0;
  animation: fadeSlideUp 1s 1s forwards;
}
.tip-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--sv-text-dim);
  background: rgba(58,46,32,0.6);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(107,90,62,0.3);
}
.tip-icon { font-size: 14px; }

/* ===== 游戏主界面 ===== */
#game-screen { display: none; width: 100%; height: 100%; position: relative; flex-direction: column; }

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: linear-gradient(180deg, var(--sv-bg2) 0%, var(--sv-bg) 100%);
  border-bottom: 3px solid var(--sv-border);
  min-height: 48px;
  z-index: 10;
  transition: background 0.5s, border-color 0.5s;
}
.header-left, .header-center, .header-right { display: flex; align-items: center; gap: 10px; }
.header-left { flex: 0 0 auto; }
.header-center { flex: 1; justify-content: center; }
.header-right { flex: 0 0 auto; }
.level-info { color: var(--sv-gold); font-size: 15px; font-weight: bold; }
.health-bar { display: flex; gap: 3px; align-items: center; }
.heart { font-size: 20px; transition: all 0.3s; }
.heart.active { filter: drop-shadow(0 0 4px rgba(255,60,60,0.5)); }
.heart.lost { opacity: 0.3; transform: scale(0.8); filter: grayscale(1); }
.score-display { color: var(--sv-gold); font-size: 14px; white-space: nowrap; }
.nickname-display { color: var(--sv-text-dim); font-size: 13px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 游戏主体 */
.game-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.map-area { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px; overflow: auto; }
.map-container { display: flex; align-items: center; justify-content: center; }

#game-grid {
  display: grid;
  gap: 1px;
  background: #0a0a08;
  border: 3px solid var(--sv-border);
  box-shadow: 0 0 20px rgba(107,90,62,0.2), inset 0 0 30px rgba(0,0,0,0.3);
  border-radius: 4px;
  position: relative;
}

/* ===== 格子样式 - 星露谷风格 ===== */
.grid-cell {
  width: 100%; height: 100%;
  background: var(--sv-panel);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  font-weight: bold;
  border: 1px solid rgba(107,90,62,0.2);
  overflow: hidden;
}

/* 未翻开 - 泥土质感 */
.grid-cell.unrevealed {
  background: var(--sv-panel);
  box-shadow: inset 2px 2px 0 rgba(255,255,255,0.05), inset -2px -2px 0 rgba(0,0,0,0.3);
}
.grid-cell.unrevealed:hover {
  filter: brightness(1.15);
}
.grid-cell.unrevealed::after {
  content: '';
  position: absolute;
  width: 3px; height: 3px;
  background: rgba(200,180,140,0.15);
  border-radius: 50%;
  top: 30%; left: 40%;
}

/* 已翻开 - 已挖开的泥土 */
.grid-cell.revealed {
  background: var(--sv-bg2);
}
.grid-cell.path {
  background: var(--sv-path);
  border-color: rgba(106,171,61,0.2);
}
.grid-cell.thorn {
  background: var(--sv-thorn);
  border-color: rgba(217,64,64,0.2);
}
.grid-cell.start-cell {
  background: linear-gradient(135deg, #2a3a4a 0%, #1a2a3a 100%);
  border-color: rgba(91,141,217,0.3);
  box-shadow: 0 0 8px rgba(91,141,217,0.3);
}
.grid-cell.exit {
  background: linear-gradient(135deg, #4a4a20 0%, #3a3a18 100%);
  border-color: rgba(240,192,64,0.3);
  animation: exitGlow 2s ease-in-out infinite;
}
@keyframes exitGlow { 0%,100%{box-shadow:0 0 6px rgba(240,192,64,0.2)} 50%{box-shadow:0 0 16px rgba(240,192,64,0.5)} }

/* === 玩家所在格 - 发光效果 === */
.grid-cell.current {
  background: var(--sv-path) !important;
  border-color: var(--sv-gold) !important;
  box-shadow:
    0 0 8px rgba(240,192,64,0.5),
    0 0 16px rgba(240,192,64,0.3),
    inset 0 0 12px rgba(240,192,64,0.15);
  animation: currentGlow 1.5s ease-in-out infinite;
  filter: brightness(1.3);
}
@keyframes currentGlow {
  0%,100% {
    box-shadow: 0 0 8px rgba(240,192,64,0.5), 0 0 16px rgba(240,192,64,0.3), inset 0 0 12px rgba(240,192,64,0.15);
  }
  50% {
    box-shadow: 0 0 12px rgba(240,192,64,0.7), 0 0 24px rgba(240,192,64,0.4), inset 0 0 16px rgba(240,192,64,0.25);
  }
}

/* 相邻可点击 */
.grid-cell.adjacent {
  outline: 2px dashed var(--sv-gold);
  outline-offset: -2px;
  animation: adjPulse 1.2s ease-in-out infinite;
}
@keyframes adjPulse { 0%,100%{outline-color:rgba(240,192,64,0.4)} 50%{outline-color:rgba(240,192,64,0.9)} }

/* 道具选择目标 */
.grid-cell.target-selectable {
  outline: 3px solid #ff9800;
  outline-offset: -3px;
  animation: targetPulse 0.6s ease-in-out infinite;
  cursor: crosshair;
}
@keyframes targetPulse { 0%,100%{box-shadow:inset 0 0 8px rgba(255,152,0,0.2)} 50%{box-shadow:inset 0 0 16px rgba(255,152,0,0.5)} }

.grid-cell.selectable-start {
  outline: 2px solid var(--sv-blue);
  animation: startPulse 1s ease-in-out infinite;
}
@keyframes startPulse { 0%,100%{background:#2a3a4a} 50%{background:#3a4a5a} }

/* 格子内容 */
.cell-number { font-size: 14px; font-weight: bold; z-index: 2; font-family: var(--font-body); }
.cell-number.safe { color: var(--sv-blue); }
.cell-number.warn { color: var(--sv-gold); }
.cell-number.danger { color: var(--sv-red); }
.cell-number.zero { color: var(--sv-green); }

.player-icon {
  font-size: 18px; z-index: 10;
  animation: playerBob 1s ease-in-out infinite;
  filter: drop-shadow(0 0 6px rgba(240,192,64,0.6));
}
@keyframes playerBob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-2px)} }

/* 玩家格内同时显示数字和图标 */
.cell-dual {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  z-index: 2;
}
.cell-dual .player-icon { font-size: 14px; line-height: 1; }
.cell-dual .cell-number { font-size: 10px; line-height: 1; opacity: 0.8; }

.thorn-icon { color: #d94040; font-size: 16px; text-shadow: 0 0 4px rgba(217,64,64,0.4); }
.item-icon { font-size: 16px; }
.soup-icon { font-size: 12px; }
.story-icon { font-size: 12px; }
.exit-icon { font-size: 18px; animation: exitSpin 3s linear infinite; }

/* 移动端格子内容适配 */
@media (max-width: 768px) {
  .cell-number { font-size: 16px; }
  .player-icon { font-size: 20px; }
  .cell-dual .player-icon { font-size: 16px; }
  .cell-dual .cell-number { font-size: 11px; }
  .thorn-icon { font-size: 18px; }
  .item-icon { font-size: 18px; }
  .soup-icon { font-size: 14px; }
  .story-icon { font-size: 14px; }
  .exit-icon { font-size: 20px; }
}
@keyframes exitSpin { 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} }

/* 迷雾 */
.fog-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(circle, rgba(80,60,40,0.85) 0%, rgba(50,40,30,0.9) 100%);
  z-index: 8; pointer-events: none;
  animation: fogSwirl 4s ease-in-out infinite;
}
@keyframes fogSwirl { 0%,100%{opacity:0.8} 50%{opacity:0.95} }
.fog-particle {
  position: absolute; width: 4px; height: 4px;
  background: rgba(180,160,120,0.3); border-radius: 50%;
  animation: fogFloat 3s ease-in-out infinite;
}
@keyframes fogFloat { 0%,100%{transform:translate(0,0) scale(1);opacity:0.3} 50%{transform:translate(3px,-3px) scale(1.3);opacity:0.6} }

/* ===== 右侧面板 - 星露谷风格 ===== */
.side-panel {
  width: 200px;
  background: linear-gradient(180deg, var(--sv-bg2) 0%, var(--sv-bg) 100%);
  border-left: 3px solid var(--sv-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  transition: width 0.3s, margin-right 0.3s, background 0.5s, border-color 0.5s;
}
.panel-toggle {
  display: none;
  position: absolute;
  top: 50%;
  left: -24px;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: var(--sv-panel);
  border: 2px solid var(--sv-border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  color: var(--sv-gold);
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.panel-inner { padding: 0; }
.panel-section { padding: 10px; border-bottom: 2px solid rgba(107,90,62,0.3); }
.panel-title {
  color: var(--sv-gold);
  font-size: 13px;
  margin-bottom: 8px;
  text-align: center;
  letter-spacing: 2px;
  font-family: var(--font-body);
}

.inventory-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; }
.inventory-slot {
  aspect-ratio: 1;
  background: var(--sv-bg2);
  border: 2px solid rgba(107,90,62,0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; font-size: 20px; position: relative;
  transition: all 0.15s;
  border-radius: 3px;
}
.inventory-slot:hover { background: var(--sv-panel); border-color: var(--sv-border); }
.inventory-slot.active { border-color: var(--sv-gold); background: var(--sv-panel); box-shadow: 0 0 8px rgba(240,192,64,0.3); }
.inventory-slot .item-count { position: absolute; bottom: 1px; right: 3px; font-size: 9px; color: var(--sv-gold); background: rgba(26,21,16,0.8); padding: 0 2px; border-radius: 2px; }
.inventory-slot .item-name { font-size: 7px; color: var(--sv-text-dim); margin-top: 1px; }

.progress-bar-bg { width: 100%; height: 10px; background: var(--sv-bg); border: 2px solid var(--sv-border); border-radius: 5px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--sv-green-dark), var(--sv-green)); transition: width 0.3s; }

.level-stats { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; font-size: 11px; }
.stat-row { display: flex; justify-content: space-between; color: var(--sv-text-dim); }
.stat-value { color: var(--sv-blue); }

.music-controls { display: flex; gap: 8px; justify-content: center; }
.music-btn {
  background: var(--sv-bg2);
  border: 2px solid rgba(107,90,62,0.4);
  color: var(--sv-text-dim);
  width: 34px; height: 34px;
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  border-radius: 3px;
}
.music-btn:hover { background: var(--sv-panel); }
.music-btn.active { color: var(--sv-gold); border-color: var(--sv-gold); }

.story-text { font-size: 11px; color: var(--sv-text-dim); line-height: 1.5; min-height: 50px; }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.75);
  display: none; align-items: center; justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: linear-gradient(180deg, #3a2e20 0%, #2a2218 100%);
  border: 4px solid var(--sv-border);
  padding: 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalPop 0.3s ease-out;
  position: relative;
  z-index: 501;
  border-radius: 6px;
}
@keyframes modalPop { 0%{transform:scale(0.85);opacity:0} 100%{transform:scale(1);opacity:1} }
.modal-title {
  color: var(--sv-gold);
  font-size: 20px;
  font-family: var(--font-title);
  margin-bottom: 12px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.modal-content { color: var(--sv-text); font-size: 14px; margin-bottom: 18px; line-height: 1.6; }
.modal-icon { font-size: 42px; margin-bottom: 8px; animation: iconBounce 0.5s ease-out; }
@keyframes iconBounce { 0%{transform:scale(0) rotate(-180deg)} 50%{transform:scale(1.2) rotate(10deg)} 100%{transform:scale(1) rotate(0)} }
.modal-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-action-btn { pointer-events: auto; cursor: pointer; position: relative; z-index: 502; }

/* ===== 排行榜 ===== */
#leaderboard-screen {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: none; flex-direction: column; align-items: center;
  background: linear-gradient(180deg, #0f0c08 0%, #1a1510 50%, #2a2018 100%);
  z-index: 100;
  padding: 20px;
  padding-top: calc(40px + var(--safe-top));
  overflow-y: auto;
}
.lb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.lb-trophy { font-size: 36px; }
.lb-title-text {
  font-family: var(--font-title);
  font-size: 32px;
  color: var(--sv-gold);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
}
.leaderboard-table {
  width: 100%; max-width: 500px;
  border-collapse: collapse;
  margin-bottom: 20px;
}
.leaderboard-table th {
  background: var(--sv-panel);
  color: var(--sv-gold);
  padding: 10px;
  border: 2px solid var(--sv-border);
  font-size: 13px;
  font-family: var(--font-body);
}
.leaderboard-table td {
  padding: 8px 10px;
  border: 1px solid rgba(107,90,62,0.3);
  text-align: center;
  font-size: 13px;
  color: var(--sv-text);
}
.leaderboard-table tr:nth-child(even) td { background: rgba(42,34,24,0.5); }
.rank-1 td { color: #ffd700 !important; } .rank-2 td { color: #c0c0c0 !important; } .rank-3 td { color: #cd7f32 !important; }
.empty-leaderboard { color: var(--sv-text-dim); font-size: 16px; margin-top: 40px; text-align: center; }

/* ===== 关卡完成/结束 ===== */
#level-complete-screen, #gameover-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
}
#level-complete-screen { background: rgba(26,21,16,0.92); }
#gameover-screen { background: rgba(40,10,10,0.92); }

.level-complete-content, .gameover-content { text-align: center; animation: completeSlide 0.5s ease-out; max-width: 500px; width: 100%; }
@keyframes completeSlide { 0%{transform:translateY(-40px);opacity:0} 100%{transform:translateY(0);opacity:1} }

.complete-title {
  font-family: var(--font-title);
  font-size: 36px;
  color: var(--sv-gold);
  text-shadow: 2px 2px 0 var(--sv-gold-dark);
  margin-bottom: 20px;
}
.complete-stats { display: flex; gap: 20px; margin-bottom: 24px; justify-content: center; flex-wrap: wrap; }
.complete-stat { text-align: center; min-width: 70px; }
.complete-stat-value { font-size: 30px; color: var(--sv-blue); display: block; font-family: var(--font-body); }
.complete-stat-label { font-size: 12px; color: var(--sv-text-dim); }

.gameover-title {
  font-family: var(--font-title);
  font-size: 42px;
  color: var(--sv-red);
  text-shadow: 2px 2px 0 #8b0000;
  margin-bottom: 20px;
  animation: goShake 0.5s ease-out;
}
@keyframes goShake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-8px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.gameover-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* 回滚特效 */
.rollback-effect {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(138,90,60,0.3);
  z-index: 100; pointer-events: none;
  animation: rbFlash 0.8s ease-out forwards;
}
@keyframes rbFlash { 0%{opacity:0} 30%{opacity:1} 100%{opacity:0} }

/* 关卡主题名称过渡动画 */
@keyframes themeShow {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1) translateY(-20px); }
}

/* 粒子 */
.particle { position: fixed; pointer-events: none; z-index: 600; font-size: 14px; }
.particle-up { animation: pUp 0.8s ease-out forwards; }
@keyframes pUp { 0%{opacity:1;transform:translateY(0)} 100%{opacity:0;transform:translateY(-50px)} }
.particle-explode { animation: pExplode 0.6s ease-out forwards; }
@keyframes pExplode { 0%{opacity:1;transform:translate(0,0) scale(1)} 100%{opacity:0;transform:translate(var(--dx),var(--dy)) scale(0)} }

/* 移动端工具栏 */
.mobile-toolbar {
  display: none;
  background: linear-gradient(180deg, var(--sv-bg2) 0%, var(--sv-bg) 100%);
  border-top: 3px solid var(--sv-border);
  padding-bottom: calc(4px + var(--safe-bottom));
  flex-shrink: 0;
  transition: background 0.5s, border-color 0.5s;
}

/* 移动端迷你统计条 */
.mobile-stats-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(107,90,62,0.3);
  flex-wrap: nowrap;
  overflow: hidden;
}
.m-stat {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--sv-text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
.m-stat span:last-child { color: var(--sv-blue); }
.m-stat-icon { font-size: 10px; }
.m-stat-progress {
  flex: 1;
  height: 6px;
  background: var(--sv-bg);
  border: 1px solid rgba(107,90,62,0.4);
  border-radius: 3px;
  overflow: hidden;
  min-width: 40px;
}
.m-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sv-green-dark), var(--sv-green));
  transition: width 0.3s;
}

/* 移动端操作栏 */
.mobile-action-bar {
  display: flex;
  align-items: center;
  padding: 5px 8px;
  gap: 8px;
}
.mobile-inventory {
  display: flex;
  gap: 5px;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-controls {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}
.m-ctrl-btn {
  width: 36px; height: 36px;
  background: var(--sv-bg);
  border: 2px solid rgba(107,90,62,0.4);
  color: var(--sv-text-dim);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.m-ctrl-btn.active { color: var(--sv-gold); border-color: var(--sv-gold); }

.mobile-inv-slot {
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: var(--sv-bg);
  border: 2px solid rgba(107,90,62,0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px;
  position: relative;
  border-radius: 4px;
}
.mobile-inv-slot.active { border-color: var(--sv-gold); box-shadow: 0 0 6px rgba(240,192,64,0.3); }
.mobile-inv-slot.empty { opacity: 0.4; }
.mobile-inv-slot .m-icon { font-size: 16px; line-height: 1; }
.mobile-inv-slot .m-count { position: absolute; bottom: 1px; right: 2px; font-size: 8px; color: var(--sv-gold); background: rgba(26,21,16,0.8); padding: 0 2px; border-radius: 2px; }
.mobile-inv-slot .m-name { font-size: 8px; color: var(--sv-text-dim); line-height: 1; }

/* 滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--sv-bg); }
::-webkit-scrollbar-thumb { background: var(--sv-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--sv-border-light); }

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
  .game-title { font-size: 42px; letter-spacing: 8px; }
  .game-subtitle { font-size: 13px; letter-spacing: 4px; }

  #game-screen { flex-direction: column; }

  .game-body {
    flex-direction: column;
    height: auto;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .map-area {
    flex: 1;
    padding: 4px;
    min-height: 0;
    overflow: hidden;
  }

  .map-container {
    width: 100%;
    height: 100%;
  }

  .side-panel {
    display: none;
  }

  .mobile-toolbar {
    display: block;
  }

  .game-header {
    padding: 5px 10px;
    padding-top: calc(5px + var(--safe-top));
    min-height: 40px;
  }
  .level-info { font-size: 13px; }
  .score-display { font-size: 12px; }
  .nickname-display { font-size: 11px; max-width: 60px; }
  .heart { font-size: 16px; }

  .sv-btn { font-size: 14px; padding: 10px 22px; }
  .modal-box { padding: 22px 18px; }
  .modal-title { font-size: 18px; }
  .modal-content { font-size: 13px; }

  .complete-title { font-size: 28px; }
  .gameover-title { font-size: 34px; }
  .complete-stat-value { font-size: 24px; }

  .cover-scene { width: 150px; height: 90px; }
  .char-body { font-size: 40px; }

  .tip-item { font-size: 11px; padding: 4px 10px; }

  .lb-title-text { font-size: 26px; }
  .lb-trophy { font-size: 28px; }

  #leaderboard-screen { padding: 15px; padding-top: calc(30px + var(--safe-top)); }
  .leaderboard-table th { padding: 8px 6px; font-size: 12px; }
  .leaderboard-table td { padding: 6px; font-size: 12px; }

  .panel-toggle { display: none; }
}

@media (max-width: 420px) {
  .game-title { font-size: 36px; letter-spacing: 6px; }
  .cover-buttons { flex-direction: column; gap: 10px; }
  .sv-btn { width: 100%; justify-content: center; }
  .cover-tips { gap: 8px; }
  .tip-item { font-size: 10px; }
}

/* 横屏手机 */
@media (max-height: 500px) and (max-width: 900px) {
  .game-header { min-height: 32px; padding: 3px 10px; }
  .heart { font-size: 14px; }
  .level-info { font-size: 12px; }
  .mobile-stats-bar { padding: 2px 8px; }
  .m-stat { font-size: 10px; }
  .mobile-action-bar { padding: 3px 6px; }
  .mobile-inv-slot { width: 32px; height: 32px; }
  .m-ctrl-btn { width: 32px; height: 32px; }
}

/* 桌面端面板切换 */
@media (min-width: 769px) {
  .panel-toggle { display: flex; }
  .side-panel.collapsed {
    width: 0;
    border-left: none;
    overflow: hidden;
  }
  .side-panel.collapsed .panel-inner { display: none; }
}
