/* ═══════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════ */
:root {
  --bg:          #0b0b0f;
  --bg-card:     #121218;
  --bg-viewer:   #13131a;
  --surface:     #1c1c26;
  --accent:      #b8902a;
  --accent-glow: rgba(184, 144, 42, 0.18);
  --accent-dim:  rgba(184, 144, 42, 0.55);
  --text-hi:     #ede8d8;
  --text-mid:    #9b9484;
  --text-lo:     #4a4640;
  --border:      rgba(184, 144, 42, 0.18);
  --border-focus:rgba(184, 144, 42, 0.65);
  --radius:      4px;
  --font-serif:  'Playfair Display', Georgia, serif;
  --font-sans:   'Inter', system-ui, sans-serif;
  --transition:  0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-hi);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Utility */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════
   NOISE TEXTURE OVERLAY
═══════════════════════════════════════════ */
.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 128px;
}

/* ═══════════════════════════════════════════
   CORNER ACCENTS
═══════════════════════════════════════════ */
.corner {
  position: fixed;
  width: 40px;
  height: 40px;
  opacity: 0.3;
  pointer-events: none;
  z-index: 1;
}
.corner::before,
.corner::after {
  content: '';
  position: absolute;
  background: var(--accent);
}
.corner::before { width: 1px; height: 100%; }
.corner::after  { width: 100%; height: 1px; }

.corner-tl { top: 24px; left: 24px; }
.corner-tl::before { left: 0; top: 0; }
.corner-tl::after  { left: 0; top: 0; }

.corner-tr { top: 24px; right: 24px; }
.corner-tr::before { right: 0; top: 0; }
.corner-tr::after  { right: 0; top: 0; }

.corner-bl { bottom: 24px; left: 24px; }
.corner-bl::before { left: 0; bottom: 0; }
.corner-bl::after  { left: 0; bottom: 0; }

.corner-br { bottom: 24px; right: 24px; }
.corner-br::before { right: 0; bottom: 0; }
.corner-br::after  { right: 0; bottom: 0; }


/* ═══════════════════════════════════════════
   LOCK SCREEN
═══════════════════════════════════════════ */
#lock-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* prevent iOS safe-area / virtual keyboard from pushing card off-center */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 40%, #16151f 0%, var(--bg) 70%);
  z-index: 100;
  transition: opacity var(--transition), transform var(--transition);
}

#lock-screen.fade-out {
  opacity: 0;
  transform: scale(1.03);
  pointer-events: none;
}

/* Card */
.lock-card {
  position: relative;
  z-index: 2;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  padding: 56px 48px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.02),
    0 24px 80px rgba(0,0,0,0.6),
    0 0 60px var(--accent-glow);
}

/* Brand block */
.brand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.brand-eyebrow {
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: clamp(24px, 5vw, 30px);
  font-weight: 500;
  color: var(--text-hi);
  letter-spacing: 0.01em;
}

.brand-rule {
  width: 40px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 4px 0;
}

.brand-subtitle {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-mid);
}

/* Auth form */
.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

.password-input {
  width: 100%;
  height: 52px;
  padding: 0 48px 0 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-family: var(--font-sans);
  font-size: 14px;
  letter-spacing: 0.1em;
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background var(--transition);
  caret-color: var(--accent);
  /* Mask characters visually without using type=password */
  -webkit-text-security: disc;
  text-security: disc;
}

.password-input::placeholder {
  color: var(--text-lo);
  letter-spacing: 0.05em;
  font-size: 13px;
}

.password-input:focus {
  border-color: var(--border-focus);
  background: #1e1e2a;
  box-shadow: 0 0 0 3px var(--accent-glow), 0 0 20px var(--accent-glow);
}

