:root {
  --bg: #f4f3f0;
  --panel: #e6e6e3;
  --panel-2: #dededa;
  --white: #ffffff;
  --ink: #111110;
  --mute: #8b8a85;
  --line: #d9d8d3;
  --sans: "Geist", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --pad: 6px;
  --cell: 20px;
  --r: 10px;
  --ease: cubic-bezier(.2, .7, .1, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 14px 34px -18px rgba(0, 0, 0, .22);
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg); color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  font: 400 14px/1.45 var(--sans); letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
  padding-bottom: 70px;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
ol { list-style: none; }
code { font-family: var(--mono); font-size: .92em; }
::selection { background: var(--ink); color: var(--bg); }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }

.lab, .k, .row > label:first-child:not(.check), .group-title, .specs dt, .unit {
  font-family: var(--mono); font-size: 10.5px; line-height: 1.3; text-transform: uppercase; letter-spacing: .02em; font-weight: 400;
}
.mute { color: var(--mute); }
.note { font-size: 12px; color: var(--mute); margin-top: 12px; max-width: 46em; }
.arr { display: inline-block; transition: transform .4s var(--ease); }
.link { border-bottom: 1px solid var(--line); transition: border-color .3s; }
.link:hover { border-color: var(--ink); }
.todo { color: var(--mute); }

/* ---------- Pastilles ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--white); color: var(--ink); border: 0; border-radius: 999px;
  padding: 5px 10px; font: 500 11px/1.2 var(--sans); letter-spacing: 0; cursor: pointer;
  transition: background .3s var(--ease), color .3s var(--ease), box-shadow .3s;
}
.pill:hover { background: var(--ink); color: var(--white); }
.pill.dark { background: var(--ink); color: var(--white); padding: 8px 14px; }
.pill.dark:hover { background: #3a3a37; }
.pill.line { background: transparent; box-shadow: inset 0 0 0 1px var(--line); padding: 8px 14px; }
.pill.line:hover { background: var(--ink); color: var(--white); box-shadow: inset 0 0 0 1px var(--ink); }
.pill.sm { padding: 5px 11px; }
.pill:disabled, .round:disabled { opacity: .35; pointer-events: none; }
.round {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: var(--white); font: 500 12px/1 var(--sans); cursor: pointer;
  transition: background .3s var(--ease), color .3s, transform .4s var(--ease);
}
.round:hover { background: var(--ink); color: var(--white); }
.tl, .tr { position: absolute; top: 12px; z-index: 2; }
.tl { left: 12px; }
.tr { right: 12px; }
.bl { position: absolute; bottom: 12px; left: 12px; z-index: 2; }

/* Navigation flottante */
.pills {
  position: fixed; bottom: 14px; left: 50%; z-index: 50; translate: -50% 0;
  display: flex; gap: 3px; padding: 3px; border-radius: 999px;
  background: rgba(244, 243, 240, .6); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .05), 0 8px 24px -12px rgba(0, 0, 0, .25);
}
.pills .pill.active { background: var(--ink); color: var(--white); }

.pagehead {
  display: flex; justify-content: space-between; gap: 20px;
  margin: 0 var(--pad); padding: 14px 8px 12px; border-bottom: 1px solid var(--line);
}

