/* ── Reset & base ─────────────────────────────────────────────────────────── */

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

:root {
  --accent: #e05a5a;
  --accent-dark: #c04040;
  --surface: rgba(20, 20, 20, 0.92);
  --surface-light: rgba(35, 35, 35, 0.95);
  --text: #f0f0f0;
  --text-muted: #aaa;
  --border: rgba(255,255,255,0.1);
  --radius: 14px;
  --toolbar-h: 72px;
}

html, body { height: 100%; overflow: hidden; font-family: system-ui, -apple-system, sans-serif; color: var(--text); background: #111; }

button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
a { text-decoration: none; color: inherit; }

.hidden { display: none !important; }

/* ── Page accueil ─────────────────────────────────────────────────────────── */

.page-accueil { position: relative; }

.accueil-bg {
  position: fixed; inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: transform 0.8s ease;
}

.accueil-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 60px;
  cursor: pointer;
  z-index: 2;
}

.accueil-overlay:hover .accueil-bg { transform: scale(1.02); }

.accueil-hint {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 14px 28px;
  border-radius: 999px;
  font-size: 1rem; font-weight: 500; letter-spacing: 0.04em;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

.hint-arrow { width: 20px; height: 20px; }

@keyframes pulse {
  0%, 100% { opacity: 0.8; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

/* Bouton (i) */
.info-btn {
  position: fixed; bottom: 24px; right: 24px; z-index: 10;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.25);
  font-size: 1rem; font-weight: 700; font-style: italic;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.info-btn:hover { background: rgba(0,0,0,0.75); }

/* ── Modals / Popup ───────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%; max-width: 440px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-card h2, .modal-card h3 {
  font-size: 1.25rem; margin-bottom: 12px;
}

.modal-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 14px; }

.popup-card { max-width: 500px; }
.popup-title { font-size: 1.5rem; margin-bottom: 16px; }
.popup-body p { line-height: 1.65; color: #ddd; margin-bottom: 12px; font-size: 0.95rem; }
.popup-close { margin-top: 8px; width: 100%; }

.modal-card input, .modal-card textarea {
  width: 100%; background: rgba(255,255,255,0.07);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 0.95rem; color: var(--text);
  resize: vertical; outline: none;
  transition: border-color 0.2s;
}
.modal-card input:focus, .modal-card textarea:focus {
  border-color: var(--accent);
}

.modal-actions { display: flex; gap: 10px; margin-top: 14px; justify-content: flex-end; }

/* Buttons */
.btn-primary {
  background: var(--accent); color: #fff;
  padding: 10px 22px; border-radius: 8px;
  font-weight: 600; font-size: 0.95rem;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: rgba(255,255,255,0.08); color: var(--text);
  padding: 10px 22px; border-radius: 8px;
  font-weight: 500; font-size: 0.95rem;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.14); }

/* ── Page viewer ──────────────────────────────────────────────────────────── */

.page-viewer { position: relative; }

#viewer-canvas {
  display: block; position: fixed; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
}

/* Loading */
.loading-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #111;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; font-size: 0.95rem; color: var(--text-muted);
  transition: opacity 0.5s;
}
.loading-overlay.fade-out { opacity: 0; pointer-events: none; }

.loading-spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Nav hint */
.nav-hint {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 10px 20px; border-radius: 999px;
  font-size: 0.9rem; color: var(--text-muted);
  pointer-events: none; z-index: 5;
  animation: fadeIn 0.5s 1s both;
  transition: opacity 0.4s;
}
.nav-hint svg { width: 20px; height: 20px; }
.nav-hint.fade-out { opacity: 0; }

/* Toolbar */
.toolbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: var(--toolbar-h);
  display: flex; align-items: stretch; justify-content: center;
  background: var(--surface); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  gap: 0;
  padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.tool-btn {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  padding: 10px;
  color: var(--text-muted);
  font-size: 0.7rem; font-weight: 500; letter-spacing: 0.04em;
  transition: color 0.2s, background 0.2s;
  border-radius: 0;
}
.tool-btn svg { width: 22px; height: 22px; }
.tool-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.tool-btn.active { color: var(--accent); }
.tool-btn.active svg { stroke: var(--accent); }

/* Annotate mode hint */
.annotate-hint {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px 18px; border-radius: 999px;
  font-size: 0.85rem; color: var(--text-muted);
  z-index: 10; pointer-events: none;
  white-space: nowrap;
}

/* ── Tiroir (drawer) ──────────────────────────────────────────────────────── */

.drawer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface-light);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 70vh;
  display: flex; flex-direction: column;
  pointer-events: none;
}
.drawer.open { transform: translateY(0); pointer-events: auto; }

.drawer-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.2);
  margin: 12px auto 0;
  flex-shrink: 0;
  cursor: grab;
}

.drawer-scroll {
  overflow-y: auto; flex: 1;
  padding: 12px 20px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

/* Scrollbar style */
.drawer-scroll::-webkit-scrollbar { width: 4px; }
.drawer-scroll::-webkit-scrollbar-track { background: transparent; }
.drawer-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.drawer-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 12px;
}
.drawer-author-info { display: flex; flex-direction: column; gap: 2px; }
.drawer-author { font-weight: 700; font-size: 1rem; }
.drawer-date { font-size: 0.8rem; color: var(--text-muted); }

.drawer-close {
  font-size: 1.4rem; color: var(--text-muted); line-height: 1;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
  flex-shrink: 0;
}
.drawer-close:hover { background: rgba(255,255,255,0.1); color: var(--text); }

.drawer-message {
  font-size: 0.95rem; line-height: 1.6; color: #ddd;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}

.drawer-replies { display: flex; flex-direction: column; gap: 12px; padding: 16px 0; }

.reply-item {
  background: rgba(255,255,255,0.04);
  border-radius: 10px; padding: 10px 14px;
}
.reply-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.reply-author { font-weight: 600; font-size: 0.88rem; }
.reply-date { font-size: 0.75rem; color: var(--text-muted); }
.reply-text { font-size: 0.9rem; color: #ccc; line-height: 1.5; }

.reply-form {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.reply-form textarea {
  width: 100%; background: rgba(255,255,255,0.07);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 0.9rem; color: var(--text);
  resize: none; outline: none;
  transition: border-color 0.2s;
}
.reply-form textarea:focus { border-color: var(--accent); }
.reply-submit { align-self: flex-end; }

/* ── Responsive desktop ───────────────────────────────────────────────────── */

@media (min-width: 768px) {
  .drawer {
    left: auto; right: 20px; bottom: calc(var(--toolbar-h) + 10px);
    width: 360px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    max-height: calc(100vh - var(--toolbar-h) - 30px);
    /* Sur desktop, bottom != 0, donc on compense pour sortir complètement de l'écran */
    transform: translateY(calc(100% + var(--toolbar-h) + 10px));
  }
  .drawer.open { transform: translateY(0); }
  .drawer-handle { display: none; }

  .toolbar { justify-content: center; gap: 8px; }
  .tool-btn { max-width: 100px; border-radius: 10px; }

  .accueil-overlay { align-items: center; padding-bottom: 0; }
}
