/* Interface noir et blanc, polices à chasse fixe, boutons pointillés —
   dans l'esprit de l'outil TAC. Seul le fond derrière la page est gris. */

@font-face {
  font-family: "sligoil";
  src: url("../fonts/Sligoil-Micro.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "anka";
  src: url("../fonts/ankacoder-b-webfont.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --black: #000;
  --white: #fff;
  --bg: #fff; /* interface */
  --panel: #fff; /* panneaux */
  --desk: #bfbfbf; /* fond derrière la page */
  --line: #8f8f8f; /* bord des champs */
  --font: "sligoil", ui-monospace, Menlo, monospace;
  --title: "anka", ui-monospace, Menlo, monospace;
  /* repères sur la page (gardés en couleur pour ne pas se confondre avec le contenu) */
  --margin: #e042c4;
  --col: #8a6cff;
  --snap: #ff2d78;
  --guide: #00a8e8;
  --sel: #2f5bff; /* sélection des éléments */
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.3 var(--font); color: var(--black); background: var(--bg); }
[hidden] { display: none !important; }
.hint { font-size: 11px; margin: 4px 0 8px; opacity: .65; }
::selection { background: var(--black); color: var(--white); }

/* ---------- Titres ---------- */

.sec h3, dialog h2 {
  margin: 0 0 12px; font: 15px/1.2 var(--title); text-transform: uppercase; font-weight: normal;
}
.sec h3::before, dialog h2::before { content: "●"; margin-right: 8px; }
.subhead, dialog h3 {
  margin: 16px 0 8px; font: 12px/1.2 var(--title); text-transform: uppercase; font-weight: normal;
}
.subhead::before, dialog h3::before { content: "•"; margin-right: 4px; }

/* ---------- Contrôles ---------- */

button {
  font: inherit; color: var(--black);
  background: var(--white);
  border: 1px dotted var(--black);
  border-radius: 0;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--black); color: var(--white); }
button:disabled { opacity: .35; cursor: default; }
button.primary { border-style: solid; }
button.link { border: 0; background: none; padding: 6px 4px 2px; text-decoration: underline; text-align: left; }
button.link:hover { background: none; color: var(--black); text-decoration: none; }
button.wide { width: 100%; padding: 6px; }
:focus-visible { outline: 1px solid var(--black); outline-offset: 2px; }

input, select { font: inherit; color: var(--black); }
input[type="number"], input[type="search"], input:not([type]), select {
  border: 1px solid var(--line); border-radius: 0; background: var(--white);
}
input:focus, select:focus { outline: none; border-color: var(--black); }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 20px !important;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0h8L4 5z' fill='%23000'/%3E%3C/svg%3E") no-repeat right 6px center;
}
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--black); margin: 0; }
input[type="color"] {
  flex: none; width: 28px; height: 22px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 0; background: var(--white);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 0; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 0; }

