/* =========================================================
   迷宫大冒险 —— 样式表
   设计取向：儿童向。大按钮、高对比、圆角、明确的按压反馈。
   布局用 flex 纵向三段式：HUD / 棋盘 / 控制区，棋盘吃掉剩余空间。
   ========================================================= */

:root {
  --bg-1: #6a5acd;
  --bg-2: #ff8fb1;
  --bg-3: #55c3f0;
  --panel: #ffffff;
  --ink: #33285c;
  --ink-soft: #6f639b;
  --accent: #ff6b6b;
  --accent-2: #ffd166;
  --good: #06d6a0;
  --shadow: 0 10px 0 rgba(51, 40, 92, 0.18);
  --radius: 22px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  background-attachment: fixed;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ------------------------------------------------------------ 主界面布局 */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  transition: filter 0.25s ease;
}

.app.is-blurred {
  filter: blur(6px) saturate(0.8);
  pointer-events: none;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.hud-chip {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 0 rgba(51, 40, 92, 0.15);
}

.hud-chip--level {
  background: var(--accent-2);
}

.hud-chip b { font-variant-numeric: tabular-nums; }

.hud-chip--food { display: inline-flex; align-items: center; gap: 5px; }

.hud-food-icon { display: inline-flex; align-items: center; }

/* 卡通形象图标统一按容器缩放，别撑破布局 */
.hud-food-icon img, .char-art img, .char-food img, .win-character img { display: block; }

.icon-btn.is-off { opacity: 0.55; filter: grayscale(1); }

.icon-btn {
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 0 rgba(51, 40, 92, 0.15);
}

.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(51, 40, 92, 0.15); }

/* ------------------------------------------------------------ 棋盘 */

.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;   /* 关掉浏览器手势，才能自己处理滑动 */
}

.toast {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -14px);
  background: rgba(51, 40, 92, 0.92);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 90%;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------ 控制区 */

.controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-btn {
  border: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  padding: 10px 16px;
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(51, 40, 92, 0.2);
  white-space: nowrap;
}

.tool-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(51, 40, 92, 0.2); }
.tool-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* 方向键：3x3 网格，中间放个指南针 */
.pad {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 62px);
  gap: 8px;
  margin-left: auto;
}

.pad-btn {
  border: none;
  cursor: pointer;
  font-size: 24px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #7d6cf0, #5a49c9);
  border-radius: 18px;
  box-shadow: 0 5px 0 #3f3193;
  touch-action: none;
}

.pad-btn.is-pressed,
.pad-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #3f3193;
  filter: brightness(1.12);
}

.pad-up    { grid-area: 1 / 2; }
.pad-left  { grid-area: 2 / 1; }
.pad-center{ grid-area: 2 / 2; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.pad-right { grid-area: 2 / 3; }
.pad-down  { grid-area: 3 / 2; }

/* ------------------------------------------------------------ 弹出界面 */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(40, 30, 80, 0.45);
  overflow-y: auto;
  z-index: 20;
  animation: fade-in 0.25s ease;
}

.screen.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  background: var(--panel);
  border-radius: 28px;
  padding: 18px 20px 20px;
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 18px 40px rgba(30, 20, 60, 0.35);
  text-align: center;
  animation: pop-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.title {
  margin: 0 0 3px;
  font-size: 28px;
  letter-spacing: 1px;
}

.subtitle {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 15px;
}

.section-title {
  margin: 10px 0 6px;
  font-size: 16px;
  color: var(--ink-soft);
  text-align: left;
}