/* shake on error */
.input-wrapper.shake {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.input-wrapper.error .password-input {
  border-color: #c0392b55;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}

.input-icon {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-lo);
  pointer-events: none;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

.password-input:focus + .input-icon,
.password-input:not(:placeholder-shown) + .input-icon {
  color: var(--accent-dim);
}

/* error message */
.error-msg {
  font-size: 11.5px;
  color: #e07070;
  letter-spacing: 0.03em;
  text-align: center;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  height: 0;
  overflow: hidden;
}
.error-msg.visible {
  opacity: 1;
  transform: translateY(0);
  height: auto;
}

/* Unlock button */
.unlock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  background: linear-gradient(135deg, #b8902a 0%, #d4a83a 50%, #b8902a 100%);
  background-size: 200% 200%;
  border: none;
  border-radius: var(--radius);
  color: #0b0b0f;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-position var(--transition),
    box-shadow var(--transition),
    transform 0.15s ease;
  position: relative;
  overflow: hidden;
}

.unlock-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 60%);
  pointer-events: none;
}

.unlock-btn:hover {
  background-position: right center;
  box-shadow: 0 6px 28px rgba(184, 144, 42, 0.4);
  transform: translateY(-1px);
}
.unlock-btn:active {
  transform: translateY(0px);
  box-shadow: 0 2px 12px rgba(184, 144, 42, 0.3);
}

.btn-arrow { display: flex; align-items: center; opacity: 0.8; }


/* ═══════════════════════════════════════════
   LOADING OVERLAY
═══════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.4s ease;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-mid);
}


/* ═══════════════════════════════════════════
   READER SCREEN
═══════════════════════════════════════════ */
#reader-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-viewer);
  opacity: 0;
  transition: opacity 0.5s ease;
}

#reader-screen.visible {
  opacity: 1;
}

/* Header */
.reader-header {
  flex-shrink: 0;
  height: 48px;
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.reader-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mid);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  white-space: nowrap;
}
.reader-back-btn:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-glow);
}

.reader-title {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-hi);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

.reader-chapter {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--text-mid);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
  text-align: right;
}

/* Main reader area — dark stage that the book sits on */
.reader-main {
  flex: 1;
  min-height: 0;
  position: relative;   /* keeps tap zones and nav buttons inside this element */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  background: #0e0e14;
  overflow: visible;
}

/* epub.js viewer — looks like a physical book page */
#epub-viewer {
  display: block;
  flex-shrink: 0;
  background: #faf6ee;
  /* paper texture via subtle gradient */
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(255,250,235,0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(235,228,210,0.4) 0%, transparent 60%);
  /* book shadow: left spine shadow + bottom lift + ambient */
  box-shadow:
    -4px 0   8px rgba(0,0,0,0.15),
     4px 0  12px rgba(0,0,0,0.08),
     0  8px 24px rgba(0,0,0,0.4),
     0 24px 60px rgba(0,0,0,0.35),
     0  2px  4px rgba(0,0,0,0.3);
  border-radius: 1px 3px 3px 1px;
  overflow: hidden;
  /* thin right-page edge highlight */
  border-right: 1px solid rgba(255,255,255,0.15);
}


/* ═══════════════════════════════════════════
   NAVIGATION BUTTONS
═══════════════════════════════════════════ */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 120px;
  background: rgba(184, 144, 42, 0.13);
  border: none;
  border-radius: 8px;
  color: var(--accent-dim);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover  { opacity: 1; background: rgba(184, 144, 42, 0.25); color: var(--accent); }
.nav-btn:active { opacity: 1; background: rgba(184, 144, 42, 0.35); }

/* Just outside the book edges on desktop */
.nav-prev { left:  calc(50% - var(--book-half, 265px) - 38px); border-radius: 8px; }
.nav-next { right: calc(50% - var(--book-half, 265px) - 38px); border-radius: 8px; }

/* Hidden when navigation is unavailable */
.nav-btn.nav-hidden {
  opacity: 0;
  pointer-events: none;
}


/* ═══════════════════════════════════════════
   TOC BUTTON
═══════════════════════════════════════════ */
.toc-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mid);
  background: none;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  white-space: nowrap;
}
.toc-btn:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-glow);
}