/* ---------- Animations ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes wipe { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }

.js [data-reveal] { opacity: 0; transform: translateY(14px); transition: opacity 1.1s var(--ease) var(--rd, 0s), transform 1.1s var(--ease) var(--rd, 0s); }
.js [data-reveal].in { opacity: 1; transform: none; }

/* ---------- Gabarit ---------- */
.gab {
  display: grid; grid-template-columns: minmax(290px, 330px) 1fr; gap: 40px; align-items: start;
  padding: var(--pad); min-height: calc(100svh - 70px);
}
.controls { padding: 14px 8px 4px; }
.stepper { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-bottom: 26px; }
.step-tab {
  display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; border: 0; border-radius: var(--r);
  background: var(--panel); cursor: pointer; font-size: 14px; font-weight: 500; text-align: left;
  transition: background .4s var(--ease), color .4s var(--ease);
}
.step-tab .lab { color: var(--mute); transition: color .4s; }
.step-tab:hover { background: var(--panel-2); }
.step-tab[aria-selected=true] { background: var(--ink); color: var(--white); }
.step-tab[aria-selected=true] .lab { color: rgba(255, 255, 255, .5); }
.panel:not([hidden]) { animation: fadeUp .7s var(--ease) both; }
.sec { padding: 12px 0 18px; border-top: 1px solid var(--line); }
.sec:first-child { border-top-color: var(--ink); }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  min-height: 38px; padding: 4px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row > label:first-child:not(.check), .row > .k { color: var(--mute); flex-shrink: 0; }
.v { display: flex; align-items: center; gap: 6px; }
.unit { color: var(--mute); }

input[type=number], input[type=text] {
  background: transparent no-repeat; border: 0; border-radius: 0; padding: 3px 0; min-width: 0; outline: none;
  font-size: 13px; text-align: right;
  background-image: linear-gradient(var(--ink), var(--ink)); background-size: 0 1px; background-position: 100% 100%;
  transition: background-size .5s var(--ease);
}
input:focus { background-size: 100% 1px; }
input[type=number] { width: 52px; -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* Menus déroulants : une pastille, sans contour ni soulignement */
select {
  -webkit-appearance: none; appearance: none; cursor: pointer; border: 0; border-radius: 999px; outline: none;
  min-width: 0; max-width: 100%; padding: 6px 28px 6px 12px; font-size: 12.5px; line-height: 1.2;
  text-overflow: ellipsis; white-space: nowrap;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M.5.5 4 4 7.5.5' fill='none' stroke='%23111110' stroke-width='1.1'/%3E%3C/svg%3E") no-repeat right 12px center / 8px 5px;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
select:hover, select:focus { background-color: var(--panel-2); }
select:focus-visible { outline: none; }
select.on {
  background-color: var(--ink); color: var(--white);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M.5.5 4 4 7.5.5' fill='none' stroke='%23ffffff' stroke-width='1.1'/%3E%3C/svg%3E");
}
select.on:hover, select.on:focus { background-color: #2c2c2a; }
select option, select optgroup { background: var(--white); color: var(--ink); }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; min-width: 0; height: 18px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type=range]::-moz-range-track { height: 1px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 11px; margin-top: -5px; border-radius: 50%; background: var(--ink); border: 0; transition: scale .3s var(--ease); }
input[type=range]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--ink); border: 0; }
input[type=range]:active::-webkit-slider-thumb { scale: 1.3; }

