/* includes/reader/epub-reader.css */

:root{
  --er-bg: #ffffff;
  --er-text: #111111;
  --er-muted: rgba(0,0,0,0.58);
  --er-border: rgba(0,0,0,0.10);
  --er-card: rgba(255,255,255,0.92);
  --er-shadow: 0 18px 60px rgba(0,0,0,0.18);
  --er-accent: #232538;
  --er-accent-2: rgba(35,37,56,0.12);
}

.epub-reader{
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  background: var(--er-bg);
  color: var(--er-text);
  overflow: hidden;
}

.epub-reader.is-open{ display: block; }
.epub-reader *{ box-sizing: border-box; }

/* =========================
   THEME CLASSES
   ========================= */
.epub-reader[data-theme="light"]{
  --er-bg: #ffffff;
  --er-text: #111111;
  --er-muted: rgba(0,0,0,0.58);
  --er-border: rgba(0,0,0,0.10);
  --er-card: rgba(255,255,255,0.92);
  --er-shadow: 0 18px 60px rgba(0,0,0,0.18);
  --er-accent: #232538;
  --er-accent-2: rgba(35,37,56,0.12);
}

.epub-reader[data-theme="sepia"]{
  --er-bg: #fbf1d3;
  --er-text: #2a241b;
  --er-muted: rgba(42,36,27,0.60);
  --er-border: rgba(42,36,27,0.14);
  --er-card: rgba(251,241,211,0.92);
  --er-shadow: 0 18px 60px rgba(0,0,0,0.18);
  --er-accent: #6a4a2a;
  --er-accent-2: rgba(106,74,42,0.14);
}

.epub-reader[data-theme="dark"]{
  --er-bg: #0b0f14;
  --er-text: #e9eef5;
  --er-muted: rgba(233,238,245,0.62);
  --er-border: rgba(233,238,245,0.14);
  --er-card: rgba(11,15,20,0.92);
  --er-shadow: 0 18px 60px rgba(0,0,0,0.55);
  --er-accent: #8ab4f8;
  --er-accent-2: rgba(138,180,248,0.14);
}

/* =========================
   TOOLBAR
   ========================= */
.epub-toolbar{
  position: relative;
  z-index: 20;
  height: 64px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--er-card);
  border-bottom: 1px solid var(--er-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--er-shadow);
}

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

.epub-backbtn{
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--er-border);
  background: transparent;
  color: var(--er-text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}

.epub-backbtn:active{ transform: scale(0.98); }

.epub-backbtn svg{
  width: 18px;
  height: 18px;
}

.epub-title-wrap{
  display:flex;
  flex-direction: column;
  min-width: 0;
}

