/* Caveat (SIL Open Font License, voir fonts/OFL.txt) : écriture manuscrite,
   hébergée ici pour un rendu identique sur tous les téléphones. */
@font-face {
  font-family: "Caveat"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/caveat-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Caveat"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/caveat-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f7f1e8;
  --bg2: #efe3d3;
  --card: #fffdf9;
  --text: #2d2420;
  --muted: #86766c;
  --accent: #9c4a3c;
  --accent2: #c2703d;
  --line: #e6d8c6;
  --ok: #3f7d3a;
  --ko: #c2410c;
  --paper: #fffaf0;
  --ink: #2a2140;
  --rule: rgba(80, 110, 170, 0.14);
  --shadow: 0 10px 30px rgba(110, 70, 40, 0.12);
  --hand: "Caveat", "Segoe Script", "Bradley Hand", cursive;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1613;
    --bg2: #241c17;
    --card: #2a221d;
    --text: #f3e9df;
    --muted: #b49f8f;
    --line: #463a31;
    --accent: #d07a62;
    --accent2: #e0a15e;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); }
.wrap { max-width: 520px; margin: 0 auto; padding: 20px 16px 40px; }
.wrap.wide { max-width: 760px; }
h1, h2 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

.hero { text-align: center; margin: 32px 0 24px; }
.logo { font-size: 3rem; }

.nav {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: 760px; margin: 0 auto; padding: 12px 16px;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.nav-links { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nav-links a, .nav-links .link { color: var(--muted); font-size: 0.95rem; }
.nav-links form { margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

label { display: block; font-weight: 600; margin-bottom: 14px; }
input:not([type="checkbox"]), textarea {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px 14px; font: inherit; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 2px; margin: 0 0 6px; }
legend { font-weight: 600; padding: 0 6px; }
.error { color: var(--ko); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }

.btn {
  display: inline-block; border: 0; cursor: pointer;
  padding: 12px 20px; border-radius: 999px;
  font-size: 1rem; font-weight: 600; text-decoration: none; text-align: center;
  background: var(--line); color: var(--text);
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; width: 100%; }
.btn.primary.auto { width: auto; }
.btn.small { padding: 8px 14px; font-size: 0.9rem; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--ko); border: 1px solid currentColor; }
.link { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.foot { text-align: center; margin-top: 20px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.letters, .list { list-style: none; padding: 0; margin: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; color: inherit; text-decoration: none; }
.letter-row { display: flex; flex-direction: column; color: inherit; text-decoration: none; font-size: 1.1rem; }
.letters p { margin: 8px 0 0; }

.paper-input {
  font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; line-height: 1.7;
  background: var(--paper); color: var(--ink); min-height: 320px;
}

.share .linkbox { display: flex; gap: 8px; margin: 10px 0; }
.share .linkbox input { margin: 0; font-size: 0.95rem; }
.qr { display: block; width: 220px; max-width: 100%; margin: 14px auto; background: #fff; border-radius: 10px; padding: 8px; }
form.inline { display: flex; gap: 8px; margin-bottom: 8px; }
form.inline input { margin: 0; }

/* Lecture d'une lettre */
.desk { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; }

.envelope {
  position: relative; display: block; width: 100%; max-width: 440px; aspect-ratio: 3 / 2;
  margin: 8vh auto 0; border: 0; border-radius: 10px; cursor: pointer; overflow: hidden;
  background: linear-gradient(160deg, #e9d3b5, #d9b98f); box-shadow: 0 18px 40px rgba(80, 50, 20, 0.25);
  color: #4a3424; font: inherit;
  animation: float 3s ease-in-out infinite;
}
.envelope .flap {
  position: absolute; inset: 0 0 auto 0; height: 58%;
  background: linear-gradient(170deg, #dcc09a, #caa476);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top; transition: transform 0.6s ease;
}
.envelope .seal {
  position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%);
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem;
  background: radial-gradient(circle at 35% 35%, #c0533f, #8c2f22); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}
.envelope-to {
  position: absolute; left: 0; right: 0; bottom: 18%; text-align: center;
  font-family: var(--hand); font-size: 1.9rem;
  padding: 0 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.envelope-hint { position: absolute; left: 0; right: 0; bottom: 6%; text-align: center; font-size: 0.8rem; opacity: 0.7; }
.envelope.open { animation: none; }
.envelope.open .flap { transform: rotateX(180deg); }
.envelope.open { transition: opacity 0.4s 0.5s, transform 0.4s 0.5s; opacity: 0; transform: translateY(30px); }
@keyframes float { 50% { transform: translateY(-6px); } }

.paper {
  background: var(--paper); color: var(--ink);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(1.8em - 1px), var(--rule) calc(1.8em - 1px), var(--rule) 1.8em);
  font-family: Georgia, "Times New Roman", serif; font-size: 1.12rem; line-height: 1.8em;
  padding: 40px 36px 48px; border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), 0 20px 50px rgba(80, 50, 20, 0.22);
  animation: unfold 0.7s ease both;
}
.paper p { margin: 0 0 1.8em; white-space: pre-wrap; overflow-wrap: anywhere; }
.paper-date { text-align: right; font-style: italic; opacity: 0.7; }
.paper-title { font-size: 1.6rem; line-height: 1.8em; margin: 0 0 0.9em; text-align: center; font-weight: 400; }
.paper-sign {
  text-align: right; font-family: var(--hand);
  font-size: 2rem; margin-top: 2.4em !important;
}
@keyframes unfold { from { opacity: 0; transform: translateY(24px) scale(0.97); } }
/* Photos dans la lettre, façon polaroïd */
.photos { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin: 0 0 1.8em; }
.photo {
  display: block; background: #fff; padding: 8px 8px 26px; max-width: 100%;
  box-shadow: 0 6px 18px rgba(60, 40, 20, 0.25); transform: rotate(-2deg);
}
.photo:nth-child(even) { transform: rotate(2.5deg); }
.photo:only-child { transform: rotate(-1deg); }
.photo img { display: block; max-width: 100%; max-height: 420px; }
.photos .photo:not(:only-child) img { max-width: 260px; }

.music-toggle {
  position: fixed; right: 16px; bottom: 16px; width: 48px; height: 48px; border-radius: 50%;
  border: 0; cursor: pointer; font-size: 1.3rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: var(--shadow);
  animation: pulse 2s ease-in-out infinite;
}
.music-toggle.paused { animation: none; opacity: 0.6; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* Lettre en attente (brouillon ou date d'ouverture) */
.envelope.locked { cursor: default; animation: none; filter: saturate(0.85); }
.waiting { margin-top: 28px; font-size: 1.05rem; }
.countdown { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.banner {
  background: var(--card); border: 1px dashed var(--accent); border-radius: 12px;
  padding: 10px 14px; text-align: center; margin: 0 auto 16px; max-width: 720px;
}
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--text); margin-right: 4px; }
.ok-tag { background: rgba(63, 125, 58, 0.15); color: var(--ok); }

/* Éditeur : médias */
input.hand { font-family: var(--hand); font-size: 1.5rem; padding: 6px 14px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.thumb { position: relative; margin: 0; }
.thumb img { display: block; width: 96px; height: 96px; object-fit: cover; border-radius: 10px; }
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; cursor: pointer; background: rgba(0, 0, 0, 0.6); color: #fff;
}
.upload input[type="file"] { padding: 10px; font-size: 0.9rem; }
.music-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.music-row audio { max-width: 100%; }
.music-row form { margin: 0; }

@media (max-width: 520px) { .paper { padding: 28px 20px 36px; font-size: 1.05rem; } }
@media (prefers-reduced-motion: reduce) {
  .envelope, .paper, .music-toggle { animation: none; }
}
@media print {
  body { background: none; }
  .nav, .foot, .envelope, .banner, .music-toggle { display: none !important; }
  .paper { display: block !important; box-shadow: none; background-image: none; }
}

/* QR de connexion d'un lecteur */
.reader-qr { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 12px 0; }
.reader-qr summary { cursor: pointer; font-weight: 600; }
.reader-qr .linkbox { display: flex; gap: 8px; margin: 10px 0; }
.reader-qr .linkbox input { margin: 0; font-size: 0.9rem; }
.row-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* Choix « le QR demande un mot de passe » */
.check.sub { margin-left: 28px; }
.qr-mode { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.unlock { max-width: 440px; margin: 24px auto 0; }
