/* ============================================================
 * H30 移动端适配（feat/mobile）
 * ① 触屏控件：#joy-base/#joy-knob 虚拟摇杆、#btn-e 大号 E 按钮（JS 仅在触屏设备创建）
 * ② @media (max-width: 768px)：登录页/HUD/字幕/回忆卡/答题卡/灯箱等覆盖层响应式
 * 桌面：本文件仅注册两条不影响既有样式的规则（控件默认不存在于 DOM）
 * ============================================================ */

/* ---------- 虚拟摇杆：动态原点，半透明圆盘 + knob ---------- */
#joy-base {
  position: fixed; z-index: 48; display: none;
  width: 112px; height: 112px; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 12, 20, .25);
  border: 1.5px solid rgba(224, 137, 156, .45);
  box-shadow: inset 0 0 24px rgba(224, 137, 156, .12);
  pointer-events: none;   /* 纯视觉：输入走 window touch 事件 */
}
#joy-base.on { display: block; }
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 48px; height: 48px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(245, 220, 225, .9), rgba(224, 137, 156, .78));
  border: 1px solid rgba(255, 240, 245, .65);
  box-shadow: 0 0 18px rgba(224, 137, 156, .5);
}

/* ---------- 右下角交互按钮（≥44px 触摸目标）：H36 玫瑰金柔光圆钮 ---------- */
#btn-e {
  position: fixed; right: 18px; bottom: 96px; z-index: 49;
  width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; color: #ffe9f0;
  background: radial-gradient(circle at 35% 28%,
    rgba(245, 208, 168, .82), rgba(224, 137, 156, .72) 55%, rgba(122, 62, 92, .58));
  border: 1px solid rgba(255, 217, 160, .6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 22px rgba(224, 137, 156, .45), 0 8px 22px rgba(0, 0, 0, .38),
    inset 0 0 12px rgba(255, 225, 190, .28);
  text-shadow: 0 0 10px rgba(255, 215, 190, .8);
  opacity: 0; pointer-events: none; transform: scale(.8);
  transition: opacity .25s, transform .15s;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#btn-e.on {
  opacity: 1; pointer-events: auto; transform: scale(1);
  animation: btnEGlow 2.4s ease-in-out infinite;
}
#btn-e.on:active { transform: scale(.92); }   /* 按压反馈 */
@keyframes btnEGlow {
  0%, 100% { box-shadow: 0 0 16px rgba(224, 137, 156, .4), 0 8px 22px rgba(0, 0, 0, .38),
    inset 0 0 10px rgba(255, 225, 190, .22); }
  50%      { box-shadow: 0 0 42px rgba(224, 137, 156, .85), 0 8px 22px rgba(0, 0, 0, .38),
    inset 0 0 18px rgba(255, 225, 190, .4); }
}

