/* IHA R171: reader-first layout. Older reader CSS remains untouched for other routes. */
html:has(.ihi-book-page),body.ihi-book-page{height:100%;min-height:0;overflow:hidden}
.ihi-book-reader{--reader-top:48px;position:relative!important;display:grid!important;grid-template-rows:var(--reader-top) 44px minmax(0,1fr) 28px!important;height:100dvh!important;min-height:0!important;max-height:100dvh!important;overflow:hidden!important}
.ihi-book-reader [hidden]{display:none!important}
.book-topbar{height:var(--reader-top)!important;min-height:0!important;padding:5px clamp(9px,1.6vw,24px)!important;gap:9px!important;grid-template-columns:32px minmax(0,1fr) auto!important;overflow:visible;z-index:15}
.book-back{width:30px!important;height:30px!important;font-size:20px!important}
.book-identity h1{font:700 clamp(13px,1.3vw,19px)/1.25 Georgia,serif!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.book-identity span{font-size:8px!important;letter-spacing:.1em!important}
.book-top-actions{display:flex!important;align-items:center;gap:4px!important;grid-column:auto!important;min-width:0}
.book-top-actions>button,.book-popover-control>summary{display:flex;align-items:center;justify-content:center;gap:5px;min-height:30px!important;height:32px!important;border:1px solid #ffffff36;border-radius:7px;background:#ffffff13;color:#fff;cursor:pointer;padding:4px 9px;font-size:12px;font-weight:750;white-space:nowrap}
.book-top-actions>button{font-size:19px!important;min-width:35px!important;padding:3px 6px!important}
.book-popover-control{position:relative;min-width:0}
.book-popover-control>summary{list-style:none;user-select:none}
.book-popover-control>summary::-webkit-details-marker{display:none}
.book-popover-control[open]>summary{background:#e9f5ed;color:#06462c}
.book-popover-panel{position:absolute;top:calc(100% + 7px);right:0;z-index:80;width:min(340px,calc(100vw - 20px));padding:14px;background:#fff;color:#203d2b;border:1px solid #cbdccf;border-radius:12px;box-shadow:0 16px 36px #00271838;font-size:13px;line-height:1.35}
.book-popover-panel strong{font-size:13px;display:block;margin-bottom:10px}
.book-tools-panel>label{display:grid;grid-template-columns:90px minmax(0,1fr);align-items:center;gap:8px;margin:8px 0;font-weight:700}
.book-tools-panel select{width:100%;min-width:0;min-height:34px;border:1px solid #c6d7cd;background:#fff;border-radius:7px;color:#143c2b;padding:4px 6px;font:inherit}
.book-tools-panel .book-interaction-controls{display:grid!important;grid-template-columns:1fr 1fr;gap:5px;margin:10px 0}
.book-tools-panel .book-interaction-controls button,.book-copy-action{font:inherit!important;border:1px solid #bbd2c0;background:#fff;color:#125536;border-radius:8px;min-height:35px;padding:6px 9px;cursor:pointer;white-space:normal}
.book-tools-panel .book-interaction-controls button.is-active{color:white;background:#075c35}
.book-copy-action{width:100%;font-weight:750}
.book-text-notice,.book-find-panel p{font-size:11px;color:#66796d;line-height:1.45;margin:8px 0 0}
.book-find-panel{width:min(410px,calc(100vw - 20px))}
.book-find-panel .book-search{display:block!important;min-width:0;width:100%;grid-column:auto}
.book-find-panel .book-search label{display:block;font-weight:800;margin-bottom:8px}
.book-find-line{display:flex;gap:6px}
.book-find-line input{height:36px;min-width:0;flex:1 1 auto;border-radius:7px;font-size:13px;text-align:start}
.book-find-line button,#bookSearch + button,[data-book-search-cancel]{min-height:36px;border-radius:7px;background:#075c35;color:#fff;border:0;padding:6px 12px;font-weight:750;cursor:pointer}
[data-book-search-cancel]{margin-top:8px;background:#f4f8f5;color:#075c35;border:1px solid #c0d3c7}
.book-toolbar{display:flex!important;align-items:center;justify-content:space-between;gap:7px!important;height:44px!important;min-height:0!important;padding:3px clamp(8px,2vw,24px)!important;grid-template-columns:none!important;grid-template-areas:none!important;overflow:hidden}
.book-nav{display:flex!important;align-items:center;gap:5px!important;justify-content:start!important;grid-area:auto!important;white-space:nowrap}
.book-nav form{gap:5px!important}
.book-toolbar button,.book-toolbar input{height:32px!important;min-height:32px!important;border-radius:7px;padding:3px 9px!important}
.book-nav>button{min-width:30px;padding:0!important;font-size:23px!important}
.book-nav input{width:51px!important;min-width:51px;font-weight:750;padding:2px 3px!important}
.book-nav form button{min-width:30px;padding:0 5px!important;font-size:18px}
.book-nav span{font-size:12px;font-variant-numeric:tabular-nums;color:#466152}
.book-zoom-controls{display:flex;align-items:center;gap:4px;white-space:nowrap}
.book-zoom-controls button{min-width:30px;font-size:16px;padding:2px 6px!important}
.book-zoom-controls output{font-size:12px;min-width:43px;text-align:center;color:#264735;font-variant-numeric:tabular-nums;font-weight:750}
.book-zoom-controls [data-book-zoom-fit]{font-size:11px}
.book-stage{height:auto!important;min-height:0!important;max-height:none!important;width:100%;display:flex!important;align-items:center!important;justify-content:safe center!important;overflow:auto!important;overscroll-behavior:contain;padding:10px!important;grid-template-columns:none!important;gap:0!important;scrollbar-width:thin;touch-action:pan-x pan-y;position:relative}
.book-spread{display:grid;flex:0 0 auto;grid-template-columns:max-content 10px max-content;align-items:center;width:max-content;max-width:none!important;max-height:none!important;justify-self:auto!important;margin:auto!important;filter:drop-shadow(0 7px 15px #17372526)!important;transform-origin:center center}
.ihi-book-reader.is-single .book-spread{grid-template-columns:max-content!important}
.book-sheet{max-width:none!important;max-height:none!important;position:relative;flex:0 0 auto}
.book-sheet canvas{display:block;max-width:none!important;max-height:none!important}
.book-sheet .book-text-layer{pointer-events:none;user-select:none;z-index:3}
[data-book-interaction="select"] .book-sheet .book-text-layer{pointer-events:auto;user-select:text;-webkit-user-select:text;touch-action:pan-x pan-y}
.book-page-number{z-index:5!important}
.book-footer{height:28px!important;min-height:28px!important;display:grid!important;grid-template-columns:32px minmax(70px,1fr) minmax(0,2fr)!important;justify-content:stretch;align-items:center;gap:9px;padding:2px clamp(10px,2vw,24px)!important}
.book-status{position:static!important;margin:0!important;display:block!important;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;height:auto!important;min-height:0!important;line-height:18px!important;text-align:right!important;font-size:11px!important;padding:0!important;pointer-events:auto}
.book-progress{max-width:none}
.book-error{grid-row:3!important;margin:auto!important;max-width:min(550px,calc(100% - 30px))!important;padding:20px!important}
.ihi-book-reader[data-state="error"]{grid-template-rows:var(--reader-top) 44px minmax(0,1fr) 28px!important}
.ihi-book-reader[data-state="error"] .book-stage{display:none!important}
.ihi-book-reader[data-state="error"] .book-error{display:block!important}
.ihi-book-reader[data-state="loading"] .book-spread{opacity:.6}
.ihi-book-reader:is(:fullscreen,.is-fullscreen){grid-template-rows:var(--reader-top) 44px minmax(0,1fr) 28px!important;position:fixed;inset:0;z-index:99999}
.ihi-book-reader .book-leaf-turn{position:absolute;top:0;left:0;z-index:8;overflow:hidden;pointer-events:none;background:#fff;box-shadow:0 5px 22px #0003;backface-visibility:hidden;transform-style:preserve-3d;border:1px solid #c9c9bf}
.book-leaf-turn canvas{display:block;max-width:100%;width:100%;height:100%}
.book-leaf-turn::after{content:"";position:absolute;inset:0;background:linear-gradient(90deg,#0000 38%,#0004 76%,#fff8 96%);mix-blend-mode:multiply}
.book-leaf-turn.turn-next{transform-origin:0% 50%;animation:iha-page-curl-next .52s cubic-bezier(.2,.65,.2,1) both}
.book-leaf-turn.turn-prev{transform-origin:100% 50%;animation:iha-page-curl-prev .52s cubic-bezier(.2,.65,.2,1) both}
@keyframes iha-page-curl-next{0%{transform:perspective(1300px) rotateY(0) scaleX(1);opacity:1;border-radius:0}52%{transform:perspective(1300px) rotateY(-67deg) skewY(-1deg) scaleX(.92);opacity:.9;border-radius:0 16% 15% 0}100%{transform:perspective(1300px) rotateY(-108deg) scaleX(.86);opacity:0}}
@keyframes iha-page-curl-prev{0%{transform:perspective(1300px) rotateY(0) scaleX(1);opacity:1;border-radius:0}52%{transform:perspective(1300px) rotateY(67deg) skewY(1deg) scaleX(.92);opacity:.9;border-radius:16% 0 0 15%}100%{transform:perspective(1300px) rotateY(108deg) scaleX(.86);opacity:0}}
.ihi-book-reader[data-state^="turn-"] .book-sheet{animation:none!important}
@media(max-width:820px){
 .ihi-book-reader{--reader-top:44px}
 .book-identity span{display:none}
 .book-identity h1{font-size:14px!important}
 .book-top-actions{gap:3px!important}
 .book-popover-control>summary{font-size:16px;min-width:32px!important;padding:3px 7px!important}
 .book-popover-control>summary span{display:none}
 .book-toolbar{padding:3px 8px!important}
 .book-stage{padding:6px!important}
 .book-footer{grid-template-columns:30px minmax(30px,1fr) minmax(0,3fr)!important}
 .book-status{font-size:10px!important}
}
@media(max-width:430px){
 .book-topbar{padding:4px 7px!important;gap:5px!important}
 .book-toolbar{padding:3px 5px!important;gap:2px!important}
 .book-nav,.book-zoom-controls{gap:2px!important}
 .book-nav input{width:39px!important;min-width:39px!important}
 .book-nav span{font-size:11px}
 .book-toolbar button{min-width:26px!important;padding:2px 4px!important}
 .book-zoom-controls output{min-width:38px;font-size:11px}
 .book-tools-panel .book-interaction-controls button{min-height:35px!important}
}
@media(prefers-reduced-motion:reduce){.ihi-book-reader .book-leaf-turn{animation:none!important;display:none!important}}
/* Keep popovers within the viewport even when opened from the last header buttons. */
.book-tools-panel,.book-find-panel{position:fixed;top:calc(var(--reader-top) + 4px);right:8px;left:auto;max-width:calc(100vw - 16px)}
@media(max-width:440px){.book-tools-panel,.book-find-panel{right:8px;left:8px;width:auto;max-width:none}}
/* Arabic reading order: curl toward the next RTL leaf, not away from it. */
.ihi-book-reader[data-direction="rtl"] .book-leaf-turn.turn-next{transform-origin:100% 50%;animation-name:iha-page-curl-prev}
.ihi-book-reader[data-direction="rtl"] .book-leaf-turn.turn-prev{transform-origin:0% 50%;animation-name:iha-page-curl-next}