* { scrollbar-width: thin; scrollbar-color: #7a7a7a transparent; }

/* ---------- Fenêtres / panneaux ---------- */

.window { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.titlebar { position: relative; flex: none; height: 34px; display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.titlebar .title {
  font: 15px/1 var(--title); text-transform: uppercase; margin: 0; padding: 0; border: 0; background: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.closebox { width: 22px; height: 22px; padding: 0; flex: none; display: grid; place-items: center; line-height: 1; }
.closebox::before { content: "×"; font-size: 15px; }

/* ===================== Accueil ===================== */

#home { min-height: 100%; padding: 0; }
.home-win .titlebar { height: auto; padding: 32px clamp(16px, 4vw, 48px) 16px; }
.home-win .titlebar .title { font-size: clamp(26px, 4vw, 44px); line-height: 1; }
.home-win .titlebar .title::before { content: "●"; margin-right: 14px; }
.infobar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  margin: 0 clamp(16px, 4vw, 48px); padding: 12px 0;
  border-top: 1px solid var(--black); border-bottom: 1px solid var(--black);
  text-transform: uppercase; font-size: 12px;
}
.home-actions { display: flex; gap: 10px; text-transform: none; font-size: 13px; }
.home-foot { margin: 0; padding: 24px clamp(16px, 4vw, 48px) 32px; font-size: 11px; opacity: .65; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 32px 24px;
  padding: 28px clamp(16px, 4vw, 48px);
}
.card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card .thumb { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 5; padding: 16px; background: var(--desk); }
.card .thumb img, .card .thumb .blank { max-width: 100%; max-height: 100%; display: block; background: var(--white); }
.card .thumb:hover { outline: 1px dotted var(--black); }
.card .meta { display: flex; flex-direction: column; min-width: 0; }
.card .meta strong { font: 13px var(--title); text-transform: uppercase; font-weight: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta span { font-size: 11px; opacity: .65; }
.card .actions { display: flex; flex-wrap: wrap; gap: 4px; visibility: hidden; }
.card:hover .actions, .card:focus-within .actions { visibility: visible; }
.card .actions button { font-size: 11px; padding: 2px 6px; }
.card.new {
  aspect-ratio: 4 / 5; height: auto; width: 100%; border-style: dotted;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: transparent;
}
.card.new .plus { font: 36px/1 var(--title); }
@media (hover: none) { .card .actions { visibility: visible; } }

/* ===================== Éditeur ===================== */

#editor { position: fixed; inset: 0; display: grid; grid-template-rows: 44px minmax(0, 1fr); }

.menubar { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--white); border-bottom: 1px solid var(--black); }
.menubar .spacer { flex: 1; }
.menubar .logo { display: none; }
.menubar button { height: 28px; padding: 0 10px; display: grid; place-items: center; }
#save-status { padding: 0 8px; font-size: 11px; opacity: .6; text-transform: uppercase; }
.zoom { display: flex; align-items: center; gap: 6px; margin: 0 4px; }
#zoom-val { min-width: 64px; font-variant-numeric: tabular-nums; }

.workspace { display: grid; grid-template-columns: auto minmax(0, 1fr) 300px; min-height: 0; }

.tools-win { background: var(--white); border-right: 1px solid var(--black); }
.tools { display: flex; flex-direction: column; gap: 6px; padding: 10px; height: 100%; }
.tools button { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }
.tools button.active { background: var(--black); color: var(--white); border-style: solid; }
.tools svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tools-help {
  margin-top: auto; width: 36px; height: 28px; display: grid; place-items: center;
  font-family: var(--title); cursor: help; position: relative; border: 1px dotted var(--black); background: var(--white);
}
.tools-help:hover { background: var(--black); color: var(--white); }
.help-pop {
  display: none; position: absolute; left: calc(100% + 10px); bottom: 0; z-index: 50; width: 310px;
  background: var(--white); color: var(--black); border: 1px dotted var(--black);
  padding: 12px 14px; font: 12px/1.35 var(--font); cursor: default;
}
.tools-help:hover .help-pop, .tools-help:focus .help-pop { display: block; }
.help-pop strong { font: 13px var(--title); text-transform: uppercase; font-weight: normal; }
.help-pop strong::before { content: "● "; }
.help-pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; }
.help-pop dt { white-space: nowrap; }
.help-pop dd { margin: 0; opacity: .7; }
.help-pop p { margin: 0; opacity: .7; }

/* ----- Document ----- */

.doc-win { min-height: 0; background: var(--white); }
.doc-win .titlebar { background: var(--white); border-bottom: 1px solid var(--black); }
#proj-name.title { width: auto; min-width: 60px; field-sizing: content; cursor: text; }
#proj-name.title:focus { text-decoration: underline dotted; }

.doc-body {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 18px minmax(0, 1fr); grid-template-rows: 18px minmax(0, 1fr);
}
.ruler-corner { background: var(--white); border-right: 1px solid var(--black); border-bottom: 1px solid var(--black); }
.ruler { display: block; width: 100%; height: 100%; cursor: copy; }
#ruler-x { grid-column: 2; grid-row: 1; }
#ruler-y { grid-column: 1; grid-row: 2; }
#viewport { grid-column: 2; grid-row: 2; overflow: auto; position: relative; overscroll-behavior: contain; background: var(--desk); }
#viewport[data-tool="text"] { cursor: text; }
#viewport[data-tool="rect"], #viewport[data-tool="ellipse"], #viewport[data-tool="line"], #viewport[data-tool="pen"] { cursor: crosshair; }
#viewport.can-pan, #viewport.can-pan * { cursor: grab !important; }
#viewport.panning, #viewport.panning * { cursor: grabbing !important; }
#viewport.drop { box-shadow: inset 0 0 0 2px var(--black); }

#stage {
  display: grid; place-items: center;
  width: max-content; height: max-content; min-width: 100%; min-height: 100%;
  padding: 56px;
  overflow: clip; /* les lignes de repère ne doivent pas agrandir la zone de défilement */
}
#pagewrap { position: relative; }
#page { position: absolute; inset: 0; overflow: hidden; background: var(--white); isolation: isolate; }
#elements, #guides, #page-bg { position: absolute; inset: 0; }
#guides { pointer-events: none; }
.g-margin { position: absolute; border: 1px solid var(--margin); }
.g-col { position: absolute; border-left: 1px solid var(--col); border-right: 1px solid var(--col); }

/* ----- Éléments : règles de base injectées par js/render.js (Render.CSS) ----- */

#elements .el-text.editing { user-select: text; -webkit-user-select: text; cursor: text; caret-color: var(--sel); }
#viewport[data-tool="select"] #elements .el:not(.locked):not(.editing):hover { outline: 1px solid var(--sel); }

/* ----- Repères utilisateur ----- */

#userguides { position: absolute; inset: 0; pointer-events: none; }
.guide { position: absolute; pointer-events: auto; }
.guide-x { top: -10000px; bottom: -10000px; width: 7px; margin-left: -3px; cursor: ew-resize; }
.guide-y { left: -10000px; right: -10000px; height: 7px; margin-top: -3px; cursor: ns-resize; }
.guide::after { content: ""; position: absolute; }
.guide-x::after { left: 3px; top: 0; bottom: 0; border-left: 1px solid var(--guide); }
.guide-y::after { top: 3px; left: 0; right: 0; border-top: 1px solid var(--guide); }
#userguides.locked .guide, #viewport:not([data-tool="select"]) .guide { pointer-events: none; }

/* ----- Sélection ----- */

#overlay { position: absolute; inset: 0; pointer-events: none; }
.sel-box { position: absolute; transform-origin: center; outline: 1px solid var(--sel); }
.sel-box.editing { outline-style: dashed; }
.sel-box.locked { outline-style: dotted; }
.sel-group { position: absolute; outline: 1px dashed var(--sel); outline-offset: 3px; }
.marquee { position: absolute; border: 1px dashed var(--sel); background: rgba(47, 91, 255, .08); }
.sel-line { position: absolute; height: 0; border-top: 1px solid var(--sel); transform-origin: 0 0; }
.handle {
  position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  background: var(--white); border: 1px solid var(--sel); pointer-events: auto;
}
.h-nw, .h-se { cursor: nwse-resize; }
.h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; }
.h-e, .h-w { cursor: ew-resize; }
.handle[data-handle="p1"], .handle[data-handle="p2"] { cursor: move; }
.handle.rot { left: 50%; top: -24px; border-radius: 50%; background: var(--sel); cursor: grab; }
.rot-stem { position: absolute; left: 50%; top: -20px; height: 20px; border-left: 1px solid var(--sel); }
.snap-x { position: absolute; top: -10000px; bottom: -10000px; border-left: 1px solid var(--snap); }
.snap-y { position: absolute; left: -10000px; right: -10000px; border-top: 1px solid var(--snap); }
.snap-seg-x { position: absolute; border-left: 1px solid var(--snap); }
.snap-seg-y { position: absolute; border-top: 1px solid var(--snap); }
.snap-seg-x::before, .snap-seg-x::after, .snap-seg-y::before, .snap-seg-y::after {
  content: "×"; position: absolute; color: var(--snap); font-size: 11px; line-height: 1; transform: translate(-50%, -50%);
}
.snap-seg-x::before { left: 0; top: 8px; } .snap-seg-x::after { left: 0; bottom: 8px; transform: translate(-50%, 50%); }
.snap-seg-y::before { top: 0; left: 8px; } .snap-seg-y::after { top: 0; right: 8px; transform: translate(50%, -50%); }
.pen-preview { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }

