/* ============================================================
   FLIPBOOK VIEWER — CSS
   Design: Warm reading-room aesthetic
   ============================================================ */

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

:root {
  --bg:          #ffffff;
  --bg2:         #eeeeee;
  --toolbar-bg:  #f7f7f7;
  --toolbar-h:   52px;
  --thumb-h:     90px;
  --gold:        #ffc629;
  --gold-light:  #e8b96a;
  --text:        #000000;
  --text-muted:  #888888;
  --border:      rgba(201,147,58,0.18);
  --shadow-book: 0 30px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(201,147,58,0.08);
  --radius:      3px;
  --font-ui:     Arial, system-ui, sans-serif;
  --font-serif:  Arial, 'Helvetica', sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); }

#app {
  display: grid;
  grid-template-rows: var(--toolbar-h) 1fr var(--thumb-h);
  height: 100vh;
  font-family: var(--font-ui);
  color: var(--text);
}

/* ── TOOLBAR ─────────────────────────────────────────── */
#toolbar {
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  user-select: none;
}

.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-center { flex: 1; justify-content: center; overflow: hidden; }

#doc-title {
	display:none !important;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 400;
  font-style: italic;
  color: var(--gold-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
  letter-spacing: 0.01em;
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  text-decoration: none;
  flex-shrink: 0;
}

.tb-btn:hover {
  color: var(--gold);
  background: rgba(201,147,58,0.1);
  border-color: var(--border);
}

.tb-btn:active { transform: scale(0.93); }

#page-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  min-width: 68px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
#page-info .sep { opacity: 0.4; }
#page-current { color: var(--text); font-weight: 500; }

#zoom-level {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tb-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ── VIEWER ──────────────────────────────────────────── */
#viewer-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(201,147,58,0.04) 0%, transparent 70%),
    var(--bg);
}

/* Subtle grain */
#viewer-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

/* ── LOADING ─────────────────────────────────────────── */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 50;
}

/* Animated book loader */
.loader-book {
  position: relative;
  width: 64px;
  height: 48px;
}

.loader-book .page-l,
.loader-book .page-r {
  position: absolute;
  bottom: 0;
  width: 28px;
  height: 44px;
  border-radius: 2px 2px 0 0;
  animation: pageflip 1.6s ease-in-out infinite;
}

.loader-book .page-l {
  left: 4px;
  background: linear-gradient(135deg, #c9933a 0%, #8a6020 100%);
  transform-origin: right center;
  animation-delay: 0s;
}

.loader-book .page-r {
  right: 4px;
  background: linear-gradient(225deg, #c9933a 0%, #8a6020 100%);
  transform-origin: left center;
  animation-delay: 0.8s;
}

.loader-book .spine {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 44px;
  background: #6a4a18;
  border-radius: 1px;
}

@keyframes pageflip {
  0%, 40%   { transform: scaleX(1); }
  50%        { transform: scaleX(0.15); }
  60%, 100% { transform: scaleX(1); }
}

#loading-text {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--text-muted);
  font-size: 15px;
  letter-spacing: 0.02em;
}

#progress-bar-wrap {
  width: 200px;
  height: 2px;
  background: rgba(201,147,58,0.15);
  border-radius: 2px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── ERROR ───────────────────────────────────────────── */
#error-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
  z-index: 50;
}

.error-icon {
  font-size: 40px;
  line-height: 1;
  color: var(--gold);
  opacity: 0.7;
}

#error-panel h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 22px;
  color: var(--text);
}

#error-panel p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 440px;
  line-height: 1.6;
}

#error-hints {
  margin-top: 8px;
  padding: 14px 20px;
  background: rgba(201,147,58,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.8;
  max-width: 480px;
  text-align: left;
}

#error-hints code {
  font-family: 'Courier New', monospace;
  color: var(--gold-light);
  font-size: 12px;
}

/* ── STAGE & FLIPBOOK ────────────────────────────────── */
#stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  z-index: 10;
}

#zoom-wrap {
  transform-origin: center center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(var(--shadow-book));
}

#flipbook {
  /* StPageFlip injects its own sizing */
}

