*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

html,body{
  height:100%;
  overflow:hidden;
  font-family:'Lato',sans-serif;
  background:#1a1a1a;
  color:#e0e0e0;
}

#app{
  display:flex;
  flex-direction:column;
  height:100vh;
  height:100dvh;
}

/* ── Toolbar ── */

#toolbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  height:48px;
  padding:0 12px;
  background:#111;
  border-bottom:1px solid #2a2a2a;
  flex-shrink:0;
  z-index:100;
  gap:8px;
}

.toolbar-left{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
}

.toolbar-left .brand{
  font-family:'Cormorant Garamond',serif;
  font-size:16px;
  font-weight:600;
  color:#c4956a;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.toolbar-center{
  display:flex;
  align-items:center;
  gap:6px;
  flex-shrink:0;
}

.toolbar-right{
  display:flex;
  align-items:center;
  gap:2px;
  flex-wrap:nowrap;
}

.tb-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:36px;
  height:36px;
  border:none;
  background:transparent;
  color:#aaa;
  border-radius:6px;
  cursor:pointer;
  transition:background .15s,color .15s;
  flex-shrink:0;
}
.tb-btn:hover{background:#2a2a2a;color:#fff}
.tb-btn.active{background:#2a2a2a;color:#c4956a}
.tb-btn svg{width:18px;height:18px}

.tb-sep{
  width:1px;
  height:24px;
  background:#333;
  margin:0 4px;
  flex-shrink:0;
}

#page-indicator{
  font-size:13px;
  color:#999;
  min-width:60px;
  text-align:center;
  white-space:nowrap;
  user-select:none;
}

#page-slider{
  width:80px;
  height:4px;
  -webkit-appearance:none;
  appearance:none;
  background:#333;
  border-radius:2px;
  outline:none;
  cursor:pointer;
}
#page-slider::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:14px;height:14px;
  background:#c4956a;
  border-radius:50%;
  cursor:pointer;
}

/* ── Main Area ── */

#main{
  display:flex;
  flex:1;
  overflow:hidden;
  position:relative;
}

/* ── Sidebar ── */

#sidebar{
  width:240px;
  background:#151515;
  border-right:1px solid #2a2a2a;
  display:none;
  flex-direction:column;
  flex-shrink:0;
  z-index:50;
  overflow:hidden;
}
#sidebar.open{display:flex}

.sidebar-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  border-bottom:1px solid #2a2a2a;
}
.sidebar-header h3{
  font-family:'Cormorant Garamond',serif;
  font-size:15px;
  font-weight:600;
  color:#c4956a;
}

