/* 閱讀字體縮放（--text-zoom-scale：0.6～1.6） */
html {
    --text-zoom-scale: 1;
}

@media (min-width: 769px) {
    html[data-text-zoom] {
        zoom: var(--text-zoom-scale);
    }
}

body:has(#text-zoom-bar):not(.text-zoom-collapsed) {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

body.text-zoom-collapsed {
    padding-bottom: calc(52px + env(safe-area-inset-bottom));
}

.text-zoom-bar {
    position: fixed;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(30, 41, 59, 0.96);
    padding: 8px 10px;
    border-radius: 999px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.text-zoom-bar.collapsed {
    transform: translateX(-50%) translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
}

.text-zoom-fab {
    position: fixed;
    bottom: max(10px, env(safe-area-inset-bottom));
    right: max(10px, env(safe-area-inset-right));
    z-index: 899;
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(30, 41, 59, 0.92);
    color: #f8fafc;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    touch-action: manipulation;
}

.text-zoom-fab.show {
    display: flex;
}

.text-zoom-bar .text-zoom-label {
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    padding: 0 4px 0 6px;
}

.text-zoom-bar .text-zoom-value {
    color: #f8fafc;
    font-size: 14px;
    font-weight: 700;
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.text-zoom-bar button {
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #334155;
    color: #f8fafc;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
    touch-action: manipulation;
}

.text-zoom-bar button.text-zoom-step {
    min-width: 44px;
    font-size: 20px;
    padding: 6px 10px;
}

.text-zoom-bar button.text-zoom-reset {
    min-width: 52px;
    font-size: 13px;
}

.text-zoom-bar button.text-zoom-collapse {
    min-width: 36px;
    font-size: 12px;
    padding: 6px 8px;
    background: #475569;
}

.text-zoom-bar button:active:not(:disabled) {
    background: #475569;
}

.text-zoom-bar button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.text-zoom-bar button.active {
    background: #2563eb;
    border-color: #93c5fd;
    color: #fff;
}

.text-zoom-bar #text-reading-mode-btn {
    min-width: 92px;
    font-size: 14px;
}

@media (max-width: 768px) {
    body:has(#text-zoom-bar):not(.text-zoom-collapsed) {
        padding-bottom: calc(110px + env(safe-area-inset-bottom));
    }

    .text-zoom-bar {
        width: calc(100vw - 16px);
        max-width: none;
        left: 8px;
        right: 8px;
        transform: none;
        border-radius: 12px;
        flex-wrap: wrap;
        justify-content: center;
        padding: 8px;
        gap: 4px;
    }

    .text-zoom-bar.collapsed {
        transform: translateY(calc(100% + 24px));
    }

    .text-zoom-bar .text-zoom-label {
        width: 100%;
        text-align: center;
        padding: 0;
        font-size: 12px;
    }

    .text-zoom-bar button {
        flex: 0 1 auto;
        min-width: 40px;
        min-height: 40px;
        padding: 6px 10px;
    }

    .text-zoom-bar button.text-zoom-step {
        min-width: 40px;
        font-size: 18px;
    }

    .text-zoom-bar button.text-zoom-reset,
    .text-zoom-bar #text-reading-mode-btn {
        flex: 1;
        min-width: 56px;
        font-size: 12px;
    }

    .text-zoom-bar button.text-zoom-collapse {
        position: absolute;
        top: 4px;
        right: 4px;
        min-width: 28px;
        min-height: 28px;
        padding: 2px 6px;
        border-radius: 6px;
        font-size: 10px;
    }
}

@media print {
    .text-zoom-bar,
    .text-zoom-fab {
        display: none !important;
    }
    html[data-text-zoom] {
        zoom: 1;
    }
}