.epub-title{
  font-weight: 900;
  letter-spacing: -0.2px;
  font-size: 14.5px;
  line-height: 1.1;
  max-width: min(58vw, 520px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.epub-author{
  font-size: 12px;
  color: var(--er-muted);
  margin-top: 4px;
  max-width: min(58vw, 520px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.epub-toolbar-right{
  display:flex;
  align-items:center;
  gap: 10px;
  flex: 0 0 auto;
}

/* =========================
   THEME DROPDOWN
   ========================= */
.epub-theme-dropdown{ position: relative; }

#jsThemeTrigger{
  height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--er-border);
  background: transparent;
  color: var(--er-text);
  font-weight: 900;
  cursor: pointer;
  display:flex;
  align-items:center;
  gap: 8px;
}

#jsThemeTrigger:active{ transform: scale(0.99); }

.epub-theme-current-icon{
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.epub-theme-current-icon svg{
  width: 16px;
  height: 16px;
}

#jsThemeMenu{
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 160px;
  background: var(--er-card);
  border: 1px solid var(--er-border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--er-shadow);
  display: none;
}

#jsThemeMenu.is-open{ display:block; }

.epub-theme-btn{
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  text-align:left;
  cursor:pointer;
  color: var(--er-text);
  font-weight: 850;
  font-size: 13px;
}

.epub-theme-btn:hover{ background: var(--er-accent-2); }

/* =========================
   EPUB HEADER WRAPPER (toolbar + progress)
   ========================= */
.epub-header{
  position: relative;
  z-index: 20;
  transition: transform 0.32s ease, opacity 0.28s ease;
  will-change: transform;
}

.epub-reader.is-immersive .epub-header{
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* =========================
   PROGRESS
   ========================= */
.epub-progressline{
  height: 4px;
  background: rgba(0,0,0,0.08);
  position: relative;
  z-index: 21;
  overflow: visible;
}

.epub-reader[data-theme="dark"] .epub-progressline{
  background: rgba(255,255,255,0.12);
}

#epubProgressFill{
  height: 100%;
  width: 0%;
  background: var(--er-accent);
  transition: width 160ms linear;
}

.epub-percent-badge{
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  height: 26px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--er-border);
  background: var(--er-card);
  color: var(--er-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  white-space: nowrap;
  pointer-events: none;
}

/* =========================
   VIEW
   ========================= */
.epub-view-wrap{
  position: absolute;
  left: 0;
  right: 0;
  top: 68px;
  bottom: 70px;
  background: var(--er-bg);
  transition: top 0.32s ease, bottom 0.32s ease;
}

.epub-reader.is-immersive .epub-view-wrap{
  top: 0;
  bottom: 0;
}

#epubView{
  position: absolute;
  inset: 0;
  z-index: 3;
}

/* tap zones */
.epub-tap-zone{
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  z-index: 6;
}

.epub-tap-left{ left: 0; }
.epub-tap-right{ right: 0; }
.epub-tap-center{ left: 30%; width: 40%; }

/* =========================
   BOTTOM CONTROLS
   ========================= */
.epub-bottom-controls{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 70px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 12px;
  background: var(--er-card);
  border-top: 1px solid var(--er-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--er-shadow);
  z-index: 20;
  transition: transform 0.32s ease, opacity 0.28s ease;
  will-change: transform;
}

.epub-reader.is-immersive .epub-bottom-controls{
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.epub-bottom-center{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 12px;
}

.epub-bottom-btn{
  height: 44px;
  min-width: 44px;
  border-radius: 14px;
  border: 1px solid var(--er-border);
  background: transparent;
  color: var(--er-text);
  font-weight: 900;
  cursor: pointer;
  padding: 0 14px;
}

.epub-bottom-btn:active{
  transform: scale(0.98);
}

.epub-bottom-btn--prev{
  justify-self: start;
}

.epub-bottom-btn--next{
  justify-self: end;
}

/* =========================
   LOADER
   ========================= */
.epub-loader{
  position: absolute;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.22);
  display:flex;
  flex-direction: column;
  align-items:center;
  justify-content:center;
  gap: 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.epub-reader[data-theme="dark"] .epub-loader{
  background: rgba(0,0,0,0.42);
}

.epub-loader-spinner{
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.35);
  border-top-color: rgba(255,255,255,0.95);
  animation: spin 0.9s linear infinite;
}

.epub-reader[data-theme="light"] .epub-loader-spinner,
.epub-reader[data-theme="sepia"] .epub-loader-spinner{
  border: 3px solid rgba(0,0,0,0.18);
  border-top-color: rgba(0,0,0,0.75);
}

#epubLoaderText{
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  text-align:center;
}

.epub-reader[data-theme="light"] #epubLoaderText,
.epub-reader[data-theme="sepia"] #epubLoaderText{
  color: rgba(0,0,0,0.78);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* =========================
   ONBOARDING
   ========================= */

