/* ============================================================
   迷宫大冒险 · style.css
   电脑版布局（宽屏：左大迷宫 / 右操作面板）+ 移动端竖屏自适应
   儿童友好圆角卡通风 / 高对比中文界面
   兼容性取向：flex + grid（gap 只用在 grid）、-webkit 前缀、safe-area
   ============================================================ */

:root {
  --bg1: #eaf4ff;
  --bg2: #fff4e4;
  --navy: #2f4372;        /* 主文字（对浅底高对比） */
  --navy-soft: #6b7ba6;
  --card: #ffffff;
  --orange: #ff8a3d;
  --orange-dark: #d96a22;
  --blue: #4a7bf7;
  --blue-dark: #2f5fd0;
  --green: #2fbe6c;
  --green-dark: #1f9953;
  --red: #ff6b5e;
  --red-dark: #d94b40;
  --yellow: #ffc53d;
  --line: #dce6f5;
  --lock: #a7b2c8;
  --radius: 20px;
  --shadow: 0 8px 20px rgba(47, 67, 114, 0.12);
}

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

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

body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--navy);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

/* 电脑版宽容器 */
.app {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(14px + env(safe-area-inset-top)) 18px calc(16px + env(safe-area-inset-bottom));
}

/* ---------------- 视图切换（hash 路由） ---------------- */
.view { display: none; }
.view.active { display: block; }

/* ---------------- 通用按钮 ---------------- */
.btn {
  border: none;
  border-radius: 16px;
  min-height: 44px;               /* 点击区域 ≥ 44px（PRD 5） */
  padding: 11px 18px;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  background: var(--card);
  box-shadow: 0 4px 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 4px 0 var(--orange-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--orange-dark); }
.btn.ghost { background: rgba(255, 255, 255, 0.85); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); }
.btn.icon { padding: 10px 14px; font-size: 15px; }
.btn.tool { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark); border-radius: 14px; }
.btn.tool:active { box-shadow: 0 1px 0 var(--blue-dark); }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---------------- 首页 ---------------- */
.home-hero { text-align: center; padding: 30px 0 14px; }
.hero-badge {
  font-size: 46px;
  line-height: 1.25;
  letter-spacing: 8px;
  background: rgba(255, 255, 255, 0.7);
  display: inline-block;
  border-radius: 999px;
  padding: 12px 26px;
  box-shadow: var(--shadow);
}
.home-hero h1 {
  margin: 10px 0 6px;
  font-size: 42px;
  letter-spacing: 12px;
  color: var(--navy);
  text-shadow: 0 4px 0 #cfe0ff;
}
.hero-sub { margin: 0; color: var(--navy-soft); font-size: 17px; font-weight: 600; }

