/* figures — feuille de style
   Gravure imprimée : papier texturé, encre, filets fins, mono pour l'interface
   et un serif pour les noms de figures. */

:root {
  --paper: #f4f1e8;
  --paper-a: #faf8f2;
  --paper-b: #e6deca;
  --ink: #17140f;
  --muted: #8b8375;
  --rule: rgba(23, 20, 15, 0.22);
  --rule-2: rgba(23, 20, 15, 0.1);
  --wash: rgba(23, 20, 15, 0.05);
  --tshadow: 0 0 0.6px rgba(23, 20, 15, 0.45);
  --grain: 0.58;
  --fibers: 0.2;
  --laid: 1;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas,
    "DejaVu Sans Mono", "Liberation Mono", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --pad: clamp(18px, 4.5vw, 56px);
}

body[data-theme="nuit"] {
  --paper: #0a0a0b;
  --paper-a: #111113;
  --paper-b: #050506;
  --ink: #e8e8e1;
  --muted: #6e6e67;
  --rule: rgba(232, 232, 225, 0.2);
  --rule-2: rgba(232, 232, 225, 0.09);
  --wash: rgba(232, 232, 225, 0.06);
  --tshadow: 0 0 7px rgba(232, 232, 225, 0.18);
  --grain: 0.3;
  --fibers: 0.12;
  --laid: 0.3;
}

body[data-theme="sepia"] {
  --paper: #efe5d4;
  --paper-a: #f6eee1;
  --paper-b: #dfd0b8;
  --ink: #46321f;
  --muted: #9b8a71;
  --rule: rgba(70, 50, 31, 0.24);
  --rule-2: rgba(70, 50, 31, 0.11);
  --wash: rgba(70, 50, 31, 0.06);
  --tshadow: 0 0 0.6px rgba(70, 50, 31, 0.45);
  --grain: 0.62;
  --fibers: 0.22;
  --laid: 1;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body { margin: 0; }

body {
  min-height: 100%;
  background:
    radial-gradient(125% 105% at 50% 30%, var(--paper-a) 0%, var(--paper) 55%, var(--paper-b) 100%) fixed;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  transition: color 0.4s ease;
}

::selection { background: var(--ink); color: var(--paper); }

a { color: inherit; }

/* ------------------------------------------------------------- entête */

.mast {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--rule);
}

.mast-in {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px var(--pad);
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.wordmark {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.02em;
  text-decoration: none;
  line-height: 1;
}

.mast-meta {
  margin: 0;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.mast-meta-end {
  margin-left: auto;
  display: flex;
  gap: 16px;
}

.mast-meta-end a { text-decoration: none; border-bottom: 1px solid transparent; }
.mast-meta-end a:hover { color: var(--ink); border-bottom-color: var(--rule); }

/* ------------------------------------------------------------- contenu */

.wrap {
  position: relative;
  z-index: 2;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--pad);
}

.kicker {
  margin: 0 0 22px;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero {
  padding: clamp(44px, 9vh, 104px) 0 clamp(30px, 5vh, 54px);
  border-bottom: 1px solid var(--rule-2);
}

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(31px, 5.4vw, 64px);
  line-height: 1.03;
  letter-spacing: -0.018em;
}

.lede {
  margin: 26px 0 0;
  max-width: 64ch;
  font-size: 12.5px;
  line-height: 1.72;
  color: var(--muted);
}

/* --------------------------------------------------------------- sections */

.sec {
  padding-top: clamp(38px, 6vh, 74px);
}

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: clamp(14px, 2.4vh, 26px);
}

.sec-num {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 14px;
}

.sec-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 18px;
  line-height: 1;
}

.sec-meta {
  margin-left: auto;
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
}

/* ---------------------------------------------------------------- planche */

.stage {
  position: relative;
  height: clamp(340px, 60vh, 640px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--rule);
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(120% 100% at 50% 40%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 70%);
}

body[data-theme="nuit"] .stage { background: none; }
body.dragging .stage { cursor: grabbing; }

#screen {
  margin: 0;
  font-family: var(--mono);
  line-height: 1;
  letter-spacing: 0;
  font-size: 13px;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  white-space: pre;
  color: var(--ink);
  text-shadow: var(--tshadow);
  contain: strict;
}

/* cadre gravé : suit la boîte d'encre de la figure */
.plate {
  position: absolute;
  top: 0;
  left: 0;
  border: 1px solid var(--rule);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.55s ease;
}

.plate::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--rule-2);
}

