/* ═══════════════ Djouney v3 — le tiroir (module D) ═══════════════
   Salutation, enveloppes de porcelaine, lettres en attente, plume ;
   phase 2 : enveloppes retenues, bougie, aube, invitation aux sons ;
   phase 4 : lignes du Salon, place de la fenêtre d'écoute.
   Classes préfixées .dr- (voir ARCHITECTURE.md § 8, § 11, § 13 et § 15). */

.dr {
  /* Encre adoucie qui garde un contraste ≥ 4,5:1 sur la porcelaine comme sur le lait. */
  --dr-soft: rgba(var(--ink-rgb),  .84);
  /* Hauteur réservée en bas à la plume. */
  --dr-foot: 100px;
  /* Hauteur ajoutée en bas quand la fenêtre d'écoute du Salon est dans un coin du bas (voir la fin du fichier). */
  --dr-dock: 0px;
}

/* ─── Défilement ─── */
.dr-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: calc(8px + var(--safe-top)) 18px calc(var(--dr-foot) + 40px + var(--dr-dock) + var(--safe-bottom));
  /* Au clavier, l'enveloppe qui prend le focus ne se cache ni sous la plume ni sous la fenêtre d'écoute. */
  scroll-padding-bottom: calc(var(--dr-foot) + 40px + var(--dr-dock) + var(--safe-bottom));
  /* Le papier s'efface doucement sous la plume. */
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--dr-foot) - 34px - var(--safe-bottom)), transparent calc(100% - 44px - var(--safe-bottom)));
  mask-image: linear-gradient(to bottom, #000 calc(100% - var(--dr-foot) - 34px - var(--safe-bottom)), transparent calc(100% - 44px - var(--safe-bottom)));
}

/* ─── En-tête ─── */
.dr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin-right: -10px;
}
.dr-brand {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: .08em;
  color: var(--ink-soft);
}
/* Les jeux ont leur espace (screens/jeux.js) : on y entre par ce bouton, en tête, au-dessus des carnets. */
.dr-head__actions { display: flex; align-items: center; gap: 4px; }
.dr-games {
  position: relative;
  min-height: 40px;
  padding: 0 16px 0 12px;
  gap: 7px;
  font-size: 14px;
}
.dr-games svg { width: 18px; height: 18px; }
.dr-games__dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--thread);
  box-shadow: 0 0 0 2px var(--milk);
}
.dr-sound { color: var(--dr-soft); transition: color var(--mid) var(--ease); }
.dr-sound[aria-pressed="true"] { color: var(--ink); }

/* ─── Salutation ─── */
.dr-hello { margin: 12px 0 26px; }
.dr-greet {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: clamp(42px, 12vw, 56px);
  line-height: 1.04;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.dr-me {
  display: inline-block;
  max-width: 100%;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  font: inherit;
  line-height: inherit;
  color: inherit;
  text-align: inherit;
  text-decoration: underline;
  text-decoration-color: var(--relief);
  text-decoration-thickness: 1.5px;
  text-underline-offset: .16em;
  overflow-wrap: anywhere;
  vertical-align: baseline;
  transition: text-decoration-color var(--mid) var(--ease);
}
.dr-me:active { text-decoration-color: var(--ink-soft); }
@media (hover: hover) {
  .dr-me:hover { text-decoration-color: var(--ink-faint); }
}
.dr-mood {
  margin: 10px 0 0;
  min-height: 1.45em;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 17px;
  line-height: 1.45;
  color: var(--dr-soft);
}

/* ─── Invitation aux sons (une seule fois) ─── */
.dr-ask {
  margin: -8px 0 26px;
  padding: 16px 18px 10px;
  border-radius: 20px;
  background: var(--milk);
  box-shadow: var(--emboss-sm), inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a)));
}
.dr-ask__text {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--ink);
}
.dr-ask__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 4px;
  margin-top: 10px;
}
.dr-ask__yes { min-height: 44px; padding: 0 18px 0 15px; font-size: 14px; }
.dr-ask__yes svg { flex: none; width: 18px; height: 18px; }
.dr-ask__no { min-height: 44px; font-size: 14px; color: var(--dr-soft); }

/* ─── Listes ─── */
.dr-list,
.dr-invs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dr-item { display: block; }

