/* ═══════════════════════════════════════════════════════════
   Mobile —— 移动端适配
   ═══════════════════════════════════════════════════════════
   核心思路：真机上不该再套一层"假手机"。手机上直接全屏，
   把省下来的 ~120px 还给内容；同时把所有可点区域放大到 44px 以上。

   断点约定（与 desk.css 保持一致）：
     ≤ 900px  左侧考勤卡变成抽屉
     ≤ 768px  手机壳折叠为全屏应用
     ≤ 480px  紧凑排版（小屏手机）
     hover:none 触屏专属：干掉 hover 粘滞、放大触控目标
   ═══════════════════════════════════════════════════════════ */

/* ─────────────── 全局触控基础（所有尺寸都生效） ─────────────── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
.tab,
.opt,
.c-row,
.act-card,
.tpill,
.cf,
.gift,
.mg-mj-tile,
.mg-mj-btn,
.mg-hp-dish,
.mg-hp-pot {
  touch-action: manipulation; /* 干掉双击缩放的 300ms 延迟 */
}

/* 游戏本体禁止选中，输入框例外 */
.screen {
  -webkit-user-select: none;
  user-select: none;
}
.screen input,
.screen textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ═══════════════ 触屏专属 ═══════════════ */

@media (hover: none), (pointer: coarse) {
  /* hover 效果在触屏上会"粘住"上一次点的元素，全部取消位移反馈 */
  .opt:hover,
  .dm-opt:hover,
  .call-opt:hover,
  .scene-opt:hover,
  .act-card:hover,
  .pending-item:hover,
  .me-top:hover,
  .gift:hover,
  .todo-item:hover {
    transform: none;
  }

  /* 触控目标统一放大到 44px 以上 */
  .tpill {
    min-height: 40px;
    padding: 9px 14px;
    font-size: 12.5px;
  }
  .cf {
    min-height: 40px;
    padding: 9px 15px;
    font-size: 12.5px;
  }
  .ci-send {
    min-height: 42px;
    min-width: 64px;
  }
  .ci-field {
    min-height: 42px;
    display: flex;
    align-items: center;
  }
  .opt,
  .dm-opt,
  .call-opt,
  .scene-opt {
    min-height: 50px;
    padding: 13px 14px;
  }
  .act-card {
    min-height: 68px;
  }
  .c-row {
    min-height: 62px;
  }
  .tab {
    min-height: 56px;
  }
  .nb-back,
  .rail-toggle {
    width: 44px;
    height: 44px;
  }
  .nb-back {
    font-size: 30px;
  }
  .sheet-skip {
    min-height: 46px;
  }
  .btn {
    min-height: 46px;
  }
  .link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 4px;
  }
}

/* ═══════════════ ≤900px：抽屉 + 手机壳折叠为全屏 ═══════════════
   断点与 desk.css 的抽屉断点保持一致。两者一旦不一致，就会出现
   "考勤卡变成抽屉但按钮不存在"或"小游戏还是桌面布局"这类死角。 */

