/* ═══════════════ Djouney v3 — double-fond et encre invisible (module M2) ═══════════════
   La photo à double-fond qu'on écorne, le papier à l'encre invisible qu'on réchauffe du doigt.
   Classes préfixées .df- et .ik- (voir ARCHITECTURE.md § 14.2). */

/* Taille du coin écorné : enregistrée pour que l'invitation au geste puisse l'animer. */
@property --df-c {
  syntax: "<length>";
  inherits: true;
  initial-value: 18px;
}

/* ═════════════════════════ La photo à double-fond ═════════════════════════ */

.df {
  --df-soft: rgba(var(--ink-rgb),.8); /* petit texte d'encre, contraste ≥ 4,5:1 sur le lait */
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(240px, 100%);
}
.df--mine { margin-left: auto; }

/* Le tirage posé sur la page : l'ombre en relief suit la forme découpée du coin. */
.df-card {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  transform: rotate(-1.2deg);
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  filter:
    drop-shadow(-4px -4px 6px rgba(var(--light-rgb), calc(.9 * var(--hl-a))))
    drop-shadow(calc(5px + 7px * var(--df-lift, 0)) calc(7px + 9px * var(--df-lift, 0)) calc(7px + 7px * var(--df-lift, 0)) rgba(var(--shadow-rgb), .26));
}
.df--mine .df-card { transform: rotate(1deg); }

.df-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-origin: 50% 50%;
}
/* Seule la face tournée vers soi se touche (le verso, posé par-dessus, ne masque pas le coin). */
.df-back,
.df.is-revealed .df-front { pointer-events: none; }
.df.is-revealed .df-back { pointer-events: auto; }

/* ─── Recto ─── */
.df-front {
  padding: 6px;
  background: var(--milk);
  box-shadow:
    inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a))),
    inset -1px -1px 0 rgba(var(--hollow-rgb), .5);
  -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--df-c)), calc(100% - var(--df-c)) 100%, 0 100%);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--df-c)), calc(100% - var(--df-c)) 100%, 0 100%);
}

.df-print {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 11px;
  background: var(--porcelain);
  box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), .05);
}
/* Lustre du papier photo. */
.df-print::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(155deg, rgba(var(--light-rgb), calc(.22 * var(--hl-a))) 0%, rgba(var(--light-rgb), calc(0 * var(--hl-a))) 38%);
  pointer-events: none;
}
/* Squelette : le papier respire pendant le chargement. */
.df-print.is-loading { animation: dfBreathe 2.6s ease-in-out infinite alternate; }
@keyframes dfBreathe {
  from {
    background-color: var(--porcelain);
    box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), .05), inset 0 0 0 0 rgba(var(--light-rgb), calc(0 * var(--hl-a)));
  }
  to {
    background-color: #F8F1E8;
    box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), .05), inset 0 0 30px 4px rgba(var(--light-rgb), calc(.75 * var(--hl-a)));
  }
}

.df-photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  -webkit-user-drag: none;
  transition: opacity 600ms var(--ease);
}
.df-print.is-loaded .df-photo { opacity: 1; }

.df-missing {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 18px;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.4;
  color: var(--df-soft);
  background: var(--porcelain);
  box-shadow: var(--deboss);
}

.df-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 1;
  padding: 2px 10px 3px;
  border-radius: 999px;
  background: rgba(var(--milk-rgb), .88);
  box-shadow: 0 2px 6px rgba(var(--ink-rgb), .12);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.4;
  letter-spacing: .2px;
  color: var(--ink);
  pointer-events: none;
}

/* Le coin écorné : le dos du tirage (lait), replié le long du pli. */
.df-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: var(--df-c);
  height: var(--df-c);
  pointer-events: none;
  filter: drop-shadow(calc(-1.5px - 3px * var(--df-lift, 0)) calc(-1.5px - 3px * var(--df-lift, 0)) calc(2px + 5px * var(--df-lift, 0)) rgba(104, 76, 54, .28));
}
.df-corner__flap {
  position: absolute;
  inset: 0;
  border-top-left-radius: 3px;
  background: linear-gradient(135deg, #FFFDF8 0%, var(--milk) 26%, #E8DCCD 50%);
  -webkit-clip-path: polygon(0 0, 100% 0, 0 100%);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* La zone où l'on saisit le coin : seule elle bloque le défilement. */
.df-peel {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 3;
  width: 54%;
  height: 44%;
  touch-action: none;
  cursor: grab;
}
.df-card.is-peeling .df-peel { cursor: grabbing; }

/* Le coin s'entrouvre trois fois, doucement, pour inviter au geste. */
.df-card.is-inviting { animation: dfInvite 4.2s var(--ease) 1.4s 3; }
@keyframes dfInvite {
  0%, 62%, 100% { --df-c: var(--df-c-rest, 18px); }
  78% { --df-c: calc(var(--df-c-rest, 18px) * 1.6); }
}

/* ─── Verso : papier réglé, marge rouge fine ─── */
.df-back {
  display: flex;
  flex-direction: column;
  padding: 12px 14px 4px 44px;
  color: var(--sepia);
  background-color: var(--milk);
  background-image:
    linear-gradient(90deg, transparent 33px, color-mix(in srgb, var(--thread) 60%, transparent) 33px 34px, transparent 34px),
    repeating-linear-gradient(180deg, transparent 0 27px, rgba(var(--hollow-rgb), .5) 27px 28px);
  background-position: 0 0, 0 16px;
  box-shadow:
    inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a))),
    inset -1px -1px 0 rgba(var(--hollow-rgb), .5);
}
.df--mine .df-back { color: var(--ink); }