/* ─── L'enveloppe ─── */
.dr-env {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  column-gap: 14px;
  min-height: 98px;
  padding: 30px 18px 16px 14px;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(176deg, #FFFDF8 0%, var(--milk) 46%, #F6EEE3 100%);
  box-shadow:
    var(--emboss),
    inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a))),
    inset -1px -1px 0 rgba(var(--hollow-rgb),  .35);
  color: var(--ink);
  text-decoration: none;
  transition: opacity var(--slow) var(--ease), transform .18s var(--ease), box-shadow .3s var(--ease);
}
a.dr-env:active {
  transform: translateY(1px);
  box-shadow: var(--emboss-sm), inset 1px 1px 0 rgba(var(--light-rgb), calc(.95 * var(--hl-a)));
}
a.dr-env:focus-visible { outline-offset: 4px; border-radius: 20px; }
.dr-env[data-calm="true"] { opacity: .82; }
/* Pâlie à .82, l'encre adoucie tomberait sous 4,5:1 : la ligne d'état reprend l'encre pleine
   (≈ 5,4:1 une fois l'enveloppe pâlie). */
.dr-env[data-calm="true"] .dr-status { color: var(--ink); }

/* Rabat en V : arête --relief, lumière juste au-dessus, ombre douce dessous. */
.dr-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 30px;
  overflow: visible;
  pointer-events: none;
}
.dr-flap__fill { fill: rgba(255, 255, 255, .6); }
.dr-flap__shadow { fill: none; stroke: rgba(var(--shadow-rgb),  .13); stroke-width: 3px; }
.dr-flap__crease { fill: none; stroke: var(--relief); stroke-width: 1px; }
.dr-flap__light { fill: none; stroke: rgba(255, 255, 255, .95); stroke-width: 1px; }
.dr-flap--dashed .dr-flap__crease { stroke-dasharray: 4 5; }

/* Le sceau, et la goutte du fil rouge posée dessus. */
.dr-seal {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
}
.dr-seal .pc-drop {
  position: absolute;
  top: -1px;
  right: 1px;
}
.dr-seal .pc-drop.is-fresh {
  animation: dr-drop 900ms var(--ease) both, pc-breathe 3.6s ease-in-out 900ms infinite;
}
@keyframes dr-drop {
  from { opacity: 0; transform: translateY(-18px) scale(.7); }
  55% { opacity: 1; }
  to { opacity: 1; transform: none; }
}

/* Petit cachet mat, pressé au pied du sceau : une lettre arrivera à l'heure que marquent ses aiguilles. */
.dr-stamp {
  position: absolute;
  right: -3px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--porcelain);
  box-shadow:
    inset 1.5px 2px 3px rgba(var(--shadow-rgb),  .38),
    inset -1px -1px 2px rgba(var(--light-rgb), calc(.95 * var(--hl-a))),
    0 0 0 2px var(--milk);
  color: var(--ink-soft);
  pointer-events: none;
}
.dr-stamp svg { display: block; width: 15px; height: 15px; overflow: visible; }
.dr-stamp__ring { fill: none; stroke: currentColor; stroke-width: .9; opacity: .5; }
.dr-stamp__hour,
.dr-stamp__minute { stroke: currentColor; stroke-linecap: round; }
.dr-stamp__hour { stroke-width: 1.6; }
.dr-stamp__minute { stroke-width: 1.1; }
.dr-stamp__pin { fill: currentColor; }
.dr-stamp.is-fresh { animation: dr-stamp-in 700ms var(--ease) backwards; }
@keyframes dr-stamp-in {
  from { opacity: 0; transform: scale(1.3); }
}

.dr-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.dr-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.dr-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 29px;
  line-height: 1.14;
  color: var(--ink);
  /* La manuscrite déborde de sa boîte à droite : sans cet air, overflow:hidden rogne la dernière lettre. */
  padding-right: .18em;
}

/* La bougie de l'autre, à droite du prénom : elle veille jusqu'au matin, puis s'éteint. */
.dr-candle {
  flex: none;
  display: inline-flex;
  align-items: center;
  margin-left: -4px;
  transform: translateY(-1px);
  transition: opacity 1.3s var(--ease);
}
.dr-candle.is-fresh { animation: dr-candle-in 900ms var(--ease) backwards; }
/* La flamme s'éteint d'abord : la bougie ne s'efface qu'une fois le filet de fumée monté (2,6 s en tout). */
.dr-candle.is-out { opacity: 0; transition-delay: 1.1s; }
@keyframes dr-candle-in {
  from { opacity: 0; transform: translateY(3px); }
}

/* L'aube de l'autre : une lumière à peine posée au fond de l'enveloppe. */
.dr-env > .pc-dawn { opacity: .8; }

/* Une seule fleur vive à l'écran : la flamme et l'aube d'une autre fleur restent couleur de cire. */
.dr-env[data-tint="muted"] .dr-candle,
.dr-env[data-tint="muted"] > .pc-dawn { filter: grayscale(1) sepia(.45); }

