/* reverse-invasion.css — 反向入侵：设置卡 / 顶栏横幅 / 屏蔽层 / 聊天回执气泡（由 style.css 拆出） */

/* ===================== 反向入侵设置卡（Char 手机·设置·桌面背景下方） ===================== */
.phone-settings-reverse-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.phone-settings-reverse-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.phone-settings-reverse-title-wrap {
    flex: 1;
    min-width: 0;
}

.phone-settings-reverse-switch {
    flex-shrink: 0;
    position: relative;
    width: 42px;
    height: 24px;
    display: inline-block;
    cursor: pointer;
}

.phone-settings-reverse-switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    cursor: pointer;
    z-index: 2;
}

.phone-settings-reverse-switch-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: rgba(120, 130, 140, 0.32);
    transition: background 0.18s ease;
}

.phone-settings-reverse-switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: transform 0.18s ease;
}

.phone-settings-reverse-switch input:checked + .phone-settings-reverse-switch-track {
    background: linear-gradient(135deg, #FF6B8A 0%, #FF9A6B 100%);
}

.phone-settings-reverse-switch input:checked + .phone-settings-reverse-switch-track::after {
    transform: translateX(18px);
}

.phone-settings-reverse-collapse-btn {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(120, 130, 140, 0.22);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    color: #555;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.phone-settings-reverse-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.9);
}

.phone-settings-reverse-collapse-arrow {
    transition: transform 0.18s ease;
    display: inline-block;
}

.phone-settings-reverse-collapse-arrow.is-open {
    transform: rotate(180deg);
}

.phone-settings-reverse-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 8px 4px 4px;
    border-top: 1px dashed rgba(120, 130, 140, 0.22);
}

.phone-settings-reverse-body[hidden] {
    display: none;
}

.phone-settings-reverse-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.phone-settings-reverse-label {
    font-size: 13px;
    color: #333;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.phone-settings-reverse-depth-actions {
    display: inline-flex;
    gap: 6px;
}

.phone-settings-reverse-depth-btn {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(120, 130, 140, 0.24);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11px;
    color: #555;
    cursor: pointer;
}

.phone-settings-reverse-depth-btn:hover {
    background: rgba(255, 255, 255, 0.95);
}

.phone-settings-reverse-interval {
    width: 110px;
    padding: 6px 10px;
    border: 1px solid rgba(120, 130, 140, 0.24);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    color: #222;
}

.phone-settings-reverse-hint {
    font-size: 11.5px;
    color: rgba(60, 60, 70, 0.62);
    line-height: 1.45;
}

.phone-settings-reverse-depth-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 10px;
}

.phone-settings-reverse-depth-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(120, 130, 140, 0.18);
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    line-height: 1.35;
}

.phone-settings-reverse-depth-item input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: #FF6B8A;
}

.phone-settings-reverse-depth-name {
    color: #333;
    font-weight: 600;
    flex: 1;
}

.phone-settings-reverse-depth-sub {
    display: block;
    width: 100%;
    color: rgba(60, 60, 70, 0.55);
    font-size: 11px;
    font-weight: 400;
    margin-left: 22px;
    margin-top: 2px;
}

.phone-settings-reverse-depth-item:has(input:checked) {
    background: linear-gradient(135deg, rgba(255, 107, 138, 0.15) 0%, rgba(255, 154, 107, 0.12) 100%);
    border-color: rgba(255, 107, 138, 0.42);
}

/* ===================== 反向入侵 · 顶部状态条 + 透明输入屏蔽层 ===================== */

/* 透明屏蔽层：覆盖整屏，吃掉所有点击/触摸事件，但 User 仍能"看见"下方页面被 Char 操作 */
.reverse-invasion-block-layer {
    position: fixed;
    inset: 0;
    z-index: 1000040;
    background: transparent;
    pointer-events: auto;
    cursor: not-allowed;
}

html.reverse-invasion-active {
    /* 阻止键盘选区 / 文本选中，强化"被锁定"感 */
    user-select: none;
    -webkit-user-select: none;
}

html.reverse-invasion-active body {
    overflow: hidden;
}