/* ---------- ≤768px 响应式 ---------- */
@media (max-width: 768px) {
  /* 登录页/门帘：卡片不溢出、触摸目标加大 */
  .gate-inner { padding: 30px 22px; width: min(92vw, 420px); box-sizing: border-box; }
  .gate-ring { width: 180px; height: 180px; }
  .gate-sub { font-size: 12px; letter-spacing: .3em; }
  .gate-title { font-size: 34px; margin-bottom: 24px; }
  .gate-btn { width: 72px; height: 72px; font-size: 28px; }
  .pwd-wrap input { width: min(240px, 74vw); min-height: 48px; font-size: 18px; }
  .pwd-hint, .pwd-wrong { font-size: 12px; }

  /* HUD：计时器允许换行，音乐按钮保持 44px */
  .hud { padding: 10px 60px 10px 10px; }
  .hud-counter { font-size: 11px; padding: 6px 12px; max-width: 72vw; white-space: normal; text-align: center; line-height: 1.6; }
  .music-toggle { width: 44px; height: 44px; top: 10px; right: 10px; }

  /* 开场封面 */
  .intro-card { padding: 30px 22px; width: min(92vw, 420px); box-sizing: border-box; }
  .intro-title { font-size: 44px; }
  .intro-hint { margin-top: 28px; font-size: 12px; letter-spacing: .2em; }

  /* 字幕 / 提示条：给底部摇杆留位 */
  .caption { bottom: 20vh; padding: 16px 18px; max-width: 92vw; }
  .cap-text { font-size: 13px; }
  .interact-hint { bottom: 172px; max-width: 56vw; white-space: normal; text-align: center; line-height: 1.7; }
  .free-hint { bottom: 14px; font-size: 11px; max-width: 92vw; text-align: center; white-space: normal; line-height: 1.8; }
  .classic-link { display: none; }  /* 小屏藏经典版入口，防误触 */

  /* 情书 */
  .letter-paper { width: 94vw; max-height: 88vh; padding: 24px 18px; }
  .letter-body { font-size: 15px; line-height: 2.0; }
  .surprise-btn { width: 100%; padding: 15px 0; letter-spacing: .2em; }

  /* 灯箱 */
  .lightbox { padding: 16px; }
  .lightbox p { font-size: 13px; max-width: 92vw; text-align: center; }

  /* 抵达卡 */
  .arrive-card { padding: 14px 26px 12px; top: 10vh; }

  /* H18 长廊回忆卡 / H23 照片墙 */
  #memory-card, #h23-wall .h23w-card { width: 94vw; padding: 16px 14px 14px; max-height: 88vh; }
  #memory-card .mc-text { font-size: 13.5px; }
  #memory-card .mc-arrow, #h23-wall .h23w-arrow { width: 44px; height: 56px; }
  #memory-card .mc-go, #h23-wall .h23w-go { min-height: 44px; padding: 10px 26px; }

  /* H19 心愿/拍照 modal（横屏预览框布局归 css/h19.css H38 段管） */
  .h19-paper { width: 94vw; padding: 20px 16px; max-height: 88vh; }
  .h19-btn { min-height: 44px; display: inline-flex; align-items: center; }

  /* H20 答题卡：选项 ≥44px */
  .h20-card { width: 94vw; padding: 14px 14px 12px; max-height: 90vh; overflow-y: auto; }
  .h20-quiz-photo img { max-height: 220px; }
  .h20-opt { min-height: 44px; display: flex; align-items: center; justify-content: center; }

  /* H22 歌单卡 */
  .h22-pl-card { min-width: 0; width: 94vw; max-height: 86vh; overflow-y: auto; padding: 20px 16px 14px; }
  .h22-pl-item { min-height: 44px; }

  /* H24 里程碑金字略缩 */
  .h24-skytext { font-size: 24px; letter-spacing: 4px; }

  /* H25 收集面板：小屏贴底横铺 */
  .h25-panel { right: 10px; left: 10px; top: auto; bottom: 12px; width: auto; max-height: 40vh; }

  /* 对话框/浮层打开时压住 E 按钮，防叠层误触 */
  #caption.on ~ #btn-e,
  .letter-overlay.on ~ #btn-e,
  .h19-overlay.on ~ #btn-e,
  .h20-overlay.on ~ #btn-e,
  #h23-wall.on ~ #btn-e,
  #h22-playlist.on ~ #btn-e { opacity: 0 !important; pointer-events: none !important; }
}

/* ================= H36 移动端目标卡：折叠药丸 / 展开 / 隐藏 三态 =================
 * 桌面完全不动（以下规则只在 pointer:coarse 生效，且 JS 仅触屏创建相关 DOM）。
 * 默认折叠：✦ + 一行短文本药丸（≤38vw，半透明不挡视野），在右上 HUD 下方；
 * 点药丸展开完整卡（≤60vw），再点或 4s 无操作自动收回；✗ 收起为 28px ✦ 小圆点，
 * 点圆点恢复药丸。状态仅会话内，不写 localStorage。 */
