:root {
  --bg: #eff5f0;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #3ac628;
  --accent-dark: #1d8e2a;
  --shadow: 0 18px 45px rgba(17, 24, 39, 0.12);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #f5faf5 0%, #e6f1e5 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell {
  width: min(1400px, calc(100% - 32px));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 18px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.7vw, 2.3rem);
  line-height: 1.1;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.controls {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.select-wrap,
.viewer-toolbar,
.mobile-tip,
.viewer-status,
#issueTitle,
#pageInfo {
  display: none !important;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #d2d6dc;
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.06);
}

.btn:active {
  transform: translateY(0);
}

#fullscreenBtn {
  width: auto;
  white-space: nowrap;
}

.viewer-card {
  flex: 1;
  min-height: 0;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(229, 231, 235, 0.95);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
}

.book-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background:
    radial-gradient(circle at top left, rgba(198, 40, 40, 0.08), transparent 30%),
    linear-gradient(180deg, #daefe2 0%, #d2e8d6 100%);
  padding: 10px;
  overflow: hidden;
}

#book {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#book [class^="stf__"],
#book [class*=" stf__"] {
  background: transparent !important;
  box-shadow: none !important;
}

.page {
  position: relative;
  background: transparent;
  overflow: hidden;
  user-select: none;
}

.page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center center;
  user-select: none;
  -webkit-user-drag: none;
  background: transparent;
}


.blank-page {
  background:
    radial-gradient(circle at top left, rgba(198, 40, 40, 0.08), transparent 30%),
    linear-gradient(180deg, #daefe2 0%, #d2e8d6 100%) !important;
}

.blank-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(198, 40, 40, 0.08), transparent 30%),
    linear-gradient(180deg, #daefe2 0%, #d2e8d6 100%);
}

.blank-page > * {
  display: none !important;
}

.page.cover-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.08);
}

.page.cover-page img {
  border-radius: 14px;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
  font-weight: 600;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.38);
  backdrop-filter: blur(2px);
}

.zoom-overlay {
  position: absolute;
  inset: 10px;
  z-index: 20;
  display: none;
  overflow: hidden;
  border-radius: 18px;
  cursor: zoom-out;
  background:
    radial-gradient(circle at top left, rgba(198, 40, 40, 0.08), transparent 30%),
    linear-gradient(180deg, #daefe2 0%, #d2e8d6 100%);
}

.zoom-overlay.active {
  display: block;
}

.book-shell.zoom-active #book {
  pointer-events: none;
}

.zoom-image {
  position: absolute;
  left: 50%;
  top: 50%;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.zoom-hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(17, 24, 39, 0.08);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.zoom-mobile-nav {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 3;
  gap: 10px;
}

.zoom-nav-btn {
  min-width: 52px;
  min-height: 44px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #0f172a;
  font-size: 1.1rem;
  font-weight: 700;
  backdrop-filter: blur(4px);
}

.zoom-overlay.is-touching {
  cursor: grab;
}

.zoom-overlay.is-touching:active {
  cursor: grabbing;
}

.fullscreen-mode {
  overflow: hidden;
}

.fullscreen-mode .app-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 12px;
}

.fullscreen-mode .viewer-card {
  border-radius: 20px;
}

@media (pointer: coarse), (max-width: 980px) {
  .zoom-mobile-nav {
    display: flex;
  }

  .zoom-hint {
    right: 50%;
    transform: translateX(50%);
    bottom: 70px;
    text-align: center;
    max-width: calc(100% - 24px);
  }
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100%, calc(100% - 16px));
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .topbar {
    align-items: center;
    gap: 12px;
  }

  .viewer-card {
    padding: 8px;
    border-radius: 18px;
  }

  .book-shell {
    padding: 8px;
  }
}

@media (max-width: 640px) {
  .eyebrow {
    margin-bottom: 4px;
  }

  h1 {
    font-size: clamp(1.25rem, 6vw, 1.8rem);
  }

  .btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.92rem;
  }

  #fullscreenBtn {
    align-self: flex-start;
  }
}

/* Correctif mobile/tablette : page simple sans double-page StPageFlip */
#book.flat-book {
  display: grid;
  place-items: center;
  max-width: 100%;
  max-height: 100%;
  touch-action: manipulation;
}

#book.flat-book .flat-page {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.16);
}

#book.flat-book .flat-page img {
  border-radius: 14px;
}

.zoom-overlay.active {
  touch-action: none;
}

.zoom-mobile-nav,
.zoom-nav-btn {
  pointer-events: auto;
  touch-action: manipulation;
}

.zoom-nav-btn {
  cursor: pointer;
}

@media (pointer: coarse), (max-width: 1099px) {
  .zoom-mobile-nav {
    display: flex;
  }
}

/* Support PDF.js : canvas + texte sélectionnable + liens cliquables */
.page.pdf-page {
  background: #ffffff;
  user-select: text;
  -webkit-user-select: text;
}

.page.pdf-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.08);
}

.pdf-page-content {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #ffffff;
  border-radius: 14px;
  user-select: text;
  -webkit-user-select: text;
  touch-action: pan-x pan-y pinch-zoom;
}

