:root {
  --ink: #0f0e0d;
  --paper: #ede4d3;
  --box: 13px 16px 12px 17px / 16px 12px 17px 13px; /* cadre tracé à la main */
}

/* ---------- page et papier ---------- */
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  position: fixed; inset: 0; overflow: clip;
  display: grid; grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr); justify-items: center;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(120, 96, 60, .16) 100%),
    var(--paper);
}
/* grain du papier */
body::before {
  content: ""; position: absolute; inset: -50%; pointer-events: none;
  opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .28  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
/* fibres plus larges, très légères */
body::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  opacity: .25; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='.012 .04' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .42  0 0 0 0 .3  0 0 0 .5 -.1'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
}

/* ---------- dessin (animation.js) ---------- */
#stage { position: relative; z-index: 1; width: min(94vw, 190vh); }
#ink path, #ghost path { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.55; }
#ghost { opacity: .32; }
#ghost path { stroke-width: .8; }
#stage svg { display: block; width: 100%; height: auto; overflow: visible; }
.dot { opacity: 0; transition: opacity .35s ease; }

/* ---------- logo et menu des langues ---------- */
#logo { position: absolute; z-index: 1; top: clamp(16px, 4vh, 36px); left: clamp(18px, 3vw, 44px); width: clamp(60px, 6vw, 84px); }
#logo svg { display: block; overflow: visible; }
#logo path, .write path { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }

#lang {
  position: absolute; z-index: 2; top: clamp(16px, 4vh, 36px); right: clamp(18px, 3vw, 44px);
  background: var(--paper); border: 1.2px solid var(--ink); border-radius: 10px 12px 9px 13px / 12px 9px 13px 10px;
}
#lang summary, #lang a { display: block; padding: 7px 9px 4px; cursor: pointer; }
#lang summary { list-style: none; }
#lang summary::-webkit-details-marker { display: none; }
#lang a { opacity: .5; transition: opacity .2s; }
#lang a:hover, #lang a:focus-visible { opacity: 1; }
#lang .write { display: block; width: calc(var(--w) * .15px); margin: 0 auto; --step: 60ms; }
#lang .write path { stroke-width: 8; }