/* Formes : vignettes dessinées */
.shapes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.shapes button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px 2px;
  border: 0; border-radius: var(--r); background: var(--panel); cursor: pointer;
  font: 400 9.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .02em; color: var(--mute);
  transition: background .3s var(--ease), color .3s, box-shadow .3s;
}
.shapes svg { width: 34px; height: 34px; overflow: visible; transition: transform .6s var(--ease); }
.shapes path { fill: var(--white); stroke: var(--mute); stroke-width: .7; transition: stroke .3s; }
.shapes button:hover { background: var(--panel-2); color: var(--ink); }
.shapes button:hover svg { transform: translateY(-2px); }
.shapes button[aria-pressed=true] { background: var(--white); color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.shapes button[aria-pressed=true] path { stroke: var(--ink); }
.shapes path.plus { fill: none; stroke: var(--mute); stroke-width: 1.5; stroke-linecap: round; }
.shapes button[aria-pressed=true] path.plus, .shapes button:hover path.plus { stroke: var(--ink); }
.custom-row { margin-top: 8px; border-bottom: 0; }
.contour-name { flex: 1; min-width: 0; font-size: 12px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hPart.locked .num button { visibility: hidden; }
#hPart.locked input { color: var(--mute); }

/* Dimensions : grands chiffres */
.dims { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 6px; margin-bottom: 6px; }
.dims.one { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 8px; border-radius: var(--r); background: var(--panel); transition: background .3s, box-shadow .3s; }
.field:focus-within { background: var(--white); box-shadow: inset 0 0 0 1px var(--ink); }
.field .k { color: var(--mute); }
.field .num { justify-content: space-between; }
.field input[type=number] { width: 100%; font-size: 26px; line-height: 1; letter-spacing: -.03em; text-align: center; padding: 2px 0; background-size: 0 0; }
.num { display: flex; align-items: center; gap: 4px; }
.num button {
  flex-shrink: 0; display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: transparent; color: var(--mute); font: 400 14px/1 var(--sans); cursor: pointer; transition: background .25s, color .25s;
}
.num button:hover { background: var(--ink); color: var(--white); }
.row .num input { width: 36px; text-align: center; }
.swap {
  align-self: center; width: 26px; height: 26px; border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  color: var(--mute); font-size: 13px; transition: color .2s, background .2s, transform .5s var(--ease);
}
.swap:hover { color: var(--white); background: var(--ink); transform: rotate(180deg); }

/* Interrupteurs */
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.check input {
  -webkit-appearance: none; appearance: none; position: relative; flex-shrink: 0; width: 26px; height: 15px; margin: 0; cursor: pointer;
  border-radius: 999px; background: var(--panel-2); transition: background .3s var(--ease);
}
.check input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--white); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: translate .35s var(--ease);
}
.check input:checked { background: var(--ink); }
.check input:checked::after { translate: 11px 0; }
.check input:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
#innerPart { transition: opacity .3s; }
#innerPart.off { opacity: .3; pointer-events: none; }

/* Récapitulatif */
.specs.mini { margin: 4px 0 16px; border-top: 1px solid var(--ink); }
.specs.mini div { padding: 8px 2px; font-size: 12px; }
.specs.mini div:hover { background: none; color: inherit; border-bottom-color: var(--line); }
.specs.mini dd { font-variant-numeric: tabular-nums; }
.specs.mini dd .mute { margin-left: 6px; }

.actions-main { display: flex; gap: 4px; }
.pill.grow { flex: 1; justify-content: center; }
.next-step {
  display: flex; align-items: baseline; gap: 10px; width: 100%; margin-top: 6px; padding: 12px; border: 0; border-radius: var(--r);
  background: var(--panel); cursor: pointer; font: 500 14px/1.2 var(--sans); text-align: left; transition: background .3s var(--ease);
}
.next-step .lab { color: var(--mute); }
.next-step .arr { margin-left: auto; }
.next-step.back .arr { margin-left: 0; }
.next-step:hover { background: var(--panel-2); }
.next-step:hover .arr { transform: translateX(3px); }
.next-step.back:hover .arr { transform: translateX(-3px); }

