:root {
  --wall: #d7cac1;        /* couleur du mur (photo égalisée) */
  --ink: #2f2a25;
  --ink-soft: #6f6358;
  --line: rgba(47, 42, 37, 0.16);
  --paper: rgba(251, 249, 245, 0.94);
  --accent: #9b8a74;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; height: 100dvh; overflow: hidden; -webkit-text-size-adjust: 100%;
  background: var(--wall); color: var(--ink); font-family: var(--sans);
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

/* ───────── le mur */
#stage {
  position: fixed; inset: -40px; overflow: hidden;
  /* le même enduit que la photo, avec un grain fin de plâtre */
  background-color: var(--wall);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .27 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  transition: transform .6s ease-out;
}
/* lumière de galerie : un éclairage doux venu du haut, et les bords qui s'assombrissent légèrement */
#light {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(ellipse 90% 60% at 50% -8%, rgba(255, 252, 246, 0.55) 0%, rgba(255, 252, 246, 0) 70%),
    radial-gradient(ellipse 120% 95% at 50% 45%, rgba(0, 0, 0, 0) 55%, rgba(70, 50, 38, 0.16) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0) 78%, rgba(70, 50, 38, 0.07) 100%);
  opacity: 0; transition: opacity 1s;
}
body.ready #light { opacity: 1; }
#stage { touch-action: none; cursor: grab; }
body.dragging, body.dragging * { cursor: grabbing !important; }
#wall {
  position: absolute; left: 40px; top: 40px; width: 2400px; height: 1600px;
  transform-origin: 0 0;
  will-change: transform;
}
.wall { position: absolute; top: 0; width: 2400px; height: 1600px; }
.bg { position: absolute; left: 0; top: 0; }
.bg > img {
  position: absolute; width: 2400px; height: 1600px; pointer-events: none;
  user-select: none; -webkit-user-drag: none;
  /* le mur de la photo est uniforme : on fond ses quatre bords dans l'enduit */
  --fx: linear-gradient(to right, transparent 0, #000 9%, #000 91%, transparent 100%);
  --fy: linear-gradient(to bottom, transparent 0, #000 9%, #000 91%, transparent 100%);
  -webkit-mask-image: var(--fx), var(--fy);
  -webkit-mask-composite: source-in;
          mask-image: var(--fx), var(--fy);
          mask-composite: intersect;
}
/* mur posé à droite d'un autre : son bord gauche s'efface pour laisser voir les cadres du voisin */
.bg > img.right { --fx: linear-gradient(to right, transparent 330px, #000 480px, #000 91%, transparent 100%); }
/* mur empilé sous un autre : son bord du haut se fond dans le mur du dessus */
.bg > img.below { --fy: linear-gradient(to bottom, transparent 0, #000 16%, #000 91%, transparent 100%); }

/* une affiche incrustée dans un cadre (la perspective est posée par le JS) */
.art {
  position: absolute; left: 0; top: 0; padding: 0; border: 0; margin: 0;
  transform-origin: 0 0; overflow: hidden; cursor: pointer;
  background: #fbfaf7;
  backface-visibility: hidden;
}
.art > canvas, .art > img {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: top;
  filter: saturate(.9) contrast(.96) brightness(1.01);
  transition: filter .35s ease;
}
.art:hover > canvas, .art:hover > img, .art:focus-visible > canvas, .art:focus-visible > img { filter: saturate(1) contrast(1) brightness(1.04); }
.art:focus-visible { outline: 6px solid rgba(255, 255, 255, 0.8); outline-offset: 30px; }
/* la lumière et les ombres de la vraie photo, posées par-dessus */
.shade {
  position: absolute; left: 0; top: 0; pointer-events: none;
  transform-origin: 0 0; background-size: 100% 100%;
  mix-blend-mode: multiply;
}
.art[hidden], .shade[hidden], .label[hidden] { display: none; }
#panel [hidden] { display: none !important; }

.label {
  position: absolute; margin: 0; transform: translateX(-50%);
  font-weight: 500; font-size: 26px; letter-spacing: -0.01em;
  color: rgba(70, 60, 52, 0.7); white-space: nowrap; pointer-events: none;
  transition: opacity .4s;
}
body.focusing .label { opacity: 0; }

/* ───────── interface */
#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 22px 12px;
  opacity: 0; transition: opacity .8s .2s;
}
body.ready #top { opacity: 1; }
.brand { font-weight: 700; letter-spacing: -0.02em; font-size: 19px; color: var(--ink); white-space: nowrap; }
.brand em { font-style: normal; font-weight: 400; letter-spacing: 0; margin-left: 8px; color: var(--ink-soft); font-size: 15px; }
#top nav { display: flex; align-items: center; gap: 14px; }
#btn-contact {
  appearance: none; cursor: pointer; min-height: 40px; padding: 0 18px;
  background: rgba(251, 249, 245, 0.7); border: 1px solid var(--line); border-radius: 999px;
  font-size: 14px; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background .2s;
}
#btn-contact:hover { background: #fff; }

#walls {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 6px 8px; border-radius: 999px;
  background: rgba(251, 249, 245, 0.6); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  opacity: 0; transition: opacity .6s .4s;
}
body.ready #walls { opacity: 1; }
body.focusing #walls { opacity: 0; pointer-events: none; transition-delay: 0s; }
#walls[hidden] { display: none; }
#walls button {
  appearance: none; cursor: pointer; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--ink);
}
#walls button:hover { background: rgba(255, 255, 255, 0.8); }
#dots { display: flex; gap: 8px; }
#dots span { width: 8px; height: 8px; border-radius: 50%; background: rgba(47, 42, 37, 0.25); cursor: pointer; transition: background .3s, transform .3s; }
#dots span.on { background: var(--ink); transform: scale(1.2); }

#hint {
  position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top)); transform: translate(-50%, -6px); z-index: 9; margin: 0;
  font-size: 14px; color: var(--ink-soft);
  opacity: 0; transition: opacity .6s, transform .6s; pointer-events: none; white-space: nowrap;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }
