:root{
  --bg-1: #cfd3d8;
  --bg-2: #9aa1ab;
  --bg-3: #eef0f2;
  --accent: #2f6d4f;
  --accent-dim: rgba(47,109,79,0.28);
  --ui-glass: rgba(255,255,255,0.55);
  --ui-glass-border: rgba(20,25,30,0.10);
  --ui-text: #1d2226;
  --ui-text-dim: rgba(29,34,38,0.55);
  font-size: 16px;
}

*{ box-sizing: border-box; }

html,body{
  margin:0;
  padding:0;
  height:100%;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--bg-3) 0%, var(--bg-1) 55%, var(--bg-2) 100%);
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ui-text);
  overflow: hidden;
}

.stage{
  height:100%;
  width:100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap: 18px;
  padding: 18px 12px;
  position:relative;
}

/* ---------- Bottom Bar Navigation ---------- */

.bottom-bar{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(12px, 2.5vw, 32px);
  position: relative;
  z-index: 30;
  flex: none;
  pointer-events: none;
}

.bottom-bar > *{
  pointer-events: auto;
}

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

.brand-title{
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ui-text);
  letter-spacing: 0.02em;
  opacity: 0.88;
  background: var(--ui-glass);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--ui-glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(20,25,30,0.06);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-full{ display: inline; }
.brand-short{ display: none; }