/* ----- Propriétés ----- */

.panel-win { background: var(--white); border-left: 1px solid var(--black); }
.panel-win > .titlebar { display: none; }
.panel { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0; }
.sec { padding: 14px 16px 18px; }
.sec + .sec { border-top: 1px solid var(--black); }
.row { display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; gap: 8px; margin: 7px 0; }
.row .lbl { font-size: 11px; text-transform: uppercase; }
.ctrl { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ctrl.col { flex-direction: column; align-items: stretch; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair .row { grid-template-columns: auto minmax(0, 1fr); }
.pair .row .lbl { min-width: 12px; }

.panel input[type="number"], .panel select, .font-btn { width: 100%; height: 24px; min-width: 0; padding: 0 6px; font-size: 13px; }
.num { position: relative; display: block; flex: 1; min-width: 0; }
.num input { padding-right: 26px !important; }
.num i { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 11px; opacity: .55; pointer-events: none; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; cursor: pointer; white-space: nowrap; }
.sec > .check { display: flex; margin: 7px 0; }
.font-btn { text-align: left; font-size: 15px; border: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; }
.font-btn:hover:not(:disabled) { background: var(--white); color: var(--black); border-color: var(--black); }

.seg { display: flex; flex: 1; gap: 4px; }
.seg button { flex: 1; padding: 3px 4px; font-size: 12px; display: grid; place-items: center; min-height: 24px; }
.seg button.on { background: var(--black); color: var(--white); border-style: solid; }

.range { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.range input { flex: 1; min-width: 0; }
.range output { width: 30px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; }

.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns button { padding: 3px 8px; font-size: 12px; }
.btns.icons { gap: 3px; flex-wrap: nowrap; }
.btns.icons button { padding: 3px 4px; display: grid; place-items: center; }
.btns.end { justify-content: flex-end; margin-top: 12px; }
.sec > .btns { margin-top: 10px; }
.x-btn { flex: none; width: 24px; height: 24px; padding: 0; font-size: 14px; line-height: 1; }
.panel input.txt { width: 100%; height: 24px; min-width: 0; padding: 0 6px; border: 1px solid var(--line); background: var(--white); }
.panel input.txt:focus { outline: none; border-color: var(--black); }
.ink { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; outline: 1px solid rgba(0, 0, 0, .25); }
.ink.big { flex: none; width: 22px; height: 22px; margin: 0; }

/* ----- Secouer ----- */

dialog.dlg-wide { width: min(1040px, calc(100vw - 32px)); }
.shake-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 16px; align-items: end; }
.shake-settings > button { margin: 10px 0; height: 30px; }
.shake-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 16px; max-height: 60vh; overflow: auto; padding: 4px; }
.shake-cell {
  display: grid; place-items: center; aspect-ratio: 1; padding: 10px; background: var(--desk); border: 1px dotted transparent;
}
.shake-cell:hover:not(:disabled) { background: var(--desk); border-color: var(--black); outline: 2px solid var(--sel); }
.shake-cell img { max-width: 100%; max-height: 100%; display: block; }
.shake-wait { opacity: .5; }

/* ----- Calques ----- */

#layers { list-style: none; margin: 0 -4px; padding: 0; }
#layers li { display: flex; align-items: center; gap: 2px; padding: 2px 4px; cursor: pointer; border: 1px dotted transparent; }
#layers li:hover { border-color: var(--black); background: var(--white); }
#layers li.on { background: var(--sel); color: var(--white); border-color: var(--sel); }
#layers li.over { border: 1px dashed var(--black); }
#layers li.empty { cursor: default; padding: 4px; font-size: 11px; opacity: .65; border: 0; background: none; }
#layers li.off .lbl, #layers li.off .kind { opacity: .4; }
#layers .icon { border: 0; background: transparent; color: inherit; padding: 2px; opacity: .35; display: grid; place-items: center; }
#layers .icon:hover, #layers .icon.active { opacity: 1; background: transparent; color: inherit; }
#layers .kind { font: 10px var(--title); text-transform: uppercase; margin: 0 4px; flex: none; opacity: .6; }
#layers .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Menu des polices ----- */

.font-menu {
  position: fixed; z-index: 100; width: 290px; max-height: min(420px, 80vh);
  display: flex; flex-direction: column; gap: 4px; padding: 6px;
  background: var(--white); border: 1px dotted var(--black);
}
.font-menu input { height: 28px; padding: 0 8px; }
.font-list { overflow-y: auto; flex: 1; min-height: 0; }
.font-item { padding: 4px 8px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.font-item:hover, .font-item.on { background: var(--black); color: var(--white); }
.font-menu .hint { padding: 0 4px; }

/* ===================== Dialogues ===================== */

dialog {
  border: 1px dotted var(--black); border-radius: 0; padding: 22px 24px;
  width: min(460px, calc(100vw - 32px)); color: var(--black); background: var(--panel);
}
dialog::backdrop { background: rgba(255, 255, 255, .75); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field span { font-size: 11px; text-transform: uppercase; }
.field input, .field select { height: 30px; padding: 0 8px; width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 22px 0 0; }
menu button { min-width: 80px; padding: 6px 12px; }

/* ===================== Impression / PDF ===================== */

#print-root { display: none; }
@media print {
  html, body { background: none; height: auto; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  .print-page { position: relative; overflow: hidden; break-inside: avoid; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