body.focusing #hint { opacity: 0; }

#loader { position: fixed; left: 50%; top: 50%; width: 120px; height: 1px; margin-left: -60px; background: var(--line); overflow: hidden; transition: opacity .5s; }
#loader span { display: block; width: 40%; height: 100%; background: var(--ink-soft); animation: load 1.1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
body.ready #loader { opacity: 0; pointer-events: none; }
#stage { opacity: 0; transition: opacity .9s ease, transform .6s ease-out; }
body.ready #stage { opacity: 1; }

/* ───────── fiche d'un site */
#panel {
  position: fixed; top: calc(76px + env(safe-area-inset-top)); right: 22px; bottom: 22px; z-index: 20;
  width: min(380px, calc(100vw - 44px)); overflow-y: auto;
  padding: 34px 30px 24px; border-radius: 18px;
  background: var(--paper); border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(60, 45, 35, 0.18);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transform: translateX(calc(100% + 40px)); opacity: 0;
  transition: transform .7s cubic-bezier(.2, .8, .2, 1), opacity .5s;
}
#panel.open { transform: none; opacity: 1; }
#panel > * { transition: opacity .2s ease, transform .2s ease; }
#panel.swap > *:not(#p-close) { opacity: 0; transform: translateY(6px); }
#p-close {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border-radius: 50%;
  appearance: none; background: none; border: 0; cursor: pointer; font-size: 26px; line-height: 1; color: var(--ink-soft);
}
#p-close:hover { background: rgba(47, 42, 37, 0.06); color: var(--ink); }
.p-num { font-size: 13px; font-weight: 600; color: var(--accent); margin: 0 0 8px; font-variant-numeric: tabular-nums; }
#panel h2 { font-weight: 700; font-size: 32px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; }
.p-meta { font-size: 15px; color: var(--ink-soft); margin: 6px 0 18px; }
#p-desc { font-size: 15px; line-height: 1.65; color: #4a423b; margin: 0 0 18px; }
#p-tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 24px; }
#p-tags li { font-size: 12px; font-weight: 500; padding: 6px 12px; background: rgba(47, 42, 37, 0.05); border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft); }
#p-visit {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; border-radius: 999px;
  text-decoration: none; color: #fbf9f5; background: var(--ink);
  font-weight: 600; font-size: 15px;
  transition: background .2s, transform .2s;
}
#p-visit:hover { background: #47403a; transform: translateY(-1px); }
.p-domain { text-align: center; font-size: 12px; color: var(--ink-soft); margin: 10px 0 0; }
.p-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); gap: 8px; }
.p-nav button { appearance: none; background: none; border: 0; cursor: pointer; color: var(--ink-soft); font-size: 14px; font-weight: 500; padding: 8px 4px; min-height: 40px; }
.p-nav button:hover { color: var(--ink); }
#p-count { font-size: 13px; color: var(--accent); font-variant-numeric: tabular-nums; }

