*{
  box-sizing:border-box
}

/* スマホの表示領域に合わせて高さを調整 */
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family:Arial,"Yu Gothic",Meiryo,sans-serif;
  background:#eee;
  color:#222
}

.app {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ヘッダーは縮ませない */
header {
  flex: 0 0 50px;
}

/* カタログ表示部分だけを伸縮させる */
#viewer {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* 下部の操作バーを画面内に固定 */
.bottom {
  flex: 0 0 auto;
  min-height: 58px;
  height: calc(58px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
  z-index: 30;
}

/* スマホの拡大縮小ボタン */
@media (max-width: 768px) {
  .zoom {
    right: 10px;
    bottom: 10px;
    z-index: 25;
  }

  .zoom button {
    min-width: 44px;
    min-height: 42px;
    font-size: 18px;
  }

  #mobilePage {
    min-height: 0;
    padding: 10px;
  }

  #mobileImage {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
  }
}

header{  
  height:55px;
  flex:0 0 55px;
  background:#fff;
  border-bottom:1px solid #ddd;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 24px;
  z-index:20;
}
.title{
  font-weight:700;
  letter-spacing:.06em;
}
.counter{
  color:#666;
}
#viewer{
  position:relative;
  flex:1;
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  background:#e9e9e9;
  touch-action:none;
}
#book{
  width:min(90vw,1220px);
  height:min(82vh,860px);
  transform-origin:center center;
}
.page{
  background:#fff;
  overflow:hidden;
  position:relative;
  box-shadow:0 2px 14px rgba(0,0,0,.18);
}
.page img{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
  user-select:none;
  -webkit-user-drag:none;
}
#mobilePage{
  display:none;
  width:100%;
  height:100%;
  align-items:center;
  justify-content:center;
  padding:20px;
}
#mobileImage{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
  background:#fff;
  box-shadow:0 2px 14px rgba(0,0,0,.18);
  transform-origin:center center;
}
.nav{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  z-index:15;
  width:48px;
  height:72px;
  border:0;
  border-radius:8px;
  background:rgba(255,255,255,.92);
  font-size:48px;
  line-height:1;
  cursor:pointer;
  box-shadow:0 2px 10px rgba(0,0,0,.12);
}
.nav.left{
  left:15px;
}
.nav.right{
  right:15px;
}
.zoom{
  position:absolute;
  right:22px;
  bottom:18px;
  z-index:16;
  display:flex;
  gap:5px;
}
.zoom button{
  background:#ffffff46;
  border:1px solid #ccc;
  border-radius:5px;
  padding:7px 12px;
  cursor:pointer;
}
.pannable{
  cursor:grab;
}
.dragging{
  cursor:grabbing;
}
.thumb-panel{
  display:none;
  height:118px;
  flex:0 0 118px;
  background:#fff;
  border-top:1px solid #ddd;
  align-items:center;
  gap:10px;
  padding:12px 16px;
  z-index:20;
}
.thumb-panel.open{
  display:flex;
}
#thumbs{
  flex:1;min-width:0;
  height:92px;
  display:flex;
  gap:10px;
  overflow-x:auto;
  align-items:center;
  scroll-behavior:smooth;
}
#thumbs::-webkit-scrollbar{
  height:7px;
}
#thumbs::-webkit-scrollbar-thumb{
  background:#aaa;
  border-radius:10px;
}
.thumb{
  flex:0 0 82px;
  width:82px;
  height:82px;
  background:#fff;
  border:1px solid #ccc;
  border-radius:5px;
  padding:2px;
  cursor:pointer;
}
.thumb.active{
  border:2px solid #005bac;
}
.thumb img{
  width:100%;height:100%;object-fit:contain;
}
.thumb-nav{
  width:42px;
  height:60px;
  flex:0 0 42px;
  background:#fff;
  border:1px solid #ccc;
  border-radius:6px;
  font-size:30px;
  cursor:pointer;
}
.bottom{
  height:58px;
  flex:0 0 58px;
  background:#fff;
  border-top:1px solid #ddd;display:flex;
  align-items:center;
  justify-content:center;
  gap:42px;z-index:20;
}
.bottom button{
  border:0;
  background:none;min-width:72px;
  font-size:20px;cursor:pointer;
}
.bottom span{
  display:block;
  font-size:10px;
  margin-top:2px;
}
.modal{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  z-index:100;
  align-items:center;
  justify-content:center;
  padding:20px;
}
.modal.open{
  display:flex;
}
.panel,.product-panel{
  position:relative;
  background:#fff;
  border-radius:10px;
  width:min(92vw,620px);
  max-height:84vh;
  overflow:auto;
  padding:32px
}
.close{
  position:absolute;
  right:12px;
  top:7px;
  border:0;
  background:none;
  font-size:30px;
  cursor:pointer
}
#searchInput{
  width:100%;
  padding:12px;
  border:1px solid #ccc;
  border-radius:5px;
  font-size:16px;
}
.toc-item,.result{
  padding:12px;
  border-bottom:1px solid #eee;
  cursor:pointer;
}
.toc-item:hover,.result:hover{
  background:#f5f5f5;
}
.product-panel{
  width:min(92vw,760px);
}
.product-panel>img{
  width:100%;
  max-height:52vh;
  object-fit:contain;
}
.label{
  font-size:11px;
  letter-spacing:.12em;
  color:#005bac;
}
.product-text h2{
  margin:5px 0;
}
.product-text p{
  line-height:1.7;
}
@media(max-width:768px){
  header{height:50px;
    flex-basis:50px;
    padding:0 14px;
  }
  .title{
    font-size:13px;
  }
  #book{
    display:none;
  }
    .nav{
      width:40px;
      height:58px;
      font-size:38px;
    }.nav.left{
      left:5px;
    }
    .nav.right{
      right:5px;
    }
    .thumb-panel{
      height:95px;
      flex-basis:95px;
      padding:8px;
    }
    .thumb{
      width:64px;
      height:70px;
      flex-basis:64px;
    }
    .thumb-nav{
      width:34px;
      flex-basis:34px;
      height:52px;
    }
    .bottom{
      height:55px;
      flex-basis:55px;
      gap:18px;
    }
    .zoom{
      right:10px;
      bottom:10px;
    }
    .product-panel{
      padding:28px 18px 20px;
    }
  }