/* Présence : œil ouvert quand l'autre est là, paupière close très légère sinon. */
.dr-presence {
  flex: none;
  display: inline-flex;
  opacity: 1;
  transition: opacity var(--slow) var(--ease);
}
.dr-env[data-present="false"] .dr-presence { opacity: .3; }
.dr-env[data-present="unknown"] .dr-presence,
.dr-env[data-present="false"][data-state="road"] .dr-presence { opacity: 0; }

/* Ligne d'état, en sérif italique. */
.dr-status {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 26px;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.4;
  color: var(--dr-soft);
}
.dr-env[data-state="unread"] .dr-status,
.dr-env[data-state="waiting"] .dr-status,
.dr-env[data-state="invite"] .dr-status { color: var(--ink); }
.dr-status__in {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
}
.dr-status__in.is-settling { animation: dr-settle var(--mid) var(--ease) both; }
@keyframes dr-settle {
  from { opacity: 0; transform: translateY(3px); }
}
.dr-status__text {
  min-width: 0;
  padding-right: 2px; /* l'italique déborde un peu à droite */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Les phrases du tempo (« une lettre t'attend dans votre carnet »…) et du Salon passent sur deux lignes au plus ;
   un titre fait d'un seul long mot se coupe plutôt que de déborder. */
.dr-status__text--wrap {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  white-space: normal;
  overflow-wrap: anywhere;
}
.dr-status .pc-eyelid { flex: none; }

/* Le brouillon de l'autre, en direct : la fin reste visible, le début s'efface. */
.dr-ink {
  display: flex;
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-hand);
  font-style: normal;
  font-weight: 500;
  font-size: 21px;
  line-height: 1.2;
  color: var(--sepia);
}
.dr-ink::after { content: ""; flex: 1 1 0; }
.dr-ink__text { flex: none; white-space: pre; }
.dr-ink.is-long {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 26px);
  mask-image: linear-gradient(to right, transparent 0, #000 26px);
}
.dr-caret {
  display: inline-block;
  width: 1.5px;
  height: .9em;
  margin-left: 2px;
  vertical-align: -.1em;
  border-radius: 1px;
  background: var(--sepia);
  animation: dr-caret 1.1s ease-in-out infinite;
}
@keyframes dr-caret {
  0%, 45% { opacity: 1; }
  60%, 100% { opacity: 0; }
}
/* La lettre vient de partir : la plume est posée, le curseur s'éteint. */
.dr-ink.is-sealed .dr-caret {
  animation: none;
  opacity: 0;
  transition: opacity var(--mid) var(--ease);
}

/* Le Salon : un petit disque en trait fin devant la ligne d'état ; il tourne lentement pendant ton écoute. */
.dr-disc {
  flex: none;
  display: inline-flex;
  width: 18px;
  height: 18px;
}
.dr-disc svg { display: block; width: 100%; height: 100%; overflow: visible; }
.dr-disc__rim { fill: none; stroke: currentColor; stroke-width: 1.1; }
.dr-disc__groove { fill: none; stroke: currentColor; stroke-width: 1; stroke-linecap: round; opacity: .55; }
.dr-disc__label { fill: currentColor; opacity: .75; }
.dr-disc.is-turning svg { animation: dr-disc-turn 6s linear infinite; }
@keyframes dr-disc-turn {
  to { transform: rotate(1turn); }
}

/* ─── Squelettes : trois enveloppes fantômes qui respirent ─── */
.dr-ghosts {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dr-ghost {
  pointer-events: none;
  animation: dr-breathe 2.6s ease-in-out infinite both;
}
.dr-ghost__seal {
  width: 44px;
  height: 44px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--porcelain);
  box-shadow: var(--deboss);
}
.dr-ghost__lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dr-ghost__bar {
  display: block;
  width: 46%;
  height: 16px;
  border-radius: 8px;
  background: var(--porcelain);
  box-shadow: var(--deboss);
}
.dr-ghost__bar--short { width: 68%; height: 11px; opacity: .8; }
@keyframes dr-breathe {
  0%, 100% { opacity: .5; }
  50% { opacity: .92; }
}

/* ─── Pose des enveloppes ─── */
.dr-land { animation: dr-land 640ms var(--ease) both; }
@keyframes dr-land {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
}

/* ─── Tiroir vide ─── */
.dr-empty {
  padding: 30px 24px 28px;
  text-align: center;
}
.dr-empty__eye {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  opacity: .7;
}
.dr-empty__title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 32px;
  line-height: 1.12;
  color: var(--ink);
}
.dr-empty__text {
  margin: 8px 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  line-height: 1.45;
  color: var(--dr-soft);
}