/* Pages rendered into the flipbook */
.flip-page {
  background: #fffef8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.flip-page canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* ── SIDE ARROWS ─────────────────────────────────────── */
.side-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  background: rgba(255,198,41,0.7);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 20;
  opacity: 0;
  backdrop-filter: blur(6px);
}

#viewer-wrap:hover .side-arrow { opacity: 1; }
.side-arrow:hover { color: #000; border-color: var(--gold); background: rgba(255,198,41,0.9); }
.side-arrow:active { transform: translateY(-50%) scale(0.92); }

#arrow-prev { left: 16px; }
#arrow-next { right: 16px; }

/* ── THUMBNAIL STRIP ─────────────────────────────────── */
#thumb-bar {
  background: var(--toolbar-bg);
  border-top: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
}

#thumb-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  height: 100%;
}

#thumb-strip::-webkit-scrollbar { height: 3px; }
#thumb-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.thumb-item {
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 2px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}

.thumb-item:hover { border-color: rgba(201,147,58,0.4); transform: translateY(-2px); }
.thumb-item.active { border-color: var(--gold); }

.thumb-item canvas {
  display: block;
  height: 64px;
  width: auto;
  image-rendering: -webkit-optimize-contrast;
}

.thumb-num {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5);
  padding: 0 3px;
  border-radius: 2px;
  line-height: 14px;
}

/* ── FULLSCREEN ──────────────────────────────────────── */
:fullscreen #app { height: 100vh; }
:fullscreen #thumb-bar { display: none; }
:fullscreen #app { grid-template-rows: var(--toolbar-h) 1fr 0; }

/* ── RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --thumb-h: 0px; }
  #thumb-bar { display: none; }
  #doc-title { max-width: 120px; font-size: 13px;}
  .side-arrow { opacity: 1; width: 36px; height: 36px; }
  #arrow-prev { left: 6px; }
  #arrow-next { right: 6px; }
}

/* ── PAGE FLIP OVERRIDES ─────────────────────────────── */
.stf__block { position: relative; }

/* ============================================================
   MOBILE SUPPORT — ajouts
   ============================================================ */

/* Safe area iOS (notch + home indicator) */
#app {
  height: calc(100vh - env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#toolbar {
  padding-left:  max(16px, env(safe-area-inset-left, 16px));
  padding-right: max(16px, env(safe-area-inset-right, 16px));
}

/* Cibles tactiles minimum 44px (recommandation Apple / WCAG) */
.tb-btn {
  width:  44px;
  height: 44px;
  -webkit-tap-highlight-color: transparent;
}

/* Empêcher la sélection de texte pendant le swipe */
#viewer-wrap, #stage, #zoom-wrap {
  -webkit-user-select: none;
  user-select: none;
}

/* Scroll fluide iOS dans la bande de vignettes */
#thumb-strip { -webkit-overflow-scrolling: touch; }

/* Supprimer le highlight tactile sur les éléments cliquables */
.side-arrow, .thumb-item {
  -webkit-tap-highlight-color: transparent;
}

/* ── MOBILE portrait (≤ 767px) ───────────────────────── */
@media (max-width: 767px) {
  :root {
    --toolbar-h: 48px;
    --thumb-h:   0px;
  }

  #app      { grid-template-rows: var(--toolbar-h) 1fr 0; }
  #thumb-bar { display: none; }

  /* Zoom CSS désactivé → pinch natif du navigateur */
  #btn-zoom-in,
  #btn-zoom-out,
  #zoom-level { display: none; }

  .tb-group.tb-right .tb-divider { display: none; }

  #doc-title { max-width: 130px; font-size: 13px; }

  /* Flèches toujours visibles sur tactile */
  .side-arrow {
    opacity: 1 !important;
    width: 40px;
    height: 40px;
  }

  #arrow-prev { left:  max(8px, env(safe-area-inset-left,  8px)); }
  #arrow-next { right: max(8px, env(safe-area-inset-right, 8px)); }
}

/* ── Paysage mobile (hauteur < 500px) ───────────────── */
@media (max-height: 500px) and (max-width: 900px) {
  :root { --toolbar-h: 40px; }

  #doc-title  { display: none; }
  .tb-divider { display: none; }

  .side-arrow { opacity: 1 !important; width: 36px; height: 36px; }
}
