@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("assets/PlusJakartaSans-VariableFont_wght.ttf") format("truetype");
  font-weight: 200 800;
  font-display: swap;
}

/* Identité Carré Croix : interface sombre, vert #003A00, jaune guépard #FACA68, crème. */
:root {
  --green: #003A00;
  --yellow: #FACA68;
  --cream: #F6F1E6;
  --bg: #0E0F0E;
  --card: #1B1C1B;
  --raised: #282827;
  --stroke: rgba(255, 255, 255, 0.07);
  --text: var(--cream);
  --muted: rgba(246, 241, 230, 0.55);
  --warning: #FF9E4D;
  --pool-w: 380px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

.app {
  height: 100vh;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 20px 18px;
}
.card { background: var(--card); border: 1px solid var(--stroke); border-radius: 24px; }

/* En-tête */
.top { display: flex; align-items: center; gap: 12px; }
.mark { height: 46px; }
h1 { margin: 0; font-size: 22px; font-weight: 800; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* Lien */
.linkbar { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 30px; }
.ico { width: 16px; height: 16px; fill: none; stroke: var(--yellow); stroke-width: 2.2; stroke-linecap: round; flex: none; }
#link { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font: inherit; font-size: 14px; }
#link::placeholder { color: var(--muted); }

/* Boutons */
.pill {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 0; border-radius: 999px; padding: 8px 16px; cursor: pointer;
  transition: opacity .15s, filter .15s;
  white-space: nowrap;
}
.pill:disabled { opacity: .4; cursor: default; }
.pill.primary { background: var(--yellow); color: var(--green); }
.pill.primary:not(:disabled):hover { filter: brightness(1.06); }
.pill.secondary { background: var(--raised); color: var(--text); }
.pill.secondary:not(:disabled):hover { background: #333432; }
.pill.ghost { background: none; color: var(--text); }
.pill.large { padding: 11px 22px; font-size: 14px; }

/* Zone centrale */
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 30px; text-align: center;
}
.big-ico { width: 40px; height: 40px; fill: none; stroke: var(--yellow); stroke-width: 1.2; }
.state-title { margin: 0; font-size: 16px; font-weight: 600; }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.warning {
  margin: 0; max-width: 460px; color: var(--warning); background: rgba(255, 158, 77, .1);
  border: 1px solid rgba(255, 158, 77, .25); border-radius: 14px; padding: 12px 16px; line-height: 1.45;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(250, 202, 104, .2); border-top-color: var(--yellow);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Éditeur */
.editor { position: absolute; inset: 0; display: flex; padding: 18px; }
.left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.canvas-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; container-type: size; }
.grid-canvas {
  position: relative;
  width: min(100cqw, 100cqh * 16 / 9);
  aspect-ratio: 16 / 9;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 8px 36px rgba(0, 0, 0, .5);
}
.checker {
  background-color: #4d4d4d;
  background-image:
    linear-gradient(45deg, #5c5c5c 25%, transparent 25%, transparent 75%, #5c5c5c 75%),
    linear-gradient(45deg, #5c5c5c 25%, transparent 25%, transparent 75%, #5c5c5c 75%);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
}
.cell { position: absolute; overflow: hidden; }
.cell.full { background: #fff; cursor: grab; }
.cell.empty {
  border: 1.5px dashed rgba(246, 241, 230, .35); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-weight: 600;
}
.cell img, .mini-cell img, .crop-frame img, #cropGhost {
  position: absolute; display: block; max-width: none; pointer-events: none; user-select: none;
}
.cell.drop-target::after, .mini.drop-target::after {
  content: ""; position: absolute; inset: 0; border: 4px solid var(--yellow); pointer-events: none;
}
.cell .tools { position: absolute; top: 6px; right: 6px; display: none; gap: 6px; }
.cell.full:hover .tools { display: flex; }
.round {
  width: 26px; height: 26px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .7); color: #fff; display: grid; place-items: center; padding: 0;
}
.round svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.round:hover { background: rgba(0, 0, 0, .85); }
.badge-crop {
  position: absolute; left: 6px; bottom: 6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--yellow); display: grid; place-items: center; pointer-events: none;
}
.badge-crop svg { width: 10px; height: 10px; fill: none; stroke: var(--green); stroke-width: 3; }

.under { display: flex; align-items: center; gap: 12px; min-height: 69px; }
.info { min-width: 150px; flex: none; }
.board-name { font-weight: 700; font-size: 15px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pages { flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; padding: 3px; justify-content: flex-end; scrollbar-width: thin; }
.mini {
  position: relative; flex: none; width: 112px; height: 63px; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--stroke); cursor: pointer; background-size: 10px 10px; background-position: 0 0, 5px 5px;
}
.mini.selected { outline: 2.5px solid var(--yellow); outline-offset: -2px; }
.mini-cell { position: absolute; overflow: hidden; background: rgba(255, 255, 255, .06); }
.mini-cell.full { background: #fff; }
.mini .num {
  position: absolute; right: 4px; bottom: 4px; background: var(--yellow); color: var(--green);
  font-size: 10px; font-weight: 700; border-radius: 999px; padding: 0 5px; line-height: 15px;
}
.add-page {
  flex: none; width: 63px; height: 63px; border-radius: 6px; border: 1px solid var(--stroke);
  background: var(--raised); color: var(--yellow); font-size: 22px; cursor: pointer;
}

/* Réglages : photos par PNG, espacement */
.settings { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; row-gap: 8px; }
.segs { display: flex; gap: 3px; padding: 3px; background: var(--raised); border-radius: 999px; }
.seg {
  display: flex; align-items: center; gap: 7px; font: inherit; font-size: 13px; font-weight: 600;
  background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.seg:hover { color: var(--text); }
.seg.on { background: var(--yellow); color: var(--green); }
.seg-ico { display: grid; gap: 1.5px; width: 22px; }
.seg-ico i { display: block; height: 6px; background: currentColor; opacity: .75; border-radius: 1px; }
.small-pill { padding: 6px 10px; font-size: 12px; }
.gapbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
#gap { width: 120px; accent-color: var(--yellow); }
.round.reset { background: var(--raised); color: var(--muted); }
.round.reset:hover { color: var(--text); background: #333432; }
#gapValue {
  width: 58px; font: inherit; font-size: 13px; color: var(--text); background: var(--raised);
  border: 1px solid var(--stroke); border-radius: 8px; padding: 4px 6px; text-align: right;
}

/* Poignée */
.handle { flex: none; width: 18px; cursor: col-resize; display: flex; align-items: center; justify-content: center; touch-action: none; }
.handle span { width: 4px; height: 56px; border-radius: 4px; background: rgba(255, 255, 255, .12); }
.handle:hover span, .handle.dragging span { background: var(--yellow); }

/* Réserve d'épingles */
.pool {
  flex: none; width: var(--pool-w); display: flex; flex-direction: column; gap: 10px;
  padding: 12px; border-radius: 12px; background: rgba(40, 40, 39, .5); min-height: 0;
}
.pool-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pool-title { font-weight: 700; }
.check { display: flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }
.pool-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; scrollbar-width: thin; }
.section-title { color: var(--yellow); font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumbs { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 2), 1fr); }
.thumb {
  position: relative; aspect-ratio: 0.86; border-radius: 5px; overflow: hidden; cursor: pointer;
  background: var(--raised);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb.in::after { content: ""; position: absolute; inset: 0; border: 3px solid var(--yellow); border-radius: 5px; }
.thumb.dim { opacity: .4; }
.thumb .tick {
  position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--yellow); display: grid; place-items: center;
}
.thumb .tick svg { width: 10px; height: 10px; fill: none; stroke: var(--green); stroke-width: 3.4; }
.thumb .used {
  position: absolute; top: 4px; right: 4px; font-size: 9px; font-weight: 700; color: #fff;
  background: rgba(0, 0, 0, .65); border-radius: 999px; padding: 1px 5px;
}
.thumb.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* Barre du bas */
.bottom { display: flex; align-items: center; gap: 10px; }
#status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Recadrage */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.modal-box { background: var(--bg); border: 1px solid var(--stroke); border-radius: 20px; padding: 22px; width: 760px; max-width: 100%; display: flex; flex-direction: column; gap: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.crop-area { position: relative; height: 520px; max-height: 60vh; border-radius: 10px; overflow: hidden; cursor: grab; touch-action: none; }
.crop-area.dragging { cursor: grabbing; }
#cropGhost { opacity: .28; }
.crop-frame { position: absolute; overflow: hidden; background: #fff; outline: 2px solid var(--yellow); }
.modal-foot { display: flex; align-items: center; gap: 12px; }
.zoom-ico { color: var(--muted); font-weight: 700; }
#zoom { width: 220px; accent-color: var(--yellow); }

/* Menu de page (clic droit) */
.menu {
  position: fixed; z-index: 20; background: var(--raised); border: 1px solid var(--stroke);
  border-radius: 10px; padding: 4px; display: flex; flex-direction: column; min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.menu button { font: inherit; background: none; border: 0; color: var(--text); text-align: left; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: rgba(255, 255, 255, .08); }

@media (max-width: 820px) {
  .editor { flex-direction: column; overflow-y: auto; }
  .handle { display: none; }
  .pool { width: 100%; height: 360px; flex: none; }
  .left { flex: none; }
  .canvas-wrap { height: 52vw; }
  .bottom { flex-wrap: wrap; }
}