.diff-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.diff-card {
  border: 3px solid #ece8fb;
  background: #f8f6ff;
  border-radius: 18px;
  padding: 8px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.diff-card:active { transform: scale(0.97); }

.diff-card.is-active {
  border-color: var(--accent);
  background: #fff2f2;
  box-shadow: 0 6px 0 rgba(255, 107, 107, 0.25);
}

.diff-emoji { font-size: 30px; }
.diff-label { font-size: 17px; font-weight: 900; color: var(--ink); }
.diff-desc  { font-size: 12px; color: var(--ink-soft); }
.diff-best  { font-size: 12px; color: var(--good); font-weight: 700; }

.char-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.char-card {
  border: 3px solid #ece8fb;
  background: #f8f6ff;
  border-radius: 16px;
  padding: 8px 4px 6px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.char-card:active:not(:disabled) { transform: scale(0.96); }

.char-card.is-active {
  border-color: var(--good);
  background: #eafff8;
  box-shadow: 0 5px 0 rgba(6, 214, 160, 0.25);
}

/* 锁定态用去色而不是半透明 —— 小动物始终是实心的，只是"还没认识" */
.char-card.is-locked { cursor: not-allowed; background: #f1eff7; }
.char-card.is-locked .char-sprite { filter: grayscale(1) brightness(0.72); }
.char-card.is-locked .char-name { color: var(--ink-soft); }

.char-art { position: relative; display: flex; align-items: flex-end; justify-content: center; height: 50px; }
.char-sprite { display: block; }

.char-need {
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: var(--ink-soft);
  border-radius: 999px;
  padding: 2px 8px;
}

.char-name { font-size: 12px; color: var(--ink); font-weight: 800; }

.char-food {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--ink-soft);
}

.char-food i { font-style: normal; }

.fog-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 2px;
  padding: 8px 12px;
  background: #f4f2ff;
  border-radius: 16px;
  cursor: pointer;
  text-align: left;
}

.fog-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.fog-text { font-size: 14px; font-weight: 700; color: var(--ink); }

.play-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  border-radius: 20px;
  background: linear-gradient(180deg, #ff8a8a, #ff5252);
  box-shadow: 0 6px 0 #d63d3d;
}

.play-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #d63d3d; }

.ghost-btn {
  border: 3px solid #ece8fb;
  background: #fff;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  padding: 12px;
  border-radius: 16px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.hint-text {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ------------------------------------------------------------ 通关界面 */

.panel--win { padding-top: 16px; }

.win-character {
  display: flex;
  justify-content: center;
  animation: cheer 0.8s ease-in-out infinite alternate;
}



@keyframes cheer {
  from { transform: translateY(0) rotate(-6deg); }
  to   { transform: translateY(-10px) rotate(6deg); }
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0 12px;
}

.stat {
  background: #f6f4ff;
  border-radius: 16px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label { font-size: 12px; color: var(--ink-soft); }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.badge {
  background: var(--accent-2);
  color: #6b4b00;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 900;
}

.win-actions { margin-top: 6px; }

/* ------------------------------------------------------------ 彩带 */

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.confetti-piece {
  position: absolute;
  top: -40px;
  animation-name: fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes fall {
  from { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  to   { transform: translateY(105vh) rotate(540deg); opacity: 0.9; }
}

/* ------------------------------------------------------------ 响应式 */

@media (max-width: 520px) {
  .pad { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); }
  .tool-btn { font-size: 13px; padding: 9px 12px; }
  .title { font-size: 25px; }
  .char-list { grid-template-columns: repeat(4, 1fr); }
}

/* 宽屏（平板横屏 / 电脑）：控制区挪到右侧，迷宫吃满整个高度 */
@media (min-width: 860px) and (min-height: 560px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px 16px;
    padding: 16px 24px 20px;
  }
  .hud { grid-column: 1 / -1; }
  .board-wrap { grid-column: 1; grid-row: 2; }
  .controls {
    grid-column: 2;
    grid-row: 2;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    gap: 26px;
  }
  .tools { order: 2; }
  .pad {
    order: 1;
    margin: 0 auto;
    grid-template-columns: repeat(3, 78px);
    grid-template-rows: repeat(3, 78px);
  }
  .pad-btn { font-size: 30px; }
}

/* 尊重系统的"减弱动态效果"设置 */
@media (prefers-reduced-motion: reduce) {
  .win-character, .confetti-piece { animation: none; }
  .panel { animation: none; }
}
