/* ============================================================
   chap1.css —— 第一章：文字迷宫
   ============================================================ */

#chapter1 {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #020203;
  z-index: 700;
  overflow: hidden;
}
#chapter1.open { display: flex; }

/* ---------- 迷宫 ---------- */
.c1-maze {
  position: relative;
  margin-bottom: 1rem;
  transition: width 0.3s ease, height 0.3s ease;
}

.c1-cells { position: absolute; }

.c1-cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 0.4s ease, color 0.6s ease;
}

/* 墙：单个「墙」字 */
.c1-wall {
  color: rgba(170, 45, 45, 0.9);
  background: rgba(16, 5, 5, 0.96);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  border: 1px solid rgba(60, 15, 15, 0.55);
  text-shadow: 0 0 12px rgba(160, 30, 30, 0.6);
}

/* 门 */
.c1-gate {
  color: #b89b5e;
  background: rgba(26, 22, 12, 0.85);
  border: 1px solid rgba(184, 155, 94, 0.5);
  border-radius: 3px;
  letter-spacing: 0;
  text-shadow: 0 0 14px rgba(184, 155, 94, 0.5);
  animation: gate-pulse 2.4s infinite;
}
@keyframes gate-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(184,155,94,0.2) inset; }
  50%      { box-shadow: 0 0 24px rgba(184,155,94,0.5) inset; }
}

/* 偏旁 */
.c1-rad {
  color: #8fd0e0;
  text-shadow: 0 0 16px rgba(120, 200, 220, 0.6);
  animation: rad-float 2.8s ease-in-out infinite;
}
@keyframes rad-float {
  0%, 100% { transform: translateY(-2px); opacity: 0.85; }
  50%      { transform: translateY(2px);  opacity: 1; }
}

/* 出口 */
.c1-exit {
  color: #f2e6bf;
  text-shadow: 0 0 20px rgba(240, 220, 150, 0.8);
  animation: gate-pulse 1.8s infinite;
}

/* 玩家 */
.c1-player {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-shadow: 0 0 14px rgba(255, 255, 255, 0.7);
  background: rgba(184, 155, 94, 0.12);
  border: 1px solid rgba(184, 155, 94, 0.55);
  border-radius: 4px;
  transition: left 0.14s ease, top 0.14s ease;
  z-index: 10;
  letter-spacing: 0;
}