/* Import de la réalisation */
.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  padding: 26px 14px; border-radius: var(--r); cursor: pointer; background: var(--panel);
  border: 1px dashed #c4c3bd; transition: background .3s var(--ease), border-color .3s, padding .4s var(--ease);
}
.drop:hover, .drop.over { background: var(--panel-2); border-color: var(--ink); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop:focus-within { outline: 1px solid var(--ink); outline-offset: 2px; }
.drop-ico { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; transition: transform .5s var(--ease); }
.drop:hover .drop-ico { transform: translateY(-2px); }
.drop-main { font-weight: 500; font-size: 13px; }
.drop.has { flex-direction: row; padding: 9px 14px; background: transparent; }
.drop.has .drop-sub { display: none; }
.drop.has .drop-ico { width: 15px; height: 15px; }
.drop.has .drop-main { font-size: 12px; }
.crop { margin-top: 6px; }
.crop-view {
  background: var(--panel); border-radius: var(--r); overflow: hidden; cursor: grab;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.crop-view.drag { cursor: grabbing; }
.crop-view svg { display: block; width: 100%; height: auto; max-height: 300px; }
.zoom { display: flex; align-items: center; gap: 10px; padding: 10px 0 4px; }
.zoom .round { background: var(--panel); flex-shrink: 0; }
.zoom .round:hover { background: var(--ink); }
.crop-actions { display: flex; gap: 4px; margin-top: 6px; }

.stage { position: sticky; top: var(--pad); }
.sheet:not([hidden]) { animation: fade .6s var(--ease) both; }
.tile {
  position: relative; display: grid; place-items: center;
  height: calc(100svh - 2 * var(--pad) - 64px); min-height: 480px; padding: 40px;
  background: var(--panel); border-radius: var(--r); container-type: size; transition: background .3s;
}
.tile.over { background: var(--panel-2); outline: 1px dashed var(--ink); outline-offset: -8px; }
.paper {
  position: relative; width: min(100cqw, 100cqh * var(--ar, .707)); background: var(--white);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 22px 44px -22px rgba(0, 0, 0, .3); overflow: hidden; cursor: crosshair;
}
.paper svg { display: block; width: 100%; height: auto; }
#sheetA .paper.anim .o { transform-box: fill-box; transform-origin: center; animation: settle 1.1s var(--ease) both; }
#sheetA .paper.anim .g { animation: fade .8s .8s both; }
#sheetB .paper.anim [data-svg] > svg { animation: wipe 1.2s var(--ease-io) both; }
@keyframes settle { from { opacity: 0; transform: translateY(-2%) scale(1.015); } to { opacity: 1; transform: none; } }
.err { aspect-ratio: 297 / 420; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--mute); }

/* compte-fils */
.loupe {
  position: absolute; left: 0; top: 0; z-index: 3; width: 170px; height: 170px; border-radius: 50%;
  overflow: hidden; pointer-events: none; background: var(--white);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .12), 0 18px 36px -12px rgba(0, 0, 0, .3);
  display: block; will-change: transform; opacity: 0; scale: .6; transition: opacity .25s, scale .5s var(--ease);
}
.loupe.on { opacity: 1; scale: 1; }

/* ---------- Références : filtres ---------- */
.filters {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap;
  padding: 10px calc(var(--pad) + 8px); background: rgba(244, 243, 240, .82);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line); transition: translate .5s var(--ease);
}
.filters.away { translate: 0 -100%; }
.f-search { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 420px; }
.f-search svg { flex-shrink: 0; width: 14px; height: 14px; fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }
.f-search input {
  flex: 1; min-width: 0; text-align: left; font-size: 13px; padding: 4px 0; border: 0; outline: none;
  background: linear-gradient(var(--ink), var(--ink)) no-repeat 0 100% / 0 1px; transition: background-size .5s var(--ease);
  -webkit-appearance: none; appearance: none;
}
.f-search input:focus { background-size: 100% 1px; }
.f-search input::placeholder { color: var(--mute); }
.f-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.f-sels { display: flex; gap: 4px; min-width: 0; }
.f-sels select { max-width: 210px; }
.f-end { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.f-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.f-reset { background: none; border: 0; cursor: pointer; color: var(--ink); border-bottom: 1px solid var(--line); padding: 0; }
.f-reset:hover { border-color: var(--ink); }
.pill svg, .round svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; flex-shrink: 0; transition: fill .3s, stroke .3s, transform .4s var(--ease); }
.f-fav { box-shadow: inset 0 0 0 1px var(--line); background: transparent; }
.f-fav[aria-pressed=true] { background: var(--ink); color: var(--white); box-shadow: none; }
.f-fav[aria-pressed=true] svg, .fav[aria-pressed=true] svg { fill: #ff5a4e; stroke: #ff5a4e; }
.f-fav .n { font-family: var(--mono); font-size: 10.5px; opacity: .7; }
.empty { grid-column: 1 / -1; display: grid; justify-items: center; gap: 14px; padding: 120px 20px; text-align: center; color: var(--mute); }
.empty svg { display: inline; width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; vertical-align: -1px; }

/* ---------- Références : grille infinie ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--pad); padding: var(--pad); }
.ref {
  --night: #0e0e0d;
  position: relative; aspect-ratio: 4 / 5; perspective: 1400px;
  animation: fadeUp 1s var(--ease) both; animation-delay: calc(var(--d) * 50ms);
  content-visibility: auto; contain-intrinsic-size: auto 260px auto 325px;
}
.ref-in { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .9s var(--ease); }
.ref.flip .ref-in { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: var(--r); overflow: hidden;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  /* la face cachée disparaît à mi-rotation : aucun élément du recto ne transparaît au verso */
  transition: visibility 0s linear .16s;
}
.ref.flip .front, .ref:not(.flip) .back { visibility: hidden; }
.hit {
  position: absolute; inset: 0; z-index: 1; border: 0; border-radius: inherit; background: none; cursor: zoom-in;
}
.hit:focus-visible { outline: 1px solid rgba(255, 255, 255, .7); outline-offset: -6px; }
.face .tl, .face .tr, .face .bl { z-index: 2; }
.front .tl, .front .bl { pointer-events: none; }