#btn-contact:focus-visible, #walls button:focus-visible, #panel button:focus-visible, #p-visit:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; }

/* ───────── téléphone */
#grab { display: none; }
@media (max-width: 760px) {
  #top { padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left)); }
  .brand { font-size: 15px; }
  .brand em { display: none; }
  #btn-contact { min-height: 44px; padding: 0 16px; }
  #hint { font-size: 14px; white-space: normal; text-align: center; width: calc(100% - 48px); }
  /* fiche en « tiroir » qui monte du bas, et qu'on referme en la tirant vers le bas */
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 56vh; max-height: 56dvh;
    padding: 22px 20px calc(16px + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; border-bottom: 0;
    transform: translateY(105%);
    overscroll-behavior: contain; touch-action: pan-y;
  }
  #panel.open { transform: none; }
  #panel.dragging { transition: none; }
  /* poignée : une large zone en haut de la fiche qu'on tire vers le bas */
  #grab { display: block; position: absolute; top: 0; left: 0; right: 56px; height: 34px; touch-action: none; cursor: grab; }
  #grab::after { content: ''; position: absolute; top: 9px; left: calc(50% + 28px); width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: rgba(47, 42, 37, 0.22); }
  #panel h2 { font-size: 26px; padding-right: 40px; }
  .p-meta { font-size: 14px; margin-bottom: 12px; }
  #p-desc { font-size: 14px; line-height: 1.55; margin-bottom: 14px; }
  #p-tags { margin-bottom: 16px; }
  #p-visit { min-height: 52px; }
  .p-nav { margin-top: 14px; padding-top: 8px; }
  .p-nav button { min-height: 44px; }
  .label { font-size: 54px; font-weight: 600; }  /* le mur est vu de loin : on grossit les noms */
}
/* petit téléphone : fiche plus compacte pour laisser voir le cadre */
@media (max-width: 760px) and (max-height: 720px) {
  #panel { max-height: 50vh; max-height: 50dvh; }
  #p-tags { display: none; }
  #p-desc { font-size: 13.5px; margin-bottom: 12px; }
  #panel h2 { font-size: 24px; }
}
/* téléphone couché : peu de hauteur */
@media (max-height: 500px) and (orientation: landscape) {
  #top { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 6px; }
  #hint { display: none; }
  #walls { bottom: calc(8px + env(safe-area-inset-bottom)); }
  #panel { top: 60px; bottom: 10px; right: calc(10px + env(safe-area-inset-right)); padding: 22px 22px 16px; }
  #panel h2 { font-size: 24px; }
  #p-desc { font-size: 13.5px; }
}
@media (prefers-reduced-motion: reduce) {
  #wall, #panel, #stage { transition-duration: .01s !important; }
}