/* ---------- HUD ---------- */
.c1-hud {
  display: flex;
  gap: 1.4rem;
  align-items: center;
  font-size: 0.76rem;
  letter-spacing: 0.2em;
  color: #7d7d88;
  margin-bottom: 0.6rem;
}
.c1-hud .c1-name { color: #b89b5e; }
.c1-hud .c1-inv  { color: #8fd0e0; }

/* ---------- 方向键 ---------- */
.c1-dpad {
  position: relative;
  width: 168px;
  height: 168px;
  margin-top: 0.4rem;
  touch-action: manipulation;
}
.c1-btn {
  position: absolute;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(140, 140, 160, 0.3);
  background: rgba(20, 20, 28, 0.7);
  color: #b8b8c4;
  font-size: 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.c1-btn:active { background: rgba(184, 155, 94, 0.3); color: #fff; }
.c1-up    { left: 57px; top: 0; }
.c1-down  { left: 57px; top: 114px; }
.c1-left  { left: 0; top: 57px; }
.c1-right { left: 114px; top: 57px; }

/* ---------- 旁白 ---------- */
.c1-narr {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(2, 2, 4, 0.94);
  z-index: 750;
  padding: 2rem;
  text-align: center;
}
.c1-narr.open { display: flex; }

/* 已废弃旧的 p.show 机制，改用 Narration 引擎（过渡/位置由 game.css 的 .narr-line 负责） */
.c1-narr p.narr-line {
  max-width: 560px;
  font-size: clamp(1rem, 4.3vw, 1.2rem);
  color: #cfcfd6;
  line-height: 2.1;
}

/* ---------- 小屏 ---------- */
@media (max-width: 480px) {
  .c1-dpad { width: 150px; height: 150px; }
  .c1-btn { width: 48px; height: 48px; font-size: 1rem; }
  .c1-up    { left: 51px; top: 0; }
  .c1-down  { left: 51px; top: 102px; }
  .c1-left  { left: 0; top: 51px; }
  .c1-right { left: 102px; top: 51px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .c1-dpad { position: fixed; right: 1rem; bottom: 1rem; width: 140px; height: 140px; }
  .c1-btn { width: 44px; height: 44px; }
  .c1-up    { left: 48px; top: 0; }
  .c1-down  { left: 48px; top: 96px; }
  .c1-left  { left: 0; top: 48px; }
  .c1-right { left: 96px; top: 48px; }
  .c1-maze { margin-bottom: 0.2rem; }
}


/* ============ 第 1 章 反馈增强 ============ */

.c1-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  opacity: 1;
  animation: c1-flash-out 0.6s ease forwards;
}
@keyframes c1-flash-out {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

.c1-player {
  box-shadow: 0 0 20px rgba(184, 155, 94, 0.55),
              inset 0 0 12px rgba(184, 155, 94, 0.3);
  animation: playerBreath 2.4s ease-in-out infinite;
}
@keyframes playerBreath {
  0%, 100% { box-shadow: 0 0 14px rgba(184,155,94,0.4),
                         inset 0 0 10px rgba(184,155,94,0.25); }
  50%      { box-shadow: 0 0 28px rgba(184,155,94,0.75),
                         inset 0 0 16px rgba(184,155,94,0.4); }
}

.c1-btn {
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.c1-btn:active {
  background: rgba(184, 155, 94, 0.4);
  color: #fff;
  box-shadow: 0 0 24px rgba(184, 155, 94, 0.6);
  transform: scale(0.92);
}

.c1-maze {
  box-shadow: 0 0 0 1px rgba(120, 30, 30, 0.3),
              0 0 60px rgba(120, 20, 20, 0.25) inset,
              0 0 40px rgba(0, 0, 0, 0.9);
  border-radius: 4px;
}

.c1-rad {
  filter: drop-shadow(0 0 8px rgba(120, 200, 220, 0.8));
}

.c1-exit {
  filter: drop-shadow(0 0 14px rgba(240, 220, 150, 0.9));
}

/* ============ 第 1 章 · 最后一关：漂移 ============ */
.c1-cell.drifting {
  will-change: transform, filter, opacity;
}
/* 墙在漂移关更暗红、更"不安" */
.c1-cell.c1-wall.drifting {
  color: rgba(190, 60, 60, 0.85);
  text-shadow: 0 0 16px rgba(180, 30, 30, 0.7);
}

/* ============ 光效动画变体 ============ */
@keyframes c1-flash-scale {
  0%   { opacity: 0.95; transform: scale(0.7); }
  100% { opacity: 0;    transform: scale(1.5); }
}
@keyframes c1-flash-in {
  0%   { opacity: 0;    transform: scale(1.3); }
  30%  { opacity: 1;    transform: scale(1); }
  100% { opacity: 0;    transform: scale(0.9); }
}

/* ============================================================
   方向键脱离 #chapter1, 固定到 body
   这样它就不受暗角影响, 与存/菜单同级
   ============================================================ */
.c1-dpad.c1-dpad-fixed {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  margin: 0;
  z-index: 1300 !important;
  display: none;
}
body.chapter1-mode .c1-dpad.c1-dpad-fixed {
  display: block;
}

@media (max-width: 480px) {
  .c1-dpad.c1-dpad-fixed { bottom: 1.2rem; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .c1-dpad.c1-dpad-fixed {
    left: auto;
    right: 1rem;
    bottom: 1rem;
    transform: none;
  }
}


/* 给底部方向键留空间, 迷宫整体上移 */

@media (orientation: landscape) and (max-height: 520px) {
  #chapter1 { padding-bottom: 0 !important; padding-right: 180px !important; }
}

/* ============================================================
   主角光源 —— 照亮周围, 抵消暗角
   ============================================================ */
.c1-player {
  position: absolute;
  z-index: 15;
}
/* 光晕层: 跟随主角 */
.c1-player::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 340px;
  height: 340px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 236, 190, 0.55) 0%,
    rgba(255, 220, 150, 0.28) 28%,
    rgba(200, 170, 90, 0.1) 55%,
    transparent 72%);
  pointer-events: none;
  z-index: -1;
  animation: playerLightBreath 3.2s ease-in-out infinite;
  mix-blend-mode: screen;
}
@keyframes playerLightBreath {
  0%, 100% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.08); }
}

/* ============================================================
   HUD 移到右侧竖排 —— 不占垂直空间, 迷宫更大
   ============================================================ */
.c1-hud {
  position: fixed !important;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  align-items: flex-end !important;
  gap: 0.5rem !important;
  max-width: 4.5rem;
  padding: 0.8rem 0.5rem;
  border-radius: 8px;
  background: rgba(10,10,14,0.5);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 1250 !important;
  margin: 0 !important;
  text-align: right;
}
.c1-hud .c1-name {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
}
.c1-hud .c1-inv {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}
/* 存/菜单按钮避让 HUD 不冲突(它们在左右上角) */

/* ============================================================
   摄像机: 视口裁剪 + 世界层平移
   ============================================================ */
.c1-maze {
  position: relative !important;
  overflow: hidden !important;
  margin-bottom: 0 !important;
  border-radius: 6px;
}
.c1-cells {
  position: absolute !important;
  left: 0;
  top: 0;
  will-change: transform;
  transition: transform 0.12s ease-out;
}
.c1-player {
  position: absolute !important;
  z-index: 15;
}
/* 玩家在视口里永远居中, 视口居中于屏幕 */
#chapter1, #chapter2 {
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}
body.chapter1-mode #chapter1,
body.chapter2-mode #chapter2 { display: flex !important; }

/* 第二章也要显示方向键 */
body.chapter2-mode .c1-dpad.c1-dpad-fixed {
  display: block;
}

/* ---------- 关卡切换淡入 ---------- */
@keyframes maze-fade-in {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
.c1-maze.maze-enter {
  animation: maze-fade-in 0.9s ease both;
}

/* ---------- 关卡切换淡出 ---------- */
@keyframes maze-fade-out {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}
.c1-maze.maze-leave {
  animation: maze-fade-out 0.55s ease both;
}

/* ---------- 旁白时隐藏 HUD ---------- */
.c1-hud.hud-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* ============================================================
   第三章：工具栏抽屉（只在第三章显示）
   ============================================================ */
#c3-drawer-handle, #mp-drawer-handle {
  display: none;
  position: fixed;
  right: 0.9rem;
  bottom: 11.5rem;
  z-index: 1320;
  width: 46px;
  height: 46px;
  font-size: 1.3rem;
  color: #c6c6cf;
  background: rgba(18,18,26,0.85);
  border: 1px solid rgba(184,155,94,0.35);
  border-radius: 50%;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
body.chapter3-mode #c3-drawer-handle { display: block; }
body.mp-mode #mp-drawer-handle { display: block; }

#c3-drawer, #mp-drawer {
  display: none;
  position: fixed;
  right: 0.9rem;
  bottom: 14.6rem;
  z-index: 1320;
  flex-direction: column;
  gap: 0.5rem;
}
#c3-drawer.open, #mp-drawer.open { display: flex; }
#c3-drawer.closing, #mp-drawer.closing { display: flex; }
#c3-drawer button, #mp-drawer button {
  width: 46px;
  height: 46px;
  padding: 0;
  font-family: inherit;
  font-size: 0.95rem;
  letter-spacing: 0;
  color: #cfcfd6;
  background: rgba(18,18,26,0.92);
  border: 1px solid rgba(184,155,94,0.35);
  border-radius: 50%;
  cursor: pointer;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
}
/* 蹦出：从中心放大 + 上移 + 淡入 */
@keyframes drawerBtnIn {
  0%   { opacity: 0; transform: scale(0.25) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
/* 收回：缩回中心 + 淡出（慢、缓） */
@keyframes drawerBtnOut {
  0%   { opacity: 1; transform: scale(1) translateY(0); }
  100% { opacity: 0; transform: scale(0.3) translateY(16px); }
}
#c3-drawer.open button, #mp-drawer.open button {
  animation: drawerBtnIn 0.5s cubic-bezier(.2,.8,.3,1.15) both;
}
#c3-drawer.open button:nth-child(1), #mp-drawer.open button:nth-child(1) { animation-delay: 0.04s; }
#c3-drawer.open button:nth-child(2), #mp-drawer.open button:nth-child(2) { animation-delay: 0.10s; }
#c3-drawer.open button:nth-child(3), #mp-drawer.open button:nth-child(3) { animation-delay: 0.16s; }
#c3-drawer.open button:nth-child(4), #mp-drawer.open button:nth-child(4) { animation-delay: 0.22s; }
#c3-drawer.open button:nth-child(5), #mp-drawer.open button:nth-child(5) { animation-delay: 0.28s; }
#c3-drawer.closing button, #mp-drawer.closing button {
  animation: drawerBtnOut 0.62s cubic-bezier(.4,0,.2,1) both;
}
#c3-drawer button:active, #mp-drawer button:active {
  color: #f2e6bf;
  border-color: rgba(184,155,94,0.85);
  transform: scale(1.08);
}


