/**
 * safe-area-compat.css —— iOS「添加到主屏幕」(独立/全屏) 顶部安全区适配
 *
 * 背景（用户反馈）：
 *   iPhone（含 17 Pro Max）用 Safari 把「love咪小手机」添加到主屏幕后，
 *   以独立应用（standalone）方式启动。此时配合 index.html 的
 *     <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
 *     <meta name="viewport" ... viewport-fit=cover>
 *   网页内容会「沉浸式」延伸到真机状态栏 / 灵动岛背后，env(safe-area-inset-top)
 *   变为约 47~62px。
 *
 * 问题：
 *   主页面（#chat-page / #wechat-page / #phone-page / #twitter-page / #settings-page …）
 *   顶部都有一个 .status-bar，已用 max(12px, env(safe-area-inset-top)) 预留安全区，
 *   所以不受影响。但「铺满 #app 的全屏浮层 / 子屏」(AO3、游乐场、一起听歌、一起看书、
 *   电影院、情侣空间各子页、推特详情/私信浮层、日历全屏面板等) 自身没有 .status-bar，
 *   它们的顶部功能栏 / 返回按钮直接贴在 top:0，于是被真机状态栏 / 灵动岛完全盖住、无法点击。
 *
 * 方案：
 *   仅在「独立 / 全屏」启动态（<html class="lovemi-standalone">，由 index.html 头部脚本
 *   依据 navigator.standalone 或 display-mode: standalone/fullscreen 判定）下，
 *   给这些全屏浮层的顶部栏补上 env(safe-area-inset-top) 的顶部内边距（或 top 偏移），
 *   让它们整体下移到真机状态栏之下。
 *
 * 安全性：
 *   - 普通浏览器标签页（Safari / Via / Chrome / Edge / 搜狗 / 雨见 / 夸克 等）不带
 *     lovemi-standalone 类，本文件所有规则都不命中，零副作用；
 *   - 仅作用于「确实贴在屏幕最顶部、且无 .status-bar 兜底」的全屏浮层顶栏，
 *     不动主页面、居中弹窗、底部上拉面板、好友手机内部页（它们各自已被 .status-bar
 *     或父壳的 env() 安全区覆盖），避免把不在顶部的元素错误下移；
 *   - 适配机型/内核：iPhone(Safari/Chrome/Edge) standalone、以及 Android（华为/小米/
 *     OPPO/魅族/vivo/三星）以独立应用安装时的 display-mode: standalone。
 *
 * 加载顺序：本文件在所有模块样式之后；规则统一带 !important，即使个别浮层样式
 *   是按需(懒)加载、晚于本文件注入，也能稳定覆盖其顶栏内边距。
 */

/* ------------------------------------------------------------------ */
/* 通用：仅独立/全屏启动态生效                                          */
/* ------------------------------------------------------------------ */

/* AO3 专区（.ao3-root 铺满 #app，无 status-bar） */
html.lovemi-standalone .ao3-root .ao3-root__header {
    padding-top: calc(18px + env(safe-area-inset-top, 0px)) !important;
}