/* recto : le timbre seul, centré sur fond noir, à l'échelle */
.front { display: grid; place-items: center; background: var(--night); transition: background .5s var(--ease); }
.ref:hover .front { background: #1a1a18; }
.face .pill.tl { display: block; }
.front .pill { background: rgba(255, 255, 255, .1); color: rgba(255, 255, 255, .86); max-width: calc(100% - 84px); overflow: hidden; text-overflow: ellipsis; }
.acts { display: flex; gap: 4px; }
.front .fav:active svg, .lb .fav:active svg { transform: scale(.8); }
.front .fav[aria-pressed=true] { background: rgba(255, 255, 255, .16); }
.front .fav[aria-pressed=true]:hover { background: var(--white); }
.front .round { background: rgba(255, 255, 255, .1); color: var(--white); font: 500 12px/1 var(--mono); }
.front .round:hover, .front .round:focus-visible { background: var(--white); color: var(--ink); }
.round:focus-visible { outline: 1px solid currentColor; outline-offset: 2px; }
.art { position: relative; width: var(--bw); aspect-ratio: var(--ar); display: grid; place-items: center; pointer-events: none; transition: transform 1s var(--ease); }
.ref:hover .art { transform: scale(1.05) translateY(-3px); }
.art svg { width: 100%; height: 100%; overflow: visible; }
.art svg path { fill: none; stroke: rgba(255, 255, 255, .5); stroke-width: .16; }
.art img {
  width: 100%; height: 100%; object-fit: contain; opacity: 0; transform: scale(.97);
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .55)); transition: opacity .8s var(--ease), transform 1s var(--ease);
}
.art.has img { opacity: 1; transform: none; }
/* en attente de l'image : l'empreinte du timbre, qui respire doucement */
.art.wait { border-radius: 2px; background: rgba(255, 255, 255, .045); animation: breathe 1.8s var(--ease-io) infinite alternate; }
@keyframes breathe { from { opacity: .5; } to { opacity: 1; } }
.front .src { color: rgba(255, 255, 255, .42); }

