/* Touch layout. Keep desktop and printed book geometry unchanged. */
.mobile-bottom-nav,.mobile-drawer-close,.mobile-backdrop{display:none}
@media screen and (max-width:900px){
  html{scroll-padding-top:84px}
  body.mobile-menu-open{overflow:hidden}
  .reference-main{margin-left:0;min-width:0;padding-bottom:calc(78px + env(safe-area-inset-bottom,0px))}
  .reference-main>.topbar,.workspace-main>.topbar{position:sticky;top:0;left:0;right:0;width:100%;height:68px;padding:8px 16px;background:#faf9f3f5;border-bottom:1px solid #dce1d4;z-index:40;backdrop-filter:blur(12px)}
  .reference-main>.topbar>.flex:first-child{display:flex}.reference-main .breadcrumb,.reference-main .topbar-actions>.icon-btn{display:none}
  .mobile-menu{display:inline-grid}.icon-btn{min-width:44px;min-height:44px}
  .header-login{font-size:13px;min-height:44px;padding:10px 14px}.header-account summary{min-height:44px}.reference-main .header-account-name{max-width:145px}.header-account-menu{max-width:calc(100vw - 32px)}
  .reference-sidebar{display:none;position:fixed;inset:0 auto 0 0;width:min(320px,calc(100vw - 40px));height:100dvh;z-index:110;padding:68px 18px 30px;overscroll-behavior:contain;overflow-y:auto}
  .reference-sidebar.open{display:flex}.mobile-drawer-close{display:grid;position:absolute;top:12px;right:12px;color:#fff;background:#ffffff15;border:1px solid #ffffff35;border-radius:50%}
  .reference-sidebar .nav{font-size:16px!important;min-height:48px!important;padding:12px!important;gap:12px}.reference-sidebar .brand{max-width:210px}.reference-sidebar .sidebar-quote{display:none}.reference-sidebar .workspace-tools{margin:10px 0}.workspace-tools summary{min-height:48px;padding:14px 8px;font-size:14px}
  .mobile-backdrop:not([hidden]){display:block;position:fixed;inset:0;background:#06281db8;backdrop-filter:blur(3px);border:0;z-index:105}
  .mobile-bottom-nav{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));position:fixed;bottom:0;left:0;right:0;z-index:45;background:#fafbf6f5;border-top:1px solid #d7dfd1;box-shadow:0 -4px 20px #173e3212;backdrop-filter:blur(14px);padding:6px 8px calc(6px + env(safe-area-inset-bottom,0px))}
  .mobile-bottom-nav button{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;min-height:54px;border:0;border-radius:12px;background:none;color:#536c5d;font-size:12px;cursor:pointer}.mobile-bottom-nav button[aria-current]{background:#e1eee3;color:#075747;font-weight:700}.mobile-bottom-nav .icon{width:22px;height:22px}
  .athenaeum-hero{height:auto;min-height:0;max-height:none;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(0,.95fr);gap:18px;padding:24px 22px 28px;background-size:auto 100%;background-position:70% center}
  .athenaeum-intro{width:100%;grid-column:1/-1}.athenaeum h1{font-size:clamp(35px,8.8vw,49px);line-height:1.2;letter-spacing:-1px;margin:20px 0 14px}.athenaeum .eyebrow{font-size:9px;letter-spacing:1.2px}.hero-lead{white-space:normal;font-size:15px;line-height:1.8;margin:10px 0 16px;letter-spacing:0}
  .reference-search{height:auto;min-height:54px;gap:4px}.reference-search label{padding-left:7px;gap:6px}.reference-search input{font-size:16px!important;min-height:44px}.reference-search>.btn{padding:8px 13px;min-height:44px;height:auto;font-size:14px}
  .popular-search{flex-wrap:nowrap;overflow-x:auto;padding:3px 0 7px;gap:7px;scrollbar-width:thin}.popular-search small{display:none}.popular-search button{flex:0 0 auto;font-size:12px;min-height:44px;padding:9px 12px}
  .spotlight-stage{position:relative;inset:auto;width:100%;height:220px;margin:0;align-self:center}.spotlight-details{position:relative;inset:auto;width:100%;align-self:center;font-size:14px}.spotlight-details small{font-size:10px;letter-spacing:1px}.selected-description h2{font-size:19px;line-height:1.5}.selected-description p{font-size:13px;line-height:1.6}.selected-description .btn{min-height:44px;font-size:14px;padding:10px 13px}.selected-description>small{font-size:12px}
  .reference-collection{padding:25px 22px}.collection-heading{align-items:flex-start;gap:12px}.collection-heading h2{font-size:26px}.collection-heading p{font-size:13px;line-height:1.7}.collection-heading>.btn{min-height:44px;font-size:13px;flex-shrink:0}
  .catalog-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:26px 22px}.catalog-grid::before{display:none}.catalog-cover .catalog-volume{height:clamp(180px,53vw,330px);max-height:330px}.catalog-caption{padding-top:15px}.catalog-caption h3{font-size:15px;line-height:1.65;overflow-wrap:anywhere}.catalog-caption p{font-size:12px;line-height:1.6}.catalog-rating{min-height:44px;font-size:14px}.catalog-disclosure{font-size:12px;line-height:1.8}.catalog-filter{flex-wrap:wrap;gap:10px}.catalog-filter select{max-width:100%;width:100%}.collection-footer>small{display:none}
  .workspace-main>.content{padding:24px 18px}.workspace-main .welcome h1{font-size:28px;letter-spacing:-.5px}.workspace-main .welcome p{font-size:15px}.workspace-main .welcome{flex-wrap:wrap;gap:14px}.workspace-main .welcome>.btn{min-height:46px;font-size:14px}
  .workspace-hero{min-height:0;display:grid;grid-template-columns:minmax(0,1fr);padding-bottom:16px}.workspace-hero-copy{width:100%;padding:24px}.workspace-hero h2{font-size:30px}.workspace-hero p{font-size:15px;max-width:none}.workspace-hero-actions{max-width:none;flex-direction:row;gap:10px}.workspace-hero-actions .btn{font-size:14px;min-height:44px}.workspace-hero-book{position:relative;inset:auto;justify-self:end;margin-right:26px;width:115px;height:155px}.workspace-main .knowledge-entries{grid-template-columns:1fr}.workspace-main .knowledge-entries strong{font-size:16px}.workspace-main .knowledge-entries small{font-size:14px}
  .hall-main>.topbar{background:#0b352bf5}.library-hall{height:auto;max-height:none;min-height:0;padding:30px 20px}.hall-heading h1{font-size:30px;line-height:1.5}.hall-heading p{font-size:15px}.hall-portals{grid-template-columns:1fr;gap:14px;padding-bottom:26px}.hall-portal{min-height:100px}.hall-portal-copy strong{font-size:18px}.hall-count{font-size:13px}.hall-portal-copy small{font-size:10px}.hall-footer{flex-wrap:wrap}.hall-footer>span:first-child{font-size:0}.hall-footer>span:first-child::after{content:'แตะชั้นหนังสือเพื่อเลือกหมวด';font-size:13px}.hall-footer>span:nth-child(2){display:none}.hall-room-heading{padding:30px 22px}.hall-room-content{padding:24px 18px}.hall-room-toolbar{flex-direction:column;align-items:stretch}.hall-room-toolbar .search{max-width:none;width:100%}.hall-books{grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}
  input:not([type=checkbox]):not([type=radio]):not([type=range]),textarea,select{font-size:16px!important;min-width:0;max-width:100%}.field label{font-size:14px}.form-row{grid-template-columns:1fr}.btn{min-height:44px}.tabs{flex-wrap:wrap}.tab{min-height:44px}.panel,.member-profile-grid,.member-passport{min-width:0}.member-profile-grid{grid-template-columns:1fr}.member-passport{flex-wrap:wrap}.member-passport h2{overflow-wrap:anywhere}.avatar-picker{grid-template-columns:repeat(3,minmax(0,1fr))}.avatar-choice span{font-size:12px}.stamp-picker{grid-template-columns:repeat(3,minmax(0,1fr))}
  dialog{width:calc(100% - 24px);max-width:620px;max-height:calc(100dvh - 24px);padding:22px 18px;overflow-y:auto;overscroll-behavior:contain;scroll-padding:18px;border-radius:18px}dialog h2{font-size:24px}dialog .between{gap:12px}dialog .between h2{overflow-wrap:anywhere}.auth-dialog .btn,.dialog-footer .btn{min-height:46px;font-size:14px}.rating-options{gap:7px;flex-wrap:wrap}.rating-options label{min-width:44px;min-height:44px}
  .editor-header{position:relative;flex-wrap:wrap;height:auto;min-height:0;padding:12px;gap:8px}.editor-header>img,.editor-header .spacer{display:none}.editor-title{min-width:calc(100% - 60px);flex:1}.editor-title b{max-width:calc(100vw - 90px);font-size:16px}.editor-header .btn{flex:1 1 42%;font-size:14px;min-height:44px}.editor-layout{display:flex;flex-direction:column;height:auto}.pages-panel{display:flex;position:static;max-width:100%;height:auto;overflow-x:auto;padding:12px;gap:9px;overscroll-behavior-x:contain}.pages-panel .panel-label,.pages-panel .toc-indicator{display:none}.page-item,.pages-panel .btn{flex:0 0 145px;width:145px;min-height:52px;font-size:14px;margin:0!important}.edit-panel{padding:24px 18px;max-height:none;overflow:visible}.preview-panel{display:block;padding:22px 18px}.page-preview{max-width:100%}
  .reader-header{position:relative;flex-wrap:wrap;padding:14px;gap:10px}.reader-tools{width:100%;flex-wrap:wrap;gap:8px}.reader-tools .btn{flex:1 1 auto;min-height:44px;font-size:14px}.reader-jump{flex:1 1 100%;max-width:none}.reader-jump select{width:100%;min-height:44px}.reader-search{min-width:0;flex:1 1 100%;max-width:none}.reader-header strong{max-width:calc(100vw - 90px);overflow-wrap:anywhere}.reader-pages{padding:18px 12px}.reader-pages .ebook-page.content-page .body-copy{font-size:calc(17px * var(--reader-scale,1));line-height:1.95}.reader-pages .ebook-page{min-height:0;padding:26px 20px}.reader-pages .ebook-page h1{font-size:29px}.reader-pages .page-gallery.columns-3{grid-template-columns:1fr}.card-theatre{grid-template-columns:1fr;gap:18px}.card-book-scene{display:none}.floating-reading-card{padding:22px 17px}.reading-card-dialog{width:calc(100% - 24px)}
  #toast{bottom:calc(86px + env(safe-area-inset-bottom,0px));max-width:calc(100vw - 32px)}
  button,a,input,select,textarea{touch-action:manipulation}button:focus-visible,a:focus-visible{outline:3px solid #9bc7ac;outline-offset:3px}
}
@media screen and (max-width:360px){.athenaeum-hero,.reference-collection{padding-left:16px;padding-right:16px}.athenaeum h1{font-size:35px}.spotlight-stage{height:190px}.catalog-grid{gap:23px 18px}.collection-heading h2{font-size:23px}.header-account-name{display:none}.avatar-picker,.stamp-picker{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(hover:none){.catalog-cover:hover .catalog-volume,.hall-portal:hover{transform:none}.hall-portal:active{background:#20674f}.catalog-cover:active{filter:brightness(1.05)}}
@media print{.mobile-bottom-nav,.mobile-backdrop,.mobile-drawer-close{display:none!important}}

/* Keep the import workbench inside the viewport, including after file previews load. */
dialog:has(.workbench-footer){box-sizing:border-box;width:min(620px,calc(100vw - 24px));max-width:100%;min-width:0}
dialog:has(.workbench-footer) :is(.between,.field,#document-queue,.pdf-page-review,.pdf-compare,.pdf-compare>*,.workbench-footer,.workbench-footer>*){min-width:0;max-width:100%}
dialog:has(.workbench-footer) :is(strong,p,small,.muted){overflow-wrap:anywhere}
dialog:has(.workbench-footer) :is(input,select,textarea,img){max-width:100%;min-width:0}
dialog:has(.workbench-footer) .workbench-footer{flex-wrap:wrap;gap:12px}
@media(max-width:639px){
  dialog:has(.workbench-footer) .workbench-footer{position:static;margin:16px 0 0;padding:12px 0 0}
  dialog:has(.workbench-footer) .workbench-footer>.flex{display:flex;flex-wrap:wrap;width:100%;gap:8px}
  dialog:has(.workbench-footer) .workbench-footer .btn{white-space:normal}
  dialog:has(.workbench-footer) .workbench-footer .btn.primary{width:100%;flex:0 0 100%;min-height:48px}
  dialog:has(.workbench-footer) .pdf-compare{grid-template-columns:minmax(0,1fr)}
}
