/* 倒退贪吃蛇 Uncoil · 糖果软糖亮场 / 双翼机台
   配色刻意避开门户首页薄荷绿 #83ffe7，改用蜜桃粉 + 薰衣草紫 + 奶油黄。 */

:root {
  --candy-pink: #ff8ab4;
  --candy-rose: #e83e68;
  --candy-lilac: #b98ce8;
  --candy-cream: #fff6ea;
  --candy-butter: #ffe2a8;
  --cocoa: #7b5a48;
  --ink: #4a3550;
  --ink-dim: #8a7896;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-line: rgba(255, 255, 255, 0.9);
  --shadow-soft: 0 10px 30px rgba(126, 78, 128, 0.18);
  --shadow-key: 0 4px 0 rgba(122, 84, 126, 0.28);
  --radius: 18px;
}

* { box-sizing: border-box; }

[hidden], .hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 12% -8%, #ffd9e6 0%, rgba(255, 217, 230, 0) 62%),
    radial-gradient(1000px 620px at 96% 6%, #e6d9ff 0%, rgba(230, 217, 255, 0) 58%),
    linear-gradient(168deg, #fff1f6 0%, #f6ecff 46%, #fff7e6 100%);
  background-attachment: fixed;
  overscroll-behavior: none;
}

#game-app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}

/* ---------- 机顶状态栏（控制项全部内嵌，严禁四角散落） ---------- */
#stage-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

#back-home {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
}

#stage-title {
  flex: 1;
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.06em;
  text-align: center;
}

.stage-actions { display: flex; gap: 8px; }

.bar-btn {
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.bar-btn:active { transform: translateY(2px); box-shadow: none; }

/* ---------- 机台主体：左右双翼 + 中央舞台 ---------- */
#stage-core {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 250px minmax(320px, 1fr) 250px;
  gap: 16px;
  align-items: start;
}

#panel-left, #panel-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 246, 234, 0.78));
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-soft);
}

.panel-chunk {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px 11px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.p-label { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.04em; }
.dim { color: var(--ink-dim); font-size: 12px; margin: 0; }

.lcd {
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  padding: 2px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.9);
  align-self: flex-start;
  min-width: 46px;
}
.lcd.big { font-size: 26px; }
.lcd.small { font-size: 14px; }

#chapter-label { margin: 0; font-size: 16px; }

#progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(120, 92, 140, 0.14);
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--candy-pink), var(--candy-lilac));
  transition: width 0.25s ease;
}

.chip {
  border: none;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: #ffffff;
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}
.chip:active { transform: translateY(2px); box-shadow: none; }
.chip.is-off { opacity: 0.45; }
.chip.is-on { background: var(--candy-butter); }

/* ---------- 中央舞台 ---------- */
#stage-cabinet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 246, 234, 0.68));
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-soft);
}

#mobile-hud { display: none; }

.board-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#board {
  border-radius: 22px;
  box-shadow: 0 14px 34px rgba(126, 78, 128, 0.22);
  touch-action: none;
  background: #fffdfa;
  display: block;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(8px);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 6px 18px rgba(126, 78, 128, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 困毙：不放弹窗，只在舞台下沿浮出两个出口 */
#stuck-bar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(92%, 420px);
  padding: 12px 14px;
  border-radius: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(232, 62, 104, 0.28);
  box-shadow: 0 12px 28px rgba(126, 78, 128, 0.26);
  animation: stuck-in 0.24s ease-out;
}
#stuck-bar.hidden { display: none; }
.stuck-title { margin: 0 0 4px; font-size: 15px; font-weight: 800; color: var(--candy-rose); }
@keyframes stuck-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- 浮层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border-radius: 22px;
  text-align: center;
  background: rgba(255, 248, 242, 0.94);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.overlay h2 { margin: 0; font-size: 22px; }
.overlay p { margin: 0; max-width: 460px; font-size: 13px; line-height: 1.6; }

.mode-row, .btn-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.btn {
  border: none;
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  background: #ffffff;
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn-primary { background: linear-gradient(180deg, var(--candy-pink), #ff6f9f); color: #fff; }
.btn.hidden { display: none; }

#level-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 420px);
  margin-top: 6px;
}
.lv-cell {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 3px 0 rgba(122, 84, 126, 0.2);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.lv-cell:active { transform: translateY(2px); }
.lv-cell.is-clear { background: linear-gradient(180deg, var(--candy-butter), #ffd18a); }
.lv-cell.is-locked { opacity: 0.4; cursor: not-allowed; }

.start-footer { display: flex; align-items: center; gap: 12px; margin-top: 6px; font-size: 12px; }
.stars-line { font-size: 20px; letter-spacing: 0.12em; color: #ff9a3c; }
.record-line { font-size: 13px; font-weight: 800; color: var(--candy-rose); }

/* ---------- 操作台：摇杆 + 道具键 ---------- */
#deck {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-soft);
}

#dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}
.pad {
  border: none;
  border-radius: 13px;
  font-size: 15px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #f4e6ff);
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.pad:active { transform: translateY(2px); box-shadow: none; }
.pad-up { grid-area: 1 / 2; }
.pad-left { grid-area: 2 / 1; }
.pad-right { grid-area: 2 / 3; }
.pad-down { grid-area: 3 / 2; }

#deck-actions { display: flex; gap: 8px; }
.deck-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  background: linear-gradient(180deg, #fff, #ffeef4);
  box-shadow: var(--shadow-key);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
}
.deck-btn:active { transform: translateY(2px); box-shadow: none; }
.deck-btn.is-off { opacity: 0.45; }

#key-tip, #touch-tip { margin: 0; font-size: 12px; text-align: center; }
#touch-tip { display: none; }

/* ---------- 响应式：窄屏一体化掌机框体 ---------- */
@media (max-width: 900px) {
  #stage-core { grid-template-columns: minmax(0, 1fr); }
  #panel-left, #panel-right { flex-direction: row; flex-wrap: wrap; }
  #panel-left .panel-chunk, #panel-right .panel-chunk { flex: 1 1 44%; }
  #mobile-hud {
    display: flex;
    gap: 14px;
    padding: 8px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.8);
  }
  .mh-item { display: flex; flex-direction: column; align-items: center; }
  .mh-item b { font-size: 16px; }
  .mh-item i { font-style: normal; font-size: 11px; color: var(--ink-dim); }
  #key-tip { display: none; }
  #touch-tip { display: block; }
}

@media (max-width: 560px) {
  /* 底部横幅广告避让：主容器必须留出 ≥68px，绝不让操作键贴底 */
  #game-app {
    padding: 10px 10px 0;
    padding-bottom: max(68px, calc(16px + env(safe-area-inset-bottom)));
  }
  #stage-core { gap: 10px; }
  #dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
  #deck { gap: 12px; flex-wrap: wrap; }
  #level-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* 降级只去动画，绝不隐藏核心交互件 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  #stuck-bar { animation: none; }
}
