#bookEditor:has(#chapterWorkspace[hidden]) #chapterFormatToolbar{display:none!important}
.chapter-photo-frame{position:relative;display:block;box-sizing:border-box;max-width:100%;line-height:0;user-select:none;-webkit-user-drag:none;cursor:grab;touch-action:none;break-inside:avoid;page-break-inside:avoid}
.chapter-photo-frame.is-dragging{opacity:.55;cursor:grabbing}
.chapter-photo-frame.is-page-panning{cursor:move;outline:3px solid #356de0;outline-offset:-3px}
.chapter-body-paragraph:has(.chapter-photo-frame){text-indent:0!important;break-inside:avoid;page-break-inside:avoid}
.chapter-photo-text-entry{min-height:1.55em;text-indent:0!important;cursor:text}
.chapter-photo-text-entry:has(> br:only-child){height:0;min-height:0;font-size:0;line-height:0;overflow:hidden}
.chapter-page-body>.chapter-body-paragraph:has(> .chapter-photo-frame):not(:has(~ .chapter-body-paragraph:not(:has(> br:only-child))))>.chapter-photo-frame{margin-bottom:0!important}
.chapter-page-body>.chapter-body-paragraph:has(> .chapter-photo-frame)~.chapter-body-paragraph:has(> br:only-child):not(:has(~ .chapter-body-paragraph:not(:has(> br:only-child)))){height:0;min-height:0;font-size:0;line-height:0;overflow:hidden}
.chapter-photo-frame>img,.chapter-photo-window>img{display:block;max-width:100%;max-height:none;border-radius:2px;object-fit:contain;pointer-events:none;-webkit-user-drag:none}
.chapter-photo-frame.is-selected{outline:2px solid #356de0;outline-offset:2px;cursor:grab}
.chapter-photo-window{position:absolute;inset:0;overflow:hidden;border-radius:2px;pointer-events:none}
.chapter-body-paragraph:has(> .chapter-photo-frame.is-side-photo){display:flex;align-items:flex-start;justify-content:center;gap:8px;flex-wrap:wrap}
.chapter-body-paragraph>.chapter-photo-frame.is-side-photo{flex:0 1 auto;margin:12px 0!important;min-width:0}
.chapter-body:has(.is-wrapped-photo){display:flow-root}
.chapter-body:has(.is-wrapped-photo)>.chapter-body-paragraph:has(> .chapter-photo-frame,> .chapter-inline-quote){clear:both}
.chapter-body:has(.is-wrapped-photo)>.chapter-body-paragraph{hyphens:auto;letter-spacing:var(--chapter-wrap-tracking,normal)}
.chapter-body:has(.is-wrapped-photo)>.chapter-page-continued-line{text-align-last:justify}
.chapter-body-paragraph>.chapter-photo-frame.is-wrapped-photo{float:var(--photo-float)}
.chapter-body-paragraph:has(> .chapter-photo-frame):has(+ .chapter-body-paragraph:has(> br:only-child) + .chapter-body-paragraph:has(> .chapter-photo-frame))>.chapter-photo-frame,
.chapter-body-paragraph:has(> .chapter-photo-frame):has(+ .chapter-body-paragraph:has(> .chapter-photo-frame))>.chapter-photo-frame{margin-bottom:4px!important}
.chapter-body-paragraph:has(> .chapter-photo-frame)+.chapter-body-paragraph:has(> br:only-child)+.chapter-body-paragraph:has(> .chapter-photo-frame)>.chapter-photo-frame,
.chapter-body-paragraph:has(> .chapter-photo-frame)+.chapter-body-paragraph:has(> .chapter-photo-frame)>.chapter-photo-frame{margin-top:4px!important}
.chapter-body-paragraph:has(> .chapter-photo-frame)+.chapter-body-paragraph:has(> br:only-child):has(+ .chapter-body-paragraph:has(> .chapter-photo-frame)){display:none}
.chapter-full-photo-page{padding:0!important;overflow:hidden}
.chapter-full-photo-page>.chapter-page-body{position:absolute;inset:0;width:100%;height:100%;overflow:hidden}
.chapter-full-photo-page .chapter-photo-frame{width:100%!important;height:100%!important;margin:0!important;border-radius:0}
.chapter-full-photo-page :is(.chapter-photo-frame>img,.chapter-photo-window,.chapter-photo-window>img){border-radius:0}
.chapter-full-photo-page .chapter-photo-resize{display:none!important}
.chapter-full-photo-page .chapter-page-number{display:none!important}
.chapter-photo-drop-before,.chapter-photo-drop-after,.chapter-photo-drop-side{position:relative}
.chapter-photo-drop-before:before,.chapter-photo-drop-after:after{content:'';position:absolute;left:0;right:0;height:4px;border-radius:4px;background:#356de0;z-index:5;pointer-events:none}
.chapter-photo-drop-before:before{top:-4px}.chapter-photo-drop-after:after{bottom:-4px}
.chapter-photo-drop-side{outline:3px solid #356de0;outline-offset:4px}
.chapter-photo-frame.is-cropping{outline:2px solid #356de0;overflow:hidden;touch-action:none}
.chapter-photo-frame.is-cropping .chapter-photo-resize{display:none!important}
.chapter-photo-crop-selection{position:absolute;z-index:3;box-sizing:border-box;border:2px solid #356de0;box-shadow:0 0 0 9999px #14253b42;pointer-events:auto;cursor:move;background:linear-gradient(90deg,transparent 33%,#ffffffa8 33.3%,#ffffffa8 33.7%,transparent 34%,transparent 66%,#ffffffa8 66.3%,#ffffffa8 66.7%,transparent 67%),linear-gradient(transparent 33%,#ffffffa8 33.3%,#ffffffa8 33.7%,transparent 34%,transparent 66%,#ffffffa8 66.3%,#ffffffa8 66.7%,transparent 67%)}
.chapter-photo-crop-selection .crop-handle{position:absolute;display:block;width:13px;height:13px;box-sizing:border-box;padding:0;border:2px solid #fff;border-radius:50%;background:#356de0;box-shadow:0 1px 4px #17223880;pointer-events:auto;touch-action:none;appearance:none}
.chapter-photo-crop-selection .crop-handle.n,.chapter-photo-crop-selection .crop-handle.s{left:0;width:100%;height:16px;border:0;border-radius:0;background:transparent;box-shadow:none;cursor:ns-resize}.chapter-photo-crop-selection .crop-handle.n{top:-8px}.chapter-photo-crop-selection .crop-handle.s{bottom:-8px}
.chapter-photo-crop-selection .crop-handle.e,.chapter-photo-crop-selection .crop-handle.w{top:0;width:16px;height:100%;border:0;border-radius:0;background:transparent;box-shadow:none;cursor:ew-resize}.chapter-photo-crop-selection .crop-handle.e{right:-8px}.chapter-photo-crop-selection .crop-handle.w{left:-8px}
.chapter-photo-crop-selection .crop-handle.n:after,.chapter-photo-crop-selection .crop-handle.s:after{content:'';position:absolute;left:calc(50% - 6px);top:1px;width:12px;height:12px;border:2px solid #fff;border-radius:50%;background:#356de0;box-shadow:0 1px 4px #17223880}.chapter-photo-crop-selection .crop-handle.s:after{top:3px}
.chapter-photo-crop-selection .crop-handle.e:after,.chapter-photo-crop-selection .crop-handle.w:after{content:'';position:absolute;left:1px;top:calc(50% - 6px);width:12px;height:12px;border:2px solid #fff;border-radius:50%;background:#356de0;box-shadow:0 1px 4px #17223880}.chapter-photo-crop-selection .crop-handle.e:after{left:3px}
.chapter-photo-crop-selection .crop-handle.nw{top:-2px;left:-2px;cursor:nwse-resize}.chapter-photo-crop-selection .crop-handle.ne{top:-2px;right:-2px;cursor:nesw-resize}.chapter-photo-crop-selection .crop-handle.sw{bottom:-2px;left:-2px;cursor:nesw-resize}.chapter-photo-crop-selection .crop-handle.se{bottom:-2px;right:-2px;cursor:nwse-resize}
.chapter-photo-crop-tools{position:fixed;z-index:801;display:flex;gap:6px;padding:4px;border:1px solid #d4dce5;border-radius:8px;background:#fff;box-shadow:0 3px 12px #17223826;pointer-events:auto}
.chapter-photo-crop-tools[hidden]{display:none}
.chapter-photo-crop-tools button{display:grid;place-items:center;width:30px;height:30px;border:0;border-radius:5px;background:#edf2f8;color:#253a4d;font:18px Arial,sans-serif;cursor:pointer}
.chapter-photo-crop-tools [data-photo-crop-done]{background:#356de0;color:#fff}
.chapter-photo-resize{position:absolute;z-index:4;right:-7px;bottom:-7px;box-sizing:border-box;width:14px;height:14px;border:2px solid #fff;border-radius:50%;background:#356de0;box-shadow:0 1px 5px #17223855;cursor:nwse-resize;display:none;pointer-events:auto}
#chapterPages .chapter-photo-frame.is-selected .chapter-photo-resize{display:block}
.chapter-photo-frame.has-resize-crop{cursor:pointer}
.chapter-photo-frame.is-crop-positioning{cursor:grab}
.chapter-photo-frame.is-crop-positioning::after{content:'';position:absolute;inset:0;z-index:2;pointer-events:none;background:linear-gradient(90deg,transparent calc(100% - 1px),#ffffffb3 0) 0 0/33.333% 100%,linear-gradient(transparent calc(100% - 1px),#ffffffb3 0) 0 0/100% 33.333%;box-shadow:inset 0 0 0 1px #ffffffb3}
.chapter-photo-frame.is-panning-crop{cursor:grabbing}
.chapter-photo-move{position:absolute;top:4px;right:4px;width:21px;height:21px;display:none;place-items:center;border-radius:4px;background:#fff;color:#356de0;box-shadow:0 1px 5px #17223855;font:18px/1 Arial,sans-serif;cursor:grab}
.chapter-photo-move:before{content:'✥'}
.chapter-photo-frame.is-crop-positioning .chapter-photo-move{display:grid}
.chapter-photo-frame.will-move-page{outline-style:dashed}
.chapter-photo-context-menu{position:fixed;z-index:800;display:grid;min-width:210px;padding:5px;border:1px solid #d4dce5;border-radius:8px;background:#fff;box-shadow:0 10px 30px #17223840}
.chapter-photo-context-menu[hidden]{display:none}.chapter-photo-context-menu button{border:0;border-radius:5px;background:transparent;padding:9px 10px;color:#253a4d;text-align:left;font:13px Arial,sans-serif;cursor:pointer}.chapter-photo-context-menu button:hover{background:#e9f0ff}
.chapter-photo-context-menu [aria-checked="true"]{background:#e9f0ff}
.chapter-photo-context-menu [aria-checked="true"]::after{content:"✓";float:right;margin-left:8px}
@media(max-height:620px){.chapter-photo-context-menu{max-height:calc(100vh - 16px);overflow:auto}}
.chapter-photo-context-menu button.is-disabled{position:relative;color:#9ba4ad;cursor:not-allowed}.chapter-photo-context-menu button.is-disabled:hover{background:#f4f5f6}.chapter-photo-context-menu button.is-disabled:hover:after,.chapter-photo-context-menu button.is-disabled:focus-visible:after{content:attr(data-disabled-help);position:absolute;z-index:2;right:calc(100% + 9px);top:0;width:250px;padding:9px 10px;border-radius:7px;background:#253a4d;color:#fff;box-shadow:0 7px 20px #17223835;font:12px/1.4 Arial,sans-serif;white-space:normal;pointer-events:none}
.chapter-photo-context-menu .chapter-photo-menu-divider{display:block;height:1px;margin:4px 6px;background:#dfe5ec}.chapter-photo-context-menu .chapter-photo-menu-divider[hidden]{display:none}
.chapter-photo-modal-preview{display:flex;align-items:center;justify-content:center;min-height:150px;max-height:320px;overflow:auto;margin:10px 0;padding:12px;background:#f3f5f4;border:1px solid #e1e5e2;border-radius:9px}
.chapter-photo-modal-preview img{display:block;max-width:100%;max-height:280px;object-fit:contain}
.chapter-photo-picker{display:inline-flex!important;align-items:center;justify-content:center;min-height:36px;padding:8px 12px!important;border:1px solid #d6dee8;border-radius:8px;background:#fff;cursor:pointer}
.chapter-photo-picker input{display:none}
.chapter-photo-modal-actions{display:flex;justify-content:space-between;gap:8px;margin-top:16px}
.chapter-photo-modal-actions button{border:1px solid #d6dee8;border-radius:8px;background:#fff;padding:9px 12px;color:#46515e;cursor:pointer}
.chapter-photo-modal-actions button.primary{background:#356de0;border-color:#356de0;color:#fff}
.chapter-photo-modal-actions button.danger{color:#b84242}
.chapter-toolbar-group [data-photo-add] svg{fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
@media print{.chapter-photo-resize,.chapter-photo-move,.chapter-photo-crop-tools,.chapter-photo-context-menu,.chapter-photo-crop-selection{display:none!important}.chapter-photo-frame.is-selected,.chapter-photo-frame.is-cropping{outline:0}}

.chapter-full-photo-page .chapter-collage-grid{position:absolute;inset:0;display:grid;width:100%;height:100%;gap:8px;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));overflow:hidden}.chapter-collage-tile{display:block;min-width:0;min-height:0;overflow:hidden}.chapter-collage-tile img{display:block;width:100%;height:100%;object-fit:cover;max-width:none;max-height:none}.chapter-collage-choices{display:grid;grid-template-columns:1fr 1fr;gap:4px;padding:5px}.chapter-collage-choices button{font-size:11px}

/* A trailing paragraph separator is part of the text, not an extra line on this sheet. */
.chapter-chunk-boundary:has(> br:only-child){height:0;min-height:0;font-size:0;line-height:0;overflow:hidden}
/* Pagination measures natural content height; a sheet never squeezes its headings or body. */
.chapter-page>*{flex-shrink:0}

.chapter-body-paragraph>.chapter-photo-frame.is-bottom-filled{margin-bottom:0!important}
/* A photo at the start of a text area needs no paragraph gap above it.
   Keep the full usable height when switching to a smaller print format. */
.chapter-page-body>.chapter-body-paragraph:first-child>.chapter-photo-frame{margin-top:0!important}
/* Compact photo library and collage editor. */
.chapter-modal.photo-library-picker,.chapter-modal.collage-editor-dialog{width:min(900px,94vw);max-width:94vw}
.photo-library-picker .photo-picker-upload{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:12px 0;border-bottom:1px solid #e4e6e3}
.photo-picker-upload label{cursor:pointer;padding:9px 14px;border-radius:8px;background:#713735;color:white;font:600 13px Arial,sans-serif}.photo-picker-upload input{display:none}
.photo-picker-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(110px,1fr));gap:12px;max-height:50vh;overflow:auto;padding:16px 2px}
.photo-picker-tile{display:grid;gap:6px;border:2px solid transparent;border-radius:9px;padding:5px;background:#f3f4f2;color:#4a4036;text-align:left;cursor:pointer;min-width:0}.photo-picker-tile.selected{border-color:#713735;background:#f8edeb}.photo-picker-tile img{width:100%;height:110px;object-fit:cover;border-radius:5px}.photo-picker-tile span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:12px Arial,sans-serif}
.photo-picker-empty{grid-column:1/-1;padding:35px;text-align:center;color:#7e817e}.photo-picker-status{font:13px Arial,sans-serif;color:#6c726d}.photo-picker-upload button{border:1px solid #ddd;border-radius:8px;background:white;padding:9px;cursor:pointer}
.collage-editor{display:grid;grid-template-columns:minmax(0,1fr) 230px;gap:24px}.collage-editor-hint{font:13px/1.5 Arial,sans-serif;color:#70776f}.collage-editor-preview{position:relative;width:min(100%,380px);max-height:62vh;margin:auto;background:#f2f0eb;overflow:hidden;box-shadow:0 2px 12px #0002;touch-action:none}.collage-editor-tile{position:absolute;overflow:hidden;cursor:move;touch-action:none}.collage-editor-tile img{width:100%;height:100%;object-fit:cover;pointer-events:none;user-select:none}.collage-editor-tile.selected{outline:3px solid #713735;outline-offset:-3px}.collage-editor-tile button{position:absolute;left:6px;top:6px;border:0;border-radius:50%;width:25px;height:25px;background:#fff;color:#713735;cursor:pointer}.collage-editor-resize{position:absolute;right:0;bottom:0;width:18px;height:18px;background:#fff;border:2px solid #713735;cursor:nwse-resize}.collage-editor-controls{display:grid;align-content:start;gap:13px;font:13px Arial,sans-serif}.collage-editor-controls label{display:grid;gap:6px}.collage-editor-controls label>span{display:flex;align-items:center;gap:8px}.collage-editor-controls input{min-width:0;flex:1;accent-color:#713735}.collage-editor-controls output{min-width:34px;text-align:right}.collage-editor-controls select,.collage-editor-controls button{padding:8px;border:1px solid #ddd;border-radius:7px;background:white;color:#51483f}.collage-editor-selection{font-weight:600;color:#713735}
@media(max-width:650px){.collage-editor{grid-template-columns:1fr}.collage-editor-preview{max-height:42vh;width:230px}.collage-editor-controls{grid-template-columns:1fr 1fr}.photo-picker-grid{grid-template-columns:repeat(auto-fill,minmax(85px,1fr))}}
.chapter-modal.collage-editor-dialog label{display:grid;gap:6px;margin:0;color:#51483f;font:13px Arial,sans-serif}
.chapter-modal.collage-editor-dialog .collage-editor-hint,.chapter-modal.photo-library-picker .photo-picker-status{color:#70776f;font:13px/1.5 Arial,sans-serif}
.chapter-modal.collage-editor-dialog input[type=range]{height:20px;margin:0;padding:0;border:0;border-radius:0;background:transparent}
.chapter-modal.collage-editor-dialog select{margin:0;height:36px}
.chapter-modal.collage-editor-dialog .chapter-photo-modal-actions .primary,.chapter-modal.photo-library-picker .chapter-photo-modal-actions .primary{background:#713735;border-color:#713735;color:white}

/* Secondary photo pages move between sheets, with the destination sheet highlighted. */
.chapter-page.chapter-photo-page-drop-target:after{content:'';position:absolute;inset:0;z-index:12;box-sizing:border-box;border:3px solid #356de0;background:#356de012;pointer-events:none}
@media print{.chapter-page.chapter-photo-page-drop-target:after{display:none!important}}
.collage-preset-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;max-height:240px;overflow:auto;padding:2px}
.collage-preset-grid .collage-preset{display:grid;gap:4px;padding:5px;font:10px Arial,sans-serif;text-align:center;cursor:pointer}.collage-preset.selected{border-color:#713735;background:#fbefec}
.collage-preset-icon{display:block;position:relative;height:48px;width:100%;background:#f2f0eb}.collage-preset-icon i{position:absolute;background:#b6bdb5;border:1px solid white;box-sizing:border-box}.collage-preset.selected i{background:#9d6c66}
.collage-editor-tile{cursor:grab}.collage-editor-tile .collage-swap-handle{left:auto;right:6px;top:6px;cursor:grab;font-size:18px}.collage-editor-tile.swap-target{outline:4px solid #af793f;outline-offset:-4px}
.collage-divider{position:absolute;z-index:4;touch-action:none}.collage-divider.x{width:12px;transform:translateX(-50%);cursor:col-resize}.collage-divider.y{height:12px;transform:translateY(-50%);cursor:row-resize}
.collage-divider:after{content:'';position:absolute;left:50%;top:50%;border:1px solid #713735;background:#fff;border-radius:4px;transform:translate(-50%,-50%)}.collage-divider.x:after{width:6px;height:30px}.collage-divider.y:after{width:30px;height:6px}

.chapter-balanced-line{display:block;box-sizing:border-box;width:100%;white-space:pre;text-align:left;text-align-last:left;line-height:inherit}
.chapter-balanced-space{font-size:0;letter-spacing:0;word-spacing:0;line-height:0}
.chapter-wrap-line{white-space:pre-wrap;hyphens:none;overflow-wrap:normal;word-break:normal;text-align:justify;text-align-last:justify}
.chapter-wrap-line>.chapter-balanced-space{white-space:pre}
.chapter-wrap-hyphen::after{content:"-"}