.epub-onboarding{
  position: absolute;
  inset: 0;
  z-index: 70;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

.epub-onb-card{
  width: 100%;
  max-width: 360px;
  background: #1c1e22;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 24px;
  overflow: hidden;
  color: #fff;
  padding: 24px 20px 20px;
  animation: epubOnbCardIn 0.38s cubic-bezier(0.34,1.2,0.64,1) both;
}

.epub-onb-heading{
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  text-align: center;
  margin: 0 0 20px;
}

/* ── Gesture zone — 3 columns ── */
.epub-onb-zones{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 0;
  padding: 0 0 20px;
}

.epub-onb-zone{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

/* Center zone with separators */
.epub-onb-zone--center{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-left: 1px solid rgba(255,255,255,0.08);
  border-right: 1px solid rgba(255,255,255,0.08);
}

/* Animated hand */
.epub-onb-hand{
  width: 64px;
  height: 64px;
  position: relative;
  flex-shrink: 0;
  color: rgba(255,255,255,0.92);
}
.epub-onb-hand svg{
  width: 100%;
  height: 100%;
  overflow: visible;
}

.epub-onb-ripple{
  fill: none;
  stroke: #9BE368;
  stroke-width: 2;
  opacity: 0;
  transform-origin: center;
}
.epub-onb-ripple--1{ animation: epubRipple 2s ease-out 0.1s infinite; }
.epub-onb-ripple--2{ animation: epubRipple 2s ease-out 0.6s infinite; }

/* Left hand taps left */
.epub-onb-hand--left .epub-onb-hand-shape{
  animation: epubHandTapLeft 2s ease-in-out infinite;
  transform-origin: 32px 36px;
}

/* Right hand taps right */
.epub-onb-hand--right .epub-onb-hand-shape{
  animation: epubHandTapRight 2s ease-in-out infinite;
  transform-origin: 32px 36px;
}

/* Center pulsing icon */
.epub-onb-center-icon{
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.epub-onb-center-icon svg{
  width: 100%;
  height: 100%;
  overflow: visible;
}
.epub-onb-center-ring--1{ animation: epubCenterPulse 2s ease-out 0s infinite; }
.epub-onb-center-ring--2{ animation: epubCenterPulse 2s ease-out 0.55s infinite; }

.epub-onb-zone-name{
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  text-align: center;
  line-height: 1.2;
}
.epub-onb-zone-hint{
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  text-align: center;
  line-height: 1.3;
}

/* Checkbox row */
.epub-onb-checkbox{
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  margin-bottom: 14px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.epub-onb-checkbox input[type="checkbox"]{
  width: 16px;
  height: 16px;
  accent-color: #9BE368;
  flex-shrink: 0;
  cursor: pointer;
}

/* Button */
.epub-onb-btn{
  width: 100%;
  height: 48px;
  border-radius: 14px;
  border: none;
  background: #9BE368;
  color: #0c1a06;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.epub-onb-btn:active{ opacity: 0.85; transform: scale(0.98); }

@keyframes epubOnbCardIn{
  from{ opacity:0; transform: scale(0.9) translateY(12px); }
  to  { opacity:1; transform: scale(1)   translateY(0);    }
}

@keyframes epubHandTapLeft{
  0%,100%{ transform: translateX(0) scale(1); }
  20%{ transform: translateX(-6px) scale(.985); }
  30%{ transform: translateX(-10px) scale(.97); }
  42%{ transform: translateX(-2px) scale(1); }
}

@keyframes epubHandTapRight{
  0%,100%{ transform: translateX(0) scale(1); }
  20%{ transform: translateX(6px) scale(.985); }
  30%{ transform: translateX(10px) scale(.97); }
  42%{ transform: translateX(2px) scale(1); }
}

@keyframes epubRipple{
  0%{ opacity:0; transform:scale(.65); }
  18%{ opacity:.95; }
  55%{ opacity:.3; }
  100%{ opacity:0; transform:scale(1.9); }
}

@keyframes epubCenterPulse{
  0%{ opacity:0; transform:scale(0.5); }
  25%{ opacity:0.9; }
  100%{ opacity:0; transform:scale(1.6); }
}