/* ─── Erreur de chargement ─── */
.dr-error {
  padding: 28px 22px 24px;
  text-align: center;
}
.dr-error__title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 28px;
  line-height: 1.15;
  color: var(--ink);
}
.dr-error__text {
  margin: 8px 0 18px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.45;
  color: var(--dr-soft);
}

/* ─── Lettres envoyées, en attente d'être ouvertes ─── */
.dr-pending { margin-top: 34px; }
.dr-pending__title {
  margin: 0 0 14px;
  padding-left: 4px;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15px;
  color: var(--dr-soft);
}
.dr-inv {
  position: relative;
  padding: 30px 16px 12px 14px;
  border: 1.5px dashed var(--relief);
  border-radius: 20px;
  background: rgba(var(--milk-rgb),  .4);
  overflow: hidden;
}
.dr-inv__head {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.dr-inv__head .pc-seal { margin-left: 4px; }
.dr-inv__text { min-width: 0; }
.dr-inv__to {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.12;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.dr-inv__meta {
  margin: 2px 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.4;
  color: var(--dr-soft);
}
.dr-inv__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 4px;
  margin-top: 12px;
}
.dr-inv__resend { min-height: 44px; padding: 0 18px; font-size: 14px; }
.dr-inv__cancel { min-height: 44px; font-size: 14px; color: var(--dr-soft); }

/* ─── La plume, en bas ─── */
.dr-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  padding: 0 18px calc(18px + var(--safe-bottom));
  pointer-events: none;
}
.dr-quill {
  pointer-events: auto;
  max-width: 100%;
  min-height: 56px;
  padding: 0 26px 0 22px;
  gap: 10px;
  font-size: 15.5px;
  text-align: center;
  box-shadow: var(--emboss);
}
.dr-quill:active { box-shadow: var(--deboss); }
.dr-quill svg { flex: none; width: 21px; height: 21px; }

/* ─── La fenêtre d'écoute du Salon (html[data-salon="dock"], ARCHITECTURE § 15.3) ───
   Dans un coin du bas, elle va de 84 à 345 px au-dessus de la zone sûre (vidéo 200 × 200, marges, barre) ;
   la plume tient dessous (18 + 56 = 74 px). La marge basse du défilement s'allonge pour que la dernière
   enveloppe (ou lettre en attente) se lise au-dessus d'elle, à 24 px : 140 + 229 = 345 + 24.
   Dans un coin du haut (data-salon-coin « haut-… »), rien n'est réservé. */
html[data-salon="dock"]:not([data-salon-coin^="haut"]) .dr { --dr-dock: 229px; }
/* Plume agrandie par de grands caractères (data-quill="tall", posé par drawer.js) : elle passerait sous
   la fenêtre ; elle monte au-dessus d'elle (345 + 12), et le défilement la suit (+ 24). Écran bas (paysage) :
   elle ne monte jamais plus haut que 72 px sous le haut de l'écran, quitte à frôler la fenêtre. */
html[data-salon="dock"]:not([data-salon-coin^="haut"]) .dr[data-quill="tall"] { --dr-dock: calc(var(--dr-quill-h, 56px) + 241px); }
html[data-salon="dock"]:not([data-salon-coin^="haut"]) .dr[data-quill="tall"] .dr-foot { padding-bottom: calc(357px + var(--safe-bottom)); }
@supports (height: 1dvh) {
  html[data-salon="dock"]:not([data-salon-coin^="haut"]) .dr[data-quill="tall"] .dr-foot {
    padding-bottom: calc(clamp(18px, 100dvh - var(--dr-quill-h, 56px) - 72px - var(--safe-top) - var(--safe-bottom), 357px) + var(--safe-bottom));
  }
}

/* ─── Petits écrans ─── */
@media (max-width: 380px) {
  .dr-name { font-size: 27px; }
  .dr-quill { padding: 0 18px; font-size: 15px; }
}

/* ─── Mouvement réduit : plus de mise en scène, seulement des fondus ─── */
@media (prefers-reduced-motion: reduce) {
  .dr-ghost,
  .dr-caret,
  .dr-land,
  .dr-status__in.is-settling,
  .dr-seal .pc-drop.is-fresh,
  .dr-stamp.is-fresh,
  .dr-candle.is-fresh,
  .dr-disc.is-turning svg { animation: none; }
  .dr-ghost { opacity: .7; }
  .dr-candle { transform: none; }
}
