:root {
  --bg: #f5f0eb;
  --text: #1f2937;
  --overlay-bg: rgba(0,0,0,0.7);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  height: 100vh;
  height: 100dvh;   /* iOS: dynamic viewport keeps the controls above the address bar */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.viewer-header {
  padding: 10px 32px 6px;
  text-align: center;
  flex-shrink: 0;
}
.viewer-header h1 { font-size: 18px; font-weight: 700; color: var(--text); }
.viewer-header p { font-size: 13px; color: #6b7280; margin-top: 2px; }

/* Flipbook area */
.viewer-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  position: relative;
}

#flipbook-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: visible;
  transition: margin-left 0.4s ease;
  pointer-events: none;
}
#flipbook,
#pan-overlay {
  pointer-events: auto;
}

/* Allow page-flip animation to extend outside the book boundary */
.stf__parent {
  overflow: visible !important;
}

/* HTML-mode flipbook pages */
.fb-page {
  background: #fff;
  overflow: hidden;
}
.fb-page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  -webkit-user-drag: none;
  user-select: none;
}

/* Controls bar */
.viewer-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 26px;
  margin-top: 2px;
  justify-content: center;
}
/* Icon-only, no boxes: light-blue idle, brand-blue on hover/active */
.ctrl-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #81ABFF;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover, .ctrl-btn:active { color: #0000ff; transform: scale(1.08); }
.ctrl-btn svg { width: 34px; height: 34px; display: block; }
.ctrl-btn:disabled { color: #c3d3f7; cursor: default; transform: none; }
.page-num {
  font-size: 14px;
  font-weight: 600;
  color: #81ABFF;
  min-width: 60px;
  text-align: center;
  letter-spacing: 0.3px;
}

/* Watermark */
.watermark {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  right: 18px;
  pointer-events: none;
  z-index: 10;
}
.watermark img { display: block; max-width: 150px; max-height: 100px; object-fit: contain; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.overlay-box {
  background: white;
  border-radius: 16px;
  padding: 40px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
}
.overlay-box h2 { margin-bottom: 8px; }
.overlay-box p { color: #6b7280; font-size: 14px; margin-bottom: 20px; }
.overlay-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 2px;
}
.overlay-box button {
  width: 100%;
  padding: 11px;
  background: #4f46e5;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
}
.overlay-box button:hover { background: #4338ca; }
.overlay-error { color: #ef4444; font-size: 13px; margin-top: 8px; }
.overlay-icon { font-size: 48px; margin-bottom: 16px; }

/* Loading spinner */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(79,70,229,0.2);
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fullscreen */
:fullscreen body { background: var(--bg); }
:-webkit-full-screen body { background: var(--bg); }

/* Stage holds the flipbook + cover overlay, centered, above the controls */
#stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Single-page cover/back cover overlay (sits on top of the flipbook) */
#cover-view {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
  perspective: 1800px;
}
#cover-img {
  display: block;
  max-width: 100%;
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  backface-visibility: hidden;
  will-change: transform;
}

/* Embed mode tweaks */
body.embed-mode .viewer-header { display: none; }
body.embed-mode .viewer-controls { margin-top: 8px; }

/* Page flip canvas fix */
.stf__parent { margin: 0 auto; }
