/*!
 * 万能墙（lhuiye.cn） — SPDX-License-Identifier: LicenseRef-Proprietary
 * Copyright (c) 2026 辉夜 <18759765356@163.com> 保留所有权利
 * 第三方组件保留各自许可（见 THIRD_PARTY_NOTICES.md）
 */
/* ==========================================================================
   【全站设备适配层】手机 / 平板 / 电脑 / 大屏 / 横屏 通用适配
   --------------------------------------------------------------------------
   加载位置：ui_polish.css 之后（全站前台页面 <head> 内，见 inc/device_css.php）。
   与既有文件的分工：
     · app.css       基础组件样式
     · desktop.css   ≥768px 的版式与容器宽度（本层在其后，可覆盖细节）
     · mobile.css    ≤767px 的手机专属样式
     · tablet.css    768–1023 平板补正
     · wide.css      ≥1440 大屏补正
     · 本文件        与断点无关的"跨设备"能力：安全区、动态视口、触控目标、
                     hover 守卫、表单与键盘、表格横向滚动、横屏、打印
   设计原则：只做加法与覆盖，不改页面结构；所有规则都能在"不支持该特性"的
   浏览器里优雅退化（env()/dvh/@supports 都有兜底）。
   ========================================================================== */

/* ---------- 0. 安全区变量（刘海屏 / 灵动岛 / 手势条 / 圆角屏） ---------- */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    /* 底部导航高度（含安全区），列表底部留白统一用它，避免最后一条被遮住 */
    --nav-space: calc(70px + var(--safe-bottom));
}

/* 顶栏/吸顶栏：viewport-fit=cover 后页面会延伸到状态栏下面，必须自己补上内边距 */
body > header,
.site-header,
header.sticky,
header.fixed,
.help-topbar,
.ctm-head {
    padding-top: var(--safe-top);
}
/* 顶部固定工具条（分享条/子页签）同理 */
.sticky-top, .sub-nav, .topbar { padding-top: var(--safe-top); }

/* 固定底栏 / 抽屉 / 悬浮按钮：左右也要避开圆角与刘海横屏时的禁区 */
.bottom-nav {
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}
.nav-sheet, .nav-sheet-mask, .modal, .perf-modal-mask {
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}
.fab-btn, .ui-to-top { margin-bottom: var(--safe-bottom); }

/* 正文底部留白：页面没有底部导航时（少）也给一点点，避免内容贴边 */
body { --ui-bottom-space: var(--nav-space); }

/* ---------- 1. 动态视口：解决手机浏览器工具栏/键盘导致的 100vh 溢出 ---------- */
@supports (height: 100dvh) {
    .modal .modal-content,
    .perf-modal,
    .nav-sheet,
    .mp-list-pop,
    .mp-panel,
    .ct-terms-box,
    .cmt-reply-bar ~ .cmt-list { max-height: calc(100dvh - 40px); }
    body.page-login main,
    body.page-verify main,
    body.page-forgot main,
    body.page-reset main { min-height: calc(100dvh - var(--safe-top)); }
    /* 弹出面板：以动态视口为上限并允许内部滚动，键盘弹出时不至于看不到输入框 */
    .nav-sheet { max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
}
/* 聊天室/评论区：把输入区固定在可视区底部上方，键盘弹出时仍然可见 */
@media (max-width: 767px) {
    body.page-chat_room .chat-input-bar,
    body.page-chat_room .msg-input-bar,
    #commentForm.is-sticky {
        padding-bottom: calc(10px + var(--safe-bottom));
        scroll-margin-bottom: 120px;
    }
    html { scroll-padding-bottom: calc(var(--nav-space) + 12px); }
}