.df-title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.1;
  color: var(--ink-soft);
}

.df-slot {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.df-slot::-webkit-scrollbar { display: none; }
/* Centré quand il y a la place, lisible depuis le début quand le verso défile. */
.df-slot > * { margin-top: auto; margin-bottom: auto; }

.df-secret-text {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.15;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.df-secret-none {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.4;
  color: var(--df-soft);
}

/* Mini-lecteur du vocal secret. */
.df-player {
  display: flex;
  align-items: center;
  gap: 12px;
}
.df-play {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--flower);
  color: var(--flower-ink, #fff);
  box-shadow:
    0 6px 14px color-mix(in srgb, var(--flower) 30%, transparent),
    inset 1px 1px 0 rgba(var(--light-rgb), calc(.25 * var(--hl-a)));
  transition: transform .15s var(--ease), opacity .3s var(--ease);
}
.df-play:active { transform: scale(.96); }
.df-play svg { width: 20px; height: 20px; }
.df-player.is-loading .df-play { opacity: .7; }
.df-player__line {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.df-track {
  position: relative;
  display: block;
  height: 2px;
  overflow: hidden;
  border-radius: 1px;
  background: var(--relief);
}
.df-track__fill {
  position: absolute;
  inset: 0;
  background: var(--flower);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform .26s linear;
}
.df-time {
  font-family: var(--font-ui);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
  color: var(--df-soft);
}

/* Le lieu. */
.df-place {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.df-pin { width: 26px; height: 26px; color: var(--stem); }
.df-place__name {
  margin: 2px 0 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.df-place__coords {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
  color: var(--df-soft);
}
.df-go {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--milk);
  box-shadow: var(--emboss-sm);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: box-shadow .25s var(--ease), transform .15s var(--ease);
}
.df-go:active { box-shadow: var(--deboss); transform: translateY(1px); }

.df-close {
  align-self: flex-end;
  min-width: 44px;
  min-height: 44px;
  margin-right: -6px;
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
.df-close:active { background: var(--porcelain); box-shadow: var(--deboss); }

/* L'alternative au geste ; sa place reste réservée quand la carte est retournée. */
.df-reveal {
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
.df-reveal:active { background: var(--porcelain); box-shadow: var(--deboss); }
.df.is-revealed .df-reveal { visibility: hidden; }

/* ═════════════════════════ L'encre invisible ═════════════════════════ */

.ik {
  --ik-soft: rgba(var(--ink-rgb),.8);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 100%;
}
.ik--mine { align-items: flex-end; }

/* La bande de papier : sa hauteur est celle des mots qu'elle cache.
   Ses calques (mots, papier peint, halo) restent entre eux, quel que soit le carnet autour. */
.ik-paper {
  position: relative;
  isolation: isolate;
  max-width: 100%;
  min-width: min(200px, 100%);
  padding: 12px 18px 14px;
  overflow: hidden;
  border-radius: 14px;
  background-color: var(--milk);
  background-image: radial-gradient(130% 120% at 0% 0%, rgba(var(--light-rgb), calc(.9 * var(--hl-a))), rgba(var(--light-rgb), calc(0 * var(--hl-a))) 60%);
  box-shadow:
    var(--emboss-sm),
    inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a))),
    inset -1px -1px 0 rgba(var(--hollow-rgb), .4);
}

.ik-text {
  position: relative;
  z-index: 1;
  min-height: 1.15em;
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.15;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--sepia);
}
.ik--mine .ik-text { color: var(--ink); }
/* Sous le papier, les mots sont teintés de la fleur ; ils se posent en sépia une fois tout révélé. */
.ik.is-sealed .ik-text {
  color: var(--flower);
  transition: text-shadow .5s var(--ease);
}
.ik.is-sealed:not(.is-covered):not(.is-revealing) .ik-text { visibility: hidden; }
.ik.is-warming .ik-text { text-shadow: 0 0 12px color-mix(in srgb, var(--flower-light) 65%, transparent); }
.ik.is-revealed .ik-text { transition: color 1.4s var(--ease); }

.ik-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  touch-action: none;
  cursor: grab;
}
.ik.is-warming .ik-cover { cursor: grabbing; }
/* Une très longue encre ne doit pas piéger le défilement du carnet : on frotte en travers. */
.ik.is-tall .ik-cover { touch-action: pan-y; }

/* La chaleur du doigt, éphémère. */
.ik-halo {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--flower-light) 42%, transparent) 0%,
    color-mix(in srgb, var(--flower-light) 16%, transparent) 38%,
    transparent 70%);
  opacity: 0;
  pointer-events: none;
  will-change: transform;
  transition: opacity .7s var(--ease);
}
.ik.is-warming .ik-halo { opacity: 1; transition-duration: .2s; }

.ik-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 12px;
  min-height: 20px;
  padding: 0 4px;
}
.ik--mine .ik-foot { justify-content: flex-end; }
.ik-note {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ik-soft);
}
/* Cible de 44 px : elle déborde vers le bas, jamais sur le papier à frotter. */
.ik-warm {
  min-width: 44px;
  min-height: 44px;
  margin: -4px 0 -10px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
.ik-warm:active { background: var(--porcelain); box-shadow: var(--deboss); }
.ik-warm[aria-disabled="true"] { opacity: .55; cursor: default; }

/* ─── Mouvement réduit : de simples fondus ─── */
@media (prefers-reduced-motion: reduce) {
  .df-print.is-loading,
  .df-card.is-inviting { animation: none; }
  .df-photo,
  .df-track__fill,
  .ik-halo,
  .ik.is-revealed .ik-text { transition: none; }
}