/* ═══════════════════════════════════════════
   TOC PANEL
═══════════════════════════════════════════ */
.toc-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 88vw);
  z-index: 300;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
}
.toc-panel.open {
  transform: translateX(0);
}

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 299;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.toc-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toc-title {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}
.toc-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-mid);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.toc-close:hover {
  color: var(--text-hi);
  border-color: var(--text-lo);
}

.toc-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--surface) transparent;
}
.toc-nav::-webkit-scrollbar { width: 4px; }
.toc-nav::-webkit-scrollbar-track { background: transparent; }
.toc-nav::-webkit-scrollbar-thumb { background: var(--surface); border-radius: 2px; }

.toc-item {
  display: block;
  width: 100%;
  padding: 10px 24px;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-mid);
  cursor: pointer;
  transition: color var(--transition), background var(--transition), padding-left var(--transition);
  line-height: 1.4;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.toc-item:hover {
  color: var(--text-hi);
  background: var(--surface);
  padding-left: 28px;
}
.toc-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left: 2px solid var(--accent);
  padding-left: 22px;
}
/* Sub-items indented */
.toc-item.depth-1 { padding-left: 36px; font-size: 12px; }
.toc-item.depth-1:hover { padding-left: 40px; }
.toc-item.depth-1.active { padding-left: 34px; }

/* ═══════════════════════════════════════════
   READER FOOTER
═══════════════════════════════════════════ */
.reader-footer {
  flex-shrink: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.progress-track {
  flex: 1;
  height: 2px;
  background: var(--surface);
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #d4a83a);
  border-radius: 1px;
  transition: width 0.4s ease;
}

.page-info {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--text-lo);
  white-space: nowrap;
  min-width: 52px;
  text-align: right;
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: color 0.2s;
}
.page-info:hover { color: var(--accent-dim); }

/* ── Jump-to-page popup ── */
.jump-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
}
.jump-backdrop.visible { display: block; }

.jump-popup {
  position: fixed;
  bottom: 52px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  padding: 14px 16px 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.jump-popup.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.jump-label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mid);
  margin-bottom: 8px;
}
.jump-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.jump-input {
  width: 90px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-size: 13px;
  padding: 5px 8px;
  outline: none;
  -moz-appearance: textfield;
}
.jump-input::-webkit-outer-spin-button,
.jump-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.jump-input:focus { border-color: var(--border-focus); }
.jump-go {
  background: var(--accent);
  color: #0b0b0f;
  border: none;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 5px 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.jump-go:hover { opacity: 0.85; }




/* ═══════════════════════════════════════════
   BACK LINK & VERSION
═══════════════════════════════════════════ */
.back-link {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-lo);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 2px;
  transition: color var(--transition), border-color var(--transition);
}
.back-link:hover {
  color: var(--accent-dim);
  border-color: var(--border);
}

/* ═══════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════ */
@keyframes shake {
  10%, 90%  { transform: translateX(-2px); }
  20%, 80%  { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60%  { transform: translateX(6px); }
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lock-card {
  animation: fadeIn 0.6s ease both;
}


/* ═══════════════════════════════════════════
   RESPONSIVE — TABLET
═══════════════════════════════════════════ */
@media (max-width: 768px) {
  .lock-card {
    padding: 44px 32px;
    gap: 32px;
  }
  .reader-header {
    padding: 0 16px;
  }
  .reader-footer {
    padding: 0 16px;
  }
  .nav-prev { left:  calc(50% - var(--book-half, 340px) - 6px); }
  .nav-next { right: calc(50% - var(--book-half, 340px) - 6px); }
}

@media (max-width: 600px) {
  .nav-prev { left: 0; border-radius: 0 8px 8px 0; }
  .nav-next { right: 0; border-radius: 8px 0 0 8px; }
}

@media (max-width: 480px) {
  .lock-card {
    padding: 40px 24px;
    gap: 28px;
  }
  .corner { width: 24px; height: 24px; }
  .corner-tl, .corner-tr, .corner-bl, .corner-br { top: 16px; }
  .corner-bl, .corner-br { top: auto; bottom: 16px; }
  .corner-tl, .corner-bl { left: 16px; }
  .corner-tr, .corner-br { right: 16px; }
}