.diff-list {
  max-width: 980px;
  margin: 28px auto 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.diff-card {
  display: -webkit-flex;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: none;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 18px 24px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease;
  border-top: 6px solid var(--line);
}
.diff-card:active { transform: scale(0.98); }
.diff-card.tone-green { border-top-color: var(--green); }
.diff-card.tone-orange { border-top-color: var(--orange); }
.diff-card.tone-red { border-top-color: var(--red); }
.diff-icon {
  width: 74px;
  height: 74px;
  border-radius: 22px;
  background: #f4f8ff;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  margin-bottom: 14px;
}
.diff-name { font-size: 22px; font-weight: 800; text-align: center; }
.diff-sub { font-size: 13px; color: var(--navy-soft); text-align: center; margin: 8px 0 16px; }
.diff-progress {
  font-size: 20px;
  font-weight: 800;
  color: var(--orange-dark);
  background: #fff3e2;
  border-radius: 999px;
  padding: 9px 20px;
  white-space: nowrap;
}
.star-ico { color: var(--yellow); }

.home-links {
  display: -webkit-flex;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0;
}
.home-links .btn { margin: 6px 8px; min-width: 150px; }
.home-foot { text-align: center; color: var(--navy-soft); font-size: 13px; margin: 22px 0 6px; }

/* ---------------- 顶部栏（选关 / 文档页共用） ---------------- */
.top-bar {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.top-title { font-size: 19px; font-weight: 800; }
.top-info { font-size: 16px; font-weight: 700; color: var(--orange-dark); min-width: 64px; text-align: right; }

/* ---------------- 选关页 ---------------- */
.level-wrap {
  max-width: 980px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.level-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 10px; }
.level-grid.grid-20 { grid-template-columns: repeat(4, 1fr); }

.level-cell {
  position: relative;
  border: none;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 3px 0 var(--line);
  padding: 8px 2px;
  min-height: 56px;
  cursor: pointer;
  touch-action: manipulation;
  display: -webkit-flex;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.level-cell:active { transform: translateY(2px); }
.lv-num { font-size: 16px; font-weight: 800; color: var(--navy); }
.lv-stars { font-size: 10px; color: var(--yellow); letter-spacing: 1px; }
.lv-empty { font-size: 10px; color: var(--line); letter-spacing: 1px; }
.lv-lock { font-size: 13px; margin-top: 1px; }
.level-cell.locked { background: #eef2f9; box-shadow: 0 3px 0 #dde5f1; cursor: default; }
.level-cell.locked .lv-num { color: var(--lock); }
.level-cell.cleared { background: #fff8e6; box-shadow: 0 3px 0 #f3e2b4; }
.level-cell.open { background: #f3f8ff; box-shadow: 0 3px 0 #d7e4fb; }

.grid-20 .level-cell { min-height: 56px; }
.grid-20 .lv-num { font-size: 17px; }
.grid-20 .lv-stars, .grid-20 .lv-empty { font-size: 11px; }
.grid-20 .lv-lock { font-size: 15px; }

.pager {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
}
.pager .btn { margin: 0 8px; }
.page-info { font-weight: 800; font-size: 15px; min-width: 48px; text-align: center; }
.level-tip { text-align: center; color: var(--navy-soft); font-size: 13px; margin: 14px 4px 0; }

/* ---------------- 游戏页：电脑版两栏布局 ---------------- */
#view-game {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  margin: 0;                    /* 不再居中收窄：整屏铺满，左操作栏贴屏幕左边 */
  max-width: none;
  display: none;
  flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  overflow: hidden;
}
#view-game.active { display: flex; }

.game-main {
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-height: 0;
  display: -webkit-flex;
  display: flex;
  flex-direction: column;
}

/* —— 移动端堆叠顺序：信息栏 → 工具 → 声音 → 迷宫 → 方向键 —— */
.game-side { display: contents; }
.side-head { order: 1; display: -webkit-flex; display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.side-stats { order: 2; display: -webkit-flex; display: flex; margin-bottom: 8px; }
.quota-tip { order: 2; }
.game-tools { order: 3; display: -webkit-flex; display: flex; justify-content: flex-end; margin-bottom: 8px; }
.sound-row { order: 3; }
.canvas-wrap { order: 4; }
.dpad { order: 5; }
.side-tip { order: 6; }

.stat-box {
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  margin-right: 10px;
  text-align: center;
}
.stat-box:last-child { margin-right: 0; }
.stat-label { font-size: 11px; color: var(--navy-soft); font-weight: 700; letter-spacing: 1px; margin-bottom: 2px; }
.stat { display: block; font-size: 16px; font-weight: 800; color: var(--navy); }
.side-tip { text-align: center; color: var(--navy-soft); font-size: 12px; margin: 6px 0 0; }

.canvas-wrap {
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  min-width: 0;                 /* 关键：允许 flex 子项收缩，否则宽屏下溢出把侧栏挤出屏幕 */
  min-height: 0;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game-canvas {
  border-radius: 18px;
  box-shadow: var(--shadow);
  touch-action: none;              /* 禁止画布手势触发页面滚动/缩放 */
  background: #fff7e8;
}

/* 虚拟方向键：上键居中一行，下排 左/下/右（对齐 PRD 3.4 框图） */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 10px;
  justify-content: center;
  padding: 10px 0 4px;
}
.dpad-btn {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 5px 0 var(--blue-dark);
  cursor: pointer;
  touch-action: none;
}
.dpad-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--blue-dark); }
.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }

/* —— 电脑版宽屏：左操作卡片 / 右大迷宫 —— */
@media (min-width: 880px) {
  .game-main { flex-direction: row; align-items: stretch; }
  .canvas-wrap { order: 2; }
  .game-side {
    display: -webkit-flex;
    display: flex;
    flex-direction: column;
    order: 1;
    width: 300px;
    min-width: 300px;
    margin-left: 0;
    margin-right: 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
  }
  .side-head, .side-stats, .quota-tip, .game-tools, .sound-row, .dpad, .side-tip { order: 0; }
  .side-head { margin-bottom: 12px; }
  .side-stats { margin-bottom: 10px; }
  .stat-box { box-shadow: none; background: #f4f8ff; margin-right: 8px; padding: 10px 8px; }
  .game-tools {
    -webkit-flex-direction: column;
    flex-direction: column;
    margin-bottom: 10px;
  }
  .game-tools .btn { margin-left: 0; margin-bottom: 10px; width: 100%; }
  .dpad { margin-top: auto; padding-top: 6px; }
  .side-tip { margin-top: 10px; }
}

/* 大屏（≥1600）：操作栏加宽、留白更舒展，避免右侧大片空洞感 */
@media (min-width: 1600px) {
  #view-game { padding-left: 18px; padding-right: 18px; }
  .game-side { width: 340px; min-width: 340px; margin-right: 20px; }
  .side-tip { font-size: 13px; }
}

/* 游戏页声音行（静音 + 音量） */
.sound-row {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.mute-btn {
  min-width: 52px;
  font-size: 20px;
  padding: 8px 10px;
  margin-right: 10px;
}
.volume-range.small { max-width: none; -webkit-flex: 1 1 auto; flex: 1 1 auto; margin-top: 0; }

/* 防沉迷剩余额度提示 */
.quota-tip {
  background: #fff4e4;
  color: var(--orange-dark);
  font-size: 13px;
  font-weight: 700;
  border-radius: 12px;
  padding: 7px 12px;
  margin-bottom: 10px;
  text-align: center;
}
.quota-tip[hidden] { display: none; }

/* 彩带层：覆盖游戏页，不拦截点击 */
.confetti-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* ---------------- 结算弹窗（PRD 3.5） ---------------- */
.modal-mask {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(47, 67, 114, 0.42);
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 82%;
  max-width: 340px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(47, 67, 114, 0.28);
  padding: 24px 20px 20px;
  text-align: center;
}
.modal-title { font-size: 26px; font-weight: 900; }
.modal-info { margin-top: 10px; font-size: 17px; color: var(--navy-soft); font-weight: 700; }
.modal-stars { margin-top: 8px; font-size: 34px; color: var(--yellow); letter-spacing: 6px; text-shadow: 0 2px 0 #e8ac1f; }
.modal-record {
  display: inline-block;
  margin-top: 8px;
  background: var(--red);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  border-radius: 12px;
  padding: 5px 12px;
}
.modal-record[hidden] { display: none; }
.modal-actions { margin-top: 18px; display: -webkit-flex; display: flex; flex-wrap: wrap; justify-content: center; }
.modal-actions .btn { margin: 5px; min-width: 92px; }

/* ---------------- 玩法说明 / 设置 / 成绩 ---------------- */
.doc-card {
  max-width: 760px;
  margin: 0 auto 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 14px;
}
.doc-card h2 { font-size: 17px; margin: 18px 0 8px; padding-left: 10px; border-left: 5px solid var(--orange); border-radius: 4px; }
.doc-card h2:first-child { margin-top: 2px; }
.doc-card p { margin: 6px 0; font-size: 15px; line-height: 1.85; color: var(--navy); }

.setting-row {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 2px dashed var(--line);
}
.setting-row:last-child { border-bottom: none; }
.setting-text { -webkit-flex: 1 1 auto; flex: 1 1 auto; padding-right: 12px; }
.setting-text b { display: block; font-size: 17px; }
.setting-text span { display: block; font-size: 13px; color: var(--navy-soft); margin-top: 3px; }
.toggle {
  border: none;
  border-radius: 999px;
  min-width: 84px;
  min-height: 44px;
  font-size: 16px;
  font-weight: 800;
  color: var(--navy-soft);
  background: #eef2f9;
  cursor: pointer;
  touch-action: manipulation;
}
.toggle.on { background: var(--green); color: #fff; box-shadow: 0 3px 0 var(--green-dark); }

.score-list { max-width: 760px; margin: 0 auto 10px; }
.score-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.score-card.total { background: #fff8e6; }
.score-card.tone-green { border-left: 6px solid var(--green); }
.score-card.tone-orange { border-left: 6px solid var(--orange); }
.score-card.tone-red { border-left: 6px solid var(--red); }
.score-card.total { border-left: 6px solid var(--yellow); }
.score-name { font-size: 18px; font-weight: 800; margin-bottom: 10px; }
.score-row {
  display: -webkit-flex;
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  color: var(--navy-soft);
  padding: 3px 0;
}
.score-row b { color: var(--navy); font-size: 16px; }

/* ---------------- 设置：音量 / 防沉迷 / 版本 ---------------- */
.volume-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 260px;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  margin-top: 10px;
  outline: none;
}
.volume-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(47, 67, 114, 0.3);
  cursor: pointer;
}
.volume-value {
  min-width: 56px;
  text-align: right;
  font-size: 16px;
  font-weight: 800;
  color: var(--navy);
}

.parental-row { border-bottom: none; }
.parental-panel {
  background: #f7faff;
  border: 2px dashed var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 4px 0 12px;
}
.parental-panel[hidden] { display: none; }
.parental-line {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  color: var(--navy);
}
.parental-line[hidden] { display: none; }
.parental-limit {
  min-height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  background: #fff;
  padding: 0 10px;
}
.pwd-input {
  width: 120px;
  min-height: 42px;
  border-radius: 10px;
  border: 2px solid var(--line);
  font-size: 18px;
  letter-spacing: 6px;
  text-align: center;
  color: var(--navy);
  background: #fff;
}
.pwd-input.big { width: 160px; margin: 12px auto 0; display: block; }
.parental-actions {
  display: -webkit-flex;
  display: flex;
  margin-top: 10px;
}
.parental-actions .btn { margin-right: 10px; }
.parental-status {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  padding: 4px 0 2px;
}
.parental-note { font-size: 12px; color: var(--navy-soft); margin: 10px 0 0; line-height: 1.6; }
.version-line {
  text-align: center;
  color: var(--navy-soft);
  font-size: 12px;
  margin: 10px 0 2px;
}

/* ---------------- 小屏微调 ---------------- */
@media (max-width: 720px) {
  .app { padding: calc(12px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom)); }
  .home-hero { padding: 18px 0 10px; }
  .hero-badge { font-size: 34px; padding: 9px 18px; letter-spacing: 5px; }
  .home-hero h1 { font-size: 30px; letter-spacing: 6px; margin: 10px 0 6px; }
  .hero-sub { font-size: 14px; }
  .diff-list {
    grid-template-columns: 1fr;
    gap: 12px;
    margin: 18px auto 8px;
  }
  .diff-card {
    flex-direction: row;
    justify-content: space-between;
    padding: 14px 16px;
    border-top: none;
    border-left: 6px solid var(--line);
    border-radius: 18px;
  }
  .diff-card.tone-green { border-left-color: var(--green); border-top-color: transparent; }
  .diff-card.tone-orange { border-left-color: var(--orange); border-top-color: transparent; }
  .diff-card.tone-red { border-left-color: var(--red); border-top-color: transparent; }
  .diff-icon { width: 52px; height: 52px; font-size: 28px; border-radius: 16px; margin: 0 12px 0 0; }
  .diff-name { font-size: 19px; text-align: left; }
  .diff-sub { text-align: left; margin: 4px 0 0; }
  .diff-progress { font-size: 17px; padding: 8px 14px; }
  .home-links .btn { min-width: 0; margin: 0 5px; }
  .level-wrap { padding: 12px; }
  .level-grid { gap: 8px; }
  .level-cell { min-height: 44px; padding: 6px 2px; }
  .lv-num { font-size: 14px; }
  .lv-stars, .lv-empty { font-size: 9px; }
}
@media (max-width: 380px) {
  .home-hero h1 { font-size: 27px; letter-spacing: 4px; }
  .hero-badge { font-size: 30px; }
  .game-tools .btn { min-width: 92px; font-size: 14px; padding: 10px 12px; }
  .dpad { grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(2, 58px); }
  .dpad-btn { width: 58px; height: 58px; }
}