/* 拡大中はページめくり用の操作を受け付けない */
#viewer.zoom-mode,
#viewer.zoom-mode #book,
#viewer.zoom-mode .page,
#viewer.zoom-mode .page img{
  touch-action:none;
}
#viewer.zoom-mode #book{
  pointer-events:none;
}
#viewer.zoom-mode .page img{
  pointer-events:none;
}

/* モバイル専用：下部操作バーを左右対称に配置。PCは変更なし。 */
.mobile-page-button{display:none;}

@media(max-width:768px){
  #viewer > .nav{display:none;}

  .bottom{
    position:relative;
    display:grid;
    grid-template-columns:44px repeat(4,minmax(0,1fr)) 44px;
    align-items:center;
    justify-content:stretch;
    gap:0;
    width:100%;
    padding:0 8px;
  }

  .bottom .mobile-page-button{
    display:flex;
    align-items:center;
    justify-content:center;
    position:static;
    transform:none;
    width:44px;
    min-width:44px;
    height:44px;
    padding:0;
    border:1px solid #ccc;
    border-radius:6px;
    background:#fff;
    font-size:28px;
    line-height:1;
  }

  #mobilePrev{grid-column:1;}
  #thumbToggle{grid-column:2;}
  #toc{grid-column:3;}
  #search{grid-column:4;}
  #fullscreen{grid-column:5;}
  #mobileNext{grid-column:6;}

  .bottom > button:not(.mobile-page-button){
    min-width:0;
    width:100%;
    padding:4px 1px;
    font-size:22px;
  }

  .bottom > button:not(.mobile-page-button) span{
    font-size:10px;
    white-space:nowrap;
    margin-top:3px;
  }
}

@media(max-width:390px){
  .bottom{
    grid-template-columns:38px repeat(4,minmax(0,1fr)) 38px;
    padding:0 6px;
  }

  .bottom .mobile-page-button{
    width:38px;
    min-width:38px;
    height:40px;
    font-size:25px;
  }

  .bottom > button:not(.mobile-page-button){
    font-size:20px;
  }

  .bottom > button:not(.mobile-page-button) span{
    font-size:8.5px;
  }
}
/* スマホのみ：全画面表示中はズーム操作ボタンを非表示 */
@media (max-width:768px){
  #viewer.fullscreen-active .zoom{
    display:none;
  }
}