/* verso : la fiche */
.back { transform: rotateY(180deg); background: var(--white); display: flex; flex-direction: column; }
.back .pill.tl { background: var(--panel); }
.back .round { background: var(--panel); }
.back .round:hover { background: var(--ink); color: var(--white); }
.back-body { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; min-height: 0; margin-top: 44px; padding: 0 14px 14px; overflow: auto; scrollbar-width: none; }
.back-title { flex-shrink: 0; font-size: 21px; font-weight: 500; line-height: 1.1; letter-spacing: -.025em; }
.back-note { font-size: 12px; line-height: 1.4; color: #4a4a46; max-width: 30em; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; flex-shrink: 0; }
.back .specs.mini, .lb-info .specs.mini { margin: 2px 0 4px; }
.back .specs.mini div, .lb-info .specs.mini div { padding: 5px 0; font-size: 11.5px; gap: 12px; }
.back .specs.mini dd, .lb-info .specs.mini dd { max-width: 65%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back .pill.dark, .lb-info .pill.dark { align-self: flex-start; }
.back .pill.dark:hover .arr, .lb-info .pill.dark:hover .arr { transform: translateX(3px); }
#more { height: 1px; }

/* vue agrandie */
.lb-open { overflow: hidden; }
.lb {
  position: fixed; inset: 0; z-index: 80; background: rgba(12, 12, 11, .97); color: var(--white);
  opacity: 0; transition: opacity .3s var(--ease);
}
.lb.on { opacity: 1; }
.lb-stage { position: absolute; inset: 0; overflow: hidden; cursor: zoom-in; touch-action: none; }
.lb-stage.max { cursor: zoom-out; }
.lb-stage.drag { cursor: grabbing; }
.lb-img {
  position: absolute; left: 50%; top: 50%; max-width: none; user-select: none; -webkit-user-select: none;
  transform-origin: center; opacity: 0; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .6));
  transition: opacity .5s var(--ease);
}
.lb-img.ready { opacity: 1; }
.lb-stage.drag .lb-img { transition: none; }
.lb .tl { position: absolute; top: 14px; left: 14px; z-index: 2; background: rgba(20, 20, 19, .72); color: rgba(255, 255, 255, .9); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); max-width: calc(100% - 120px); overflow: hidden; text-overflow: ellipsis; }
.lb-tr { position: absolute; top: 14px; right: 14px; z-index: 2; display: flex; gap: 4px; }
.lb .round { width: 30px; height: 30px; background: rgba(20, 20, 19, .72); color: var(--white); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); font: 500 13px/1 var(--mono); }
.lb .round:hover, .lb .round[aria-pressed=true] { background: var(--white); color: var(--ink); }
.lb-zoom {
  position: absolute; bottom: 16px; left: 50%; translate: -50% 0; z-index: 2; display: flex; align-items: center; gap: 10px;
  padding: 3px; border-radius: 999px; background: rgba(20, 20, 19, .72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.lb-zoom .round { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(255, 255, 255, .1); }
.lb-pct { min-width: 30px; text-align: center; color: rgba(255, 255, 255, .7); }
.lb-hd { position: absolute; bottom: 24px; left: 18px; z-index: 2; color: rgba(255, 255, 255, .45); }
.lb-info {
  position: absolute; right: 14px; bottom: 64px; z-index: 3; width: min(340px, calc(100% - 28px)); max-height: calc(100% - 124px);
  display: flex; flex-direction: column; gap: 10px; padding: 16px; overflow: auto;
  background: var(--white); color: var(--ink); border-radius: var(--r); animation: fadeUp .5s var(--ease) both;
}

/* ---------- Sujet ---------- */
.split { display: grid; grid-template-columns: 1fr 1fr; margin: 0 var(--pad); }
.cell { display: flex; flex-direction: column; gap: 28px; padding: 12px var(--cell) 24px; min-height: 66vh; }
.cell + .cell { border-left: 1px solid var(--line); }
.lead { margin: auto 0; max-width: 23em; font-size: clamp(19px, 1.75vw, 26px); line-height: 1.22; letter-spacing: -.02em; }
.specs { margin-top: auto; }
.specs div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 20px;
  padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 12.5px;
  transition: background .3s, color .3s;
}
.specs div:hover, .specs .inv { background: var(--ink); color: var(--white); border-bottom-color: var(--ink); }
.specs div:hover .todo, .specs .inv .todo { color: inherit; }
.specs dd { text-align: right; }
.block { margin: 140px var(--pad) 0; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 12px 8px; border-top: 1px solid var(--line); }
.steps { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.step { display: flex; flex-direction: column; gap: 24px; padding: 12px var(--cell) 24px; min-height: 56vh; border-bottom: 1px solid var(--line); }
.step:nth-child(even) { border-left: 1px solid var(--line); }
.illus { display: block; width: min(100%, 360px); height: auto; margin: auto; fill: none; stroke: var(--ink); stroke-width: .4; stroke-linejoin: round; stroke-linecap: round; }
.illus text { fill: var(--mute); stroke: none; font-family: var(--mono); font-size: 3.2px; }
.js .illus path { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.js .illus text { opacity: 0; }
.step.in .illus path { animation: draw 1.8s var(--ease-io) forwards; animation-delay: calc(var(--i, 0) * 60ms + var(--rd, 0s) + .2s); }
.step.in .illus text { animation: fade .8s forwards; animation-delay: calc(var(--rd, 0s) + 1.3s); }
.step p { max-width: 26em; font-size: 15px; line-height: 1.35; letter-spacing: -.01em; }
.intro { margin: auto 0; display: flex; flex-direction: column; gap: 18px; }
.intro .lead { margin: 0; }
.sub { max-width: 32em; font-size: 15px; line-height: 1.38; letter-spacing: -.01em; }
.specs.plan { margin-top: 0; border-top: 1px solid var(--ink); }
.specs.plan dd .mute { margin-left: 10px; font-variant-numeric: tabular-nums; }
.specs.plan .inv dd .mute, .specs.plan div:hover dd .mute { color: rgba(255, 255, 255, .55); }
.mentions { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.mentions li { display: flex; flex-direction: column; gap: 10px; min-height: 34vh; padding: 12px var(--cell) 24px; border-bottom: 1px solid var(--line); }
.mentions li + li { border-left: 1px solid var(--line); }
.mentions strong { margin-top: auto; font-weight: 400; font-size: clamp(19px, 1.75vw, 26px); line-height: 1.15; letter-spacing: -.02em; }
.mentions strong + span { font-size: 12.5px; line-height: 1.35; max-width: 22em; }
.rules { border-top: 1px solid var(--line); }
.rules li { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 14px 8px 18px; border-bottom: 1px solid var(--line); }
.rules p { max-width: 36em; font-size: 15px; line-height: 1.38; letter-spacing: -.01em; }
.rules strong { font-weight: 500; }
.aside { margin: 0 8px; padding: 18px 0 0; max-width: 40em; font-size: 15px; line-height: 1.38; letter-spacing: -.01em; }
.split.flush { margin: 0; }
.split.flush .col + .col { border-left: 1px solid var(--line); }
.rows li { display: flex; gap: 14px; align-items: baseline; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.38; }
.rows li:first-child { border-top: 1px solid var(--ink); }
.rows .lab { flex: none; width: 22px; }
ul.rows { list-style: none; }
.split.flush .block-head { border-top: 0; }
.res { list-style: none; border-top: 1px solid var(--line); }
.res a { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; padding: 14px 8px; border-bottom: 1px solid var(--line); font-size: clamp(16px, 1.3vw, 19px); letter-spacing: -.015em; transition: background .3s, color .3s; }
.res a:hover { background: var(--ink); color: var(--white); }
.res a:hover .mute { color: rgba(255, 255, 255, .55); }
.res a:hover .arr { transform: translate(2px, -2px); }
.res .lab { flex: none; }

.foot {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; align-items: center;
  margin: 160px var(--pad) 0; padding: 14px 8px 0; border-top: 1px solid var(--line);
}
.foot .up { justify-self: end; }
.foot .up:hover .arr { transform: translateX(3px); }

.toast {
  position: fixed; left: 50%; top: 16px; z-index: 60; translate: -50% -12px; opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--white); border-radius: 999px; padding: 7px 14px; font-size: 12px;
  transition: opacity .35s, translate .6s var(--ease);
}
.toast.on { opacity: 1; translate: -50% 0; }

/* ---------- Responsive ---------- */
/* Gabarit : tout tient dans l'écran, sans défilement de la page */
@media (min-width: 901px) {
  body[data-page=gabarit] { height: 100svh; overflow: hidden; padding-bottom: 0; }
  .gab { height: 100svh; min-height: 0; }
  .controls { max-height: calc(100svh - 2 * var(--pad)); overflow-y: auto; scrollbar-width: none; }
  .controls::-webkit-scrollbar { display: none; }
}
/* Colonne de gauche : pleine hauteur, réglages plus généreux, impression calée en bas */
@media (min-width: 901px) {
  .controls { display: flex; flex-direction: column; height: calc(100svh - 2 * var(--pad)); padding-bottom: 64px; }
  .panel:not([hidden]) { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .panel > .actions-main { margin-top: auto; padding-top: 16px; }
  .panel .pill.dark, .panel .pill.line { padding-top: 11px; padding-bottom: 11px; font-size: 12px; }
  .sec { padding: 14px 0 22px; }
  .sec-head { margin-bottom: 14px; }
  .shapes { gap: 4px; }
  .shapes button { aspect-ratio: 1; padding: 0; }
  .shapes svg { width: 40px; height: 40px; }
  .field { padding: 14px 12px 12px; gap: 10px; }
  .field input[type=number] { font-size: 36px; }
  .row { min-height: 44px; }
  /* étape 02 : la zone d'import et le cadrage prennent la place libre */
  .panel[data-panel="2"] > .sec:first-of-type { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .panel[data-panel="2"] .drop:not(.has) { flex: 1; }
  .panel[data-panel="2"] .crop:not([hidden]) { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .panel[data-panel="2"] .crop-view { flex: 1; min-height: 0; display: grid; place-items: center; }
  .panel[data-panel="2"] .crop-view svg { max-height: 100%; height: 100%; }
}
@media (min-width: 901px) and (max-height: 760px) {
  .stepper { margin-bottom: 16px; }
  .sec { padding: 10px 0 14px; }
  .sec-head { margin-bottom: 10px; }
  .shapes button { aspect-ratio: auto; padding: 10px 0; }
  .shapes svg { width: 34px; height: 34px; }
  .field { padding: 9px 10px 8px; gap: 6px; }
  .field input[type=number] { font-size: 26px; }
  .row { min-height: 36px; }
}
@media (max-width: 900px) {
  .gab { grid-template-columns: 1fr; gap: 10px; }
  .stage { position: static; }
  .tile { height: auto; min-height: 0; padding: 24px; container-type: normal; }
  .paper { width: 100%; }
}
@media (max-width: 760px) {
  .pills { bottom: 10px; }
  .split, .steps { grid-template-columns: 1fr; }
  .cell { min-height: 0; padding-bottom: 48px; }
  .cell + .cell, .step:nth-child(even) { border-left: 0; }
  .cell + .cell { border-top: 1px solid var(--line); }
  .step { min-height: 0; padding-bottom: 40px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { padding: 10px 16px; gap: 8px 12px; }
  .f-search { flex-basis: 100%; max-width: none; }
  .f-sels { flex: 1 1 100%; gap: 4px; }
  .f-sels select { flex: 1 1 0; max-width: none; min-width: 0; }
  .f-end { margin-left: 0; flex: 1 1 100%; }
  .f-count { margin-left: auto; }
  .block { margin-top: 100px; }
  .mentions { grid-template-columns: 1fr 1fr; }
  .mentions li { min-height: 0; padding-bottom: 32px; }
  .mentions li:nth-child(3) { border-left: 0; }
  .mentions strong { margin-top: 28px; }
  .rules li { grid-template-columns: 40px 1fr; gap: 12px; }
  .split.flush .col + .col { border-left: 0; margin-top: 56px; }
  .res a { flex-direction: column; gap: 4px; }
  .foot { grid-template-columns: 1fr; gap: 8px; }
  .foot .up { justify-self: start; }
}
@media (max-width: 560px) { .tiles { grid-template-columns: minmax(0, 1fr); } }
@media (hover: none) { .loupe { display: none; } .paper { cursor: auto; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition-duration: .001ms !important; transition-delay: 0s !important; }
}

/* ---------- Impression : seules les planches demandées, A3 à 100 % ---------- */
#print { display: none; }
@media print {
  @page { size: A3 portrait; margin: 0; }
  html, body { background: #fff; padding: 0; }
  body { background-image: none; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; }
  .print-page { width: 297mm; height: 420mm; overflow: hidden; break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page svg { display: block; width: 297mm; height: 420mm; }
}
