/* 手机适配：刘海/底部横条安全区、触控尺寸、横屏布局、禁止页面滚动和缩放。只在这里加，不改 style.css 原有规则 */
html, body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }
button, input, .char, .room { touch-action: manipulation; }
.sheet, .panel { touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* 加载进度条 */
#loadBar { width: min(260px, 70vw); height: 6px; border-radius: 3px; background: #ffffff1a; overflow: hidden; }
#loadBar i { display: block; height: 100%; width: var(--p, 0%); background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width 0.2s; }
#loadText { font-variant-numeric: tabular-nums; }
.char { position: relative; }
.char[data-pct]::after { content: attr(data-pct); position: absolute; right: 6px; top: 4px; font-size: 10px; color: var(--gold); }

/* 安全区：刘海、圆角、底部横条 */
#hud .top { top: max(12px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); }
#hud .bottom { bottom: max(14px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); }
.hype { right: max(16px, env(safe-area-inset-right)); }
.panel { padding-bottom: max(22px, env(safe-area-inset-bottom)); }

/* 触控：按钮至少 44px 高，按下有反馈；输入框 16px 字号，iOS 聚焦时才不会自动放大页面 */
@media (pointer: coarse) {
  .dock button { min-height: 52px; }
  .chat input, .panel input { font-size: 16px; }
  .chat button { min-width: 44px; min-height: 44px; }
  .pill { min-height: 34px; }
  .room { padding: 9px 14px; }
  .grid4 button, .acts button { min-height: 46px; }
  .hint { display: none; }
}
@media (max-width: 520px) {
  #hud .top { gap: 6px; }
  .pill { padding: 6px 10px; font-size: 13px; }
  #trackPill { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stamina i { width: 64px; }
  /* 竖屏大厅：角色按钮三列、面板矮一点，上面能看到自己的角色 */
  .chars { grid-template-columns: repeat(3, 1fr); gap: 6px; } .char { padding: 8px 4px; font-size: 12px; }
  .panel { padding: 16px; } .panel h1 { font-size: 24px; } .panel .sub { margin-bottom: 8px; }
  .lbl { margin: 10px 0 6px; } .panel label { margin-top: 10px; } .primary { margin-top: 12px; padding: 12px; }
  .sheet { bottom: calc(150px + env(safe-area-inset-bottom)); max-height: 46vh; }
  .hype { bottom: calc(150px + env(safe-area-inset-bottom)); }
}

/* 手机横屏（高度很矮）：聊天和操作栏放一排，嗨按钮 2×2，面板变矮 */
@media (orientation: landscape) and (max-height: 520px) {
  #hud .bottom { flex-direction: row; align-items: flex-end; justify-content: center; gap: 8px; }
  .chat { width: auto; flex: 1 1 260px; max-width: 420px; }
  .dock { flex: none; padding: 4px; }
  .dock button { width: 58px; min-height: 46px; padding: 4px 0; font-size: 11px; }
  .dock button b { font-size: 18px; }
  .hype { bottom: calc(76px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(2, auto); gap: 8px; }
  .hype button { width: 50px; height: 50px; }
  .sheet { bottom: calc(72px + env(safe-area-inset-bottom)); max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); }
  #hud .top { top: max(8px, env(safe-area-inset-top)); }
  #trackPill { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #shoutBanner { top: 50px; }
  .panel { top: 50%; bottom: auto; transform: translateY(-50%); right: max(16px, env(safe-area-inset-right)); max-height: calc(100% - 20px); width: min(380px, 55vw); padding: 16px; }
  .panel h1 { font-size: 22px; display: inline; } .panel .sub { display: inline; margin: 0 0 0 8px; font-size: 12px; }
  .lbl { margin: 8px 0 5px; }
  .chars { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .char { padding: 6px 4px; font-size: 12px; } .char i { margin-bottom: 4px; height: 4px; }
  .panel label { margin-top: 8px; flex-direction: row; align-items: center; } .panel label input { flex: 1; min-width: 0; padding: 7px 10px; }
  .rooms { flex-wrap: nowrap; overflow-x: auto; } .room { padding: 6px 10px; flex: none; }
  .primary { margin-top: 10px; padding: 10px; }
  #mc { top: 22%; }
}

/* landscape overflow fix (2026-11-17): at 844x390 chat + dock were 848px wide in an 812px row */
@media (orientation: landscape) and (max-height: 520px) {
  #hud .bottom { box-sizing: border-box; min-width: 0; }
  .chat { flex: 1 1 180px; min-width: 0; }
  .chat input { min-width: 0; }
  .dock { flex: 0 1 auto; min-width: 0; }
  .dock button { width: 50px; }
  .hype { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* 竖屏手机（2026-11-20）：操作栏两排时，摇杆压住聊天框、跑步键压住发送、🌸 压住 📺。
   改成放在底栏实际高度（--hud-bottom-h，由 js/mobile.js 量出来）上方 10px。 */
@media (orientation: portrait) and (max-width: 520px) {
  #joyWrap { bottom: calc(var(--hud-bottom-h, 168px) + 10px); }
  .hype { bottom: calc(var(--hud-bottom-h, 160px) + 10px); }
}