@media (max-width: 900px) {
  /* 手机上 288px 的抽屉会占掉 3/4 屏宽，留不出多少可点的遮罩 */
  .rail {
    width: min(300px, 78vw);
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }
  .rail-stack {
    max-width: 100%;
  }
  /* 抽屉里的显式关闭按钮：手机上只剩 90px 的遮罩可点，太窄了 */
  .rail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px 10px;
  }
  .rail-head-title {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.24em;
    color: var(--text-mute);
    text-transform: uppercase;
  }
  .rail-close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-dim);
    font-size: 16px;
    transition: background var(--t-fast);
  }
  .rail-close:active {
    background: rgba(255, 255, 255, 0.16);
  }
  /* 抽屉打开时，开关变成 ✕ */
  .desk.rail-open .rail-toggle {
    background: rgba(255, 255, 255, 0.1);
  }

  .desk {
    grid-template-columns: minmax(0, 1fr);
  }

  .phone-wrap {
    padding: 0;
    gap: 0;
    min-height: 0;
    overflow: hidden;
  }

  .phone {
    width: 100%;
    height: 100%;
    max-height: none;
    min-height: 0;
  }

  /* 拆掉假手机的一切装饰 */
  .phone-halo,
  .phone-shadow,
  .phone-island,
  .phone-btn,
  .phone-reflect,
  .desk-hint,
  .desk-grain {
    display: none;
  }

  .phone-frame {
    border-radius: 0;
    padding: 0;
    background: var(--wx-bg-dark);
    box-shadow: none;
  }

  .screen {
    border-radius: 0;
  }

  /* 真机已经有系统状态栏了，假的收起来，把高度还给内容 */
  .statusbar {
    display: none;
  }

  .navbar {
    height: auto;
    min-height: 52px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .rail-toggle {
    display: grid;
  }

  .tabbar {
    height: auto;
    min-height: 56px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .phone-toasts {
    top: calc(64px + env(safe-area-inset-top, 0px));
  }

  /* 叙事层要避开刘海和home指示条 */
  .narr {
    padding: calc(52px + env(safe-area-inset-top, 0px)) 26px calc(52px + env(safe-area-inset-bottom, 0px));
  }
  .narr p {
    font-size: 16px;
  }
  .narr-hint {
    bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  }

  .call-inner {
    padding: calc(36px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  /* 覆盖层贴边 */
  .scene,
  .modal-mask {
    padding: 14px;
  }
  .scene-card {
    max-height: calc(100dvh - 28px);
    border-radius: var(--r-lg);
    padding: 20px 18px;
  }
  .modal {
    padding: 20px 18px 16px;
  }

  /* 小游戏全屏，别在手机上还留一圈黑边 */
  .mgstage {
    padding: 0;
  }
  .mgstage-inner {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
  }
  .mgstage-head {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    gap: 10px;
  }
  .ms-icon {
    font-size: 24px;
  }
  .mgstage-head h2 {
    font-size: 16px;
  }
  .ms-brief {
    display: none; /* 太挤，玩法说明放在小游戏内部 */
  }
  .mgstage-body {
    padding: 14px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
  }

  /* 手机视图内边距收紧 */
  .person,
  .me {
    padding: 16px 14px calc(32px + env(safe-area-inset-bottom, 0px));
  }
  .week {
    padding: 14px 12px calc(32px + env(safe-area-inset-bottom, 0px));
  }
  .panel {
    padding: 14px;
    border-radius: var(--r-md);
  }
  .wh-title {
    font-size: 19px;
  }
  .p-id h2 {
    font-size: 18px;
  }
  .p-tagline {
    font-size: 14px;
  }
  .end-inner {
    padding: 46px 20px calc(60px + env(safe-area-inset-bottom, 0px));
  }
  .end-title {
    font-size: clamp(30px, 9vw, 44px);
  }
  .end-text p {
    font-size: 15px;
    line-height: 2.1;
  }
  .er-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ═══════════════ 小游戏：窄屏布局重排 ═══════════════ */

@media (max-width: 900px) {
  /* ── 火锅点菜 ── */
  .mg-hp-pots {
    grid-template-columns: 1fr;
  }
  .mg-hp-pot {
    min-height: 56px;
  }
  .mg-hp-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .mg-hp-dish {
    min-height: 62px;
    padding: 10px;
  }
  .mg-hp-budget {
    font-size: 22px;
  }
  .mg-hp-row {
    min-height: 52px;
    flex-wrap: wrap;
  }
  .mg-hp-state {
    margin-left: auto;
  }
  .mg-hp-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, transparent, var(--ink-850) 26%);
    padding-top: 10px;
  }
  .mg-hp-btn {
    min-height: 50px;
  }

  /* ── 血战到底（麻将）── */
  .mg-mj-root {
    max-width: 100%;
    font-size: 13px;
  }
  /* 右侧信息栏改成横向条，别再挤占牌桌宽度 */
  .mg-mj-main {
    flex-direction: column;
    gap: 8px;
  }
  .mg-mj-side {
    flex: none;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .mg-mj-side > * {
    flex: 1 1 30%;
    min-width: 84px;
  }
  .mg-mj-seat {
    padding: 7px 6px;
  }
  .mg-mj-seatname {
    font-size: 12px;
  }
  .mg-mj-av {
    width: 28px;
    height: 28px;
  }
  .mg-mj-river {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }
  .mg-mj-rcell {
    min-height: 44px;
  }
  /* 手牌放大到能点 */
  .mg-mj-tile {
    width: 38px;
    height: 50px;
    font-size: 16px;
    border-radius: 5px;
  }
  .mg-mj-mini {
    width: 26px;
    height: 34px;
    font-size: 11px;
  }
  .mg-mj-backtile {
    width: 26px;
    height: 34px;
  }
  .mg-mj-back {
    width: 5px;
    height: 15px;
  }
  .mg-mj-hand {
    min-height: 74px;
    padding: 10px 4px 6px;
    gap: 5px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* 右侧渐隐，暗示可以横滑 */
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  }
  .mg-mj-hand::-webkit-scrollbar {
    display: none;
  }
  .mg-mj-handtile,
  .mg-mj-tile {
    flex: none;
  }
  .mg-mj-log {
    height: 62px;
  }
  .mg-mj-btn {
    min-height: 48px;
    flex: 1 1 auto;
  }
  .mg-mj-btns {
    gap: 8px;
  }

  /* ── 狼人杀 ── */
  .mg-ww {
    max-width: 100%;
    font-size: 13px;
  }
  .mg-ww-seats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .mg-ww-seat {
    min-height: 62px;
  }
  .mg-ww-seat .mg-ww-av {
    width: 30px;
    height: 30px;
  }
  .mg-ww-seat .mg-ww-nm {
    font-size: 10px;
  }
  .mg-ww-stream {
    height: 34vh;
    min-height: 170px;
    -webkit-overflow-scrolling: touch;
  }
  .mg-ww-btn {
    min-height: 48px;
    flex: 1 1 auto;
  }

  /* ── KTV ── */
  .mg-ktv-songs {
    grid-template-columns: 1fr;
  }
  .mg-ktv-song {
    min-height: 62px;
  }
  .mg-ktv-lyric {
    font-size: 19px;
  }
  .mg-ktv-track {
    height: 62px;
  }
  .mg-ktv-btn {
    min-height: 50px;
  }

  /* ── 饭局对话 ── */
  .mg-dn-opt {
    min-height: 56px;
  }
  .mg-dn-say p {
    font-size: 15px;
  }
}

/* ═══════════════ ≤480px：小屏手机 ═══════════════ */

@media (max-width: 480px) {
  .mg-hp-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .mg-mj-side > * {
    flex: 1 1 45%;
  }
  .mg-ww-seats {
    grid-template-columns: repeat(3, 1fr);
  }
  .chat-stream {
    padding: 10px 8px 14px;
  }
  .msg-body {
    max-width: 78%;
  }
  .msg-bubble {
    font-size: 13.5px;
  }
  .sheet-opts {
    max-height: 42vh;
  }
  .er-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .me-stats {
    grid-template-columns: repeat(3, 1fr);
  }
  .p-actions .btn {
    min-width: 100%;
  }
}

/* ═══════════════ 横屏手机：竖向空间极度紧张 ═══════════════ */

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .navbar {
    min-height: 44px;
  }
  .tabbar {
    min-height: 46px;
  }
  .tab {
    flex-direction: row;
    gap: 5px;
    font-size: 11px;
    min-height: 46px;
  }
  .tab-i {
    font-size: 14px;
  }
  .chat-stream {
    padding: 8px;
  }
  .chat-topics {
    padding: 5px 10px;
  }
  /* 横屏下把整个插话面板做成一个可滚动区，
     比逐个压缩选项高度更稳，不会再把面板顶到标签栏底下 */
  .chat-sheet {
    max-height: 52vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sheet-opts {
    max-height: none;
    padding: 5px 12px 8px;
  }
  .opt {
    min-height: 44px;
    padding: 9px 12px;
  }
  .sheet-skip {
    min-height: 40px;
    margin-bottom: 8px;
  }
  .chat-input {
    padding: 5px 10px 6px;
  }
  .ci-field,
  .ci-send {
    min-height: 40px;
  }
  .narr p {
    font-size: 14px;
    line-height: 1.9;
  }
  .mgstage-body {
    padding: 10px 14px;
  }
  .mg-mj-hand {
    min-height: 60px;
  }
  .mg-ww-stream {
    height: 30vh;
  }
  /* 横屏高度不够，日志区让位给牌桌 */
  .mg-mj-log {
    height: 46px;
  }
}
