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

:root {
  --wall-bg: #e8dfd0;
  --wall-texture: #ddd4c4;
  --polaroid-bg: #fefefe;
  --ink: #2c2416;
  --ink-muted: #6b5d4d;
  --accent: #8b4513;
  --shadow: rgba(44, 36, 22, 0.25);
  --font-hand: "Caveat", cursive;
  --font-body: "Segoe UI", system-ui, sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink);
}

body {
  background-color: #d4c9b8;
}

/* Viewport & canvas */
#wall {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  z-index: 5;
  cursor: grab;
}

#wall.is-panning {
  cursor: grabbing;
}

#wall-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  min-width: 2400px;
  min-height: 1800px;
  background-color: var(--wall-bg);
  background-image:
    radial-gradient(circle at 20% 30%, var(--wall-texture) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, var(--wall-texture) 0%, transparent 40%),
    linear-gradient(135deg, #ebe2d3 0%, #e0d5c4 100%);
}

.polaroid {
  position: absolute;
  width: 220px;
  background: var(--polaroid-bg);
  padding: 12px 12px 48px;
  box-shadow:
    0 4px 12px var(--shadow),
    0 1px 3px rgba(0, 0, 0, 0.1);
  transform: rotate(var(--rotation, 0deg));
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s ease;
}

.polaroid:hover {
  box-shadow:
    0 8px 24px var(--shadow),
    0 2px 6px rgba(0, 0, 0, 0.12);
}

.polaroid.dragging {
  cursor: grabbing;
  z-index: 9999 !important;
  box-shadow:
    0 16px 40px rgba(44, 36, 22, 0.35),
    0 4px 12px rgba(0, 0, 0, 0.15);
  transition: none;
}

.polaroid img {
  display: block;
  width: 100%;
  height: 196px;
  object-fit: cover;
  background: #f0ebe3;
  pointer-events: none;
}

