/* =====================================================
   翻译模块（独立组件）
   - 桌面非全屏：control-frame 内「翻译」按钮 + 视窗左侧浮窗
   - 全屏（桌面+移动）：fs-toolbar 内圆形按钮 + 半透明覆盖层（直接贴在 .page 上）
   - 移动端非全屏：不提供入口（按需求本期不做）
   ===================================================== */

/* ===================================================== */
/* ========= 1. 非全屏：control-frame 内的「翻译」按钮 == */
/* ===================================================== */

.translate-btn {
    height: 32px;
    padding: 0 12px;
    background-color: transparent;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.2s ease;
    order: 9; /* 与下载按钮同序，靠 DOM 顺序排在其前面 */
}

.translate-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #666;
    border-color: rgba(0, 0, 0, 0.4);
}

.translate-btn .option-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
}

.translate-btn .option-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.translate-btn .option-text {
    font-size: 13px;
    line-height: 1;
}

/* 开启中：黑白配色高亮 */
.translate-btn.active {
    background: #1a1a1a;
    border-color: transparent;
    color: #fff;
}

.translate-btn.active:hover {
    background: #1a1a1a;
    color: #fff;
}

/* 移动端非全屏：本期不提供入口 */
@media (max-width: 768px) {
    .translate-btn {
        display: none !important;
    }
}

/* ===================================================== */
/* ========= 2. 非全屏：视窗左侧浮窗 ===================== */
/* ===================================================== */
/* 注意：面板是 body 的直接子元素（由 translate.js 挂载），
   刻意不放进 .main-viewer-frame，避免被它的 transform:scale
   影响导致字体被跟着缩小。定位以「整个浏览器视窗」为基准。 */

.translate-panel {
    position: fixed;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 340px;
    height: 460px;
    min-width: 280px;
    min-height: 240px;
    max-width: 90vw;
    max-height: 90vh;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s;
}

.translate-panel.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.translate-panel.is-dragging,
.translate-panel.is-resizing {
    transition: none;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.32);
}

.translate-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #1a1a1a;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.translate-panel.is-dragging .translate-panel-header {
    cursor: grabbing;
}

.translate-panel-title {
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 1px;
}

.translate-panel-close {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.12s ease;
    flex-shrink: 0;
}

.translate-panel-close:hover {
    background: rgba(255, 255, 255, 0.32);
}

.translate-panel-close:active {
    transform: scale(0.9);
}

/* ===================================================== */
/* ========= 浮窗内翻页导航条（跟随书本原生翻页联动）=== */
/* ===================================================== */
/* 夹在深色 header 跟白色 body 之间的浅灰导航条：左右各一颗箭头按钮，
   中间显示目前页码。到达第一页/最后一页时对应按钮转为禁用态。 */

.translate-panel-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 10px 16px;
    background: #f7f7f8;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.translate-nav-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.14);
    background: #fff;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.translate-nav-btn svg {
    width: 15px;
    height: 15px;
}

.translate-nav-btn:hover:not(:disabled) {
    background: #eee;
}

.translate-nav-btn:active:not(:disabled) {
    transform: scale(0.92);
}

.translate-nav-btn:disabled {
    opacity: 0.32;
    cursor: default;
}

.translate-nav-pageinfo {
    font-size: 13px;
    color: #555;
    min-width: 88px;
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
}

.translate-panel-body {
    padding: 16px 18px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    flex: 1 1 auto;
    min-height: 0;
}

.translate-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* 双页模式：上下两块之间加一条分隔线，视觉上区分左/右页 */
.translate-block-bottom {
    padding-top: 16px;
    border-top: 1px dashed rgba(0, 0, 0, 0.14);
}

.translate-block-label {
    font-size: 12px;
    font-weight: bold;
    color: #1a1a1a;
    letter-spacing: 0.5px;
}

.translate-block-text {
    font-size: 15px;
    line-height: 1.9;
    color: #333;
    white-space: pre-line;
    transition: opacity 0.18s ease;
}

.translate-block-text.is-fading {
    opacity: 0;
}

/* 面板内滚动条稍作美化，不喧宾夺主 */
.translate-panel-body::-webkit-scrollbar {
    width: 6px;
}
.translate-panel-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* 右下角缩放把手：三条斜线的经典 grip 图示 */
.translate-panel-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    background:
        linear-gradient(135deg, transparent 0 40%, rgba(0,0,0,0.28) 40% 46%, transparent 46% 58%, rgba(0,0,0,0.28) 58% 64%, transparent 64% 76%, rgba(0,0,0,0.28) 76% 82%, transparent 82%);
    background-position: bottom right;
    background-repeat: no-repeat;
    background-size: 14px 14px;
    touch-action: none;
}

/* ===================================================== */
/* ========= 3. 全屏：fs-toolbar 内的圆形入口按钮 ======= */
/* ===================================================== */
/* 沿用 book.css 里 #orientation-btn / #fullscreen-btn 同一套
   玻璃药丸圆形按钮规格（40x40、透明、hover 变亮），保持视觉一致 */