@media (pointer: coarse) {
  /* 折叠药丸（基态） */
  #quest-card {
    top: 92px !important;               /* HUD 计时器/音乐钮之下 */
    right: 12px !important;
    max-width: 38vw !important;
    padding: 7px 14px !important;
    border-radius: 999px !important;
    pointer-events: auto !important;
    cursor: pointer;
    background: rgba(12, 10, 26, .52) !important;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 217, 160, .32) !important;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .35) !important;
  }
  #quest-card .qc-title,
  #quest-card .qc-sub,
  #quest-card .qc-dots { display: none; }   /* 药丸态只留主句 */
  #quest-card .qc-text {
    display: block;
    max-width: 100%;
    font-size: 12.5px !important;
    line-height: 1.4 !important;
    letter-spacing: .5px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #quest-card .qc-text::before {
    content: "✦";
    margin-right: 6px;
    color: #ffd9a0;
    font-size: 11px;
  }

  /* 展开态：完整卡（原标题/副文/圆点进度），≤60vw，4s 无操作自动收回 */
  #quest-card.mq-expanded {
    max-width: min(60vw, 250px) !important;
    padding: 12px 30px 12px 16px !important;
    border-radius: 14px !important;
    background: linear-gradient(160deg, rgba(14, 18, 40, .93), rgba(8, 10, 26, .93)) !important;
  }
  #quest-card.mq-expanded .qc-title,
  #quest-card.mq-expanded .qc-sub,
  #quest-card.mq-expanded .qc-dots { display: block; }
  #quest-card.mq-expanded .qc-text {
    font-size: 15px !important;
    white-space: normal;
  }

  /* 隐藏态：卡片消失，只剩 28px ✦ 小圆点 */
  #quest-card.mq-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(-6px) !important;
  }
  #quest-dot {
    position: fixed; top: 92px; right: 12px; z-index: 40;
    width: 28px; height: 28px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    font-size: 13px; color: #ffd9a0;
    background: rgba(12, 10, 26, .52);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 217, 160, .35);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
  #quest-dot.on { display: flex; }

  /* 展开态卡片右上角 ✗ 收起钮（JS 重建 innerHTML 后会重挂） */
  #quest-close {
    position: absolute; top: -7px; right: -7px;
    width: 22px; height: 22px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    font-size: 10px; line-height: 1; color: #98a2c0;
    background: rgba(12, 10, 26, .85);
    border: 1px solid rgba(152, 162, 192, .4);
  }
  #quest-card.mq-expanded #quest-close { display: flex; }
}

/* ================= H32 页面钉死（防浏览器手势干扰） =================
 * 问题：手机拖动触发下拉刷新/地址栏伸缩，画布跟着晃、不断 resize。
 * 做法：触屏设备上把文档钉在视口内（fixed + 禁橡皮筋），画布禁默认触摸行为，
 * 内部滚动容器放行并 containment（卡片内滚动不冒泡成页面手势）。 */
@media (pointer: coarse) {
  html, body {
    position: fixed; inset: 0;
    width: 100%; height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  #scene { touch-action: none; }
  /* 按钮/输入框保留点击响应，去掉双击缩放延迟 */
  button, input, a { touch-action: manipulation; }
  /* 卡片内部滚动：允许，且滚动到顶/底不再触发页面级下拉刷新 */
  #memory-card, .h19-paper, #h23-wall .h23w-card, .h25-panel,
  .letter-paper, .h20-card, .h22-pl-card {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

/* ================= H33 画布全屏贴合 =================
 * renderer.setSize 会写内联 px 尺寸，视口变化瞬间可能露出白底；
 * 用 !important 钉满视口，html/body 底色改成夜空色兜底。 */
@media (pointer: coarse) {
  #scene { width: 100% !important; height: 100% !important; }
  html, body { background: #0b0e20; }
}

/* ================= H33b 全屏按钮 =================
 * 默认隐藏（桌面不出现）；仅触屏显示，样式复刻 music-toggle 排在它左边。 */
#btn-fs { display: none; }
@media (pointer: coarse) {
  #btn-fs {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; right: 64px; z-index: 45;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid rgba(224,137,156,.4);
    background: rgba(20, 10, 18, .45); backdrop-filter: blur(6px);
    color: #e0899c; font-size: 17px; cursor: pointer;
  }
}

/* ================= H38 横屏拍照 modal 补充 =================
 * mobile.css 的 768px 段把 .h19-paper 钉在 88vh/16px padding，窄横屏装不下预览框+按钮；
 * 横屏放宽到 96vh（预览框尺寸归 css/h19.css H38 段管）。 */
@media (max-width: 980px) and (orientation: landscape) {
  .h19-paper { max-height: 96vh; padding: 10px 22px; }
}