.polaroid-img--error {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.polaroid-img--error::after {
  content: "Image non disponible";
}

.polaroid--new {
  animation: pinDrop 0.4s ease-out;
}

@keyframes pinDrop {
  from {
    opacity: 0;
    transform: rotate(var(--rotation, 0deg)) scale(0.85) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: rotate(var(--rotation, 0deg)) scale(1) translateY(0);
  }
}

.polaroid-caption {
  position: absolute;
  bottom: 10px;
  left: 12px;
  right: 12px;
  text-align: center;
  pointer-events: none;
}

.polaroid-title {
  font-family: var(--font-hand);
  font-size: 1.25rem;
  line-height: 1.1;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.polaroid-author {
  font-size: 0.7rem;
  font-style: italic;
  color: var(--ink-muted);
  margin-top: 2px;
}

.wall-nav {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.nav-arrow {
  position: absolute;
  width: 2rem;
  height: 2rem;
  padding: 0.35rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 252, 247, 0.55);
  color: rgba(44, 36, 22, 0.45);
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(4px);
  transition: background 0.15s, color 0.15s;
}

.nav-arrow:hover {
  background: rgba(255, 252, 247, 0.85);
  color: var(--accent);
}

.nav-arrow svg {
  width: 100%;
  height: 100%;
}

.nav-arrow--n {
  top: 0.5rem;
  left: 0;
  right: 0;
  margin-inline: auto;
}

.nav-arrow--s {
  bottom: 0.5rem;
  left: 0;
  right: 0;
  margin-inline: auto;
}

.nav-arrow--w {
  left: 0.5rem;
  top: 0;
  bottom: 0;
  margin-block: auto;
}

.nav-arrow--e {
  right: 0.5rem;
  top: 0;
  bottom: 0;
  margin-block: auto;
}

/* Zoom — au-dessus de la flèche SW */
.zoom-controls {
  position: fixed;
  bottom: 3.75rem;
  left: 1rem;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: rgba(255, 252, 247, 0.7);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 12px var(--shadow);
  pointer-events: auto;
}

.zoom-controls button {
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.zoom-controls button:hover {
  background: rgba(139, 69, 19, 0.12);
  color: var(--accent);
}

#zoom-level {
  font-size: 0.7rem;
  color: var(--ink-muted);
  min-width: 2.5rem;
  text-align: center;
  user-select: none;
}

/* Formulaire */
.form-panel {
  position: fixed;
  z-index: 10000;
  pointer-events: auto;
}

.form-fab {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px var(--shadow);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.form-fab:hover {
  background: #6d3610;
  transform: scale(1.03);
}

.form-fab-icon {
  width: 1.25rem;
  height: 1.25rem;
}

.form-fab-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.form-content {
  width: min(320px, calc(100vw - 2rem));
  background: rgba(255, 252, 247, 0.95);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 8px 32px var(--shadow);
}

.form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.form-header h2 {
  font-family: var(--font-hand);
  font-size: 1.75rem;
  color: var(--accent);
}

.form-close {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: 50%;
  background: rgba(139, 69, 19, 0.1);
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.form-close:hover {
  background: rgba(139, 69, 19, 0.2);
}

.form-panel label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--ink-muted);
}

.form-panel label .label-hint {
  font-weight: 400;
}

.form-panel input[type="text"],
.form-panel input[type="file"],
.form-panel textarea {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #d4c9b8;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  background: #fff;
}

.form-panel textarea {
  resize: vertical;
  min-height: 60px;
}

.char-count {
  font-size: 0.7rem;
  color: var(--ink-muted);
  text-align: right;
  margin-top: -0.5rem;
  margin-bottom: 0.5rem;
}

.preview {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.form-panel button[type="submit"] {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.form-panel button[type="submit"]:hover:not(:disabled) {
  background: #6d3610;
}

.form-panel button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-error {
  color: #b33;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

/* Desktop : panneau classique */
@media (min-width: 769px) {
  .form-panel {
    bottom: 1.5rem;
    right: 1.5rem;
  }

  .form-fab {
    display: none !important;
  }

  .form-content {
    display: block !important;
  }

  .form-close {
    display: none;
  }
}

/* Mobile : bouton compact + tiroir */
@media (max-width: 768px) {
  .form-panel {
    bottom: 1rem;
    right: 1rem;
  }

  .form-panel.is-collapsed .form-fab {
    display: flex;
  }

  .form-panel.is-collapsed .form-content {
    display: none;
  }

  .form-panel.is-expanded {
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(20, 16, 10, 0.35);
  }

  .form-panel.is-expanded .form-fab {
    display: none;
  }

  .form-panel.is-expanded .form-content {
    display: block;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    animation: slideUp 0.25s ease-out;
  }

  .nav-arrow--s {
    bottom: 0.5rem;
  }

  .zoom-controls {
    bottom: 5rem;
  }

  .polaroid {
    width: 180px;
    padding: 10px 10px 42px;
  }

  .polaroid img {
    height: 160px;
  }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Lightbox */
.lightbox {
  --lightbox-margin: clamp(0.5rem, 2vw, 0.875rem);
  --lightbox-photo-inset-x: clamp(0.875rem, 4vw, 1.375rem);
  --lightbox-control-size: 2.75rem;
  --lightbox-safe-top: max(var(--lightbox-margin), env(safe-area-inset-top, 0px));
  --lightbox-safe-right: max(var(--lightbox-margin), env(safe-area-inset-right, 0px));
  --lightbox-safe-bottom: max(var(--lightbox-margin), env(safe-area-inset-bottom, 0px));
  --lightbox-safe-left: max(var(--lightbox-margin), env(safe-area-inset-left, 0px));
  --lightbox-bg: rgba(20, 16, 10, 0.97);

  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: var(--lightbox-safe-top) var(--lightbox-safe-right)
    var(--lightbox-safe-bottom) var(--lightbox-safe-left);
  background: var(--lightbox-bg);
  backdrop-filter: blur(6px);
  cursor: zoom-out;
  touch-action: none;
  overflow: hidden;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  height: 100%;
  height: 100dvh;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  overflow: clip;
  background: var(--lightbox-bg);
  isolation: isolate;
}

.lightbox-close {
  position: absolute;
  top: var(--lightbox-safe-top);
  right: var(--lightbox-safe-right);
  z-index: 20;
  width: var(--lightbox-control-size);
  height: var(--lightbox-control-size);
  border: none;
  border-radius: 50%;
  background: rgba(20, 16, 10, 0.72);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  transition: background 0.15s, transform 0.15s;
}

.lightbox-close:hover {
  background: rgba(20, 16, 10, 0.88);
  transform: scale(1.05);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 20;
}

.lightbox-nav--left {
  left: var(--lightbox-safe-left);
}

.lightbox-nav--right {
  right: var(--lightbox-safe-right);
}

.lightbox-nav-btn {
  width: var(--lightbox-control-size);
  height: var(--lightbox-control-size);
  border: none;
  border-radius: 50%;
  background: rgba(20, 16, 10, 0.72);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  transition: background 0.15s, opacity 0.15s, transform 0.15s;
}

.lightbox-nav-btn:hover:not(:disabled) {
  background: rgba(20, 16, 10, 0.88);
  transform: scale(1.05);
}

.lightbox-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.lightbox-img {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--lightbox-photo-inset-x);
  right: var(--lightbox-photo-inset-x);
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  cursor: default;
  transition: filter 0.25s ease;
}

.lightbox-img--loading {
  filter: blur(8px);
}

html.lightbox-open #wall,
html.lightbox-open .wall-nav,
html.lightbox-open .zoom-controls {
  visibility: hidden;
}

.lightbox-meta {
  flex-shrink: 0;
  text-align: center;
  color: #f5f0e8;
  padding: 0 0.25rem 0.125rem;
  pointer-events: none;
}

.lightbox-title {
  font-family: var(--font-hand);
  font-size: 2rem;
  line-height: 1.1;
}

.lightbox-author {
  font-size: 0.9rem;
  font-style: italic;
  color: rgba(245, 240, 232, 0.75);
  margin-top: 0.25rem;
}

.lightbox-comment {
  font-size: 0.95rem;
  color: rgba(245, 240, 232, 0.85);
  margin-top: 0.5rem;
  line-height: 1.4;
}

.lightbox-date {
  font-size: 0.8rem;
  color: rgba(245, 240, 232, 0.6);
  margin-top: 0.75rem;
  font-style: italic;
}