/* ---------- 2. 触控设备（手机/平板）：可点区域、点击反馈、hover 守卫 ---------- */
@media (pointer: coarse) {
    /* 统一去掉触屏上的悬停位移动效（没有 hover 的设备上这些动效只会造成"点了没反应"的错觉） */
    .post-card:hover, .ct-card:hover, .food-card:hover, .event-card:hover,
    .hero-card:hover, .listing-card:hover, .card:hover { transform: none !important; }
    /* 主要可点元素给足触控面积（44px 是 iOS/Android 的通用推荐下限） */
    .btn:not(.btn-xs), .gradient-btn, button.btn, .comment-submit, .ct-submit-btn,
    .ct-vote-btn, .nav-item, .nav-sheet-item, .ct-tab, .ct-filter,
    .cmt-act, .cmt-sort, .cmt-filter, .publish-as-btn, .lang-btn, .ct-radio,
    input[type="submit"], input[type="button"] { min-height: 44px; }
    /* 行内小按钮（表格操作、卡片操作）放宽到 34px，避免过小但仍保持紧凑 */
    .pc-actions button, .post-actions button, .report-btn, .del-own-comment,
    .del-own-comment, .float-close, .adm-icon-btn { min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
    /* 触屏点击反馈：用透明度/底色代替位移，避免布局抖动 */
    a:active, button:active, [role="button"]:active { opacity: .72; }
    /* 阻止双击缩放导致的 300ms 延迟与误缩放 */
    button, a, [role="button"], .nav-item, .ct-vote-btn, .cmt-like { touch-action: manipulation; }
    /* 触屏上的滚动惯性（iOS 上老版本默认就没有，显式声明更稳） */
    .nav-sheet, .modal-content, .table-scroll, .cmt-list, .mp-list { -webkit-overflow-scrolling: touch; }
    /* 自定义背景图在触屏上关闭 fixed 附着（低端机滚动重绘的主因） */
    body { background-attachment: scroll !important; }
}
/* 只有"精确指针 + 支持 hover"的设备才启用悬停动效（笔记本鼠标/桌面） */
@media (hover: hover) and (pointer: fine) {
    .cmt:hover { background: #fafafb; }
    .cmt-act:hover { color: var(--primary, #7e57c2); }
}
/* 触屏设备上常显操作栏（很多组件默认 hover 才显示，触屏上会"找不到按钮"） */
@media (hover: none), (pointer: coarse) {
    .post-card .pc-actions,
    .pc-comments .pc-more,
    .ct-card .ct-actions,
    .listing-card .lc-actions,
    .food-card .fc-actions { opacity: 1 !important; visibility: visible !important; }
}

/* ---------- 3. 表单与键盘：防 iOS 聚焦缩放、合适的键盘类型与回车键 ---------- */
@media (max-width: 1023px) and (pointer: coarse) {
    input[type="text"], input[type="search"], input[type="email"], input[type="password"],
    input[type="number"], input[type="tel"], input[type="url"], input[type="date"],
    input[type="time"], input[type="datetime-local"], textarea, select {
        font-size: 16px;              /* < 16px 时 iOS Safari 会自动放大页面 */
    }
    /* 下拉框在 iOS 上默认样式很怪：统一高度与内边距 */
    select { min-height: 44px; appearance: none; -webkit-appearance: none;
        background-image: linear-gradient(45deg, transparent 50%, #94a3b8 50%), linear-gradient(135deg, #94a3b8 50%, transparent 50%);
        background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
        background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
    /* 日期/时间控件在安卓上文字容易溢出 */
    input[type="date"], input[type="time"], input[type="datetime-local"] { min-height: 44px; }
}
/* 表单提交后自动滚到第一个错误提示（JS 见 assets/js/device_adapt.js） */
.form-error, .alert-error, .cmt-composer-foot + .alert-error { scroll-margin-top: 80px; }

/* ---------- 4. 溢出治理：长单词、宽表格、代码块、媒体 ---------- */
img, video, canvas, iframe, svg, table { max-width: 100%; }
img, video { height: auto; }
body .post-content, body .detail-content, .cmt-body, .msg-content, .listing-body,
.md-body, .prose, .fb-content, .ct-bio, .ct-desc { overflow-wrap: anywhere; word-break: break-word; }
/* 表格：包一层可横滑容器（device_adapt.js 自动包裹，类名 .table-scroll） */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 520px; }
/* 横滑时的边缘阴影提示（右侧还有内容） */
.table-scroll { background-image: linear-gradient(to right, rgba(0,0,0,.06), rgba(0,0,0,0)), linear-gradient(to left, rgba(0,0,0,.06), rgba(0,0,0,0));
    background-position: 0 0, 100% 0; background-size: 18px 100%, 18px 100%; background-repeat: no-repeat; background-attachment: local, local; }
pre, code, .apl-code { max-width: 100%; overflow-x: auto; }
/* flex/grid 子项默认不允许收缩是移动端横向溢出的头号原因 */
.post-card, .cmt, .cmt-main, .listing-card, .food-card, .event-card, .hero-card,
.input-row, .form-row, .ct-card, .msg-item, .fb-item { min-width: 0; }

/* ---------- 5. 手机竖屏细节（≤480 / ≤360） ---------- */
@media (max-width: 480px) {
    .container, .mk-wrap, .help-container, .ctm-wrap { padding-left: 14px; padding-right: 14px; }
    /* 卡片更紧凑，减少滚动距离 */
    .card, .post-card { border-radius: 14px; }
    /* 操作栏允许换行而不是溢出 */
    .pc-actions, .post-actions, .cmt-actions, .ct-head-actions { flex-wrap: wrap; row-gap: 4px; }
    /* 标题层级在窄屏降一档，避免两行以上 */
    h1 { font-size: 1.45rem; }
    h2 { font-size: 1.2rem; }
}
@media (max-width: 360px) {
    .container, .mk-wrap, .help-container, .ctm-wrap { padding-left: 10px; padding-right: 10px; }
    /* 320–360px 的老机型：头像与字号再收一点，保证一行能放下昵称+操作 */
    .avatar, .cmt-avatar { width: 32px !important; height: 32px !important; }
    .cmt-avatar { flex-basis: 32px !important; }
    .cmt-head { gap: 4px; }
    .ct-grid { grid-template-columns: 1fr 1fr !important; }
    .post-card { padding: 11px 12px !important; }
}

/* ---------- 6. 手机横屏：降低纵向占用（顶栏/底栏/英雄区） ---------- */
@media (orientation: landscape) and (max-height: 520px) {
    /* 顶栏变薄 */
    body > header, .site-header, header.sticky { padding-top: var(--safe-top); padding-bottom: 2px !important; }
    /* 底部导航收成图标条（隐藏文字标签），把高度还给内容 */
    .bottom-nav { height: 52px; align-items: center; padding-bottom: var(--safe-bottom); }
    .bottom-nav .nav-label { display: none !important; }
    .bottom-nav .nav-icon { font-size: 19px; line-height: 1; }
    .nav-item { min-height: 44px; padding: 4px 0; }
    /* 装饰性大块（标语/倒计时/统计/节日特效）横屏时收起，先让内容可见 */
    .quote-card, .gaokao-card, .uptime-card, .contest-pin, .hero-banner { display: none !important; }
    /* 弹层改为左右分栏可滚动，避免被高度挤压 */
    .modal .modal-content, .nav-sheet { max-height: 96dvh; overflow-y: auto; }
    /* 首屏内容减少上下留白 */
    main { padding-top: 10px !important; padding-bottom: calc(var(--nav-space) + 6px) !important; }
}

/* ---------- 7. 打印：去掉导航与交互件 ---------- */
@media print {
    .bottom-nav, .site-header, header.sticky, .fab-btn, .ui-to-top, .nav-sheet,
    .nav-sheet-mask, .site-loader, #musicPlayer, .legal-notice { display: none !important; }
    body { background: #fff !important; padding: 0 !important; }
    .post-card, .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
    a[href]::after { content: " (" attr(href) ")"; font-size: 11px; color: #666; }
}

/* ---------- 8. 低配/极速模式：适配层不引入任何额外合成层 ---------- */
html[data-perf="lite"] .bottom-nav,
html[data-perf="lite"] .site-header { box-shadow: none !important; }
html[data-perf="lite"] .table-scroll { background-image: none !important; }

/* ---------- 9. 应用内 WebView / 网页封装壳：按"低配 + 受限"降级 ----------
   由服务端 UA 识别写入 <html data-webview="1" data-webview-name="WeChat|QQ|Douyin|…">，
   客户端 legacy_compat.js 兜底。这些环境的共同问题：
     · 毛玻璃/固定背景/大阴影开销高、滚动容易掉帧
     · 平滑滚动（scroll-behavior:smooth）在部分 WebView 里会卡住或与原生手势冲突
     · 长按/选择文本行为与浏览器不同，会误触
   所以这里只做"减法"，不改变布局结构。 */
html[data-webview="1"] * {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
}
html[data-webview="1"] { scroll-behavior: auto !important; }
html[data-webview="1"] * { scroll-behavior: auto !important; }
html[data-webview="1"] body {
    background-attachment: scroll !important;
    background-image: none !important;
    background-color: #f5f3f7 !important;
}
html[data-webview="1"] .site-header,
html[data-webview="1"] .bottom-nav,
html[data-webview="1"] .post-card,
html[data-webview="1"] .card { box-shadow: none !important; }
/* 封装壳里长按选择/放大镜体验差：正文默认不可选，需要复制的输入框保持可选 */
html[data-webview="1"] body { -webkit-user-select: none; user-select: none; }
html[data-webview="1"] input,
html[data-webview="1"] textarea,
html[data-webview="1"] .md-body,
html[data-webview="1"] .post-content,
html[data-webview="1"] .cmt-body { -webkit-user-select: text; user-select: text; }
/* 去掉"点按高亮块"，用正常的 :active 反馈 */
html[data-webview="1"] * { -webkit-tap-highlight-color: transparent; }
/* 内容区允许惯性滚动 */
html[data-webview="1"] body { -webkit-overflow-scrolling: touch; }
