
/* 杜绝整页被浏览器二次缩放 */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
body {
    max-width: 100%;
    overflow-x: hidden;
}
/* mobile_patch.css - 界面优化、手写适配、触摸翻页与代码保护、手机端完整显示修复 */

/* 1. 隐藏原有的所有分散控制按钮 */
.lang-switch,
.audio-controls {
    display: none !important;
}

/* 2. 统一保留唯一控制入口：⚙️ 设置按钮 */
.unified-settings-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 9999;
    background: #111;
    color: #fff;
    border: 1px solid #8b0000;
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.unified-settings-btn:hover {
    background: #8b0000;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
}

/* 3. 设置模态弹窗样式 */
.settings-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    /* backdrop-filter removed for iOS stability */
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.settings-modal.active {
    display: flex;
}

.settings-content {
    background: #111;
    border: 1px solid #444;
    color: #eee;
    width: 90%;
    max-width: 420px;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.9);
    max-height: 90vh;
    overflow-y: auto;
}

.settings-header {
    font-size: 1.2rem;
    color: #8b0000;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    cursor: pointer;
    font-size: 1.2rem;
    color: #aaa;
}

.settings-group {
    margin-bottom: 15px;
}

.settings-group label {
    display: block;
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 6px;
}

.settings-opt-btns {
    display: flex;
    gap: 8px;
}

.settings-opt-btn {
    flex: 1;
    background: #222;
    border: 1px solid #444;
    color: #ccc;
    padding: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

.settings-opt-btn.active {
    background: #8b0000;
    color: #fff;
    border-color: #ff0000;
}

.disclaimer-box {
    margin-top: 15px;
    padding: 12px;
    background: #080808;
    border: 1px dashed #444;
    font-size: 0.75rem;
    color: #999;
    line-height: 1.55;
    text-align: left;
    max-height: 220px;
    overflow-y: auto;
}
.disclaimer-box strong {
    color: #c44;
    display: block;
    text-align: center;
    margin-bottom: 4px;
}

/* 4. 移动端专属手写板组件样式 */
.mobile-handwrite-container {
    display: none; /* 默认隐藏，仅在移动端渲染 */
    flex-direction: column;
    margin-top: 8px;
    gap: 4px;
}

.mobile-handwrite-title {
    font-family: var(--death-font);
    font-size: 0.95rem;
    color: #111;
}

#handwriteCanvas {
    width: 100%;
    height: 110px;
    background: #fdfbf7;
    border: 1px solid #aaa;
    border-radius: 4px;
    touch-action: none; /* 阻止画画时页面滚动与翻页 */
    cursor: crosshair;
}

.handwrite-tools {
    display: flex;
    gap: 8px;
}

