/* Presentation only. Processing, image slicing and PDF dimensions remain in index.html. */
@media screen {
    html { -webkit-text-size-adjust: 100%; }
    body { margin: 0; line-height: 1.65; }
    body > header { padding: 20px max(16px, env(safe-area-inset-right)); }
    body > header > div, body > main { max-width: 1440px; }
    header h1 { overflow-wrap: anywhere; line-height: 1.4; }
    header > div > div:last-child { flex-wrap: wrap; justify-content: center; }
    main > div { min-width: 0; }
    body > main { width: 100%; align-items: start; }
    main > div:first-child { border-radius: 18px; }
    main > div:last-child > div:first-child { gap: 12px; align-items: start; }
    main > div:last-child > div:first-child > span { flex-shrink: 0; direction: ltr; }
    main > div:last-child > div:last-child {
        width: 100%;
        max-width: 826px;
        margin-inline: auto;
        padding: 12px;
        max-height: none;
        border-radius: 16px;
        background: #dce2e6;
        border-color: #c8d1d8;
    }
    #a4PaperLayout {
        width: 100%;
        min-width: 0 !important;
        height: auto;
        min-height: 0 !important;
        aspect-ratio: 210 / 297;
        padding: 6.428571% 8.095238%;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-rows: repeat(9, minmax(0, 1fr));
        flex-shrink: 0;
    }
    #a4PaperLayout > div { min-width: 0; min-height: 0; }
    button, #dropzone, label:has(input[name="bookDirection"]) {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(24, 188, 156, .18);
    }
    button { min-height: 48px; }
    button:focus-visible, #dropzone:focus-within, label:has(input:focus-visible) {
        outline: 3px solid #0c8b74;
        outline-offset: 3px;
    }
    label:has(input[name="bookDirection"]) {
        position: relative;
        min-height: 52px;
        text-align: center;
        line-height: 1.6;
    }
    input[name="bookDirection"] {
        display: block;
        position: absolute;
        width: 1px;
        height: 1px;
        opacity: 0;
    }
    #dropzone { min-height: 144px; position: relative; }
    #fileInput {
        display: block;
        position: absolute;
        width: 1px;
        height: 1px;
        opacity: 0;
    }
    #downloadPdfBtn { min-height: 54px; line-height: 1.6; }
    #downloadPdfBtn svg { flex-shrink: 0; }
    #editModal { padding: 12px; overscroll-behavior: contain; }
    #editModal > div {
        margin: 0;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 20px;
    }
    #editModal > div > div:first-child { gap: 8px; }
    #closeModalBtn { min-width: 48px; flex-shrink: 0; border-radius: 10px; }
    body:has(#editModal:not(.hidden)) { overflow: hidden; }
    @media (max-width: 639px) {
        body > header { padding-block: 20px 16px; }
        header > div { align-items: stretch; gap: 12px; }
        header h1 { font-size: 20px; }
        header p { line-height: 1.8; }
        header > div > div:last-child { justify-content: flex-start; gap: 8px; }
        body > main { padding: 16px 12px 24px; gap: 24px; }
        main > div:first-child { padding: 18px 16px; gap: 18px; }
        main > div:last-child > div:first-child { flex-wrap: wrap; }
        main h2 { font-size: 15px; line-height: 1.7; }
        main p { font-size: 13px; line-height: 1.8; }
        main > div:last-child > div:last-child { padding: 8px; border-radius: 12px; }
        #editModal { align-items: flex-end; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
        #editModal > div { border-radius: 20px; }
        #editModal button { padding-inline: 8px; }
        #a4PaperLayout [class*="text-[6px]"] { font-size: 4px; }
        #a4PaperLayout [class*="text-[8px]"] { font-size: 6px; }
    }
    /* Header hierarchy and compact control surfaces. */
    body > header {
        background: linear-gradient(115deg, #071c20, #101827);
        border-bottom: 1px solid #18bc9c40;
        box-shadow: 0 4px 20px #0f172a12;
        padding-block: 22px;
    }
    header > div > div:first-child {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: center;
        min-width: 0;
    }
    header h1 { color: #f1faf8; letter-spacing: -.4px; direction: ltr; text-align: right; }
    header p { color: #acc1c5; font-size: 13px; }
    header > div > div:last-child > span:first-child {
        background: #ffffff06;
        border-color: #ffffff16;
        color: #c5d3d7;
        line-height: 1.8;
        padding: 8px 12px;
        border-radius: 10px;
    }
    header > div > div:last-child > span:last-child {
        background: #18bc9c1a;
        color: #73e8d0;
        border: 1px solid #18bc9c33;
        font-family: inherit;
        white-space: nowrap;
        border-radius: 8px;
        padding: 5px 9px;
        box-shadow: none;
    }
    main > div:first-child { box-shadow: 0 6px 24px #0f172a06; }
    #editModal > div { box-shadow: 0 24px 80px #02061740; border-radius: 22px; gap: 20px; }
    #closeModalBtn { background: #f1f5f9; color: #475569; font-size: 24px; }
    #editModal label { font-size: 13px; color: #475569; }
    #modalDirArBtn, #modalDirEnBtn { min-height: 56px; line-height: 1.7; }
    #saveModalBtn, #deleteCoverBtn { min-height: 52px; font-size: 13px; }
    @media (max-width: 639px) {
        body > header { padding: 16px; }
        header > div { gap: 14px; }
        header h1 { font-size: 22px; }
        header > div > div:last-child {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            gap: 8px;
            align-items: center;
            padding-top: 12px;
            border-top: 1px solid #ffffff12;
        }
        header > div > div:last-child > span:first-child { font-size: 11px; padding: 6px 8px; }
        header > div > div:last-child > span:last-child { font-size: 10px; padding: 5px 7px; }
        main > div:first-child { padding: 16px; gap: 14px; border-radius: 18px; }
        main > div:first-child p { line-height: 1.7; }
        main > div:first-child > div:first-child > div { padding: 4px; gap: 4px; }
        label:has(input[name="bookDirection"]) { padding-inline: 6px; border-radius: 8px; }
        #dropzone { min-height: 112px; padding: 16px 12px; border-color: #a8cfc6; background: #f4fbf9; }
        #dropzone svg { width: 30px; height: 30px; color: #16876f; }
        main > div:first-child > div:has(#loadedCount) { padding: 12px; }
        main > div:first-child > div:has(#loadedCount) h3 { color: #64748b; font-size: 12px; }
        #loadedCount + span, #pagesCount + span { color: #64748b; font-size: 11px; }
        #downloadPdfBtn, #resetBtn { border-radius: 12px; }
        #editModal { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
        #editModal > div {
            width: 100%;
            max-width: 480px;
            padding: 18px 16px;
            max-height: calc(100dvh - 32px - env(safe-area-inset-bottom));
            gap: 18px;
        }
        #editModal h3 { font-size: 15px; }
        #editModal > div > div:last-child { display: flex; flex-direction: column-reverse; gap: 10px; margin-top: 0; padding-top: 16px; }
        #editModal > div > div:last-child button { width: 100%; }
        #deleteCoverBtn { background: white; border-color: #f1d5d5; }
    }
    @media (max-height: 480px) and (orientation: landscape) {
        #editModal { align-items: center; }
        #editModal > div { padding: 12px 16px; gap: 10px; }
        #editModal > div > div:last-child { display: grid; grid-template-columns: 1fr 1fr; padding-top: 10px; }
    }
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
    }
}