/* 顶部状态条（2026-07 重做）
   —— 用户集中反馈两类问题，这里一次解决：
   ① iPhone(灵动岛/刘海机型) Safari 等场景下，横幅 top:12px 会顶进真机状态栏 / 灵动岛
      背后，按钮完全点不到。现在下移：56px 基础偏移 + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) 安全区
      （与项目 safe-area-compat.css 同一套方案；不支持 env() 的老内核回落到纯 56px，
      也已避开顶部框架）。
   ② 显示面积太小、只有一行半文字，看不清 Char 做了什么。改为纵向大卡片：
      标题行 + 当前动态(最多 6 行) + 最近操作轨迹 + 全宽"知道了"大按钮(≥44px 触控高度)。 */
.reverse-invasion-banner {
    position: fixed;
    top: 56px; /* 老内核（不支持 env()/calc 嵌套）兜底 */
    top: calc(56px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
    left: 50%;
    /* 收起态不再用 -120% 甩出屏外（下移后甩不干净会露一截），改淡出+上移 */
    transform: translate(-50%, -16px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 1000060;
    width: min(480px, calc(100vw - 20px));
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease, visibility 0s linear 0.32s;
}

.reverse-invasion-banner.is-open {
    transform: translate(-50%, 0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

.reverse-invasion-banner-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(48, 18, 38, 0.96) 0%, rgba(38, 12, 38, 0.96) 100%);
    border: 1px solid rgba(255, 107, 138, 0.42);
    box-shadow: 0 10px 28px rgba(20, 0, 30, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    color: #fff;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.reverse-invasion-banner-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reverse-invasion-banner-pulse {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #FF6B8A;
    box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.7);
    animation: reverse-invasion-pulse 1.8s ease-in-out infinite;
}

@keyframes reverse-invasion-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.55); transform: scale(1); }
    70%  { box-shadow: 0 0 0 12px rgba(255, 107, 138, 0); transform: scale(1.08); }
    100% { box-shadow: 0 0 0 0 rgba(255, 107, 138, 0); transform: scale(1); }
}

.reverse-invasion-banner-title {
    font-size: 13px;
    letter-spacing: 0.08em;
    font-weight: 800;
    color: #FFD0DC;
    text-transform: uppercase;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reverse-invasion-banner-status {
    font-size: 14.5px;
    color: rgba(255, 255, 255, 0.95);
    line-height: 1.55;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
}

/* 最近操作轨迹：把 Char 刚做过的几步留在屏上，User 能连续看清整个过程 */
.reverse-invasion-banner-log {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 208, 220, 0.28);
}

.reverse-invasion-banner-log[hidden] {
    display: none;
}

.reverse-invasion-banner-log-item {
    font-size: 12px;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.55);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reverse-invasion-banner-log-item::before {
    content: '·';
    margin-right: 5px;
    color: rgba(255, 107, 138, 0.7);
}

/* "知道了"：全宽大按钮，≥44px 触控高度（iOS 人机指南最小触控目标），
   touch-action: manipulation 消除双击缩放判定带来的点击延迟 */
.reverse-invasion-banner-skip {
    width: 100%;
    min-height: 44px;
    background: linear-gradient(135deg, #FF6B8A 0%, #FF9A6B 100%);
    border: none;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 10px 16px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255, 107, 138, 0.35);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.12s ease, filter 0.12s ease, background 0.2s ease;
}

.reverse-invasion-banner-skip:active:not(:disabled) {
    transform: scale(0.97);
    filter: brightness(0.9);
}