/* ---------- textes écrits au crayon (lettering.js) ---------- */
.write { position: relative; z-index: 1; margin: 0; visibility: hidden; }
.write svg { display: block; width: 100%; overflow: visible; }
.write.on { visibility: visible; }
.write path { stroke-dasharray: 1 2; opacity: 0; }
.write.on path { animation: write .16s linear calc(var(--delay, 0s) + var(--i) * var(--step)) forwards; }
@keyframes write { 0% { opacity: 0; stroke-dashoffset: 1; } 1% { opacity: 1; } 100% { opacity: 1; stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .write.on path { animation: none; opacity: 1; } }
h1.write { align-self: end; width: min(84vw, calc(var(--w) * .57px), calc(var(--w) * .085vh)); --step: 30ms; }
h1.write path { stroke-width: 5; }
h1.write g { filter: url(#pencil-text); }
footer { display: flex; flex-direction: column; align-items: center; gap: 22px; padding-top: clamp(4px, 3vh, 30px); }
p.write { width: min(84vw, calc(var(--w) * .205px), calc(var(--w) * .045vh)); --step: 10ms; --delay: .5s; }
p.write path { stroke-width: 6.5; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- boutons ---------- */
#actions {
  position: relative; z-index: 1;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
}
button {
  padding: 13px 24px; color: var(--ink); background: none; cursor: pointer;
  font: 500 16px/1.2 system-ui, sans-serif;
  border: 1.5px solid var(--ink);
  border-radius: 17px 19px 16px 20px / 19px 16px 20px 17px; /* contour tracé à la main */
  transition: background .2s, color .2s;
}
button:hover, button:focus-visible, button.full { background: var(--ink); color: var(--paper); }
button:disabled { opacity: .5; cursor: default; }

/* les deux boutons de la page : contour tracé à la main (outline.js) */
#actions button { position: relative; isolation: isolate; border-color: transparent; background: none; }
#actions svg { position: absolute; z-index: -1; top: -1.5px; left: -1.5px; width: calc(100% + 3px); height: calc(100% + 3px); overflow: visible; }
#actions path { fill: transparent; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; transition: fill .2s; }
#actions .full path, #actions button:hover path, #actions button:focus-visible path { fill: var(--ink); }

/* ---------- formulaires (forms.js) ---------- */
dialog {
  box-sizing: border-box; width: min(92vw, 500px); max-height: 94dvh; overflow: auto;
  padding: clamp(22px, 5vw, 36px); color: var(--ink); background: var(--paper);
  font: 16px/1.45 system-ui, sans-serif;
  border: 1.5px solid var(--ink); border-radius: 28px 34px 27px 35px / 34px 27px 35px 28px;
}
dialog::backdrop { background: rgba(60, 48, 30, .35); }
dialog h2.write { width: min(calc(100% - 44px), calc(var(--w) * .36px)); --step: 12ms; }
dialog h2.write path { stroke-width: 6; }
dialog p { margin: 12px 0 0; }
dialog form { display: grid; gap: 18px; margin-top: 20px; }
dialog label, dialog legend { font-weight: 600; }
dialog fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 8px; }
dialog legend { padding: 0 0 8px; }
dialog input:not([type=checkbox]), dialog textarea {
  box-sizing: border-box; display: block; width: 100%; margin-top: 6px; padding: 10px 12px; color: inherit;
  background: rgba(255, 255, 255, .5); font: 400 16px/1.4 system-ui, sans-serif; resize: none;
  border: 1.5px solid var(--ink); border-radius: var(--box); outline: none;
}
dialog input:not([type=checkbox]):focus, dialog textarea:focus { background: #fff; box-shadow: 0 0 0 1px var(--ink); }
dialog ::placeholder { color: var(--ink); opacity: .5; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* case et coche dessinées à la main */
.check { display: flex; gap: 12px; align-items: center; cursor: pointer; }
label.check { font-weight: 400; }
.check input {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 20px; height: 20px; margin: 0; cursor: pointer;
  border: 1.5px solid var(--ink); border-radius: 6px 7px 5px 7px / 7px 5px 7px 6px;
}
.check input:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.check input:checked::before {
  content: ""; position: absolute; left: -1px; top: -8px; width: 28px; height: 28px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath d='M5 16 C8 18 10 20 11 23 C14 15 19 8 26 3' fill='none' stroke='%230f0e0d' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.close { position: absolute; top: 14px; right: 16px; padding: 4px 10px; border: 0; font-size: 24px; line-height: 1; }
.close:hover, .close:focus-visible { background: none; color: inherit; }
.nickname { position: absolute; left: -9999px; }
.status:empty { display: none; }

/* ---------- petits écrans ---------- */
/* écran bas (téléphone à l'horizontale) */
@media (max-height: 480px) {
  #stage { width: min(94vw, 150vh); }
  footer { gap: 8px; padding-top: 0; }
  #actions button { padding: 9px 18px; font-size: 15px; }
}

/* téléphones et tablettes : pas d'effets recalculés à chaque image, pour une animation fluide */
@media (pointer: coarse), (max-width: 600px) {
  body::before, body::after { inset: 0; mix-blend-mode: normal; }
  #stage { will-change: transform; }
  #ink, h1.write g { filter: none; }
  #ghost { display: none; }
  .write path, .write.on path { animation: none; opacity: 1; stroke-dasharray: none; }
  .write.on { animation: fade .6s ease both; }
  @keyframes fade { from { opacity: 0; } }
}
/* téléphone tenu droit */
@media (max-width: 600px) {
  body {
    box-sizing: border-box; padding: 108px 0 max(32px, env(safe-area-inset-bottom));
    grid-template-rows: auto auto auto; align-content: space-between;
  }
  #logo { width: 72px; }
  #stage { width: 100vw; }
  #ink path { stroke-width: 2.1; }
  #lang { top: 32px; }
  dialog { padding: 18px 20px; }
  dialog form { gap: 13px; margin-top: 14px; }
  dialog fieldset { gap: 6px; }
  dialog input:not([type=checkbox]), dialog textarea { margin-top: 4px; padding: 8px 10px; }
  h1.write { width: min(86vw, calc(var(--w) * .125vw)); }
  h1.write path { stroke-width: 5.5; }
  p.write { width: min(84vw, calc(var(--w) * .0375vw)); }
  footer { width: 84vw; gap: 20px; padding: 0; }
  #actions { width: 100%; flex-direction: column; }
  #actions button { padding: 15px 4px; font-size: clamp(13px, 3.85vw, 16px); }
}
/* petit téléphone */
@media (max-width: 600px) and (max-height: 660px) {
  body { padding: 76px 0 20px; }
  h1.write { width: min(80vw, calc(var(--w) * .105vw)); }
  footer { gap: 14px; }
  #actions { gap: 10px; }
  #actions button { padding: 11px 4px; }
}
