/* ============ HueForge Studio ============ */
:root {
  --bg: #0b0e14;
  --bg-2: #11151f;
  --card: #151a26;
  --card-2: #1a2030;
  --line: #232a3d;
  --line-2: #2c3448;
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent: #22d3ee;
  --accent-2: #a855f7;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* L'attribut [hidden] doit TOUJOURS masquer, même quand une classe ou un
   sélecteur CSS pose display:flex/block/grid (comme .vp-empty display:flex,
   .vp-stats, .drop-thumb…). Sans cette règle, « Aucune image chargée »
   restait affiché par-dessus l'image déjà traitée. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(168, 85, 247, 0.12), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, rgba(34, 211, 238, 0.10), transparent 60%),
    var(--bg);
}

.muted { color: var(--muted); font-weight: normal; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}
.brand h1 span {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--bg-2);
  white-space: nowrap;
}
.badge-local { color: var(--ok); border-color: rgba(52, 211, 153, 0.35); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr 320px;
  gap: 18px;
  padding: 18px 28px;
  align-items: start;
  max-width: 1680px;
  margin: 0 auto;
}

.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel-left { max-height: calc(100vh - 110px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.panel-right { max-height: calc(100vh - 110px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}
.step-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  font-size: 0.75rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0e14;
  font-weight: 800;
  flex: none;
}

.hint { font-size: 0.78rem; color: var(--muted); line-height: 1.5; margin: 10px 0 0; }
.readout { font-size: 0.85rem; margin: 12px 0 0; }
.readout strong { color: var(--accent); }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line-2);
  border-radius: 12px;
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, color 0.18s;
  position: relative;
  background: rgba(255, 255, 255, 0.02);
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); color: var(--text); background: rgba(34, 211, 238, 0.05); }
.dropzone.dragover { border-color: var(--accent-2); background: rgba(168, 85, 247, 0.08); color: #fff; }
.dropzone p { margin: 10px 0 0; line-height: 1.45; }
.drop-thumb {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  max-height: 130px;
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}
.dropzone.has-image > svg,
.dropzone.has-image > p { display: none; }
.dropzone.has-image > .drop-thumb { display: block; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--card-2);
  border: 1px solid var(--line-2);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s, background 0.12s;
  text-align: center;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #0891b2, #7e22ce);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(34, 211, 238, 0.18);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 22px rgba(168, 85, 247, 0.3); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.btn-mini { font-size: 0.72rem; padding: 4px 10px; border-radius: 7px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Sliders / inputs ---------- */
input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none;
  margin: 6px 0 2px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
}
.range-marks { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--muted); margin-bottom: 6px; }
#k-out {
  margin-left: auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0e14;
  font-weight: 800;
  border-radius: 8px;
  padding: 2px 10px;
  font-size: 0.85rem;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.field label { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.field input, .field select {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-row { display: flex; gap: 10px; margin-bottom: 4px; }
.field-row.three .field { flex: 1; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 12px;
  font-size: 0.82rem;
  cursor: pointer;
  line-height: 1.4;
}
.check-row input { margin-top: 2px; accent-color: var(--accent); flex: none; }

/* ---------- Palette ---------- */
.palette-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  margin: 14px 0 8px;
}
.palette-editor { display: flex; flex-direction: column; gap: 6px; }
.swatch-row {
  display: grid;
  grid-template-columns: 30px 1fr 70px 60px 26px;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
}
.swatch {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 0;
  cursor: pointer;
  background: none;
  position: relative;
}
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: none; border-radius: 8px; }
.swatch::-moz-color-swatch { border: none; border-radius: 8px; }
.swatch-row .name { font-size: 0.78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch-row input[type="number"] {
  font: inherit;
  font-size: 0.78rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 5px 6px;
  width: 100%;
}
.swatch-row .h { font-size: 0.7rem; color: var(--muted); text-align: right; }
.swatch-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}
.swatch-del:hover { color: var(--err); background: rgba(248, 113, 113, 0.12); }

