/* ═══════════════════════ Djouney v3 — Rose & Flamme ═══════════════════════
   Jetons, base et composants partagés. Les modules ont chacun leur fichier CSS
   et préfixent leurs classes (voir ARCHITECTURE.md § 8 et § 16).
   La nuit : un velours bordeaux presque noir, la lueur d'une bougie, l'or des flammes, la rose.
   Les lettres et les enveloppes restent sur un parchemin chaud, éclairé par la flamme (.parchemin et
   les surfaces listées plus bas) : c'est là qu'on lit.
   Les noms des jetons sont ceux de la porcelaine d'origine : toute l'app change d'ambiance d'un coup.
   Les couleurs avec transparence passent par des canaux (--ink-rgb, --shadow-rgb…) : rgba(var(--ink-rgb), .7). */

:root {
  /* Matières de la nuit : velours, satin, relief et creux */
  --porcelain: #1A0A10;
  --milk: #2A121B;
  --relief: #3F1D28;
  --hollow: #57303B;
  --porcelain-rgb: 26, 10, 16;
  --milk-rgb: 42, 18, 27;
  --hollow-rgb: 120, 72, 84;
  /* Encres (crème de bougie sur le velours ; contrastes ≥ 4,5:1 sur --milk et --porcelain) */
  --ink: #F7E8DA;
  --ink-rgb: 247, 232, 218;
  --ink-soft: rgba(247, 232, 218, .74);
  --ink-faint: rgba(247, 232, 218, .44);
  --sepia: #E9C6A2;
  --stem: #F3DFCC;
  /* La flamme et la rose */
  --gold: #E8C27E;
  --gold-rgb: 232, 194, 126;
  --flame: #FF9E4A;
  --ember-rgb: 255, 140, 60;
  --rose: #E8455F;
  --thread: #E2405A;
  --thread-rgb: 226, 64, 90;
  --carmine: #F2667A;
  /* Fleur du duo (posée par applyFlower) */
  --flower: #C81E0F;
  --flower-light: #E17470;
  --flower-ink: #FFFFFF;
  /* Lumières et ombres : la flamme éclaire d'en haut, le velours boit la lumière */
  --light-rgb: 255, 214, 170;
  --shadow-rgb: 0, 0, 0;
  --hl-a: .12; /* force des reflets de lumière des modules (1 sur le parchemin) */

  --emboss: inset 0 1px 0 rgba(255, 214, 170, .07), 0 0 0 1px rgba(232, 194, 126, .11), 0 14px 32px rgba(0, 0, 0, .48);
  --emboss-sm: inset 0 1px 0 rgba(255, 214, 170, .07), 0 0 0 1px rgba(232, 194, 126, .12), 0 6px 16px rgba(0, 0, 0, .42);
  --deboss: inset 0 2px 7px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(232, 194, 126, .09);
  --glow: 0 0 22px rgba(255, 140, 60, .28);

  /* Grain du velours : bruit fractal chaud, tuile SVG en data URI (aucun fichier). */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .6 0 0 0 0 .5 0 0 0 1.4 -.35'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)' opacity='.045'/%3E%3C/svg%3E");
  --grain-papier: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .25 0 0 0 0 .17 0 0 0 1.4 -.35'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)' opacity='.06'/%3E%3C/svg%3E");

  --font-hand: "Caveat", "Segoe Script", cursive;
  --font-script: "Pinyon Script", "Caveat", cursive;
  --font-serif: "Cormorant Garamond", "Fraunces", Georgia, serif;
  --font-ui: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --ease: cubic-bezier(.22, .8, .24, 1);
  --slow: 700ms;
  --mid: 420ms;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

/* ─── Le parchemin : ce qu'on ouvre et ce qu'on écrit ───
   La conversation se lit sur le velours ; les objets (l'enveloppe scellée, la feuille à déchirer, la lettre
   d'invitation, la feuille où l'on écrit, les papiers secrets) sont en parchemin.
   Les mêmes jetons, en clair : tout ce qui est posé dessus redevient encre brune sur papier. */
.parchemin,
.pc-tear__sheet,
.pc-env,
.dr-env,
.ar-sheet,
.wr-sheet,
.cn-first__paper,
.ob-paper,
.ik-paper {
  --porcelain: #EEDCC6;
  --milk: #F7EBDC;
  --relief: #DCC4A8;
  --hollow: #C6A787;
  --porcelain-rgb: 238, 220, 198;
  --milk-rgb: 247, 235, 220;
  --hollow-rgb: 198, 167, 135;
  --ink: #2A1416;
  --ink-rgb: 42, 20, 22;
  --ink-soft: rgba(42, 20, 22, .72);
  --ink-faint: rgba(42, 20, 22, .42);
  --sepia: #5E3A2C;
  --stem: #2A1416;
  --gold: #9A6A26;
  --gold-rgb: 154, 106, 38;
  --thread: #B8243A;
  --thread-rgb: 184, 36, 58;
  --carmine: #A3121B;
  --light-rgb: 255, 250, 240;
  --shadow-rgb: 120, 80, 50;
  --hl-a: 1;
  --emboss: 0 0 0 1px rgba(120, 70, 40, .10), 0 18px 38px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .25);
  --emboss-sm: 0 0 0 1px rgba(120, 70, 40, .10), 0 6px 14px rgba(0, 0, 0, .35);
  --deboss: inset 3px 4px 9px rgba(120, 80, 50, .22), inset -3px -3px 7px rgba(255, 250, 240, .7);
  --grain: var(--grain-papier);
  /* Les teintes que chaque module dérive de l'encre, recalculées sur le papier. */
  --cn-soft: rgba(var(--ink-rgb), .84);
  --dr-soft: rgba(var(--ink-rgb), .84);
  --ar-soft: rgba(var(--ink-rgb), .74);
  --ar-rule: rgba(var(--hollow-rgb), .5);
  --wr-soft: rgba(var(--ink-rgb), .74);
  --wr-rule: rgba(var(--hollow-rgb), .58);
  --wr-sep: rgba(var(--hollow-rgb), .55);
  --sh-soft: rgba(var(--ink-rgb), .74);
  --au-soft: rgba(var(--ink-rgb), .74);
  --df-soft: rgba(var(--ink-rgb), .8);
  --ik-soft: rgba(var(--ink-rgb), .8);
  --ns-soft: rgba(var(--ink-rgb), .82);
  --ns-faint: rgba(var(--ink-rgb), .58);
  --sl-soft: rgba(var(--ink-rgb), .84);
  color: var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { background: #12060A; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  /* Le velours, la lueur d'une bougie en haut, l'ombre aux bords ; grain par-dessus. */
  background-color: #12060A;
  background-image:
    var(--grain),
    radial-gradient(70vmax 55vmax at 50% -8%, rgba(255, 150, 70, .16) 0%, rgba(160, 40, 50, .10) 38%, transparent 70%),
    radial-gradient(120vmax 90vmax at 50% 30%, #241018 0%, #170910 55%, #0C0306 100%);
  background-size: 180px 180px, auto, auto;
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
}
/* La lueur de la bougie respire, très doucement (rien si le téléphone demande moins d'animation). */
body::before {
  content: "";
  position: fixed;
  inset: -10vmax -10vmax auto;
  height: 70vmax;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(50% 50% at 50% 20%, rgba(255, 160, 80, .10), transparent 70%);
  animation: lueur 6s ease-in-out infinite alternate;
}
@keyframes lueur {
  0% { opacity: .55; transform: translateY(0) scale(1); }
  45% { opacity: .9; }
  60% { opacity: .7; transform: translateY(-1.5vmax) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1.02); }
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ink); }
::selection { background: rgba(232, 69, 95, .35); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 8px; }
.parchemin :focus-visible, .paper :focus-visible { outline-color: var(--ink-soft); }
[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

#app { position: relative; height: 100%; max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; }

/* ─── Démarrage ─── */
.boot { flex: 1; display: grid; place-content: center; justify-items: center; gap: 18px; }
.boot-name { margin: 0; font-family: var(--font-script); font-size: 54px; font-weight: 400; color: var(--ink); letter-spacing: .5px; text-shadow: 0 0 24px rgba(255, 150, 70, .35); }
.boot-thread { width: 1.5px; height: 90px; background: linear-gradient(var(--gold), var(--thread)); transform-origin: top; animation: threadDrop 1.4s var(--ease) infinite alternate; }
@keyframes threadDrop { from { transform: scaleY(.15); } to { transform: scaleY(1); } }

/* ─── Écran ─── */
.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  animation: screenIn var(--slow) var(--ease);
}
@keyframes screenIn { from { opacity: 0; transform: translateY(6px); } }