.sidebar-tabs{
  display:flex;
  border-bottom:1px solid #2a2a2a;
}
.sidebar-tab{
  flex:1;
  padding:8px 4px;
  background:transparent;
  border:none;
  color:#666;
  font-size:11px;
  cursor:pointer;
  text-align:center;
  border-bottom:2px solid transparent;
  transition:color .15s,border-color .15s;
}
.sidebar-tab:hover{color:#aaa}
.sidebar-tab.active{color:#c4956a;border-bottom-color:#c4956a}

.panel{
  flex:1;
  overflow-y:auto;
  padding:10px;
  display:none;
}
.panel.active{display:block}

.panel::-webkit-scrollbar{width:4px}
.panel::-webkit-scrollbar-thumb{background:#333;border-radius:2px}

/* Thumbnails */
.thumb-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}
.thumb-item{
  cursor:pointer;
  border:2px solid transparent;
  border-radius:4px;
  overflow:hidden;
  transition:border-color .15s;
  background:#222;
  aspect-ratio:1/1.414;
  position:relative;
}
.thumb-item:hover{border-color:#555}
.thumb-item.active{border-color:#c4956a}
.thumb-num{
  position:absolute;
  bottom:2px;right:4px;
  font-size:10px;
  color:#999;
  background:rgba(0,0,0,.6);
  padding:1px 4px;
  border-radius:2px;
}
.thumb-canvas{
  width:100%;
  height:100%;
  object-fit:cover;
}

/* TOC */
.toc-list{list-style:none}
.toc-item{
  padding:8px 10px;
  cursor:pointer;
  border-radius:4px;
  font-size:13px;
  color:#bbb;
  transition:background .15s;
  display:flex;
  align-items:center;
  gap:8px;
}
.toc-item:hover{background:#222}
.toc-section{
  font-family:'Cormorant Garamond',serif;
  font-weight:600;
  color:#c4956a;
  font-size:14px;
  padding:10px 10px 4px;
}
.toc-dot{
  width:8px;height:8px;
  border-radius:50%;
  flex-shrink:0;
}

/* Search */
.search-input{
  width:100%;
  padding:8px 10px;
  background:#222;
  border:1px solid #333;
  border-radius:6px;
  color:#ddd;
  font-size:13px;
  outline:none;
  margin-bottom:8px;
}
.search-input:focus{border-color:#c4956a}
.search-results{list-style:none}
.search-result{
  padding:8px 10px;
  cursor:pointer;
  border-radius:4px;
  font-size:12px;
  color:#aaa;
  transition:background .15s;
}
.search-result:hover{background:#222}
.search-result strong{color:#c4956a}

/* Bookmarks */
.bookmark-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px 10px;
  cursor:pointer;
  border-radius:4px;
  font-size:13px;
  color:#bbb;
  transition:background .15s;
}
.bookmark-item:hover{background:#222}
.bookmark-remove{
  background:none;border:none;
  color:#666;cursor:pointer;
  padding:2px;
}
.bookmark-remove:hover{color:#e44}
.bookmark-empty{
  text-align:center;
  color:#555;
  font-size:13px;
  padding:20px 10px;
}

/* ── Flipbook Wrapper ── */

#flipbook-wrapper{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  position:relative;
  padding:12px;
}

#zoom-container{
  transition:transform .3s ease;
  transform-origin:center center;
}

#flipbook{
  position:relative;
}

/* page-flip overrides */
.stf__parent{
  margin:0 auto;
}

/* ── Share Modal ── */

#modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.7);
  z-index:200;
  display:none;
}
#modal-overlay.open{display:block}

#modal-share{
  position:fixed;
  top:50%;left:50%;
  transform:translate(-50%,-50%);
  background:#1e1e1e;
  border:1px solid #333;
  border-radius:12px;
  padding:24px;
  width:90%;
  max-width:440px;
  z-index:201;
  display:none;
}
#modal-share.open{display:block}

.modal-title{
  font-family:'Cormorant Garamond',serif;
  font-size:20px;
  font-weight:600;
  color:#c4956a;
  margin-bottom:16px;
}

.share-section{margin-bottom:16px}
.share-label{
  font-size:12px;
  color:#888;
  margin-bottom:6px;
  text-transform:uppercase;
  letter-spacing:.5px;
}

.share-link-row{
  display:flex;
  gap:6px;
}
.share-link-input{
  flex:1;
  padding:8px 10px;
  background:#111;
  border:1px solid #333;
  border-radius:6px;
  color:#ddd;
  font-size:13px;
  outline:none;
}
.share-copy-btn{
  padding:8px 14px;
  background:#c4956a;
  color:#111;
  border:none;
  border-radius:6px;
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  transition:background .15s;
}
.share-copy-btn:hover{background:#d4a57a}

.share-social{
  display:flex;
  gap:8px;
}
.share-social-btn{
  flex:1;
  padding:10px;
  border:1px solid #333;
  border-radius:6px;
  background:transparent;
  color:#bbb;
  font-size:12px;
  cursor:pointer;
  text-align:center;
  transition:background .15s,color .15s;
}
.share-social-btn:hover{background:#2a2a2a;color:#fff}

.share-embed-area{
  width:100%;
  padding:8px 10px;
  background:#111;
  border:1px solid #333;
  border-radius:6px;
  color:#888;
  font-size:11px;
  font-family:monospace;
  resize:none;
  height:60px;
}

.modal-close{
  position:absolute;
  top:12px;right:12px;
  background:none;border:none;
  color:#666;cursor:pointer;
}
.modal-close:hover{color:#fff}

/* ── Autoplay indicator ── */

#autoplay-indicator{
  position:absolute;
  bottom:16px;left:50%;
  transform:translateX(-50%);
  background:rgba(0,0,0,.8);
  color:#c4956a;
  padding:6px 16px;
  border-radius:20px;
  font-size:12px;
  display:none;
  z-index:60;
}
#autoplay-indicator.visible{display:block}

/* ── Keyboard hints ── */

.kb-hint{
  position:fixed;
  bottom:16px;
  right:16px;
  background:rgba(0,0,0,.85);
  padding:12px 16px;
  border-radius:8px;
  font-size:11px;
  color:#888;
  line-height:1.8;
  z-index:300;
  display:none;
}
.kb-hint.open{display:block}
.kb-hint kbd{
  background:#333;
  padding:2px 6px;
  border-radius:3px;
  color:#ccc;
  font-family:inherit;
  font-size:11px;
}

/* ── Toast ── */

.toast{
  position:fixed;
  bottom:20px;
  left:50%;
  transform:translateX(-50%) translateY(60px);
  background:#333;
  color:#fff;
  padding:10px 20px;
  border-radius:8px;
  font-size:13px;
  z-index:400;
  opacity:0;
  transition:transform .3s,opacity .3s;
  pointer-events:none;
}
.toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

/* ── Responsive ── */

@media(max-width:768px){
  #toolbar{height:44px;padding:0 8px}
  .toolbar-left .brand{display:none}
  .tb-btn{width:32px;height:32px}
  .tb-btn svg{width:16px;height:16px}
  #page-slider{width:50px}
  .tb-sep{display:none}
  #sidebar{
    position:absolute;
    top:0;bottom:0;left:0;
    width:260px;
    z-index:90;
    box-shadow:4px 0 20px rgba(0,0,0,.5);
  }
  #flipbook-wrapper{padding:4px}
  #modal-share{padding:16px;width:95%}
  .toolbar-right .hide-mobile{display:none}
}

@media(max-width:480px){
  .toolbar-center #page-slider{display:none}
  .toolbar-right .hide-sm{display:none}
}

/* ── Fullscreen ── */

#app:fullscreen #toolbar,
#app:-webkit-full-screen #toolbar{
  background:rgba(17,17,17,.95);
}

/* ── Print ── */

@media print{
  #toolbar,#sidebar,#modal-overlay,#modal-share,
  #autoplay-indicator,.toast,.kb-hint{display:none!important}
  #main{display:block}
  #flipbook-wrapper{
    display:block;
    padding:0;
    overflow:visible;
  }
  .stf__parent{
    box-shadow:none!important;
  }
  .page{
    page-break-after:always;
    break-after:page;
  }
}

/* ── Scroll / Reader Mode ── */

#app.reader-mode #flipbook-wrapper{
  overflow-y:auto;
  align-items:flex-start;
}
#app.reader-mode #zoom-container{
  display:flex;
  flex-direction:column;
  gap:8px;
}
#app.reader-mode .stf__parent{
  display:none;
}
#app.reader-mode .reader-pages{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:12px;
  padding:20px;
}
#app.reader-mode .reader-page{
  width:min(600px,90vw);
  aspect-ratio:1/1.414;
  border-radius:4px;
  overflow:hidden;
  box-shadow:0 2px 12px rgba(0,0,0,.3);
}