.pdf-page-inner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  background: #ffffff;
}

.pdf-canvas,
.pdf-page-content .textLayer,
.pdf-page-content .annotationLayer {
  position: absolute;
  inset: 0;
}

.pdf-canvas {
  z-index: 1;
  display: block;
  background: #ffffff;
}

.pdf-page-content .textLayer {
  z-index: 2;
  opacity: 1;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none;
}

.pdf-page-content .textLayer span,
.pdf-page-content .textLayer br {
  user-select: text;
  -webkit-user-select: text;
}

.pdf-page-content .textLayer span {
  pointer-events: auto;
  cursor: text;
}

.pdf-page-content .annotationLayer,
.pdf-page-content .customAnnotationLayer {
  z-index: 3;
  pointer-events: none;
}

.pdf-link-annotation {
  position: absolute;
  display: block;
  pointer-events: auto;
  background: rgba(58, 198, 40, 0);
  border-radius: 2px;
}

.pdf-link-annotation:hover,
.pdf-link-annotation:focus-visible {
  background: rgba(58, 198, 40, 0.16);
  outline: 2px solid rgba(58, 198, 40, 0.45);
}

.pdf-page-loading,
.pdf-page-error {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.8);
  font-weight: 700;
}

#book.flat-book .flat-page.pdf-page {
  background: #ffffff;
}

#book.flat-book .flat-page.pdf-page .pdf-page-content {
  border-radius: 14px;
}

.zoom-image {
  display: none;
}

.zoom-image.visible {
  display: block;
}

.zoom-pdf-stage {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  will-change: transform;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.16);
}

.zoom-pdf-stage.visible {
  display: block;
}

.zoom-overlay.active .zoom-pdf-stage {
  touch-action: none;
}

/* En mode PDF, on garde la sélection du texte et les liens prioritaires sur le clic de page. */
.pdf-page-content a,
.pdf-page-content .textLayer,
.pdf-page-content .annotationLayer {
  -webkit-tap-highlight-color: rgba(58, 198, 40, 0.18);
}

/* Correctif final mobile/tablette : le rendu principal PDF est un vrai <img> visible immédiatement. */
#book.flat-book .flat-page.pdf-page.mobile-pdf-image-page {
  position: relative;
  display: block;
  background-color: #ffffff !important;
  overflow: hidden;
  transform: translateZ(0);
  backface-visibility: hidden;
  contain: layout paint;
}

.pdf-mobile-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translateZ(0);
  transform-origin: center center;
  background: #ffffff;
  overflow: hidden;
  user-select: text;
  -webkit-user-select: text;
  backface-visibility: hidden;
}

.pdf-mobile-page-image {
  position: absolute !important;
  inset: 0 !important;
  z-index: 1 !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: fill !important;
  opacity: 1 !important;
  visibility: visible !important;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  transform: translateZ(0);
  background: #ffffff;
}

.pdf-mobile-text-layer,
.pdf-mobile-annotation-layer {
  position: absolute !important;
  inset: 0 !important;
}

.pdf-mobile-text-layer {
  z-index: 2 !important;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none;
}

.pdf-mobile-text-layer span {
  pointer-events: auto;
  cursor: text;
}

.pdf-mobile-annotation-layer {
  z-index: 3 !important;
  pointer-events: none;
}

.pdf-force-mobile-paint,
.pdf-mobile-painted {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Correctif mobile définitif : rendu PDF principal sans transform/absolute fragile. */
#book.flat-book .flat-page.pdf-page.mobile-pdf-image-page {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  contain: none !important;
  transform: none !important;
  background-color: #ffffff !important;
}

#book.flat-book .flat-page.pdf-page.mobile-pdf-image-page .pdf-mobile-stage {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  flex: 0 0 auto !important;
  max-width: 100% !important;
  max-height: 100% !important;
  background-color: #ffffff !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: 100% 100% !important;
}

#book.flat-book .flat-page.pdf-page.mobile-pdf-image-page .pdf-mobile-page-image {
  transform: none !important;
  backface-visibility: visible !important;
}

/* Correctif sélection mobile/tablette uniquement.
   Desktop inchangé : cette classe est ajoutée seulement dans le rendu page simple. */
@media (pointer: coarse), (max-width: 1099px) {
  #book.flat-book .pdf-mobile-selection-precise {
    -webkit-text-size-adjust: none !important;
    text-size-adjust: none !important;
    line-height: 1 !important;
    transform: none !important;
    transform-origin: 0 0 !important;
    overflow: hidden !important;
    contain: none !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    touch-action: auto !important;
  }

  #book.flat-book .pdf-mobile-selection-precise span,
  #book.flat-book .pdf-mobile-selection-precise br {
    -webkit-text-size-adjust: none !important;
    text-size-adjust: none !important;
    transform-origin: 0 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    touch-action: auto !important;
  }

  #book.flat-book .pdf-mobile-selection-precise .pdf-text-empty-touch-gap {
    pointer-events: none !important;
  }

  #book.flat-book .pdf-mobile-selection-precise .endOfContent {
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
  }
}