/* 点击后的确认态：变绿 + "✓ 已知晓"，让用户明确感知点击已生效 */
.reverse-invasion-banner-skip.is-acked {
    background: linear-gradient(135deg, #38C98E 0%, #2BB3A3 100%);
    box-shadow: 0 4px 12px rgba(43, 179, 163, 0.35);
    cursor: default;
    opacity: 1;
}

/* 被无视态：Char 依角色性格拒不收手时，按钮转深灰红"✗ TA 无视了你的确认"，
   配合一次轻微横向抖动，传达"确认已送达但被对方无视"的挫败感 */
.reverse-invasion-banner-skip.is-defied {
    background: linear-gradient(135deg, rgba(90, 30, 46, 0.95) 0%, rgba(60, 20, 40, 0.95) 100%);
    border: 1px solid rgba(255, 107, 138, 0.5);
    color: #FFB3C4;
    box-shadow: 0 4px 12px rgba(20, 0, 10, 0.4);
    cursor: default;
    opacity: 1;
    animation: reverse-invasion-defy-shake 0.45s ease;
}

@keyframes reverse-invasion-defy-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

.reverse-invasion-banner-skip:disabled:not(.is-acked):not(.is-defied) {
    opacity: 0.65;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .reverse-invasion-banner {
        top: 48px;
        top: calc(48px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
        width: calc(100vw - 16px);
    }
    .phone-settings-reverse-depth-grid {
        grid-template-columns: 1fr;
    }
    .reverse-invasion-banner-pulse {
        animation: none;
    }
}

/* 矮屏（横屏手机等）：压缩动态区行数，防止卡片高过可视区 */
@media (max-height: 520px) {
    .reverse-invasion-banner-status {
        -webkit-line-clamp: 3;
    }
    .reverse-invasion-banner-log {
        display: none;
    }
}

/* ============================================================
   反向入侵·真实操作回执（可折叠卡片）
   --------------------------------------------------------------
   覆盖普通微信气泡的字数限制：完整记录 Char 在 User 手机上的
   每一步浏览、看到的内容、实际执行的动作。默认折叠，点击展开。
   ============================================================ */
.chat-message-bubble--reverse-invasion-receipt {
    background: transparent !important;
    padding: 0 !important;
    max-width: 100% !important;
    width: 100%;
    box-shadow: none !important;
}

.chat-message-bubble--reverse-invasion-receipt .rir-card {
    border-radius: 14px;
    background: linear-gradient(160deg, rgba(255, 246, 247, 0.95), rgba(243, 232, 255, 0.92));
    border: 1px solid rgba(255, 110, 130, 0.22);
    box-shadow: 0 6px 18px rgba(255, 110, 130, 0.12);
    overflow: hidden;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
    color: #4a2030;
    transition: background-color 0.18s ease;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head:hover {
    background-color: rgba(255, 200, 210, 0.25);
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-badge {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff6b81, #c071ff);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.6;
    box-shadow: 0 2px 4px rgba(255, 107, 129, 0.32);
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-text {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d1023;
    line-height: 1.35;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-summary {
    margin-top: 4px;
    font-size: 12.5px;
    line-height: 1.45;
    color: #5b3142;
    /* 折叠时摘要最多两行，避免标题区过高 */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    word-break: break-word;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-ts {
    margin-top: 4px;
    font-size: 11px;
    color: #8c5f70;
    opacity: 0.85;
}

.chat-message-bubble--reverse-invasion-receipt .rir-head-arrow {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    color: #ad2d4d;
    font-size: 12px;
    transition: transform 0.22s ease;
}

.chat-message-bubble--reverse-invasion-receipt .rir-card:not([data-collapsed="1"]) .rir-head-arrow {
    transform: rotate(180deg);
}

.chat-message-bubble--reverse-invasion-receipt .rir-card:not([data-collapsed="1"]) .rir-head-summary {
    -webkit-line-clamp: unset;
    display: block;
}

.chat-message-bubble--reverse-invasion-receipt .rir-body {
    padding: 4px 14px 14px;
    border-top: 1px dashed rgba(255, 110, 130, 0.25);
    background: rgba(255, 252, 253, 0.65);
    color: #3a1c2c;
    font-size: 13px;
    line-height: 1.55;
}

.chat-message-bubble--reverse-invasion-receipt .rir-body[hidden] {
    display: none;
}

.chat-message-bubble--reverse-invasion-receipt .rir-section {
    margin-top: 10px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-section:first-child {
    margin-top: 8px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #ad2d4d;
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}

.chat-message-bubble--reverse-invasion-receipt .rir-line {
    margin: 2px 0;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message-bubble--reverse-invasion-receipt .rir-open {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 110, 130, 0.14);
}

.chat-message-bubble--reverse-invasion-receipt .rir-open-name {
    font-weight: 600;
    color: #6b1c3c;
    font-size: 12.5px;
    margin-bottom: 4px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-open-narration {
    color: #4a2030;
    font-size: 12.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message-bubble--reverse-invasion-receipt .rir-open-actions {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-action {
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 235, 240, 0.85);
    border-left: 3px solid #ff6b81;
    font-size: 12.5px;
    line-height: 1.45;
}

.chat-message-bubble--reverse-invasion-receipt .rir-action-kind {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 6px;
    border-radius: 6px;
    background: #ff6b81;
    color: #fff;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: 1px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-action-content {
    margin-top: 3px;
    color: #4a2030;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message-bubble--reverse-invasion-receipt .rir-evidence {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(247, 237, 255, 0.78);
    border: 1px solid rgba(192, 113, 255, 0.18);
}

.chat-message-bubble--reverse-invasion-receipt .rir-evidence-app {
    font-weight: 600;
    color: #58208c;
    font-size: 12.5px;
    margin-bottom: 4px;
}

.chat-message-bubble--reverse-invasion-receipt .rir-section-fallback {
    background: rgba(255, 255, 255, 0.78);
    padding: 8px 10px;
    border-radius: 10px;
    color: #3a1c2c;
}

/* ============================================================
   反向入侵 · 触发瞬间「夺屏」特效（2026-08 新增）
   --------------------------------------------------------------
   触发反向入侵的一刻不再让 User 看到"从 Char 手机桌面平平无奇地退回
   查手机主界面"，而是：整屏抖动 → 雪花噪点铺满 → 模型以 Char 阴暗面
   口吻现写的重影文字浮现（颜色 / 重影是否扩大 / 是否裂屏由模型决定）。
   兼容性要点：
   - 雪花优先用 <canvas> 低分辨率噪点（所有主流内核支持）；canvas 不可用
     时回落到 CSS 渐变噪点动画（.reverse-invasion-glitch-noise-fallback）。
   - 重影用 ::before/::after + attr(data-text) 双拷贝（全内核支持），
     不依赖 @property / backdrop-filter 等新特性。
   - 抖屏只作用在特效层自身（stage），绝不 transform body/html——
     避免 iOS Safari / 各安卓 WebView 上 position:fixed 元素错位的老坑。
   - prefers-reduced-motion: reduce 时自动关掉抖动与高频闪烁。
   ============================================================ */
.reverse-invasion-glitch {
    position: fixed;
    inset: 0;
    z-index: 1000080; /* 高于状态条(1000060)与输入屏蔽层(1000040)，夺屏期间盖住一切 */
    background: #05030a;
    overflow: hidden;
    pointer-events: auto;
    cursor: not-allowed;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    opacity: 1;
    transition: opacity 0.55s ease;
}

.reverse-invasion-glitch.is-leaving {
    opacity: 0;
}

/* stage 四周多出血 18px，抖动时不会露出底下的页面边缘 */
.reverse-invasion-glitch-stage {
    position: absolute;
    inset: -18px;
    animation: reverse-glitch-shake-md 0.5s linear infinite;
}

.reverse-invasion-glitch[data-intensity="low"] .reverse-invasion-glitch-stage {
    animation: reverse-glitch-shake-low 0.7s linear infinite;
}

.reverse-invasion-glitch[data-intensity="high"] .reverse-invasion-glitch-stage,
.reverse-invasion-glitch.is-cracked .reverse-invasion-glitch-stage {
    animation: reverse-glitch-shake-high 0.36s linear infinite;
}

@keyframes reverse-glitch-shake-low {
    0%   { transform: translate(0, 0); }
    25%  { transform: translate(-2px, 1px); }
    50%  { transform: translate(2px, -1px); }
    75%  { transform: translate(-1px, -2px); }
    100% { transform: translate(0, 0); }
}

@keyframes reverse-glitch-shake-md {
    0%   { transform: translate(0, 0); }
    15%  { transform: translate(-4px, 2px); }
    30%  { transform: translate(3px, -3px); }
    45%  { transform: translate(-3px, -2px); }
    60%  { transform: translate(4px, 3px); }
    75%  { transform: translate(-2px, 4px); }
    90%  { transform: translate(2px, -4px); }
    100% { transform: translate(0, 0); }
}

@keyframes reverse-glitch-shake-high {
    0%   { transform: translate(0, 0); }
    12%  { transform: translate(-7px, 4px); }
    24%  { transform: translate(6px, -5px); }
    36%  { transform: translate(-5px, -6px); }
    48%  { transform: translate(7px, 5px); }
    60%  { transform: translate(-6px, 7px); }
    72%  { transform: translate(5px, -7px); }
    84%  { transform: translate(-4px, 3px); }
    100% { transform: translate(0, 0); }
}

/* 雪花噪点画布：JS 用低分辨率缓冲绘制再拉伸铺满，省电且更像老电视雪花 */
.reverse-invasion-glitch-noise {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    opacity: 0.82;
    transition: opacity 0.45s ease;
}

/* 台词亮出后（is-burst）：雪花整体压暗，把舞台让给文字——
   否则满亮度噪点会把台词"吃"得看不清（用户反馈修复） */
.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-noise {
    opacity: 0.3;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-noise-fallback {
    opacity: 0.18;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-scanlines {
    opacity: 0.45;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-tearband {
    /* 撕裂带的 keyframes 自带 opacity，会盖过静态 opacity——直接停掉动画再压暗 */
    animation: none;
    opacity: 0.3;
}

/* canvas 不可用（极老内核）时的 CSS 雪花兜底：多层渐变错位滚动 */
.reverse-invasion-glitch-noise-fallback {
    position: absolute;
    inset: 0;
    opacity: 0.5;
    transition: opacity 0.45s ease;
    background-image:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.14) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0 1px, transparent 1px 2px),
        radial-gradient(circle at 30% 40%, rgba(255, 255, 255, 0.2), transparent 55%),
        radial-gradient(circle at 70% 65%, rgba(255, 255, 255, 0.16), transparent 50%);
    background-size: 100% 4px, 3px 100%, 160px 160px, 200px 200px;
    animation: reverse-glitch-noise-roll 0.24s steps(3) infinite;
}

@keyframes reverse-glitch-noise-roll {
    0%   { background-position: 0 0, 0 0, 0 0, 0 0; }
    50%  { background-position: 0 -2px, 2px 0, -40px 30px, 50px -20px; }
    100% { background-position: 0 2px, -2px 0, 30px -40px, -30px 40px; }
}

/* 扫描线 + 随机横向撕裂带：叠在噪点上增强"信号被劫持"质感 */
.reverse-invasion-glitch-scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 2px, transparent 2px 5px);
    mix-blend-mode: multiply;
    pointer-events: none;
    transition: opacity 0.45s ease;
}

.reverse-invasion-glitch-tearband {
    position: absolute;
    left: -6%;
    width: 112%;
    height: 9%;
    top: 30%;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.16) 45%, rgba(120, 220, 255, 0.12) 55%, transparent);
    filter: blur(1px);
    animation: reverse-glitch-tear 1.7s steps(6) infinite;
    pointer-events: none;
}

@keyframes reverse-glitch-tear {
    0%   { top: 8%;  transform: translateX(0) scaleY(1); opacity: 0.9; }
    20%  { top: 62%; transform: translateX(-14px) scaleY(0.6); opacity: 0.4; }
    40%  { top: 34%; transform: translateX(10px) scaleY(1.3); opacity: 0.85; }
    60%  { top: 81%; transform: translateX(-8px) scaleY(0.5); opacity: 0.35; }
    80%  { top: 18%; transform: translateX(12px) scaleY(1.1); opacity: 0.75; }
    100% { top: 47%; transform: translateX(0) scaleY(0.8); opacity: 0.5; }
}

/* ---------- 第一阶段：入侵宣告字群（2026-08 新增） ----------
   雪花屏出现后，「XX 正在入侵你的手机」的副本以随机位置 / 角度 / 字号 / 明暗
   逐渐铺满屏幕（由 JS 定时生成，DOM 数量封顶 + 循环回收，低端机不掉帧）。
   台词亮出（is-burst）后整个字群退到近乎不可见，把舞台让给阴暗面台词。 */
.reverse-invasion-glitch-swarm {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-swarm {
    opacity: 0.08;
}

.reverse-invasion-glitch-swarm-item {
    position: absolute;
    white-space: nowrap;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
    /* 基础透明度 0：动画未开始（delay 期间）不可见，一到点就以"信号闪现"的方式蹦出来；
       每条的明暗差异走 color 的 alpha（JS 随机内联），keyframes 保持定值以兼容老内核 */
    opacity: 0;
    animation-name: reverse-glitch-swarm-flicker;
    animation-timing-function: steps(2, end);
    animation-iteration-count: infinite;
    /* duration / delay 由 JS 逐条随机内联，避免整片字群同频闪烁像贴图 */
}

@keyframes reverse-glitch-swarm-flicker {
    0%, 100% { opacity: 1; }
    38%      { opacity: 0.35; }
    52%      { opacity: 0.9; }
    74%      { opacity: 0.55; }
}

/* 等待模型输出期间的底部小字（第一阶段） */
.reverse-invasion-glitch-hint {
    position: absolute;
    left: 50%;
    bottom: 12%;
    bottom: calc(12% + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    transform: translateX(-50%);
    max-width: calc(100vw - 48px);
    font-size: 13px;
    letter-spacing: 0.28em;
    text-indent: 0.28em;
    color: rgba(255, 255, 255, 0.72);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: reverse-glitch-hint-flicker 1.1s steps(2) infinite;
    pointer-events: none;
}

@keyframes reverse-glitch-hint-flicker {
    0%, 100% { opacity: 0.85; }
    45%      { opacity: 0.25; }
    55%      { opacity: 0.95; }
}

/* ---------- 第二阶段：模型现写的阴暗面台词（重影大字） ---------- */
.reverse-invasion-glitch-text-wrap {
    position: absolute;
    inset: 18px; /* 抵消 stage 的负出血，保证文字定位相对真实视口 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    pointer-events: none;
}

.reverse-invasion-glitch-text {
    position: relative;
    max-width: min(560px, 100%);
    text-align: center;
    font-weight: 800;
    font-size: 24px; /* 老内核不支持 clamp() 时的兜底 */
    font-size: clamp(19px, 5.6vw, 34px);
    line-height: 1.6;
    letter-spacing: 0.06em;
    word-break: break-word;
    color: var(--rig-color, #ff3355);
    /* 可读性（用户反馈修复）：
       ① 不再用大半径光晕当主阴影——那本身就是"发糊"效果；改为贴身深色投影锚住字形，
          只留一圈很轻的本色微光弥补氛围；
       ② 文字底下垫半透明近黑衬板 + 大范围柔和暗影，把身后的雪花噪点隔开。 */
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 0.95),
        0 2px 10px rgba(0, 0, 0, 0.8),
        0 0 16px var(--rig-color, #ff3355);
    background: rgba(4, 2, 10, 0.62);
    border-radius: 18px;
    padding: 18px 22px;
    box-shadow: 0 0 48px 30px rgba(4, 2, 10, 0.62);
    opacity: 0;
    transform: scale(1.06);
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-text {
    animation: reverse-glitch-text-in 0.5s ease-out forwards,
               reverse-glitch-text-jitter 0.9s steps(2) 0.5s infinite;
}

@keyframes reverse-glitch-text-in {
    0%   { opacity: 0; transform: scale(1.18) skewX(-4deg); filter: blur(6px); }
    55%  { opacity: 1; transform: scale(0.98) skewX(2deg);  filter: blur(0.5px); }
    100% { opacity: 1; transform: scale(1) skewX(0);        filter: blur(0); }
}

@keyframes reverse-glitch-text-jitter {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(1px, -1px); }
}

/* 重影双拷贝：::before 用模型指定色、::after 用冷色，构成 RGB 分离式重影 */
.reverse-invasion-glitch-text::before,
.reverse-invasion-glitch-text::after {
    content: attr(data-text);
    position: absolute;
    inset: 0;
    /* 与主文字的内边距对齐，重影才能逐字重叠而不是整体错版 */
    padding: inherit;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    text-shadow: none;
    background: transparent;
    box-shadow: none;
}

.reverse-invasion-glitch-text::before {
    color: var(--rig-color, #ff3355);
    z-index: -1;
}

.reverse-invasion-glitch-text::after {
    color: rgba(90, 225, 255, 0.9);
    z-index: -2;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-text::before {
    animation: reverse-glitch-ghost-a 1.4s ease-in-out 0.35s infinite alternate;
}

.reverse-invasion-glitch.is-burst .reverse-invasion-glitch-text::after {
    animation: reverse-glitch-ghost-b 1.4s ease-in-out 0.35s infinite alternate;
}

/* 默认：小幅错位抖动的重影（透明度压低：重影几乎贴着正字，太实会把正字糊掉） */
@keyframes reverse-glitch-ghost-a {
    0%   { opacity: 0.32; transform: translate(3px, -2px); }
    100% { opacity: 0.42; transform: translate(-4px, 2px); }
}

@keyframes reverse-glitch-ghost-b {
    0%   { opacity: 0.26; transform: translate(-3px, 2px); }
    100% { opacity: 0.36; transform: translate(4px, -3px); }
}

/* 模型选择 ghostGrow=true：重影逐渐向外扩大、离散，压迫感拉满 */
.reverse-invasion-glitch.is-ghost-grow.is-burst .reverse-invasion-glitch-text::before {
    animation: reverse-glitch-ghost-grow-a 2.6s ease-in 0.35s infinite;
}

.reverse-invasion-glitch.is-ghost-grow.is-burst .reverse-invasion-glitch-text::after {
    animation: reverse-glitch-ghost-grow-b 2.6s ease-in 0.35s infinite;
}

@keyframes reverse-glitch-ghost-grow-a {
    0%   { opacity: 0.45; transform: translate(2px, -2px) scale(1); }
    70%  { opacity: 0.3;  transform: translate(-10px, 7px) scale(1.05); }
    100% { opacity: 0.06; transform: translate(-18px, 12px) scale(1.12); }
}

@keyframes reverse-glitch-ghost-grow-b {
    0%   { opacity: 0.38; transform: translate(-2px, 2px) scale(1); }
    70%  { opacity: 0.26; transform: translate(11px, -8px) scale(1.06); }
    100% { opacity: 0.05; transform: translate(20px, -13px) scale(1.14); }
}

/* ---------- 裂屏（模型 crackScreen=true 时触发） ---------- */
.reverse-invasion-glitch-cracks {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: scale(0.72);
    pointer-events: none;
}

.reverse-invasion-glitch.is-cracked .reverse-invasion-glitch-cracks {
    animation: reverse-glitch-crack-in 0.32s cubic-bezier(0.16, 1.2, 0.4, 1) forwards;
}

@keyframes reverse-glitch-crack-in {
    0%   { opacity: 0;   transform: scale(0.72); }
    40%  { opacity: 1;   transform: scale(1.04); }
    100% { opacity: 0.95; transform: scale(1); }
}

/* 裂屏瞬间的白闪，模拟"屏幕被击碎"的一击 */
.reverse-invasion-glitch-flash {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 46%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.35) 40%, transparent 72%);
    opacity: 0;
    pointer-events: none;
}

.reverse-invasion-glitch.is-cracked .reverse-invasion-glitch-flash {
    animation: reverse-glitch-flash 0.5s ease-out forwards;
}

@keyframes reverse-glitch-flash {
    0%   { opacity: 1; }
    100% { opacity: 0; }
}

/* 用户系统开启"减弱动态效果"：关掉抖屏与高频闪烁，保留静态雪花与文字 */
@media (prefers-reduced-motion: reduce) {
    .reverse-invasion-glitch-stage,
    .reverse-invasion-glitch[data-intensity="low"] .reverse-invasion-glitch-stage,
    .reverse-invasion-glitch[data-intensity="high"] .reverse-invasion-glitch-stage,
    .reverse-invasion-glitch.is-cracked .reverse-invasion-glitch-stage {
        animation: none;
    }
    .reverse-invasion-glitch-hint,
    .reverse-invasion-glitch-tearband {
        animation: none;
        opacity: 0.6;
    }
    /* 字群条目的可见性依赖 flicker 动画；关动画时必须给静态透明度，否则整片消失 */
    .reverse-invasion-glitch-swarm-item {
        animation: none;
        opacity: 0.5;
    }
    .reverse-invasion-glitch.is-burst .reverse-invasion-glitch-text {
        animation: reverse-glitch-text-in 0.5s ease-out forwards;
    }
}

/* ============================================================
   反向入侵 · 夺屏特效夜间模式（2026-08 新增；同月升级为双向判定）
   --------------------------------------------------------------
   夜间判定（满足任意一条即算夜间，JS 在 overlay 创建瞬间判定并定格 .is-night）：
   ① 设备本地系统时间处于 19:00 ≤ 夜间 < 06:00；
   ② User 手动开启了夜间模式（悬浮球快捷菜单 / 主题设置，data-appearance="dark"）。
   日间保持原有雪花屏；夜间整屏熄成近黑：
   - canvas 只画极暗底噪颗粒（JS 侧降帧降亮），像屏幕彻底断了信号；
   - 抖屏 / 扫描线 / 撕裂带 / 入侵宣告字群 / SIGNAL LOST 小字全部关闭，
     死寂里只浮现模型现写的 Char 台词（重影大字样式与日间共用）。
   夜间动画更少、DOM 更少，性能开销低于日间。
   ============================================================ */
.reverse-invasion-glitch.is-night {
    background: #000;
}

/* 夜间：所有强度档的抖屏一律压平，黑屏必须"死寂" */
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-stage,
.reverse-invasion-glitch.is-night[data-intensity="low"] .reverse-invasion-glitch-stage,
.reverse-invasion-glitch.is-night[data-intensity="high"] .reverse-invasion-glitch-stage,
.reverse-invasion-glitch.is-night.is-cracked .reverse-invasion-glitch-stage {
    animation: none;
}

/* 夜间：雪花系亮噪层与字群、小字全部隐去（JS 也不会启动字群定时器） */
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-scanlines,
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-tearband,
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-swarm,
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-hint {
    display: none;
}

/* 夜间底噪画布：满透明度呈现（画布内容本身就是 0~46 灰阶的暗颗粒），
   台词亮出后再压一点，让那行字成为黑暗里唯一的光 */
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-noise {
    opacity: 1;
}

.reverse-invasion-glitch.is-night.is-burst .reverse-invasion-glitch-noise {
    opacity: 0.8;
}

/* canvas 不可用的极老内核：CSS 噪点兜底在夜间同样压到近黑 */
.reverse-invasion-glitch.is-night .reverse-invasion-glitch-noise-fallback {
    opacity: 0.07;
}

.reverse-invasion-glitch.is-night.is-burst .reverse-invasion-glitch-noise-fallback {
    opacity: 0.05;
}

/* 矮屏（横屏手机）：台词字号收一档，避免溢出 */
@media (max-height: 520px) {
    .reverse-invasion-glitch-text {
        font-size: 18px;
        font-size: clamp(15px, 4vw, 22px);
        line-height: 1.45;
    }
}

/* ============================================================
   反向入侵 · 定时突袭前的授权弹窗（2026-08 新增）
   --------------------------------------------------------------
   Char 设置了「日常突袭」时，动手前必须先弹窗询问：
   「XX 申请入侵你的手机，是否给予权限？」
   授权 → 正常进入反向入侵；拒绝 / 超时未响应 → 取消本次入侵。
   ============================================================ */
.reverse-invasion-permit {
    position: fixed;
    inset: 0;
    z-index: 1000070;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(24px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
    padding-bottom: calc(24px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    background: rgba(8, 4, 14, 0.58);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.reverse-invasion-permit.is-open {
    opacity: 1;
}

.reverse-invasion-permit-card {
    width: min(380px, 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 18px 16px;
    border-radius: 20px;
    background: linear-gradient(150deg, rgba(46, 18, 40, 0.97) 0%, rgba(30, 10, 34, 0.97) 100%);
    border: 1px solid rgba(255, 107, 138, 0.45);
    box-shadow: 0 14px 36px rgba(16, 0, 26, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    color: #fff;
    transform: scale(0.94);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.reverse-invasion-permit.is-open .reverse-invasion-permit-card {
    transform: scale(1);
}

.reverse-invasion-permit-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reverse-invasion-permit-pulse {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #FF6B8A;
    box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.7);
    animation: reverse-invasion-pulse 1.8s ease-in-out infinite;
}

.reverse-invasion-permit-title {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 800;
    color: #FFD0DC;
    line-height: 1.4;
    word-break: break-word;
}

.reverse-invasion-permit-desc {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
    word-break: break-word;
}

.reverse-invasion-permit-hint {
    font-size: 11.5px;
    color: rgba(255, 208, 220, 0.55);
    line-height: 1.5;
}

.reverse-invasion-permit-actions {
    display: flex;
    gap: 10px;
    margin-top: 2px;
}

.reverse-invasion-permit-btn {
    flex: 1;
    min-height: 46px; /* ≥44px 触控高度 */
    border-radius: 999px;
    border: none;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.12s ease, filter 0.12s ease;
}

.reverse-invasion-permit-btn:active {
    transform: scale(0.97);
    filter: brightness(0.9);
}

.reverse-invasion-permit-btn.is-deny {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: rgba(255, 255, 255, 0.88);
}

.reverse-invasion-permit-btn.is-allow {
    background: linear-gradient(135deg, #FF6B8A 0%, #FF9A6B 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(255, 107, 138, 0.35);
}

@media (max-width: 480px) {
    .reverse-invasion-permit {
        padding: 16px;
        padding-top: calc(16px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
        padding-bottom: calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    }
    .reverse-invasion-permit-pulse {
        animation: none;
    }
}