.hw-btn {
    flex: 1;
    padding: 4px;
    font-size: 0.8rem;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

/* 手写预览在书页中的样式 */
.handwrite-preview-wrap {
    margin-top: 8px;
    padding: 6px;
    background: rgba(0,0,0,0.03);
    border: 1px dashed #999;
    border-radius: 4px;
}

.handwrite-preview-label {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 4px;
    font-family: var(--death-font);
}

.handwrite-preview-img {
    max-width: 100%;
    height: auto;
    display: block;
    border: 1px solid #ccc;
    background: #fff;
}

/* 5. 移动端 UI 适配与倒计时文字缩放修复 + 封面完整显示 */
@media (max-width: 600px) {
    .single-book {
        width: calc(100vw - 16px) !important;
        max-width: 100% !important;
        height: 80vh !important;
        touch-action: pan-y;
        transform: none !important;
        -webkit-transform: none !important;
    }
    
    .content-page {
        padding: 18px 15px 30px 15px !important;
    }

    .giant-target-name {
        font-size: 1.8rem !important;
    }

    .single-death-detail, .entry-desc {
        font-size: 1rem !important;
        line-height: 24px !important;
    }

    .write-input {
        height: 65px !important;
    }

    .action-btn {
        font-size: 0.8rem !important;
        padding: 6px 2px !important;
    }

    /* 修复问题：手机端40秒倒计时文字过大看不清，结束时 DEATH NOTE 完整显示 */
    .countdown-timer {
        font-size: 3rem !important; /* 缩小数字 */
    }

    .countdown-target {
        font-size: 1.1rem !important; /* 缩小目标姓名 */
        word-break: break-all;
        padding: 0 10px;
    }

    .light-voice-subtitle {
        font-size: 0.85rem !important; /* 缩小台词字幕 */
        line-height: 1.3;
        padding: 0 15px;
    }

    .countdown-box {
        width: 92%;
    }

    /* 结束时的 DEATH NOTE Logo：与电脑端一致，单行完整显示 */
    .death-logo {
        font-size: clamp(1.8rem, 9vw, 3.2rem) !important;
        letter-spacing: 3px !important;
        text-align: center;
        padding: 0 8px;
        width: 100%;
        box-sizing: border-box;
        word-break: keep-all;
        white-space: nowrap !important;
        overflow: visible;
        line-height: 1.1;
    }

    /* 手写区域：手写时禁止页面滚动与翻页 */
    .mobile-handwrite-container {
        touch-action: none;
    }
    #handwriteCanvas {
        touch-action: none !important;
    }

    /* 在手机上激活手写板块 */
    .mobile-handwrite-container {
        display: flex;
    }

    /* ===== 关键修复：手机端封面与背景 DEATH NOTE 文字完整显示 ===== */
    .bg-logo-layer {
        font-size: clamp(3.5rem, 14vw, 8rem) !important;
        letter-spacing: 6px !important;
        opacity: 0.12;
        white-space: nowrap;
        width: 100%;
        text-align: center;
        left: 50%;
        transform: translate(-50%, -50%);
        overflow: visible;
    }

    .cover-logo-image {
        font-size: clamp(1.5rem, 6.5vw, 2.4rem) !important;
        letter-spacing: 2px !important;
        width: 92% !important;
        white-space: nowrap !important;
        overflow: visible;
        text-align: center;
        padding-bottom: 8px;
        line-height: 1.15;
    }

    .cover-page {
        padding-top: 28% !important;
    }

    .cover-corner-fold {
        font-size: 0.75rem !important;
        bottom: 18px !important;
        right: 18px !important;
    }

    /* 确保规则页与内容文字在手机端完整可读 */
    .rule-header-title {
        font-size: 1.15rem !important;
    }
    .rule-en, .rule-cn {
        font-size: 0.78rem !important;
        line-height: 1.35 !important;
    }

    .entry-title {
        font-size: 1.25rem !important;
    }

    .page-indicator {
        font-size: 0.7rem !important;
    }
}

/* 6. 基础代码保护辅助CSS */
body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* 输入框与文本域允许选择 */
input, textarea {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* 额外：防止长按菜单 */
img, canvas {
    -webkit-touch-callout: none;
    pointer-events: auto;
}

/* 手写时防止父级滚动 */
.mobile-handwrite-container, #handwriteCanvas {
    overscroll-behavior: contain;
}