body.fullscreen-active .fs-toolbar .translate-fs-btn {
    position: relative !important;
    width: 40px !important;
    height: 40px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    color: #fff !important;
    cursor: pointer;
    transition: background 0.2s, transform 0.12s;
}

body.fullscreen-active .fs-toolbar .translate-fs-btn:hover {
    background: rgba(255, 255, 255, 0.14) !important;
}

body.fullscreen-active .fs-toolbar .translate-fs-btn:active {
    transform: scale(0.92);
}

body.fullscreen-active .fs-toolbar .translate-fs-btn svg {
    width: 20px;
    height: 20px;
}

/* 开启中：用反色（白底黑图示）在深色玻璃工具条上标示状态，跟品牌色脱钩 */
body.fullscreen-active .fs-toolbar .translate-fs-btn.active {
    background: #ffffff !important;
    color: #111 !important;
}

/* 非全屏时不占位（跟 orientation/fullscreen 按钮一致的处理方式） */
.translate-fs-btn {
    display: none;
}

/* ===================================================== */
/* ========= 4. 全屏：半透明覆盖层（贴在 .page 内） ===== */
/* ===================================================== */
/* 直接以 .page 的实际尺寸/位置为准（.page 本身 position:relative），
   覆盖层是它的绝对定位子元素，图片多大它就多大，不需要额外算坐标 */

.translate-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    /* 原本 0.66 太透，遇到原图里较亮的区块（比如插画里的屏幕/光源）会透出来，
       看起来像一块不该在那里的"阴影"/亮块。调高不透明度 + 模糊半径，
       把底图彻底压下去，译文背景保持均匀纯黑。 */
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    padding: 28px 30px;
    box-sizing: border-box;
    /* 注意：本层自己不再 overflow-y:auto——滚动交给里面的 .translate-overlay-text，
       这样才能在它外面钉一条不随内容滚动的底部提示渐层（.translate-scroll-hint）。 */

    opacity: 0;
    animation: translateOverlayFadeIn 0.25s ease forwards;
}

@keyframes translateOverlayFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 双页模式：左右覆盖层视觉上区分「这是两页」——只在书脊处画一条细白线，
   不叠内阴影（试过之后觉得那层暗影不好看，去掉）。
   注意双页模式本身分「横排（左右并排）」和「竖排（上下堆叠）」两种：
   book.js 会在 .ebook-container 上切换 .landscape-mode / .portrait-mode，
   .page 的宽高、左右页的对齐方式也整套跟着变（见 book.css 463-517 行）。
   分隔线要跟着这套逻辑走：横排时是竖线，竖排时改画横线；只画一条，
   避免左右/上下各画一条贴在一起变成一条 2px 的粗线。旋转设备切换排列
   方式时，这里的类名也会跟着 book.js 重新渲染而更新，不用额外处理。 */
.landscape-mode .translate-overlay-left {
    border-right: 1px solid rgba(255, 255, 255, 0.3);
}
.portrait-mode .translate-overlay-left {
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

/* 顶部小标签「左页 · 第 X 页」/「右页 · 第 Y 页」，文案与桌面浮窗面板一致；
   固定在顶部不随文字滚动（flex-shrink:0），下方译文在剩余空间里居中/滚动 */
.translate-overlay-label {
    flex-shrink: 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.62);
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.translate-overlay-text {
    color: #fff;
    font-size: 16px;
    line-height: 1.9;
    white-space: pre-line;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: opacity 0.18s ease;

    /* 内容短时用 margin:auto 上下置中；内容溢出容器时 auto margin 自动归零，
       文字从顶部开始显示，靠下面的 overflow-y:auto 在内部滚动（手机端由
       book.js 的翻页遮罩层把纵向滑动手势转发到这里，含放手后的惯性滚动）。 */
    margin: auto 0;
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* 隐藏原生滚动条：滚动本身走触控转发/桌面原生滚轮都不受影响，
       只是不想在译文上叠一条滚动条，视觉上跟悬浮面板的细滚动条风格区分开 */
    scrollbar-width: none;
}
.translate-overlay-text::-webkit-scrollbar {
    display: none;
}

.translate-overlay-text.is-fading {
    opacity: 0;
}

/* 底部渐层：常驻一点点淡淡的渐变收个尾（纯装饰，不管内容有没有溢出都在）；
   真的溢出且还没滚到底时（show 类由 translate.js 控制）才加深，
   兼作"还有更多内容"的提示。 */
.translate-scroll-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.55) 100%);
    pointer-events: none;
    opacity: 0.4;
    transition: opacity 0.2s ease;
}
.translate-scroll-hint.show {
    opacity: 1;
}

/* 移动端全屏：字级/内边距稍微缩小，避免小屏幕上文字太挤 */
@media (max-width: 576px) {
    .translate-overlay {
        padding: 22px 18px;
    }
    .translate-overlay-text {
        font-size: 14px;
        line-height: 1.75;
    }
    .translate-overlay-label {
        font-size: 11px;
        margin-bottom: 8px;
        padding-bottom: 6px;
    }
}