/* ============================================================
   第三章：背包 / 工作台面板
   ============================================================ */
.c3-panel {
  display: none;
  position: fixed;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1360;
  min-width: min(320px, 86vw);
  max-width: 92vw;
  padding: 1.4rem;
  background: rgba(10,10,16,0.96);
  border: 1px solid rgba(184,155,94,0.35);
  border-radius: 12px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
@keyframes panelSlideIn {
  0%   { opacity: 0; transform: translateY(-50%) translateX(130%); }
  100% { opacity: 1; transform: translateY(-50%) translateX(0); }
}
@keyframes panelSlideOut {
  0%   { opacity: 1; transform: translateY(-50%) translateX(0); }
  100% { opacity: 0; transform: translateY(-50%) translateX(130%); }
}
.c3-panel.open { display: block; }
.c3-panel-title {
  font-size: 1rem;
  letter-spacing: 0.3em;
  color: #b89b5e;
  margin-bottom: 1rem;
  text-align: center;
}
.c3-panel-hint {
  font-size: 0.76rem;
  line-height: 1.8;
  letter-spacing: 0.06em;
  color: #8a8a96;
  margin-bottom: 0.9rem;
  text-align: center;
}
.c3-bag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.c3-slot {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: #e8dcbf;
  background: rgba(20,20,30,0.7);
  border: 1px solid rgba(184,155,94,0.4);
  border-radius: 8px;
}
.c3-slot.empty {
  border-style: dashed;
  border-color: rgba(120,120,140,0.3);
}
.c3-slot.sel {
  border-color: rgba(184,155,94,1);
  box-shadow: 0 0 14px rgba(184,155,94,0.5);
  color: #fff;
}
.c3-panel-btn {
  font-family: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  padding: 0.6rem 1.2rem;
  margin: 0.3rem 0.3rem 0 0;
  color: #cfcfd6;
  background: rgba(30,26,18,0.7);
  border: 1px solid rgba(184,155,94,0.5);
  border-radius: 8px;
  cursor: pointer;
}
.c3-panel-btn:active {
  color: #fff;
  border-color: rgba(184,155,94,1);
}
.c3-bench {
  color: #8fd0e0 !important;
  text-shadow: 0 0 12px rgba(143,208,224,0.6);
}
.c3-word {
  color: #e8dcbf !important;
  text-shadow: 0 0 10px rgba(184,155,94,0.5);
}


/* ============================================================
   第三章：容器显示
   ============================================================ */
#chapter3 {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #020203;
  z-index: 700;
  overflow: hidden;
}
body.chapter3-mode #chapter3 { display: flex !important; }
body.chapter3-mode #game,
body.chapter3-mode #memory,
body.chapter3-mode #ending,
body.chapter3-mode #narration,
body.chapter3-mode #hud { display: none !important; }
body.chapter3-mode #c3-drawer-handle { display: block; }
body.mp-mode #mp-drawer-handle { display: block; }


/* 第三章：显示方向键 */
body.chapter3-mode .c1-dpad.c1-dpad-fixed { display: block; }


/* ---------- 工作台/背包：弹出收回 ---------- */
@keyframes c3-pop-in {
  0%   { opacity: 0; transform: translate(-50%, -46%) scale(0.92); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes c3-pop-out {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -42%) scale(0.94); }
}
.c3-panel.open {
  display: block;
  animation: panelSlideIn 0.62s cubic-bezier(.2,.8,.3,1.05) both;
}
.c3-panel.closing {
  display: block;
  animation: panelSlideOut 0.9s cubic-bezier(.4,0,.2,1) both;
}


/* ---------- 菜单打开时隐藏关卡 UI ---------- */
body.menu-open .c1-dpad.c1-dpad-fixed { display: none !important; }


/* ---------- 第三章旁白：stack 撑满宽度 ---------- */
.c1-narr .narr-stack {
  width: 100%;
  max-width: 560px;
}