/* ===== 高分辨率设备（iPhone Pro Max 等）画面清晰度优化 ===== */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body, .single-book, .content-page, .cover-page {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 避免整页被缩放导致模糊：限制最大设备宽度逻辑像素 */
@media screen and (min-width: 428px) and (max-width: 520px) {
    /* iPhone 16 Pro Max 等：宽度绝不超过视口，防止 Safari 整页缩小导致发糊 */
    html, body {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
    }
    .scene {
        width: 100% !important;
        max-width: 100vw !important;
        overflow: hidden !important;
        transform: none !important;
    }
    .single-book {
        width: calc(100vw - 20px) !important;
        max-width: 100% !important;
        height: 78vh !important;
        max-height: 780px !important;
        transform: none !important;
        -webkit-transform: none !important;
        zoom: 1 !important;
    }
    .cover-logo-image {
        font-size: clamp(1.6rem, 5.5vw, 2.2rem) !important;
        letter-spacing: 2px !important;
        white-space: nowrap !important;
        width: 90% !important;
    }
    .bg-logo-layer {
        font-size: clamp(3.5rem, 12vw, 6rem) !important;
        letter-spacing: 4px !important;
        opacity: 0.08;
    }
    .giant-target-name {
        font-size: 1.75rem !important;
    }
    .entry-title {
        font-size: 1.25rem !important;
    }
    .entry-desc, .single-death-detail {
        font-size: 1rem !important;
        line-height: 26px !important;
    }
    .countdown-timer {
        font-size: 3rem !important;
    }
    .death-logo {
        font-size: clamp(1.8rem, 7vw, 2.8rem) !important;
        white-space: nowrap !important;
        letter-spacing: 2px !important;
    }
}


/* 超高 DPR（3x）字体与边框更锐利 */
@media (-webkit-min-device-pixel-ratio: 2.5), (min-resolution: 2.5dppx) {
    .single-book {
        box-shadow: -12px 12px 30px rgba(0,0,0,0.9), 0 0 15px rgba(0,0,0,0.7);
    }
    .content-page {
        -webkit-font-smoothing: subpixel-antialiased;
    }
    .write-input, .write-input-small {
        -webkit-font-smoothing: antialiased;
    }
}

/* 防止封面旋转时残留模糊 */
.cover-page {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}
.cover-page.opened {
    /* will-change 在部分机型会糊 */
}

/* ===== 左上角世界人口 / 写入统计面板 ===== */
.world-stats-panel {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 900;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(139, 0, 0, 0.45);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.72rem;
    color: #ff4d4d;
    line-height: 1.45;
    max-width: 200px;
    pointer-events: none;
    text-shadow: 0 0 6px rgba(255, 40, 40, 0.35);
}
.world-stats-panel .ws-line span {
    color: #ff7777;
    font-weight: 600;
}
.world-stats-panel .ws-writes {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed rgba(139, 0, 0, 0.4);
    color: #c66;
}
.world-stats-panel .ws-quote {
    margin-top: 6px;
    font-size: 0.68rem;
    color: #a55;
    font-style: italic;
    line-height: 1.3;
    min-height: 2.6em;
}

/* 夜间浓墨滤镜 */
body.ink-heavy {
    filter: contrast(1.08) brightness(0.92) saturate(0.85);
}
body.ink-heavy .page-light-full {
    filter: contrast(1.12) brightness(0.95);
}

/* 死因模板按钮 */
.cause-templates {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.cause-tpl-btn {
    background: #222;
    color: #ccc;
    border: 1px solid #555;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 3px;
    cursor: pointer;
}
.cause-tpl-btn:hover {
    background: #8b0000;
    color: #fff;
    border-color: #ff0000;
}

/* ===== 手机端人口面板：左上角单行，不挡书本 ===== */
@media (max-width: 600px) {
    .world-stats-panel {
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        bottom: auto !important;
        right: auto !important;
        transform: none !important;
        max-width: calc(100vw - 100px); /* 给右上角设置按钮留空 */
        width: auto !important;
        padding: 3px 8px !important;
        font-size: 0.58rem !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 5px !important;
        align-items: center !important;
        background: rgba(0, 0, 0, 0.55) !important;
        border: 1px solid rgba(139, 0, 0, 0.35) !important;
        border-radius: 4px !important;
        z-index: 95 !important;
        pointer-events: none !important;
        /* 减少闪烁：独立合成层，避免整页重绘 */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        backface-visibility: hidden;
        contain: layout style;
    }
    .world-stats-panel .ws-line {
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        display: inline !important;
    }
    .world-stats-panel .ws-writes {
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        display: none !important; /* 手机隐藏今日写入，节省空间 */
    }
    .world-stats-panel .ws-quote {
        display: none !important;
    }

    /* 联机角标：右上、设置按钮下方 */
    .online-badge {
        position: fixed !important;
        top: 48px !important;
        right: 12px !important;
        left: auto !important;
        bottom: auto !important;
        font-size: 0.62rem !important;
        background: rgba(0,0,0,0.55);
        padding: 2px 8px;
        border-radius: 10px;
        z-index: 95;
        pointer-events: none;
    }

    /* 关闭可能引起闪烁的滤镜在滚动/动画时的问题 */
    body.ink-heavy {
        filter: none !important;
        /* 用背景略暗代替整页 filter，避免 Safari 闪屏 */
        background: #000 !important;
    }
    body.ink-heavy .page-light-full {
        filter: none !important;
        background-color: #e8e0d0 !important;
    }

    /* 手机关闭鼠标光晕（触摸设备无意义且易触发重绘） */
    .cursor-light {
        display: none !important;
    }

    /* 设置按钮区域避免与人口条重叠 */
    .mobile-settings-btn {
        top: 8px !important;
        right: 8px !important;
    }
}


/* ===== iPhone Safari 写入页防闪黑 / 防误触 ===== */
@media (max-width: 600px) {
    .typing-wrapper {
        -webkit-user-select: text;
        user-select: text;
        touch-action: manipulation;
    }
    .write-input,
    .write-input-small {
        -webkit-user-select: text !important;
        user-select: text !important;
        touch-action: manipulation;
        font-size: 16px !important; /* 防止 iOS 聚焦时自动放大导致闪屏 */
        transform: translateZ(0);
        -webkit-appearance: none;
        border-radius: 0;
    }
    .page-click-zone {
        /* 写入时由 JS 关闭 pointer-events；默认也缩小热区 */
        width: 12% !important;
    }
    .content-page {
        -webkit-overflow-scrolling: touch;
        /* 避免键盘弹出时整页被系统缩放闪一下 */
        overflow-anchor: none;
    }
    .single-book {
        /* 不用 translateZ，避免 Pro Max 文字发糊 */
    }
    /* 按钮点击不要触发 300ms 与高亮闪白 */
    .action-btn,
    .cause-tpl-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* Pro Max / 高分屏：文字锐利，禁止整页缩放模糊 */
@media screen and (min-width: 390px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
    .single-book, .content-page, .cover-page, .page-light-full {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: geometricPrecision;
    }
    .giant-target-name, .entry-title, .entry-desc, .single-death-detail, .cover-logo-image {
        transform: none !important;
        -webkit-transform: none !important;
        filter: none !important;
    }
    /* 书本不要被额外 scale */
    .scene {
        transform: none;
    }
}


/* ===== 流克的日常 · 触发文字（一行金色） ===== */
.ryuk-game-trigger {
    position: fixed;
    top: 118px;
    left: 12px;
    z-index: 890;
    font-family: 'Cinzel Decorative', 'Cloister Black', serif;
    font-size: 0.82rem;
    font-weight: 700;
    color: #d4af37;
    letter-spacing: 0.14em;
    text-shadow: 0 0 8px rgba(212, 175, 55, 0.5), 0 0 2px #000;
    cursor: pointer;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 4px;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.2s, border-color 0.2s;
    pointer-events: auto;
}
.ryuk-game-trigger:hover {
    background: rgba(139, 0, 0, 0.35);
    border-color: #d4af37;
    color: #ffd700;
}

/* 流克小游戏模态框（仿设置面板） */
.ryuk-game-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.72);
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.ryuk-game-modal.active {
    display: flex;
}
.ryuk-game-modal-content {
    background: #0e0e0e;
    border: 1px solid rgba(212, 175, 55, 0.55);
    border-radius: 10px;
    padding: 14px 16px 16px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 0 24px rgba(212, 175, 55, 0.18);
    position: relative;
}
.ryuk-game-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-family: 'Cinzel Decorative', 'Cloister Black', serif;
    font-size: 1rem;
    color: #d4af37;
    letter-spacing: 0.1em;
}
.ryuk-game-close {
    cursor: pointer;
    font-size: 1.4rem;
    color: #888;
    line-height: 1;
    padding: 0 4px;
}
.ryuk-game-close:hover {
    color: #ff4d4d;
}
.ryuk-mode-bar {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 8px;
}
.ryuk-mode-btn {
    background: #1a1a1a;
    color: #c9a227;
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 0.72rem;
    font-family: Consolas, "Courier New", monospace;
    cursor: pointer;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}
.ryuk-mode-btn:hover,
.ryuk-mode-btn.active {
    background: #8b0000;
    color: #ffd700;
    border-color: #d4af37;
}
.ryuk-mode-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
#ryukGameCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: #0a0a0a;
    border: 1px solid rgba(139, 0, 0, 0.35);
    border-radius: 4px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: pointer;
    touch-action: none;
}
.ryuk-game-status {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.68rem;
    color: #c9a227;
    text-align: center;
    margin-top: 6px;
    line-height: 1.35;
    min-height: 1.4em;
}

/* 手机端：触发文字紧贴统计下方，不挡书本 */
@media (max-width: 600px) {
    .ryuk-game-trigger {
        top: 42px !important;
        left: 10px !important;
        font-size: 0.7rem !important;
        padding: 3px 8px !important;
        letter-spacing: 0.08em !important;
        z-index: 94 !important;
    }
    .ryuk-game-modal-content {
        max-width: 94vw;
        padding: 12px;
    }
    .ryuk-mode-btn {
        font-size: 0.65rem !important;
        padding: 4px 10px !important;
    }
    .ryuk-game-status {
        font-size: 0.6rem !important;
    }
}