/* ---------- Viewport ---------- */
.viewport-wrap { display: flex; flex-direction: column; gap: 10px; min-width: 0; position: sticky; top: 84px; }
.tabs { display: flex; gap: 6px; }
.tab {
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px 10px 10px 10px;
  padding: 8px 18px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab.active { color: #0b0e14; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }

.viewport {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(180deg, #0d1220, #0a0d15);
  height: calc(100vh - 190px);
  min-height: 420px;
  box-shadow: var(--shadow);
}
#gl { display: block; width: 100%; height: 100%; }
.preview-2d { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.preview-2d[hidden] { display: none; }

.vp-overlay {
  position: absolute;
  background: rgba(11, 14, 20, 0.72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.72rem;
  color: var(--muted);
}
.vp-stats { top: 12px; left: 12px; display: flex; gap: 14px; }
.vp-stats span { white-space: nowrap; }
.vp-help { bottom: 12px; left: 12px; }
.vp-gl-fallback { bottom: 12px; right: 12px; max-width: 430px; font-size: 12px; line-height: 1.45; }
.tab:disabled { opacity: 0.45; cursor: not-allowed; }
.vp-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}
.vp-empty-inner h3 { margin: 14px 0 6px; color: var(--text); }
.vp-empty-inner p { margin: 0; line-height: 1.5; }
.vp-empty-inner svg { opacity: 0.5; }

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  background: rgba(11, 14, 20, 0.66);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.busy[hidden] { display: none; }
.spinner {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy p { margin: 0; font-weight: 600; }

/* Progress bar dans l'overlay busy */
.busy-progress {
  width: min(320px, 70%);
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}
.busy-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #a855f7);
  border-radius: 999px;
  transition: width 0.18s ease-out;
}
.busy-percent {
  font-size: 0.78rem !important;
  font-weight: 500 !important;
  color: var(--muted);
}

.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.74rem; color: var(--muted); padding: 0 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- Right panel ---------- */
.print-plan { display: flex; flex-direction: column; gap: 8px; }
.plan-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 9px;
}
.plan-row .chip { width: 28px; height: 20px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.15); }
.plan-row .z-range { color: var(--muted); font-size: 0.72rem; }
.plan-total {
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ok);
  text-align: right;
}

.distribution { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: grid; grid-template-columns: 20px 1fr 44px; align-items: center; gap: 8px; font-size: 0.74rem; }
.dist-row .chip { width: 20px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.15); }
.dist-bar { height: 10px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.dist-bar i { display: block; height: 100%; border-radius: 999px; }
.dist-pct { text-align: right; color: var(--muted); }

/* ---------- Footer / toast ---------- */
.foot { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 8px 20px 22px; }

.toast-root {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  align-items: center;
}
.toast {
  background: var(--card-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.82rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.25s ease;
  max-width: min(90vw, 460px);
}
.toast.ok { border-color: rgba(52, 211, 153, 0.5); }
.toast.err { border-color: rgba(248, 113, 113, 0.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Modal d'import ---------- */
.badge-version {
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.35);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in { from { opacity: 0; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

.modal {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line-2);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  width: min(760px, 96vw);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  animation: modal-pop 0.22s ease;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; flex: none; }
.modal-steps { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.m-step {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
  white-space: nowrap;
  transition: color 0.15s;
}
.m-step i {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--line-2);
  font-style: normal; font-size: 0.7rem; font-weight: 800;
  flex: none;
}
.m-step.active { color: var(--accent); }
.m-step.active i {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #0b0e14;
}
.m-step.done { color: var(--ok); }
.m-step.done i { background: var(--ok); border-color: transparent; color: #0b0e14; }
.m-step-arrow { color: var(--line-2); font-size: 0.75rem; }
.modal-close {
  font: inherit; background: none; border: none; color: var(--muted);
  font-size: 1.05rem; cursor: pointer; padding: 4px 8px; border-radius: 8px;
  flex: none; margin-left: auto;
}
.modal-close:hover { color: var(--err); background: rgba(248, 113, 113, 0.12); }

.modal-body { padding: 18px 20px; overflow-y: auto; }
.m-field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.m-field-row .field label { font-size: 0.76rem; display: block; margin-bottom: 5px; color: var(--muted); font-weight: 600; }
.m-field-row .field input, .m-field-row .field select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}
.m-field-row .field input:focus, .m-field-row .field select:focus { outline: none; border-color: var(--accent); }

/* — Crop — */
.m-crop-wrap {
  background:
    repeating-conic-gradient(rgba(255, 255, 255, 0.035) 0% 25%, transparent 0% 50%) 0 0/22px 22px,
    #0a0d15;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  position: relative;
}
#m-crop-canvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; border-radius: 7px; }

.m-crop-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.m-crop-actions .btn { flex: none; }

/* — Couleurs repérées (étape 1) — */
.m-colors-box {
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.m-colors-title { margin: 0; font-size: 0.88rem; font-weight: 700; }
.m-color-names { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.m-color-row { display: flex; align-items: center; gap: 8px; }
.m-color-row .m-color-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: none;
}
.m-color-row .m-color-name {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 9px;
  font: inherit;
  font-size: 0.82rem;
}
.m-color-row .m-color-name:focus { outline: none; border-color: var(--accent); }
@media (max-width: 520px) { .m-color-names { grid-template-columns: 1fr; } }

/* — Finish — */
.m-finish { text-align: center; padding: 8px 4px; }
.m-finish-icon { font-size: 2.4rem; margin-bottom: 4px; }
.m-finish h3 { margin: 0 0 14px; font-size: 1.05rem; }
.m-recap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  text-align: left;
  margin-bottom: 14px;
}
.m-recap-item {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.m-recap-item .k { font-size: 0.7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.m-recap-item .v { font-size: 0.95rem; font-weight: 700; color: var(--accent); margin-top: 3px; }
.m-recap-item .v.plain { color: var(--text); font-weight: 500; }

.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}
.modal-spacer { flex: 1; }

@media (max-width: 640px) {
  .m-field-row { grid-template-columns: 1fr; }
  .modal-head h2 { flex-basis: 100%; }
  .modal-steps { justify-content: flex-start; }
  .modal-close { margin-left: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 320px 1fr; }
  #panel-right { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  #panel-right .card { flex: 1 1 280px; }
  .panel-left, .panel-right { max-height: none; }
  .viewport-wrap { position: static; }
  .viewport { height: 60vh; }
}
@media (max-width: 900px) {
  .topbar { flex-direction: column; text-align: center; }
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .viewport { height: 52vh; min-height: 320px; }
  .panel-left, .panel-right { overflow: visible; }
}
