/* ════════════════════════════════════════════════════════════════════════════
   mud_web 移动端统一规范基础样式 v1.0
   配套规范: docs/MOBILE_SPEC.md

   引用方式: 所有 HTML 页面 <head> 中按顺序加载:
     <link rel="stylesheet" href="/static/css/mobile-base.css?v=1.0">

   本文件只放"硬规范",不放具体页面样式。具体页面样式各自放自己的 CSS,
   断点必须用本规范定义的 sm/md/lg/xl。
   ════════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────
   1. ROOT — 全局基准 (16px / 系统字体栈 / 动态视口)
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* 字体基准 */
  font-size: 16px;
  font-family:
    -apple-system, BlinkMacSystemFont,
    "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* safe-area 变量 (供各页面消费) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  /* z-index 体系 */
  --z-base:     0;
  --z-sticky:   100;
  --z-dropdown: 500;
  --z-modal:    1500;
  --z-toast:    1800;
  --z-loading:  2000;
  --z-prompt:   3000;
}

/* ─────────────────────────────────────────────────────────────────────────
   2. HTML/BODY — 滚动行为 + 动态视口
   ───────────────────────────────────────────────────────────────────────── */
/* 注意：html 不再设置 height，让内容自然撑开（PC 滚动布局需要）
   移动端需要 height: 100dvh 的场景在 mobile.css 的 html.is-mobile 块里 */
html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: var(--bg, #0d0d1a);
  color: var(--text, #e8e0d0);
}

/* ─────────────────────────────────────────────────────────────────────────
   3. TOUCH — 所有交互元素统一行为
   ───────────────────────────────────────────────────────────────────────── */
button,
[role="button"],
.btn,
a.btn,
.dpad-btn,
.dbtn,
.combat-btn,
.tool-btn,
.npc-sprite,
.item-sprite,
.send-btn,
.emoji-btn,
.attach-btn,
.gate-btn,
.sect-job-btn,
.ferry-btn,
.scroll-bottom-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

/* hover 只在真悬停设备生效,触摸设备不"黏连" */
@media (hover: hover) {
  button:hover,
  .btn:hover {
    background: var(--hover-bg, rgba(255, 215, 0, 0.18));
  }
}

/* 触摸设备:active 反馈 */
@media (hover: none) and (pointer: coarse) {
  button:active,
  .btn:active,
  .dpad-btn:active,
  .dbtn:active {
    transform: scale(0.96);
    transition: transform 0.05s ease;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   4. INPUT — 输入框特例 (可缩放、不阻止默认行为)
   ───────────────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
textarea,
select {
  font-size: 16px;                    /* iOS 不自动缩放阈值 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* 输入框允许 user-select(不能禁止) */
  user-select: auto;
  -webkit-user-select: auto;
}

/* ─────────────────────────────────────────────────────────────────────────
   5. SCROLL — 滚动容器统一行为
   ───────────────────────────────────────────────────────────────────────── */
.scrollable,
.modal-body,
.output-box,
.scroll-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

/* ─────────────────────────────────────────────────────────────────────────
   6. SCENE-WRAPPER — 已被移到 mobile.css 的 html.is-mobile 块内
   (2026-07-05 修复:之前无条件 .scene-wrapper { height: 100dvh } 破坏了 PC 布局)
   ───────────────────────────────────────────────────────────────────────── */

/* ─────────────────────────────────────────────────────────────────────────
   7. 横竖屏引导遮罩 (麻将/掼蛋等横屏游戏专用)
   ───────────────────────────────────────────────────────────────────────── */
.orientation-prompt {
  display: none;
}

/* 默认:is-mobile 设备 + portrait 才提示 */
@media (max-width: 1024px) and (orientation: portrait) {
  html.is-mobile:not(.force-portrait) .orientation-prompt {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: var(--z-prompt);
    background: var(--bg, #0d0d1a);
    color: var(--text, #e8e0d0);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    font-size: 1.1rem;
    line-height: 1.6;
  }
  html.is-mobile:not(.force-portrait) .orientation-prompt .icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    animation: rotate-hint 2s ease-in-out infinite;
  }
  @keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    50%      { transform: rotate(90deg); }
  }
  /* 跳过按钮: 2026-07-19 owner 拍板让玩家能在 portrait 下用掼蛋 */
  .orientation-prompt .orientation-skip-btn {
    margin-top: 1.8rem;
    padding: 12px 28px;
    font-size: 0.95rem;
    color: var(--text, #e8e0d0);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .orientation-prompt .orientation-skip-btn:active {
    background: rgba(255, 255, 255, 0.18);
    transform: scale(0.97);
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   8. 暗色模式(默认深色游戏主题)
   ───────────────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
  /* 浅色模式预留入口(暂未启用) */
}

/* ─────────────────────────────────────────────────────────────────────────
   9. 减少动画(无障碍)
   ───────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   10. 标准断点系统(供各页面 CSS 引用本文件后扩展)
   ───────────────────────────────────────────────────────────────────────── */
/* sm: ≤640px  - 默认样式生效范围(本文件大部分规则已在此范围内)
   md: 641-1024px - 横屏游戏 / 平板
   lg: 1025-1440px - 桌面
   xl: ≥1441px - 大屏 */

/* ════════════════════════════════════════════════════════════════════════════
   END OF mobile-base.css v1.0
   ════════════════════════════════════════════════════════════════════════════ */