/* ─── Matières ─── */
/* .parchemin : le papier éclairé par la flamme (bords un peu plus sombres, lumière chaude en haut). */
.parchemin {
  background-color: var(--milk);
  background-image: var(--grain), radial-gradient(130% 90% at 50% 0%, rgba(255, 246, 228, .9) 0%, rgba(247, 235, 220, 0) 60%), linear-gradient(180deg, #F8EDDF, #EFDEC8);
  background-size: 180px 180px, auto, auto;
  border-radius: var(--radius);
  box-shadow: var(--emboss);
}
/* .paper et .velours : une surface de la nuit (cartes, réglages, formulaires). */
.paper,
.velours {
  background-color: var(--milk);
  background-image: var(--grain), linear-gradient(160deg, rgba(255, 214, 170, .05), rgba(0, 0, 0, 0) 45%);
  background-size: 180px 180px, auto;
  border-radius: var(--radius);
  box-shadow: var(--emboss);
}
.emboss { box-shadow: var(--emboss); }
.deboss { box-shadow: var(--deboss); background: var(--porcelain); }

/* ─── Textes ─── */
.hand { font-family: var(--font-hand); font-weight: 500; }
.script { font-family: var(--font-script); font-weight: 400; }
.serif-i { font-family: var(--font-serif); font-style: italic; font-weight: 400; }
.ui-label { font-family: var(--font-ui); font-size: 12.5px; font-weight: 500; letter-spacing: .3px; color: var(--ink-soft); }

/* ─── Boutons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px;
  border: 0; border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 214, 170, .06), rgba(255, 214, 170, 0)), var(--milk); color: var(--ink);
  box-shadow: var(--emboss-sm);
  font-family: var(--font-ui); font-size: 15px; font-weight: 500;
  transition: transform .15s var(--ease), box-shadow .25s var(--ease), opacity .2s, filter .2s;
}
.btn:active { transform: translateY(1px); box-shadow: var(--deboss); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--quiet { background: transparent; box-shadow: none; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; text-decoration-color: rgba(var(--gold-rgb), .7); min-height: 40px; padding: 0 10px; }
.btn--quiet:active { box-shadow: none; }
/* Le bouton de la fleur : la cire, avec une lueur de flamme. */
.btn--flower {
  background: radial-gradient(120% 140% at 30% 0%, color-mix(in srgb, var(--flower) 70%, #fff 30%) 0%, var(--flower) 45%, color-mix(in srgb, var(--flower) 70%, #000 30%) 100%);
  color: var(--flower-ink, #fff);
  box-shadow: 0 0 0 1px rgba(255, 214, 170, .18), 0 8px 22px color-mix(in srgb, var(--flower) 40%, transparent), 0 0 26px rgba(255, 140, 60, .18);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
}
.btn--block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--milk); color: var(--stem);
  box-shadow: var(--emboss-sm);
  transition: transform .15s var(--ease), box-shadow .25s;
}
.icon-btn:active { box-shadow: var(--deboss); transform: translateY(1px); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn--bare { background: transparent; box-shadow: none; }

/* ─── Champs ─── */
.field {
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border: 0; border-radius: 16px;
  background: var(--porcelain);
  box-shadow: var(--deboss);
  color: var(--ink);
  font-size: 16px;
  outline: none;
}
.field::placeholder { color: var(--ink-faint); }
.field:focus { box-shadow: var(--deboss), 0 0 0 2px rgba(var(--gold-rgb), .55); }
.field-label { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }

/* ─── Feuilles modales : du velours qui monte, bordé d'or ─── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 2, 4, .62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fadeIn .3s var(--ease);
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  padding: 12px 20px calc(24px + var(--safe-bottom));
  background-color: #241018;
  background-image: var(--grain), radial-gradient(120% 60% at 50% 0%, rgba(255, 150, 70, .10), transparent 70%);
  background-size: 180px 180px, auto;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -1px 0 rgba(232, 194, 126, .35), 0 -18px 50px rgba(0, 0, 0, .6);
  animation: sheetIn .55s var(--ease);
}
.sheet-grabber { width: 42px; height: 5px; border-radius: 3px; background: rgba(232, 194, 126, .35); margin: 0 auto 16px; }
.sheet-title { margin: 0 0 4px; font-family: var(--font-script); font-size: 38px; font-weight: 400; color: var(--ink); line-height: 1.15; }
.sheet-sub { margin: 0 0 18px; font-family: var(--font-serif); font-style: italic; font-size: 17px; color: var(--ink-soft); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes sheetIn { from { transform: translateY(48px); opacity: 0; } }

/* ─── Messages éphémères ─── */
#toasts { position: fixed; z-index: 100; left: 0; right: 0; top: calc(14px + var(--safe-top)); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 440px;
  padding: 12px 18px; border-radius: 18px;
  background: #2E141E; color: var(--ink);
  box-shadow: var(--emboss-sm);
  font-size: 14px;
  animation: toastIn .5s var(--ease);
}
.toast--error { box-shadow: var(--emboss-sm), inset 3px 0 0 var(--thread); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  body::before { animation: none; opacity: .8; }
}
