html, body {
    margin: 0;
    height: 100%;
    background: #f5f6f8;
    font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
}
body { overflow: hidden; }

.main-area { height: calc(100dvh - 164px); }

.pdf-panel {
    height: 100%;
    padding: 0;
    border-right: 1px solid #ddd;
    background: #303238;
    position: relative;
}
.pdf-panel iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
    background: white;
}
.placeholder-panel {
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    color: #ddd;
    padding: 20px;
}

.text-panel {
    height: 100%;
    overflow-y: auto;
    padding: 24px 30px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
.welcome-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 24px;
}
.article-reader {
    max-width: 860px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    padding: 28px 30px;
    font-size: 18px;
    line-height: 2.02;
    box-shadow: 0 4px 18px rgba(0,0,0,.03);
}
.sentence {
    display: inline;
    padding: 2px 1px;
    border-radius: 5px;
    transition: background-color .18s ease, box-shadow .18s ease, color .18s ease;
    cursor: pointer;
}
.sentence:hover { background: rgba(13,110,253,.08); }
.sentence.active {
    background: linear-gradient(180deg, rgba(255,235,120,.35), rgba(255,224,64,.76));
    box-shadow: 0 0 0 3px rgba(255,193,7,.12), 0 2px 12px rgba(255,193,7,.18);
    color: #191919;
}
.sentence.selected-ai {
    outline: 2px solid rgba(13,110,253,.28);
    outline-offset: 2px;
}
.sentence.spoken { color: #707780; }
.sentence.heading {
    display: block;
    font-weight: 700;
    font-size: 1.09em;
    margin: 22px 0 8px;
    color: #212529;
}
.sentence.active::after {
    content: "▍";
    display: inline-block;
    margin-left: 2px;
    animation: readerPulse 1s ease-in-out infinite;
}
@keyframes readerPulse { 0%,100%{opacity:.2} 50%{opacity:1} }

.player {
    min-height: 108px;
    background: white;
    border-top: 1px solid #ddd;
    padding: 7px 12px calc(7px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
}
.player-top,
.player-options {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.control-group { display: flex; gap: 6px; align-items: center; }
.compact-btn { width: 38px; padding-left: 0; padding-right: 0; }
.play-btn { min-width: 86px; }


.option-item label {
    display: block;
    font-size: 10px;
    line-height: 1;
    color: #6c757d;
    margin: 0 0 2px 2px;
}
.option-item select { height: 30px; padding-top: 2px; padding-bottom: 2px; }
.browser-voice-option, .bg-voice-option { width: 205px; }
.small-option { width: 92px; }
.timer-option { width: 102px; }
.timer-status {
    font-size: 11px;
    font-weight: 600;
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffe69c;
    padding: 5px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.lock-voice-option { display: none; }

.ai-offcanvas { width: min(440px, 94vw) !important; }
.ai-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.selected-text {
    background: #f7f8fa;
    border-radius: 10px;
    padding: 10px;
    font-size: 14px;
    max-height: 120px;
    overflow: auto;
}
.ai-result {
    margin-top: 7px;
    min-height: 180px;
    white-space: pre-wrap;
    background: #fbfbfc;
    border: 1px solid #e6e8eb;
    border-radius: 12px;
    padding: 14px;
    line-height: 1.7;
}
.toast-message {
    position: fixed;
    left: 50%;
    bottom: 128px;
    transform: translateX(-50%);
    z-index: 2000;
    color: white;
    background: rgba(20,20,20,.92);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    box-shadow: 0 4px 18px rgba(0,0,0,.2);
}

@media (min-width: 992px) and (max-width: 1280px) {
    .main-area { height: calc(100dvh - 158px); }
    .text-panel { padding: 18px; }
    .article-reader { padding: 24px; font-size: 17px; }
    .browser-voice-option, .bg-voice-option { width: 175px; }
}

@media (max-width: 991px) {
    body {
        overflow: auto;
        padding-bottom: 124px;
    }
    .main-area { height: auto; }
    .pdf-panel {
        height: 36dvh;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    .text-panel {
        height: auto;
        min-height: 64dvh;
        padding: 12px;
    }
    .article-reader {
        border-radius: 10px;
        padding: 18px 16px;
        font-size: 17px;
        line-height: 1.93;
    }
    .player {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 1020;
        min-height: 112px;
        padding: 5px 7px calc(5px + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 18px rgba(0,0,0,.08);
    }
    .player-top { gap: 6px; }
    .player-options {
        width: 100%;
        gap: 4px;
        overflow-x: auto;
        justify-content: flex-start;
        scrollbar-width: none;
        padding: 0 2px;
    }
    .player-options::-webkit-scrollbar { display: none; }
    .compact-btn { width: 34px; padding: 4px 0; }
    .play-btn { min-width: 76px; padding: 4px 8px; }
    .mode-group select { width: 112px; }
    #backgroundButton { padding: 4px 7px; font-size: 12px; }
    .browser-voice-option, .bg-voice-option { min-width: 145px; width: 145px; }
    .small-option { min-width: 74px; width: 74px; }
    .timer-option { min-width: 82px; width: 82px; }
    .option-item select { font-size: 12px; }
    .toast-message { bottom: 122px; }
}

@media (max-width: 600px) {
    .navbar { min-height: 48px; }
    .navbar-brand { font-size: 1rem; }
    .pdf-panel { height: 27dvh; }
    .text-panel { min-height: 73dvh; padding: 8px; }
    .article-reader {
        font-size: 16px;
        line-height: 1.88;
        padding: 16px 13px;
        border-radius: 8px;
    }
    body { padding-bottom: 118px; }
    .player { min-height: 106px; }
    .player-top { justify-content: space-between; }
    .mode-group select { width: 105px; font-size: 12px; }
    .ai-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
    .pdf-panel { height: 23dvh; }
    .text-panel { min-height: 77dvh; }
    .compact-btn { width: 31px; font-size: 12px; }
    .play-btn { min-width: 68px; font-size: 12px; }
    .mode-group select { width: 96px; padding-left: 6px; padding-right: 20px; }
    #backgroundButton { max-width: 105px; overflow: hidden; white-space: nowrap; }
}

.lockscreen-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 9px;
    border: 1px solid #e2e5e9;
    border-radius: 999px;
    background: #f8f9fa;
}
.lockscreen-toggle .form-check-label {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.lockscreen-status {
    font-size: 11px;
    color: #198754;
    white-space: nowrap;
}
.lock-voice-option { width: 205px; }

@media (max-width: 991px) {
    .lockscreen-toggle {
        padding: 2px 7px;
        gap: 5px;
    }
    .lockscreen-toggle .form-check-label { font-size: 11px; }
    .lockscreen-status { font-size: 10px; }
    .lock-voice-option { min-width: 145px; width: 145px; }
}

@media (max-width: 480px) {
    .lockscreen-toggle .form-check-label {
        max-width: 112px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .lockscreen-status { display: none; }
}


/* V0.4.3 upload progress */
.upload-overlay {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(20, 24, 28, .42);
    backdrop-filter: blur(3px);
}
.upload-card {
    width: min(520px, 94vw);
    background: #fff;
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 18px 55px rgba(0,0,0,.22);
    border: 1px solid rgba(0,0,0,.06);
}
.upload-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}
.upload-title {
    font-size: 18px;
    font-weight: 700;
}
.upload-filename {
    margin-top: 3px;
    color: #6c757d;
    font-size: 13px;
    overflow-wrap: anywhere;
}
.upload-percent {
    font-size: 24px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.upload-progress {
    height: 10px;
    margin-top: 16px;
    border-radius: 999px;
    overflow: hidden;
}
.upload-stage-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    color: #495057;
    font-size: 14px;
}
.upload-overlay.upload-success .upload-card {
    border-color: rgba(25,135,84,.30);
}
.upload-overlay.upload-error .upload-card {
    border-color: rgba(220,53,69,.35);
}
.upload-overlay.upload-error .upload-percent {
    color: #dc3545;
}
.upload-overlay.upload-success .upload-percent {
    color: #198754;
}

@media (max-width: 600px) {
    .upload-overlay {
        place-items: end center;
        padding: 12px 10px calc(124px + env(safe-area-inset-bottom));
    }
    .upload-card {
        width: 100%;
        border-radius: 16px;
        padding: 16px;
    }
    .upload-title { font-size: 16px; }
    .upload-percent { font-size: 20px; }
}

/* PaperVoice V0.4.4 cache-bust build */
