/* Collapse the shelf before it begins to crowd the text. Its dialog remains accessible. */
@media (min-width:736px) and (max-width:1100px) {
  .workspace {grid-template-columns:minmax(0,1fr) clamp(245px,26vw,284px);gap:18px}
  .left-rail {display:none}
  .mobile-library {display:inline-flex}
  .reading-body {padding:26px clamp(25px,3vw,38px) 18px}
  .paper-cover {min-height:225px}
  .top-inner,.shell {padding-left:max(20px,env(safe-area-inset-left));padding-right:max(20px,env(safe-area-inset-right))}
}

/* In portrait give the text a full measure and bring up definitions on demand. */
@media (min-width:736px) and (max-width:900px) {
  .workspace {display:block;max-width:760px;margin-inline:auto}
  .shell .page-title {max-width:760px;margin-inline:auto}
  .right-rail {display:contents;position:static}
  .progress-panel {max-width:100%;margin-top:16px}
  .dictionary {display:none}
  .dictionary.mobile-open,.focus-mode .dictionary.mobile-open {
    position:fixed;display:flex;flex-direction:column;z-index:8;
    left:max(16px,env(safe-area-inset-left));right:max(16px,env(safe-area-inset-right));
    bottom:max(12px,env(safe-area-inset-bottom));width:auto;max-width:520px;
    max-height:62vh;max-height:62dvh;margin-inline:auto;
    border-color:#adbfad;box-shadow:0 10px 65px #15251b43
  }
  .dictionary .panel-heading {flex:none;padding:6px 13px 6px 18px}
  .dictionary .language-tag {margin-left:auto}
  .dictionary .dict-close {display:inline-flex}
  .dictionary #dict-content {max-height:none;min-height:0;overflow:auto}
  .reading-body {padding:28px clamp(27px,6vw,48px) 18px}
  .paper-cover {min-height:244px}
  .cover-title {font-size:clamp(43px,6.5vw,54px)}
}

@media (any-pointer:coarse) {
  .topbar {padding-top:env(safe-area-inset-top)}
  .workspace,.collection-shell {padding-bottom:max(32px,calc(env(safe-area-inset-bottom) + 14px))}
  .global-nav a,.import-top,.page-actions button,.toc-item,.shelf-row,.paper-footer button,
  .reader-tools button,.context-translations button,.dictionary button,dialog button,
  .collection-shell button,.rail-heading button,#select-tools button {
    min-height:44px;min-width:44px;touch-action:manipulation
  }
  button,nav a,#select-tools {-webkit-touch-callout:none}
  #reading-body,#reading-body p,#reading-body .word {
    -webkit-user-select:text;user-select:text;-webkit-touch-callout:default
  }
  .dict-close,.speak,.reader-tools .icon-btn {width:44px;height:44px}
  .context-translations {gap:8px}
  .context-translations button {flex:1 1 auto}
  dialog .text,dialog input,dialog textarea,.filter-input {font-size:16px}
  dialog {max-height:calc(100vh - 42px);max-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 28px)}
  /* Keep actions away from the native long-press menu and selection handles. */
  #select-tools {
    left:50%!important;top:auto!important;
    bottom:max(12px,env(safe-area-inset-bottom));transform:translateX(-50%);z-index:10;
    max-width:calc(100vw - 24px);box-shadow:0 5px 24px #15251b48
  }
  #select-tools button {padding-inline:15px}
  #toast {bottom:max(22px,env(safe-area-inset-bottom))}
}