/* 一起听歌（.lt-overlay 铺满 #app） */
html.lovemi-standalone .lt-overlay .lt-topbar {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 一起看书（#rt-overlay-root 铺满 #app） */
html.lovemi-standalone #rt-overlay-root .rt-topbar {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}

/* 游乐场（#sub-screen-game-hub）右上角关闭按钮：绝对定位 top，需整体下移 */
html.lovemi-standalone #sub-screen-game-hub .sub-screen-game-hub__close {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* love咪放映厅（.lmc-cinema 铺满 #app） */
html.lovemi-standalone .lmc-cinema-topbar {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 购物·商品详情全屏面板（盖住 #shopping-page 的 status-bar） */
html.lovemi-standalone #shopping-page .shopping-product-detail-panel .shopping-detail-toolbar {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}

/* ------------------------------------------------------------------ */
/* 推特（#twitter-page 内的全屏浮层；列表态头栏在 .status-bar 之下，无需处理） */
/* ------------------------------------------------------------------ */

/* 推文详情页（.twitter-detail-page: position:absolute; inset:0; 盖住状态栏） */
html.lovemi-standalone #twitter-page .twitter-detail-page .twitter-detail-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 私信会话浮层（.twitter-dm-root: position:absolute; inset:0 铺满 #twitter-page）。
   会话头 .twitter-dm-chat-header / 多选顶栏 .twitter-dm-multiselect-topbar 二者
   择一可见，都贴在浮层物理顶部，需补安全区。
   ⚠ 上一版只挂 [data-dm-chat-overlay="on"] 单一 hook：该属性由 setChatOverlayActive()
   设置，但 renderChatView() 重入（切到别的 Tab 再切回消息）时不会恢复，导致属性可能
   为 off / 缺失而规则不命中。改用 [data-dm-page="chat"] 作主 hook（openConversation 设置后
   一直保留、只在回列表时清除，最稳定），并叠加页面 class 与原 overlay 属性作三重保险。
   （已同步在 twitter-dm.js 的 renderChatView 开头补 setChatOverlayActive(true) 兜底。） */
html.lovemi-standalone .twitter-dm-root[data-dm-page="chat"] .twitter-dm-chat-header,
html.lovemi-standalone .twitter-dm-root[data-dm-page="chat"] .twitter-dm-multiselect-topbar,
html.lovemi-standalone .twitter-dm-root[data-dm-chat-overlay="on"] .twitter-dm-chat-header,
html.lovemi-standalone .twitter-dm-root[data-dm-chat-overlay="on"] .twitter-dm-multiselect-topbar,
html.lovemi-standalone #twitter-page.twitter-page--dm-chat-overlay .twitter-dm-chat-header,
html.lovemi-standalone #twitter-page.twitter-page--dm-chat-overlay .twitter-dm-multiselect-topbar {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* ------------------------------------------------------------------ */
/* 情侣空间（各子浮层均铺满 #app，无 status-bar）                       */
/* ------------------------------------------------------------------ */

/* 情侣空间主页（排除已自带安全区的 --private 私密态头栏） */
html.lovemi-standalone .couple-space-overlay .couple-space-header:not(.couple-space-header--private) {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 情侣空间·票务须知浮层 */
html.lovemi-standalone .couple-ticketing-notice-overlay .couple-ticketing-notice-header {
    padding-top: calc(22px + env(safe-area-inset-top, 0px)) !important;
}

/* 情侣空间·纪念日 */
html.lovemi-standalone .cs-anniv-overlay .cs-anniv-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 情侣空间·恋爱日记（普通头栏 + 封面上悬浮头栏） */
html.lovemi-standalone .cs-lj-overlay .cs-lj-header {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone .cs-lj-overlay .cs-lj-header--over-cover {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}

/* 情侣空间·经期记录 */
html.lovemi-standalone .couple-period-overlay .couple-period-topbar {
    padding-top: calc(18px + env(safe-area-inset-top, 0px)) !important;
}

/* 情侣空间·甜蜜日记（封面态绝对顶栏 + 内页头栏） */
html.lovemi-standalone .cs-sd-overlay .cs-sd-topbar {
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone .cs-sd-overlay .cs-sd-page-topbar {
    padding-top: calc(18px + env(safe-area-inset-top, 0px)) !important;
}

/* ------------------------------------------------------------------ */
/* 子屏日历：仅「全屏型」面板（闹钟编辑 / 来电）；普通底部上拉面板不处理   */
/* ------------------------------------------------------------------ */
html.lovemi-standalone .ssc-overlay.ssc-overlay--full .ssc-sheet-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px)) !important;
}

/* ------------------------------------------------------------------ */
/* IF 线板块（#love-mi-if-line-root.if-line-root 铺满 #app，无 status-bar） */
/*                                                                    */
/* .if-line-topbar 由 sub-screen-if-line.js 通过 <style> 注入（非 inline，*/
/* 故可用 !important + 后加载稳定覆盖），覆盖：IF线 Hub（世界线列表）、    */
/* 当前世界（地图）、回到过去(Past AVG)、以及未来可能启用的 timeline 页。  */
/*                                                                    */
/* 注意：原样式写死 height:64px（矮屏 56px），若只加 padding-top 会把       */
/* 返回/关闭按钮与标题挤压；这里改用 min-height 并放开 height，让顶栏       */
/* 随安全区自然增高。                                                    */
/* ------------------------------------------------------------------ */
html.lovemi-standalone .if-line-topbar {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    height: auto !important;
    min-height: calc(64px + env(safe-area-inset-top, 0px)) !important;
}

@media (max-height: 700px) {
    html.lovemi-standalone .if-line-topbar {
        padding-top: calc(7px + env(safe-area-inset-top, 0px)) !important;
        min-height: calc(56px + env(safe-area-inset-top, 0px)) !important;
    }
}

/* Past AVG 背景网格层写死 inset-top:64px（对齐原顶栏高度）；顶栏随安全区
   增高后，把网格起点同步下移，避免网格顶端被加高的顶栏盖住而错位。 */
html.lovemi-standalone .past-avg-screen::before {
    top: calc(64px + env(safe-area-inset-top, 0px)) !important;
}

/* ------------------------------------------------------------------ */
/* 游戏板块·双保险                                                      */
/*                                                                    */
/* 游乐场各全屏游戏（你画我猜 / 真心话大冒险 / 好友助手）的顶栏在各自源      */
/* CSS 里已用 calc(基数 + env(safe-area-inset-top)) 预留安全区。这里在      */
/* 独立/全屏态再用同等基数 + !important 兜底，防止个别机型/浏览器内核        */
/* 因样式加载时序或 env 计算时序问题导致源规则一时未生效时顶栏被状态栏盖住。 */
/* 基数与源 CSS 保持一致（你画我猜 8 / 真心话 10 / 好友助手 8），故正常态     */
/* 视觉零变化。                                                          */
/* ------------------------------------------------------------------ */
html.lovemi-standalone .draw-guess-game .dg-header {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone .truth-or-dare-game .tod-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone .sgh-friend-assistant .sgh-fa-header {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}

/* ================================================================== */
/* 微信模块·全屏覆盖式子页面 / 浮层顶栏统一安全区适配                    */
/*                                                                    */
/* 背景：#wechat-page / #wechat-me-page / #wechat-discover-page /      */
/* #chat-page 这些主页面首子元素是 .status-bar，已预留安全区；但它们    */
/* 之上还会弹出大量「position:absolute; inset:0 铺满、且自己没有        */
/* .status-bar」的子页面 / 浮层（聊天设置、好友设置、专属美化、钱包、   */
/* 收藏、亲属卡、添加好友、查找聊天记录、长期记忆、线下模式各页等）。   */
/* 它们的顶栏直接贴 top:0，独立/全屏态会被真机状态栏 / 灵动岛盖住。     */
/*                                                                    */
/* 处理分两类：                                                        */
/*  (一) 贴顶全宽顶栏（有 border-bottom、无 margin 偏移）→ 加 padding-top， */
/*       顶栏背景延伸到状态栏背后，文字下移，观感最佳；                  */
/*  (二) 从聊天页打开 / 心动记录页里被改成「margin 定位的悬浮圆角卡片」  */
/*       的顶栏 → 必须加 margin-top 把整张卡片下移（并把 padding-top    */
/*       还原，避免卡片被撑高）。                                       */
/*                                                                    */
/* 特异性：部分源规则带 #id + !important（如 #wechat-me-page            */
/* .wechat-settings-header / #chat-page .chat-fullscreen-glass …），   */
/* 故覆盖规则统一前缀 html.lovemi-standalone 并按需带 #id + !important，*/
/* 确保稳定生效。                                                      */
/* ================================================================== */

/* ---------------- (一) 贴顶全宽顶栏：加 padding-top ---------------- */

/* 微信「设置」/「聊天设置」/「专属美化」页（#wechat-me-page 内，header
   规则带 #wechat-me-page + !important，需同级 #id 覆盖） */
html.lovemi-standalone #wechat-me-page .wechat-settings-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 钱包 / 我的余额 / 银行卡 / 账单（通用贴顶；#chat-page 悬浮态在下方还原） */
html.lovemi-standalone .wallet-page-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 亲属卡 */
html.lovemi-standalone .kinship-page-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 收藏页 + 收藏详情（通用贴顶；#chat-page / 心动记录悬浮态在下方还原） */
html.lovemi-standalone .favorites-page-header {
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}

/* 添加好友（手机端为 top:0 全屏壳） */
html.lovemi-standalone #add-friend-modal.add-friend-page-shell .add-friend-page-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 聊天页内 chat-fullscreen-glass 全屏层（聊天设置 / 好友设置 / 群设置 /
   专属美化 / AI时间感知 / 群专属气泡成员等，共用 .modal-header，
   源规则 #chat-page .chat-fullscreen-glass .modal-content.xxx > .modal-header
   带 !important，本规则特异性更高且后加载） */
html.lovemi-standalone #chat-page .chat-fullscreen-glass .modal-content > .modal-header,
html.lovemi-standalone .offline-script-chat-page .chat-fullscreen-glass .modal-content > .modal-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
}

/* 查找聊天记录全屏（含线下剧本页同源） */
html.lovemi-standalone #chat-page #search-chat-modal.search-chat-fullscreen .modal-content > .modal-header,
html.lovemi-standalone #offline-script-chat-page #search-chat-modal.search-chat-fullscreen .modal-content > .modal-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 长期记忆全屏（含旅行长记忆，复用 .chat-long-memory-header） */
html.lovemi-standalone .chat-long-memory-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 线下模式全屏层各顶栏（线下模式 / 文风选择 / 新建文风 / 剧本大纲）；
   #chat-page 下「线下模式」头是悬浮卡片，在下方单独还原 + margin */
html.lovemi-standalone .offline-mode-header,
html.lovemi-standalone .offline-style-picker-header,
html.lovemi-standalone .offline-style-new-header,
html.lovemi-standalone .offline-script-outline-header {
    padding-top: calc(14px + env(safe-area-inset-top, 0px)) !important;
}

/* ---------------- (二) 悬浮圆角卡片顶栏：加 margin-top ---------------- */
/* 这些顶栏用 margin 定位、离屏幕顶部有圆角间距，必须整张卡片下移；
   同时把 padding-top 还原为原值，避免被上面的通用规则撑高。 */

/* 从聊天页打开的：收藏 / 钱包（及账单）/ 线下模式 头栏（margin:10px） */
html.lovemi-standalone #chat-page .favorites-page-header {
    padding-top: 8px !important;
    margin-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone #chat-page .wallet-page-header {
    padding-top: 12px !important;
    margin-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}
html.lovemi-standalone #chat-page .offline-mode-header {
    padding-top: 14px !important;
    margin-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
}

/* 心动记录收藏页 / 详情页头栏（margin:8px 悬浮卡片） */
html.lovemi-standalone #favorites-heartbeat-page .favorites-page-header,
html.lovemi-standalone #favorites-heartbeat-detail-page .favorites-page-header {
    padding-top: 8px !important;
    margin-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
}