.bottom-center-group{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.download-wrap{
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex: 1 1 0;
}

/* ---------- Download Button & Icon Animation ---------- */

.download-btn{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 14px;
  background: var(--ui-glass);
  border: 1px solid var(--ui-glass-border);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ui-text);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(20,25,30,0.08);
  transition: background 0.22s ease, border-color 0.22s ease, color 0.22s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.22s ease;
  pointer-events: auto;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.download-btn:hover{
  background: #ffffff;
  border-color: rgba(47,109,79,0.38);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(47,109,79,0.18);
}

.download-btn:active{
  transform: translateY(0) scale(0.96);
}

.download-btn:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.download-icon-wrap{
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: inherit;
}

.download-icon{
  width: 18px;
  height: 18px;
  display: block;
}

/* Subtle idle bounce */
.arrow-group{
  transform-origin: center top;
  animation: arrowIdle 2.4s ease-in-out infinite;
}

@keyframes arrowIdle{
  0%, 100%{ transform: translateY(0); }
  50%{ transform: translateY(2.5px); }
}

/* Hover drop loop animation effect */
.download-btn:hover .arrow-group{
  animation: arrowDrop 0.82s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes arrowDrop{
  0%{ transform: translateY(0); opacity: 1; }
  44%{ transform: translateY(6px); opacity: 0; }
  45%{ transform: translateY(-6px); opacity: 0; }
  72%{ transform: translateY(0); opacity: 1; }
  100%{ transform: translateY(0); opacity: 1; }
}

.download-btn:hover .tray-line{
  animation: trayBounce 0.82s ease infinite;
}

@keyframes trayBounce{
  0%, 100%{ transform: translateY(0) scaleX(1); }
  48%{ transform: translateY(1.5px) scaleX(1.1); }
}

.tray-line{
  transform-origin: center bottom;
  transition: transform 0.2s ease;
}

.download-text{
  font-weight: 500;
  letter-spacing: 0.01em;
}

.download-tag{
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--accent);
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.download-btn:hover .download-tag{
  background: #23593f;
}



.loader{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap: 18px;
  background: linear-gradient(180deg, var(--bg-3), var(--bg-1));
  z-index: 9999;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.loader.is-hidden{
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
.loader p{ margin:0; font-size:0.85rem; color: var(--ui-text-dim); letter-spacing:0.02em; }
.loader-book{ display:flex; gap:4px; }
.loader-page{
  width:14px; height:38px;
  background: linear-gradient(180deg, #fff, #dfe2e5);
  border-radius: 2px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  animation: loaderFlip 1.1s ease-in-out infinite;
  transform-origin: left center;
}
.loader-page:nth-child(2){ animation-delay: 0.15s; }
.loader-page:nth-child(3){ animation-delay: 0.3s; }
@keyframes loaderFlip{
  0%, 100%{ transform: rotateY(0deg); }
  50%{ transform: rotateY(-140deg); }
}

/* ---------- Book ---------- */

.book-wrap{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: clamp(8px, 2.6vw, 30px);
  width:100%;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  z-index: 5;
}

.book-container{
  position:relative;
  width: min(calc(100vw - 120px), 1800px, calc((100vh - 100px) * 20 / 7));
  aspect-ratio: 20 / 7;
  max-height: calc(100vh - 100px);
  filter: drop-shadow(0 24px 40px rgba(20,25,30,0.28));
  cursor: zoom-in;
  transition: width 0.15s ease, max-height 0.15s ease;
}

/* ---------- 1-Page High-Resolution Reading View ---------- */

.single-page-view{
  position: relative;
  width: min(calc(100vw - 120px), 1250px, calc((100vh - 100px) * 10 / 7));
  aspect-ratio: 10 / 7;
  max-height: calc(100vh - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 24px 44px rgba(20,25,30,0.32));
  cursor: zoom-in;
  border-radius: 4px;
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
  transition: width 0.15s ease, max-height 0.15s ease;
}

.single-page-img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  image-rendering: auto;
  image-rendering: high-quality;
  background: #ffffff;
}

.book-container::before{
  content:'';
  position:absolute;
  left: 8%;
  right: 8%;
  bottom: -16px;
  height: 28px;
  background: radial-gradient(closest-side, rgba(20,25,30,0.35), rgba(20,25,30,0));
  filter: blur(8px);
  z-index: 0;
}

/* page-flip.js draws into canvas/DOM children it creates inside this element */
.book-container .stf__parent{
  margin: 0 auto;
}

.stf__wrapper{
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

.page-img{
  width:100%;
  height:100%;
  object-fit: cover;
  display:block;
  -webkit-user-drag: none;
  user-select: none;
}

.page-face{
  width:100%;
  height:100%;
  background: #fdfdfb;
  display:flex;
  align-items:center;
  justify-content:center;
  color: rgba(0,0,0,0.28);
  font-size: 0.8rem;
}

/* ---------- Edge nav buttons ---------- */

.edge-btn{
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--ui-glass-border);
  background: var(--ui-glass);
  color: var(--ui-text);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(20,25,30,0.12);
  transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
  z-index: 25;
}
.edge-btn:hover{
  background: #ffffff;
  border-color: var(--accent-dim);
}
.edge-btn:active{ transform: scale(0.93); }
.edge-btn:disabled{
  opacity: 0.28;
  cursor: default;
  pointer-events: none;
}
.edge-btn:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- HUD ---------- */

.hud{
  display:flex;
  align-items:center;
  gap: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--ui-glass);
  border: 1px solid var(--ui-glass-border);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(20,25,30,0.10);
  flex: none;
  z-index: 30;
}

.hud-btn{
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ui-text-dim);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.hud-btn:hover{ color: var(--ui-text); background: rgba(20,25,30,0.07); }
.hud-btn:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }

.hud-btn--zoom-level{
  width: auto;
  min-width: 44px;
  height: 26px;
  padding: 0 6px;
  font-size: 0.74rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-radius: 6px;
  background: rgba(20,25,30,0.06);
}
.hud-btn--zoom-level:hover{
  background: rgba(20,25,30,0.12);
}

.page-indicator{
  font-size: 0.82rem;
  color: var(--ui-text-dim);
  min-width: 52px;
  text-align:center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.page-indicator .sep{ margin: 0 3px; opacity: 0.5; }
.page-indicator #pageNum{ color: var(--ui-text); font-weight: 500; }

.progress-track{
  position:relative;
  width: clamp(120px, 26vw, 260px);
  height: 4px;
  border-radius: 4px;
  background: rgba(20,25,30,0.14);
  cursor: pointer;
}
.progress-fill{
  position:absolute;
  left:0; top:0; bottom:0;
  width: 0%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.progress-handle{
  position:absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  transform: translate(-50%, -50%);
  transition: left 0.25s ease;
}

.hint{
  font-size: 0.76rem;
  color: var(--ui-text-dim);
  letter-spacing: 0.01em;
  margin: 0;
  flex: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 700px){
  .edge-btn{ width: 36px; height: 36px; }
  .hint{ display:none; }
  .hud{ gap: 10px; padding: 8px 12px; }
  .progress-track{ width: clamp(80px, 28vw, 150px); }
}

@media (max-width: 480px){
  .book-wrap{ gap: 6px; }
}

@media (max-height: 480px){
  .hint{ display:none; }
  .book-container{ max-height: 78vh; }
}

/* Fullscreen mode: uses full screen resolution */
.stage:fullscreen,
.stage:-webkit-full-screen{
  padding: 8px 16px 14px 16px;
  gap: 8px;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--bg-3) 0%, var(--bg-1) 55%, var(--bg-2) 100%);
}

.stage:fullscreen .book-wrap,
.stage:-webkit-full-screen .book-wrap{
  gap: 12px;
  width: 100%;
  flex: 1 1 auto;
}

.stage:fullscreen .book-container,
.stage:-webkit-full-screen .book-container{
  width: min(calc(100vw - 100px), calc((100vh - 78px) * 20 / 7));
  max-height: calc(100vh - 78px);
}

.stage:fullscreen .single-page-view,
.stage:-webkit-full-screen .single-page-view{
  width: min(calc(100vw - 100px), calc((100vh - 78px) * 10 / 7));
  max-height: calc(100vh - 78px);
}

/* ---------- High-Resolution Zoom & Pan Overlay ---------- */

.zoom-overlay{
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 22, 26, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.zoom-overlay.is-active{
  opacity: 1;
  pointer-events: auto;
}

.zoom-viewport{
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.zoom-viewport.is-dragging{
  cursor: grabbing;
}

.zoom-canvas{
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  transform-origin: center center;
  transition: transform 0.08s cubic-bezier(0.1, 0.8, 0.2, 1);
}

.zoom-canvas.is-dragging{
  transition: none;
}

.zoom-img{
  display: block;
  max-width: none;
  max-height: none;
  height: min(88vh, 1050px);
  width: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  background: #ffffff;
  image-rendering: auto;
  image-rendering: high-quality;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.38);
}

.zoom-img--left{
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.zoom-img--right{
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.zoom-close-btn{
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--ui-glass-border);
  background: var(--ui-glass);
  color: var(--ui-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: background 0.18s ease, transform 0.15s ease;
  z-index: 35;
}

.zoom-close-btn:hover{
  background: #ffffff;
  transform: scale(1.06);
}

.zoom-close-btn:active{
  transform: scale(0.94);
}

@media (max-width: 1280px){
  .brand-full{ display: none; }
  .brand-short{ display: inline; }
}

@media (max-width: 960px){
  .brand{ display: none; }
  .bottom-bar{ justify-content: center; }
  .download-wrap{ position: absolute; right: clamp(12px, 2.5vw, 24px); bottom: 0; }
}

@media (max-width: 700px){
  .zoom-close-btn{
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }
  .download-btn{ padding: 7px 11px; font-size: 0.78rem; gap: 6px; }
  .download-text{ display: none; }
}

@media (max-width: 440px){
  .download-btn{ padding: 6px 10px; }
}

/* ---------- Active HUD Button States ---------- */

.hud-btn.is-active{
  background: var(--accent);
  color: #ffffff;
}
.hud-btn.is-active:hover{
  background: #23593f;
  color: #ffffff;
}

/* ---------- Text Reader Modal / Drawer ---------- */

.text-modal-backdrop{
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 24, 30, 0.68);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
  padding: 16px;
}

.text-modal-backdrop.is-active{
  opacity: 1;
  pointer-events: auto;
}

.text-modal-card{
  background: #ffffff;
  color: #1a2026;
  border-radius: 16px;
  width: 100%;
  max-width: 760px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 28px 64px rgba(10, 16, 22, 0.4);
  transform: translateY(12px) scale(0.98);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.text-modal-backdrop.is-active .text-modal-card{
  transform: translateY(0) scale(1);
}

.text-modal-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid rgba(20, 25, 30, 0.08);
  background: #f8fafb;
}

.text-modal-title-group{
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.text-modal-badge{
  align-self: flex-start;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 4px;
}

.text-modal-title{
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a2228;
}

.text-modal-actions{
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-size-btn{
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  background: #eef2f5;
  border: 1px solid rgba(20, 25, 30, 0.1);
  color: #2c353d;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.text-size-btn:hover{
  background: #dfe5eb;
  color: #000;
}

.text-modal-close{
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eef2f5;
  border: 1px solid rgba(20, 25, 30, 0.1);
  color: #2c353d;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.text-modal-close:hover{
  background: #e0e5eb;
  transform: scale(1.05);
}

.text-modal-body{
  padding: 26px 30px;
  overflow-y: auto;
  line-height: 1.78;
  font-size: var(--modal-font-size, 0.98rem);
  color: #2a3138;
}

.text-modal-body p{
  margin: 0 0 16px 0;
}

.text-modal-body p:last-child{
  margin-bottom: 0;
}

.text-modal-body strong{
  color: #11161b;
  font-weight: 600;
}

.text-modal-body .quote-callout{
  background: #edf5f0;
  border-left: 4px solid var(--accent);
  padding: 12px 18px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
  font-style: italic;
  color: #1a422d;
}

.text-modal-body .signature-block{
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(20, 25, 30, 0.08);
  font-weight: 500;
  color: #1f272e;
}