.plate-num {
  position: absolute;
  top: -14px;
  right: 0;
  font-size: 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.marks { position: absolute; inset: 14px; pointer-events: none; }

.mark {
  position: absolute;
  width: 13px;
  height: 13px;
  border: 0 solid var(--rule);
}

.mark.tl { top: 0; left: 0; border-top-width: 1px; border-left-width: 1px; }
.mark.tr { top: 0; right: 0; border-top-width: 1px; border-right-width: 1px; }
.mark.bl { bottom: 0; left: 0; border-bottom-width: 1px; border-left-width: 1px; }
.mark.br { bottom: 0; right: 0; border-bottom-width: 1px; border-right-width: 1px; }

.caption {
  position: absolute;
  left: 16px;
  bottom: 13px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  pointer-events: none;
}

.cap-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cap-hint { font-size: 8.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

/* ---------------------------------------------------------------- outils */

.tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 26px;
  padding: 14px 0 0;
  border-top: 1px solid var(--rule-2);
  margin-top: 14px;
}

.ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.ctl span { min-width: 48px; }

.ctl input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(88px, 12vw, 150px);
  height: 1px;
  background: var(--rule);
  outline: none;
  cursor: ew-resize;
}

.ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 6px;
  height: 13px;
  border-radius: 0;
  background: var(--ink);
}

.ctl input[type="range"]::-moz-range-thumb {
  width: 6px;
  height: 13px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
}

.ctl input[type="range"]:focus-visible { background: var(--ink); }

.drop {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px dashed var(--rule);
  color: var(--muted);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.drop:hover,
.drop.is-over { border-color: var(--ink); background: var(--wash); color: var(--ink); }

.drop input { display: none; }

.acts { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; }

.acts button {
  padding: 7px 11px;
  border: 1px solid var(--rule);
  background: none;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.acts button:hover { background: var(--wash); }
.acts button.is-done { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.acts button.is-on { background: var(--wash); border-color: var(--ink); }

button:focus-visible,
.drop:focus-within,
a:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

.note {
  margin: 9px 0 0;
  font-size: 9px;
  letter-spacing: 0.06em;
  line-height: 1.5;
  color: var(--muted);
  min-height: 13px;
}

/* ------------------------------------------------------------- collection */

.figs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 10px 22px;
}

.fig {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 12px 0 14px;
  border: 0;
  border-top: 1px solid var(--rule-2);
  background: none;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.fig:hover { border-top-color: var(--ink); }

.fig.is-active { border-top-color: var(--ink); }

.fig-art {
  margin: 0;
  font-family: var(--mono);
  font-size: 5.3px;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre;
  height: 118px;
  overflow: hidden;
  color: var(--ink);
  opacity: 0.72;
  transition: opacity 0.2s ease;
}

.fig:hover .fig-art,
.fig.is-active .fig-art { opacity: 1; }

.fig-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.fig-n {
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.fig-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1;
}

.fig.is-active .fig-name { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }

/* ------------------------------------------------------------- procédé */

.proc {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 26px 40px;
}

.proc article { border-top: 1px solid var(--rule-2); padding-top: 12px; }

.p-num {
  display: block;
  font-size: 8.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.proc h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 16px;
}

.proc p {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
}

/* ------------------------------------------------------------------ pied */

.foot {
  position: relative;
  z-index: 2;
  max-width: 1240px;
  margin: clamp(56px, 9vh, 110px) auto 0;
  padding: 16px var(--pad) 34px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  justify-content: space-between;
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------------------------------------------------------- papier */

.fibers,
.laid,
.grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.fibers {
  opacity: var(--fibers);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='4' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='420' height='420' filter='url(%23f)' opacity='0.55'/></svg>");
}

.laid {
  opacity: var(--laid);
  background-image:
    repeating-linear-gradient(to bottom,
      rgba(96, 74, 44, 0.055) 0 1px,
      rgba(0, 0, 0, 0) 1px 4px),
    repeating-linear-gradient(to right,
      rgba(96, 74, 44, 0.035) 0 1px,
      rgba(0, 0, 0, 0) 1px 27px);
}

.grain {
  opacity: var(--grain);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.2'/></svg>");
}

#probe {
  position: fixed;
  left: -9999px;
  top: 0;
  white-space: pre;
  line-height: 1;
  letter-spacing: 0;
  font-family: var(--mono);
  visibility: hidden;
  pointer-events: none;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .hero h1 br { display: none; }
  .mast-meta-end { display: none; }
  .stage { height: clamp(280px, 48vh, 460px); }
  .acts { margin-left: 0; }
  .cap-hint { display: none; }
  .fig-art { height: 104px; }
}

@media (max-width: 520px) {
  .figs { grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
  .fig-art { font-size: 4.4px; height: 86px; }
  .tools { gap: 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ------------------------------------------------- canevas : planche et vignettes */

/* le rendu se fait désormais dans un canevas : les glyphes y sont peints, puis
   remplis par l'image de couleur d'une cellule par caractère */
#screen {
  display: block;
  text-shadow: none;
  image-rendering: auto;
}

canvas.fig-art {
  display: block;
  width: 100%;
  height: auto;
  font-size: 0; /* le texte n'est plus dans le DOM */
  image-rendering: pixelated;
}
